From 026b023892c45ce3c7457f5177f0bccce1089e63 Mon Sep 17 00:00:00 2001 From: sergeych Date: Mon, 9 Feb 2026 01:40:31 +0300 Subject: [PATCH] Step 5: allow bytecode for delegated var decls --- bytecode_migration_plan.md | 7 ++++--- .../src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bytecode_migration_plan.md b/bytecode_migration_plan.md index 7502a7d..9524f3c 100644 --- a/bytecode_migration_plan.md +++ b/bytecode_migration_plan.md @@ -19,9 +19,10 @@ Goal: migrate the compiler so all values live in frames/bytecode, keeping JVM te - [x] Step 4: Allow bytecode wrapping for supported declaration statements. - [x] Enable `DestructuringVarDeclStatement` and `ExtensionPropertyDeclStatement` in `containsUnsupportedForBytecode`. - [x] Keep JVM tests green before commit. -- [ ] Step 5: Enable bytecode for delegated var declarations. - - [ ] Revisit `containsDelegatedRefs` guard for `DelegatedVarDeclStatement`. - - [ ] Ensure delegate binding uses explicit `Statement` objects (no inline suspend lambdas). +- [x] Step 5: Enable bytecode for delegated var declarations. + - [x] Revisit `containsDelegatedRefs` guard for `DelegatedVarDeclStatement`. + - [x] Ensure delegate binding uses explicit `Statement` objects (no inline suspend lambdas). + - [x] Keep JVM tests green before commit. - [ ] Step 6: Map literal spread in bytecode. - [ ] Replace `MapLiteralEntry.Spread` bytecode exception with runtime `putAll`/merge logic. - [ ] Step 7: Class-scope member refs in bytecode. diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index d6aa3db..9c8857a 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -1894,6 +1894,7 @@ class Compiler( is InlineBlockStatement -> target.statements().any { containsUnsupportedForBytecode(it) } is VarDeclStatement -> target.initializer?.let { containsUnsupportedForBytecode(it) } ?: false is DestructuringVarDeclStatement -> containsUnsupportedForBytecode(target.initializer) + is DelegatedVarDeclStatement -> containsUnsupportedForBytecode(target.initializer) is BreakStatement -> target.resultExpr?.let { containsUnsupportedForBytecode(it) } ?: false is ContinueStatement -> false is ReturnStatement -> target.resultExpr?.let { containsUnsupportedForBytecode(it) } ?: false @@ -1993,7 +1994,7 @@ class Compiler( is ExpressionStatement -> containsDelegatedRefs(target.ref) is BlockStatement -> target.statements().any { containsDelegatedRefs(it) } is VarDeclStatement -> target.initializer?.let { containsDelegatedRefs(it) } ?: false - is DelegatedVarDeclStatement -> true + is DelegatedVarDeclStatement -> containsDelegatedRefs(target.initializer) is DestructuringVarDeclStatement -> containsDelegatedRefs(target.initializer) is IfStatement -> { containsDelegatedRefs(target.condition) ||