From 58581d6bf004210183a6c0e955cdbcc1e3dadca2 Mon Sep 17 00:00:00 2001 From: sergeych Date: Mon, 9 Feb 2026 02:09:29 +0300 Subject: [PATCH] Step 9: module-level bytecode execution --- bytecode_migration_plan.md | 6 ++--- .../kotlin/net/sergeych/lyng/Compiler.kt | 27 +++++++++---------- .../kotlin/net/sergeych/lyng/Script.kt | 7 +++++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bytecode_migration_plan.md b/bytecode_migration_plan.md index e3ba613..8c470c8 100644 --- a/bytecode_migration_plan.md +++ b/bytecode_migration_plan.md @@ -29,9 +29,9 @@ Goal: migrate the compiler so all values live in frames/bytecode, keeping JVM te - [x] Support `ClassScopeMemberRef` without scope-map fallback. - [x] Step 8: ObjDynamic member access in bytecode. - [x] Allow dynamic receiver field/method lookup without falling back to interpreter. -- [ ] Step 9: Module-level bytecode execution. - - [ ] Compile `Script` bodies to bytecode instead of interpreting at module scope. - - [ ] Keep import/module slot seeding in frame-only flow. +- [x] Step 9: Module-level bytecode execution. + - [x] Compile `Script` bodies to bytecode instead of interpreting at module scope. + - [x] Keep import/module slot seeding in frame-only flow. ## Notes diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index e771dff..e0b155b 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -1526,25 +1526,24 @@ class Compiler( resolutionScriptDepth == 1 && statements.none { containsUnsupportedForBytecode(it) } && statements.none { containsDelegatedRefs(it) } - val finalStatements = if (wrapScriptBytecode) { + val (finalStatements, moduleBytecode) = if (wrapScriptBytecode) { val unwrapped = statements.map { unwrapBytecodeDeep(it) } val block = InlineBlockStatement(unwrapped, start) - listOf( - BytecodeStatement.wrap( - block, - "