removed unnecessary debug traces
This commit is contained in:
parent
758f49603f
commit
9ae9752634
@ -501,10 +501,9 @@ class Compiler {
|
|||||||
var closure: Context? = null
|
var closure: Context? = null
|
||||||
|
|
||||||
val fnBody = statement(t.pos) { callerContext ->
|
val fnBody = statement(t.pos) { callerContext ->
|
||||||
// remember closure where the function was defined:
|
// restore closure where the function was defined:
|
||||||
val context = closure ?: Context()
|
val context = closure ?: Context()
|
||||||
// load params from caller context
|
// load params from caller context
|
||||||
println("calling function $name in context $context <- ${context.parent}")
|
|
||||||
for ((i, d) in params.withIndex()) {
|
for ((i, d) in params.withIndex()) {
|
||||||
if (i < callerContext.args.size)
|
if (i < callerContext.args.size)
|
||||||
context.addItem(d.name, false, callerContext.args.list[i].value)
|
context.addItem(d.name, false, callerContext.args.list[i].value)
|
||||||
@ -523,9 +522,12 @@ class Compiler {
|
|||||||
fnStatements.execute(context)
|
fnStatements.execute(context)
|
||||||
}
|
}
|
||||||
return statement(start) { context ->
|
return statement(start) { context ->
|
||||||
println("adding function $name to context $context")
|
// we added fn in the context. now we must save closure
|
||||||
|
// for the function
|
||||||
closure = context
|
closure = context
|
||||||
context.addItem(name, false, fnBody)
|
context.addItem(name, false, fnBody)
|
||||||
|
// as the function can be called from anywhere, we have
|
||||||
|
// saved the proper context in the closure
|
||||||
fnBody
|
fnBody
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ class Context(
|
|||||||
fun copy(args: Arguments = Arguments.EMPTY): Context = Context(this, args)
|
fun copy(args: Arguments = Arguments.EMPTY): Context = Context(this, args)
|
||||||
|
|
||||||
fun addItem(name: String, isMutable: Boolean, value: Obj?) {
|
fun addItem(name: String, isMutable: Boolean, value: Obj?) {
|
||||||
println("ading item $name=$value in $this <- ${this.parent}")
|
|
||||||
objects.put(name, StoredObj(name, value, isMutable))
|
objects.put(name, StoredObj(name, value, isMutable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ class Script(
|
|||||||
) : Statement() {
|
) : Statement() {
|
||||||
|
|
||||||
override suspend fun execute(context: Context): Obj {
|
override suspend fun execute(context: Context): Obj {
|
||||||
// todo: run script
|
|
||||||
println("exec script in $context <- ${context.parent}")
|
|
||||||
var lastResult: Obj = ObjVoid
|
var lastResult: Obj = ObjVoid
|
||||||
for (s in statements) {
|
for (s in statements) {
|
||||||
lastResult = s.execute(context)
|
lastResult = s.execute(context)
|
||||||
|
@ -425,7 +425,6 @@ class ScriptTest {
|
|||||||
"""
|
"""
|
||||||
val count = 3
|
val count = 3
|
||||||
val res = if( count > 10 ) "too much" else "just " + count
|
val res = if( count > 10 ) "too much" else "just " + count
|
||||||
println(res)
|
|
||||||
res
|
res
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
@ -438,26 +437,10 @@ class ScriptTest {
|
|||||||
val count = 3
|
val count = 3
|
||||||
var res = if( count > 10 ) "too much" else "it's " + count
|
var res = if( count > 10 ) "too much" else "it's " + count
|
||||||
res = if( count > 10 ) "too much" else "just " + count
|
res = if( count > 10 ) "too much" else "just " + count
|
||||||
println(res)
|
|
||||||
res
|
res
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
.toString()
|
.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@Test
|
|
||||||
fun bookTest1() = runTest {
|
|
||||||
// assertEquals(
|
|
||||||
// "just 3",
|
|
||||||
eval(
|
|
||||||
"""
|
|
||||||
val count = 3
|
|
||||||
println(
|
|
||||||
if( count > 10 ) "too much" else "just " + count
|
|
||||||
)
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
// .toString()
|
|
||||||
// )
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user