Compare commits
8 Commits
fix_decode
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d8fdce637 | |||
| 5a8881bfd5 | |||
| d487886c8f | |||
| 180471e4cd | |||
| 71a37a2906 | |||
| ab05f83e77 | |||
| a2d26fc777 | |||
| dd1a1544c6 |
@ -516,6 +516,23 @@ open class Scope(
|
|||||||
|
|
||||||
open fun applyClosure(closure: Scope): Scope = ClosureScope(this, closure)
|
open fun applyClosure(closure: Scope): Scope = ClosureScope(this, closure)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve and evaluate a qualified identifier exactly as compiled code would.
|
||||||
|
* For input like `A.B.C`, it builds the same ObjRef chain the compiler emits:
|
||||||
|
* `LocalVarRef("A", Pos.builtIn)` followed by `FieldRef` for each segment, then evaluates it.
|
||||||
|
* This mirrors `eval("A.B.C")` resolution semantics without invoking the compiler.
|
||||||
|
*/
|
||||||
|
suspend fun resolveQualifiedIdentifier(qualifiedName: String): Obj {
|
||||||
|
val trimmed = qualifiedName.trim()
|
||||||
|
if (trimmed.isEmpty()) raiseSymbolNotFound("empty identifier")
|
||||||
|
val parts = trimmed.split('.')
|
||||||
|
var ref: ObjRef = LocalVarRef(parts[0], Pos.builtIn)
|
||||||
|
for (i in 1 until parts.size) {
|
||||||
|
ref = FieldRef(ref, parts[i], false)
|
||||||
|
}
|
||||||
|
return ref.evalValue(this)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun new(): Scope =
|
fun new(): Scope =
|
||||||
|
|||||||
@ -83,15 +83,16 @@ open class LynonDecoder(val bin: BitInput, val settings: LynonSettings = LynonSe
|
|||||||
scope.raiseClassCastError("Expected obj class but got ${it::class.simpleName}")
|
scope.raiseClassCastError("Expected obj class but got ${it::class.simpleName}")
|
||||||
it
|
it
|
||||||
} ?: run {
|
} ?: run {
|
||||||
val fallback = runCatching { scope.eval(className.value) }.getOrNull()
|
// Use Scope API that mirrors compiler-emitted ObjRef chain for qualified identifiers
|
||||||
if (fallback != null) {
|
val evaluated = scope.resolveQualifiedIdentifier(className.value)
|
||||||
println("Fallback to eval successful")
|
if (evaluated !is ObjClass)
|
||||||
fallback as ObjClass
|
scope.raiseClassCastError("Expected obj class but got ${evaluated::class.simpleName}")
|
||||||
}
|
evaluated
|
||||||
else scope.raiseSymbolNotFound("can't deserialize: not found type $className")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper moved to Scope as resolveQualifiedIdentifier
|
||||||
|
|
||||||
suspend fun decodeAnyList(scope: Scope, fixedSize: Int? = null): MutableList<Obj> {
|
suspend fun decodeAnyList(scope: Scope, fixedSize: Int? = null): MutableList<Obj> {
|
||||||
return if (bin.getBit() == 1) {
|
return if (bin.getBit() == 1) {
|
||||||
// homogenous
|
// homogenous
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user