less debug noise
open ObjDynamic found a pfoblem with dynamic, see todo in OOTest.kt
This commit is contained in:
		
							parent
							
								
									5d4d548275
								
							
						
					
					
						commit
						ba725fc9ed
					
				@ -47,10 +47,7 @@ class ObjDynamicContext(val delegate: ObjDynamic) : Obj() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ObjDynamic : Obj() {
 | 
			
		||||
 | 
			
		||||
    internal var readCallback: Statement? = null
 | 
			
		||||
    internal var writeCallback: Statement? = null
 | 
			
		||||
open class ObjDynamic(var readCallback: Statement? = null,var writeCallback: Statement? = null) : Obj() {
 | 
			
		||||
 | 
			
		||||
    override suspend fun readField(scope: Scope, name: String): ObjRecord {
 | 
			
		||||
        return readCallback?.execute(scope.createChildScope(Arguments(ObjString(name))))?.let {
 | 
			
		||||
 | 
			
		||||
@ -91,14 +91,15 @@ open class LynonDecoder(val bin: BitInput, val settings: LynonSettings = LynonSe
 | 
			
		||||
            val type = LynonType.entries[getBitsAsInt(4)]
 | 
			
		||||
            val list = mutableListOf<Obj>()
 | 
			
		||||
            val objClass = if (type == LynonType.Other)
 | 
			
		||||
                decodeClassObj(scope).also { println("detected class obj: $it") }
 | 
			
		||||
                decodeClassObj(scope)//.also { println("detected class obj: $it") }
 | 
			
		||||
            else type.objClass
 | 
			
		||||
            val size = fixedSize ?: bin.unpackUnsigned().toInt()
 | 
			
		||||
            println("detected homogenous list type $type, $size items")
 | 
			
		||||
//            println("detected homogenous list type $type, $size items")
 | 
			
		||||
            for (i in 0..<size) {
 | 
			
		||||
                list += decodeObject(scope, objClass, type).also {
 | 
			
		||||
                    println("decoded: $it")
 | 
			
		||||
                }
 | 
			
		||||
                list += decodeObject(scope, objClass, type)
 | 
			
		||||
                //.also {
 | 
			
		||||
//                    println("decoded: $it")
 | 
			
		||||
//                }
 | 
			
		||||
            }
 | 
			
		||||
            list
 | 
			
		||||
        } else {
 | 
			
		||||
 | 
			
		||||
@ -137,4 +137,53 @@ class OOTest {
 | 
			
		||||
            assertEquals(Point(1,2), Point(1,2) )
 | 
			
		||||
            """.trimIndent())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun testDynamicClass() = runTest {
 | 
			
		||||
        eval("""
 | 
			
		||||
            
 | 
			
		||||
            fun getContract(contractName) {
 | 
			
		||||
                dynamic {
 | 
			
		||||
                    get { name ->
 | 
			
		||||
                        println("Call: %s.%s"(contractName,name))
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            getContract("foo").bar
 | 
			
		||||
       """)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun testDynamicClassReturn2() = runTest {
 | 
			
		||||
        // todo: should work without extra parenthesis
 | 
			
		||||
        // see below
 | 
			
		||||
        eval("""
 | 
			
		||||
            
 | 
			
		||||
            fun getContract(contractName) {
 | 
			
		||||
                println("1")
 | 
			
		||||
                dynamic {
 | 
			
		||||
                    get { name ->
 | 
			
		||||
                        println("innrer %s.%s"(contractName,name))
 | 
			
		||||
                        { args... ->
 | 
			
		||||
                            if( name == "bar" ) args.sum() else null
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            val cc = dynamic {
 | 
			
		||||
                get { name ->
 | 
			
		||||
                    println("Call cc %s"(name))
 | 
			
		||||
                    getContract(name)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            val x = cc.foo.bar
 | 
			
		||||
            println(x)
 | 
			
		||||
            x(1,2,3)
 | 
			
		||||
            assertEquals(6, x(1,2,3))
 | 
			
		||||
            //               v  HERE    v
 | 
			
		||||
            assertEquals(15, (cc.foo.bar)(10,2,3))
 | 
			
		||||
       """)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user