fixed bug in dynamic val/var compilation

This commit is contained in:
Sergey Chernov 2026-02-19 16:32:00 +03:00
parent 6bf99d354b
commit 529f76489b
2 changed files with 23 additions and 3 deletions

View File

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

View File

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