Step 20: bytecode NopStatement

This commit is contained in:
sergeych committed 2026-02-09 12:04:51 +03:00
1 parent ae88898f58
commit b49f291bff
5 files changed
+60

No files matched your search

@@ -1934,6 +1934,7 @@ class Compiler(
is ContinueStatement -> false
is ReturnStatement -> target.resultExpr?.let { containsUnsupportedForBytecode(it) } ?: false
is ThrowStatement -> containsUnsupportedForBytecode(target.throwExpr)
is NopStatement -> false
is ExtensionPropertyDeclStatement -> false
is ClassDeclStatement -> false
is FunctionDeclStatement -> false
@@ -202,6 +202,23 @@ class BytecodeCompiler(
localSlotMutables
)
}
is net.sergeych.lyng.NopStatement -> {
val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid))
val slot = allocSlot()
builder.emit(Opcode.CONST_OBJ, voidId, slot)
builder.emit(Opcode.RET, slot)
builder.build(
name,
localCount = maxOf(nextSlot, slot + 1) - scopeSlotCount,
addrCount = nextAddrSlot,
returnLabels = returnLabels,
scopeSlotIndices,
scopeSlotNames,
scopeSlotIsModule,
localSlotNames,
localSlotMutables
)
}
else -> null
}
}
@@ -3920,6 +3937,12 @@ class BytecodeCompiler(
private fun compileStatementValue(stmt: Statement): CompiledValue? {
return when (stmt) {
is ExpressionStatement -> compileRefWithFallback(stmt.ref, null, stmt.pos)
is net.sergeych.lyng.NopStatement -> {
val slot = allocSlot()
val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid))
builder.emit(Opcode.CONST_OBJ, voidId, slot)
CompiledValue(slot, SlotType.OBJ)
}
else -> null
}
}
@@ -3990,6 +4013,12 @@ class BytecodeCompiler(
is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
is net.sergeych.lyng.ThrowStatement -> compileThrow(target)
is net.sergeych.lyng.TryStatement -> emitTry(target, false)
is net.sergeych.lyng.NopStatement -> {
val slot = allocSlot()
val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid))
builder.emit(Opcode.CONST_OBJ, voidId, slot)
CompiledValue(slot, SlotType.OBJ)
}
else -> {
emitFallbackStatement(target)
}
@@ -4037,6 +4066,12 @@ class BytecodeCompiler(
is net.sergeych.lyng.ThrowStatement -> compileThrow(target)
is net.sergeych.lyng.TryStatement -> emitTry(target, false)
is net.sergeych.lyng.WhenStatement -> compileWhen(target, false)
is net.sergeych.lyng.NopStatement -> {
val slot = allocSlot()
val voidId = builder.addConst(BytecodeConst.ObjRef(ObjVoid))
builder.emit(Opcode.CONST_OBJ, voidId, slot)
CompiledValue(slot, SlotType.OBJ)
}
else -> {
emitFallbackStatement(target)
}
@@ -132,6 +132,7 @@ class BytecodeStatement private constructor(
target.resultExpr?.let { containsUnsupportedStatement(it) } ?: false
is net.sergeych.lyng.ThrowStatement ->
containsUnsupportedStatement(target.throwExpr)
is net.sergeych.lyng.NopStatement -> false
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> false
is net.sergeych.lyng.ClassDeclStatement -> false
is net.sergeych.lyng.FunctionDeclStatement -> false
@@ -209,6 +209,18 @@ class BytecodeRecentOpsTest {
)
}
@Test
fun staticMemberDeclNopStatement() = runTest {
eval(
"""
class C {
static fun ping() { 7 }
}
assertEquals(7, C.ping())
""".trimIndent()
)
}
@Test
fun objectReceiverMemberError() = runTest {
val failed = try {