Enable stdlib/lynon tests and add try wrapper
This commit is contained in:
1 parent
f788f79d4b
commit
c7e2455340
7 files changed
+63
-22
No files matched your search
@@ -2247,7 +2247,7 @@ class Compiler(
|
||||
throw ScriptError(cc.currentPos(), "try block must have either catch or finally clause or both")
|
||||
|
||||
val stmtPos = body.pos
|
||||
return object : Statement() {
|
||||
val tryStatement = object : Statement() {
|
||||
override val pos: Pos = stmtPos
|
||||
override suspend fun execute(scope: Scope): Obj {
|
||||
var result: Obj = ObjVoid
|
||||
@@ -2296,6 +2296,7 @@ class Compiler(
|
||||
return result
|
||||
}
|
||||
}
|
||||
return TryStatement(tryStatement, stmtPos)
|
||||
}
|
||||
|
||||
private fun parseEnumDeclaration(isExtern: Boolean = false): Statement {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2026 Sergey S. Chernov
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.sergeych.lyng
|
||||
|
||||
import net.sergeych.lyng.obj.Obj
|
||||
|
||||
class TryStatement(
|
||||
private val delegate: Statement,
|
||||
private val startPos: Pos,
|
||||
) : Statement() {
|
||||
override val pos: Pos = startPos
|
||||
|
||||
override suspend fun execute(scope: Scope): Obj {
|
||||
return delegate.execute(scope)
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,23 @@ class BytecodeCompiler(
|
||||
is VarDeclStatement -> compileVarDecl(name, stmt)
|
||||
is net.sergeych.lyng.ThrowStatement -> compileThrowStatement(name, stmt)
|
||||
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> compileExtensionPropertyDecl(name, stmt)
|
||||
is net.sergeych.lyng.TryStatement -> {
|
||||
val value = emitStatementEval(stmt)
|
||||
builder.emit(Opcode.RET, value.slot)
|
||||
val localCount = maxOf(nextSlot, value.slot + 1) - scopeSlotCount
|
||||
builder.build(
|
||||
name,
|
||||
localCount,
|
||||
addrCount = nextAddrSlot,
|
||||
returnLabels = returnLabels,
|
||||
scopeSlotDepths,
|
||||
scopeSlotIndices,
|
||||
scopeSlotNames,
|
||||
localSlotNames,
|
||||
localSlotMutables,
|
||||
localSlotDepths
|
||||
)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -297,12 +314,7 @@ class BytecodeCompiler(
|
||||
builder.emit(Opcode.NEG_REAL, a.slot, out)
|
||||
CompiledValue(out, SlotType.REAL)
|
||||
}
|
||||
else -> {
|
||||
val obj = ensureObjSlot(a)
|
||||
val methodId = builder.addConst(BytecodeConst.StringVal("negate"))
|
||||
builder.emit(Opcode.CALL_VIRTUAL, obj.slot, methodId, 0, 0, out)
|
||||
CompiledValue(out, SlotType.OBJ)
|
||||
}
|
||||
else -> compileEvalRef(ref)
|
||||
}
|
||||
UnaryOp.NOT -> {
|
||||
when (a.type) {
|
||||
@@ -312,13 +324,7 @@ class BytecodeCompiler(
|
||||
builder.emit(Opcode.INT_TO_BOOL, a.slot, tmp)
|
||||
builder.emit(Opcode.NOT_BOOL, tmp, out)
|
||||
}
|
||||
SlotType.OBJ, SlotType.UNKNOWN -> {
|
||||
val obj = ensureObjSlot(a)
|
||||
val methodId = builder.addConst(BytecodeConst.StringVal("logicalNot"))
|
||||
val tmpObj = allocSlot()
|
||||
builder.emit(Opcode.CALL_VIRTUAL, obj.slot, methodId, 0, 0, tmpObj)
|
||||
builder.emit(Opcode.OBJ_TO_BOOL, tmpObj, out)
|
||||
}
|
||||
SlotType.OBJ, SlotType.UNKNOWN -> return compileEvalRef(ref)
|
||||
else -> return null
|
||||
}
|
||||
CompiledValue(out, SlotType.BOOL)
|
||||
@@ -328,10 +334,7 @@ class BytecodeCompiler(
|
||||
builder.emit(Opcode.INV_INT, a.slot, out)
|
||||
return CompiledValue(out, SlotType.INT)
|
||||
}
|
||||
val obj = ensureObjSlot(a)
|
||||
val methodId = builder.addConst(BytecodeConst.StringVal("bitNot"))
|
||||
builder.emit(Opcode.CALL_VIRTUAL, obj.slot, methodId, 0, 0, out)
|
||||
CompiledValue(out, SlotType.OBJ)
|
||||
return compileEvalRef(ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1825,6 +1828,7 @@ class BytecodeCompiler(
|
||||
is net.sergeych.lyng.ClassDeclStatement -> emitStatementEval(target)
|
||||
is net.sergeych.lyng.FunctionDeclStatement -> emitStatementEval(target)
|
||||
is net.sergeych.lyng.EnumDeclStatement -> emitStatementEval(target)
|
||||
is net.sergeych.lyng.TryStatement -> emitStatementEval(target)
|
||||
is net.sergeych.lyng.BreakStatement -> compileBreak(target)
|
||||
is net.sergeych.lyng.ContinueStatement -> compileContinue(target)
|
||||
is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
|
||||
|
||||
@@ -105,6 +105,7 @@ class BytecodeStatement private constructor(
|
||||
is net.sergeych.lyng.ClassDeclStatement -> false
|
||||
is net.sergeych.lyng.FunctionDeclStatement -> false
|
||||
is net.sergeych.lyng.EnumDeclStatement -> false
|
||||
is net.sergeych.lyng.TryStatement -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user