less debug noise

This commit is contained in:
Sergey Chernov 2025-08-14 01:36:37 +03:00
parent f45310f7d9
commit 202e70a99a
6 changed files with 26 additions and 13 deletions

View File

@ -88,18 +88,15 @@ class ObjInstance(override val objClass: ObjClass) : Obj() {
val vars = instanceVars.values.map { it.value }
if( vars.isNotEmpty()) {
encoder.encodeAnyList(scope, vars)
println("serialized state vars $vars")
}
}
internal suspend fun deserializeStateVars(scope: Scope, decoder: LynonDecoder) {
val localVars = instanceVars.values.toList()
if( localVars.isNotEmpty() ) {
println("gonna read vars")
val vars = decoder.decodeAnyList(scope)
if (vars.size > instanceVars.size)
scope.raiseIllegalArgument("serialized vars has bigger size than instance vars")
println("deser state vars $vars")
for ((i, v) in vars.withIndex()) {
localVars[i].value = v
}

View File

@ -29,7 +29,6 @@ class ObjInstanceClass(val name: String) : ObjClass(name) {
override suspend fun deserialize(scope: Scope, decoder: LynonDecoder, lynonType: LynonType?): Obj {
val args = decoder.decodeAnyList(scope)
println("deserializing constructor $name, $args params")
val actualSize = constructorMeta?.params?.size ?: 0
if( args.size > actualSize )
scope.raiseIllegalArgument("constructor $name has only $actualSize but serialized version has ${args.size}")

View File

@ -59,6 +59,9 @@ val ObjIterable by lazy {
}
addFn("toSet") {
if( thisObj.isInstanceOf(ObjSet.type) )
thisObj
else {
val result = mutableSetOf<Obj>()
val it = thisObj.invokeInstanceMethod(this, "iterator")
while (it.invokeInstanceMethod(this, "hasNext").toBool()) {
@ -66,6 +69,7 @@ val ObjIterable by lazy {
}
ObjSet(result)
}
}
addFn("toMap") {
val result = ObjMap()

View File

@ -109,7 +109,7 @@ class ObjSet(val set: MutableSet<Obj> = mutableSetOf()) : Obj() {
companion object {
val type = object : ObjClass("Set", ObjCollection) {
val type: ObjClass = object : ObjClass("Set", ObjCollection) {
override suspend fun callOn(scope: Scope): Obj {
return ObjSet(scope.args.list.toMutableSet())
}

View File

@ -65,7 +65,6 @@ open class LynonDecoder(val bin: BitInput, val settings: LynonSettings = LynonSe
private suspend fun decodeClassObj(scope: Scope): ObjClass {
val className = decodeObject(scope, ObjString.type, null) as ObjString
println("expected class name $className")
return scope.get(className.value)?.value?.let {
if (it !is ObjClass)
scope.raiseClassCastError("Expected obj class but got ${it::class.simpleName}")

View File

@ -28,7 +28,7 @@ import net.sergeych.lyng.obj.ObjString
object ObjLynonClass : ObjClass("Lynon") {
suspend fun encodeAny(scope: Scope, obj: Obj): Obj {
suspend fun encodeAny(scope: Scope, obj: Obj): ObjBitBuffer {
val bout = MemoryBitOutput()
val serializer = LynonEncoder(bout)
serializer.encodeAny(scope, obj)
@ -52,3 +52,17 @@ object ObjLynonClass : ObjClass("Lynon") {
}
}
}
@Suppress("unused")
suspend fun lynonEncodeAny(scope: Scope, value: Obj): UByteArray =
(ObjLynonClass.encodeAny(scope, value))
.bitArray.asUbyteArray()
@Suppress("unused")
suspend fun lynonDecodeAny(scope: Scope, encoded: UByteArray): Obj =
ObjLynonClass.decodeAny(
scope,
ObjBitBuffer(
BitArray(encoded, 8)
)
)