From 529f76489bbee15f04700e3d3f80e583a8539fb2 Mon Sep 17 00:00:00 2001 From: sergeych Date: Thu, 19 Feb 2026 16:32:00 +0300 Subject: [PATCH] fixed bug in dynamic val/var compilation --- .../kotlin/net/sergeych/lyng/Compiler.kt | 6 +++--- .../kotlin/net/sergeych/lyng/FrameAccess.kt | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index d3b65f8..04de9dd 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -1182,10 +1182,10 @@ class Compiler( if (!record.visibility.isPublic) continue if (nameObjClass.containsKey(name)) continue val resolved = when (val raw = record.value) { - is FrameSlotRef -> raw.read() - is RecordSlotRef -> raw.read() + is FrameSlotRef -> raw.peekValue() + is RecordSlotRef -> raw.peekValue() else -> raw - } + } ?: continue when (resolved) { is ObjClass -> nameObjClass[name] = resolved is ObjInstance -> nameObjClass[name] = resolved.objClass diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/FrameAccess.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/FrameAccess.kt index 171fcf8..5be9a55 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/FrameAccess.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/FrameAccess.kt @@ -60,6 +60,17 @@ class FrameSlotRef( return this.frame === frame && this.slot == slot } + internal fun peekValue(): Obj? { + val bytecodeFrame = frame as? net.sergeych.lyng.bytecode.BytecodeFrame ?: return read() + val raw = bytecodeFrame.getRawObj(slot) ?: return null + if (raw is FrameSlotRef && raw.refersTo(bytecodeFrame, slot)) return null + return when (raw) { + is FrameSlotRef -> raw.peekValue() + is RecordSlotRef -> raw.peekValue() + else -> raw + } + } + fun write(value: Obj) { when (value) { is ObjInt -> frame.setInt(slot, value.value) @@ -87,6 +98,15 @@ class RecordSlotRef( return if (direct is FrameSlotRef) direct.read() else direct } + internal fun peekValue(): Obj? { + val direct = record.value + return when (direct) { + is FrameSlotRef -> direct.peekValue() + is RecordSlotRef -> direct.peekValue() + else -> direct + } + } + fun write(value: Obj) { record.value = value }