Enable binding/miniast tests and support decl bytecode eval

This commit is contained in:
Sergey Chernov 2026-01-28 23:22:31 +03:00
parent 5d5453d994
commit 1eb8793e35
7 changed files with 22 additions and 6 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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
}
}

View File

@ -27,7 +27,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@Ignore("TODO(bytecode-only): uses fallback")
class BindingHighlightTest {
private suspend fun compileWithMini(code: String): Pair<Script, MiniAstBuilder> {

View File

@ -29,7 +29,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@Ignore("TODO(bytecode-only): uses fallback")
class BindingTest {
private suspend fun bind(code: String): net.sergeych.lyng.binding.BindingSnapshot {

View File

@ -29,7 +29,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@Ignore("TODO(bytecode-only): uses fallback")
class MiniAstTest {
private suspend fun compileWithMini(code: String): Pair<Script, net.sergeych.lyng.miniast.MiniAstBuilder> {
@ -278,6 +277,7 @@ class MiniAstTest {
assertEquals("Doc6", e1.doc?.summary)
}
@Ignore("TODO(bytecode-only): uses fallback")
@Test
fun resolve_inferred_member_type() = runTest {
val code = """
@ -292,6 +292,7 @@ class MiniAstTest {
assertEquals("String", DocLookupUtils.simpleClassNameOf(type))
}
@Ignore("TODO(bytecode-only): uses fallback")
@Test
fun resolve_inferred_val_type_from_extern_fun() = runTest {
val code = """
@ -379,6 +380,7 @@ class MiniAstTest {
assertTrue(test.isExtern, "function 'test' should be extern")
}
@Ignore("TODO(bytecode-only): uses fallback")
@Test
fun resolve_object_member_doc() = runTest {
val code = """
@ -398,6 +400,7 @@ class MiniAstTest {
assertEquals("O3", resolved.first)
assertEquals("doc for name", resolved.second.doc?.summary)
}
@Ignore("TODO(bytecode-only): uses fallback")
@Test
fun miniAst_captures_nested_generics() = runTest {
val code = """

View File

@ -24,7 +24,6 @@ import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
@Ignore("TODO(bytecode-only): uses fallback")
class ParamTypeInferenceTest {
@Test