Enable binding/miniast tests and support decl bytecode eval

This commit is contained in:
sergeych committed 2026-01-28 23:22:31 +03:00
1 parent 5d5453d994
commit 1eb8793e35
7 files changed
+22 -6

No files matched your search

@@ -2447,7 +2447,7 @@ class Compiler(
val initScope = popInitScope()
return object : Statement() {
val declStatement = object : Statement() {
override val pos: Pos = startPos
override suspend fun execute(scope: Scope): Obj {
val parentClasses = baseSpecs.map { baseSpec ->
@@ -2478,6 +2478,7 @@ class Compiler(
return instance
}
}
return ClassDeclStatement(declStatement, startPos)
}
private suspend fun parseClassDeclaration(isAbstract: Boolean = false, isExtern: Boolean = false): Statement {
@@ -1761,6 +1761,14 @@ class BytecodeCompiler(
)
}
private fun emitStatementEval(stmt: Statement): CompiledValue {
val constId = builder.addConst(BytecodeConst.StatementVal(stmt))
val slot = allocSlot()
builder.emit(Opcode.EVAL_STMT, constId, slot)
updateSlotType(slot, SlotType.OBJ)
return CompiledValue(slot, SlotType.OBJ)
}
private fun compileStatementValueOrFallback(stmt: Statement, needResult: Boolean = true): CompiledValue? {
val target = if (stmt is BytecodeStatement) stmt.original else stmt
return if (needResult) {
@@ -1791,6 +1799,9 @@ class BytecodeCompiler(
is BlockStatement -> emitBlock(target, true)
is VarDeclStatement -> emitVarDecl(target)
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> emitExtensionPropertyDecl(target)
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.BreakStatement -> compileBreak(target)
is net.sergeych.lyng.ContinueStatement -> compileContinue(target)
is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
@@ -45,8 +45,9 @@ class BytecodeStatement private constructor(
if (statement is BytecodeStatement) return statement
val hasUnsupported = containsUnsupportedStatement(statement)
if (hasUnsupported) {
val statementName = statement::class.qualifiedName ?: statement.javaClass.name
throw BytecodeFallbackException(
"Bytecode fallback: unsupported statement in '$nameHint'",
"Bytecode fallback: unsupported statement $statementName in '$nameHint'",
statement.pos
)
}
@@ -101,6 +102,9 @@ class BytecodeStatement private constructor(
is net.sergeych.lyng.ThrowStatement ->
containsUnsupportedStatement(target.throwExpr)
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> false
is net.sergeych.lyng.ClassDeclStatement -> false
is net.sergeych.lyng.FunctionDeclStatement -> false
is net.sergeych.lyng.EnumDeclStatement -> false
else -> true
}
}