less debug noise
This commit is contained in:
parent
f45310f7d9
commit
202e70a99a
@ -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
|
||||
}
|
||||
|
@ -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}")
|
||||
|
@ -59,12 +59,16 @@ val ObjIterable by lazy {
|
||||
}
|
||||
|
||||
addFn("toSet") {
|
||||
val result = mutableSetOf<Obj>()
|
||||
val it = thisObj.invokeInstanceMethod(this, "iterator")
|
||||
while (it.invokeInstanceMethod(this, "hasNext").toBool()) {
|
||||
result += it.invokeInstanceMethod(this, "next")
|
||||
if( thisObj.isInstanceOf(ObjSet.type) )
|
||||
thisObj
|
||||
else {
|
||||
val result = mutableSetOf<Obj>()
|
||||
val it = thisObj.invokeInstanceMethod(this, "iterator")
|
||||
while (it.invokeInstanceMethod(this, "hasNext").toBool()) {
|
||||
result += it.invokeInstanceMethod(this, "next")
|
||||
}
|
||||
ObjSet(result)
|
||||
}
|
||||
ObjSet(result)
|
||||
}
|
||||
|
||||
addFn("toMap") {
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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}")
|
||||
|
@ -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)
|
||||
@ -51,4 +51,18 @@ object ObjLynonClass : ObjClass("Lynon") {
|
||||
decodeAny(this, requireOnlyArg<Obj>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user