From 6c50043a4a36c16a30ae09381fed7d63e473786b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 28 Jun 2019 02:57:13 +0200 Subject: [PATCH] swap isn't yet finished --- compiler/src/prog8/astvm/AstVm.kt | 13 ++++++++++--- examples/test.p8 | 23 +++++++++-------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/compiler/src/prog8/astvm/AstVm.kt b/compiler/src/prog8/astvm/AstVm.kt index c2088bb18..c00566087 100644 --- a/compiler/src/prog8/astvm/AstVm.kt +++ b/compiler/src/prog8/astvm/AstVm.kt @@ -272,9 +272,7 @@ class AstVm(val program: Program) { is BuiltinFunctionStatementPlaceholder -> { if(target.name=="swap") { // swap cannot be implemented as a function, so inline it here - val a1 = (stmt.arglist[0] as IdentifierReference).targetVarDecl(program.namespace)!! - val a2 = (stmt.arglist[1] as IdentifierReference).targetVarDecl(program.namespace)!! - runtimeVariables.swap(a1, a2) + executeSwap(sub, stmt) } else { val args = evaluate(stmt.arglist) functions.performBuiltinFunction(target.name, args, statusflags) @@ -396,6 +394,15 @@ class AstVm(val program: Program) { } } + private fun executeSwap(sub: INameScope, swap: FunctionCallStatement) { + // TODO: can swap many different parameters.... in all combinations... + println("TODO SWAP ${swap.arglist}") +// val a1 = (swap.arglist[0] as IdentifierReference).targetVarDecl(program.namespace)!! +// val a2 = (swap.arglist[1] as IdentifierReference).targetVarDecl(program.namespace)!! +// runtimeVariables.swap(a1, a2) +// TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + fun performAssignment(target: AssignTarget, value: RuntimeValue, contextStmt: IStatement, evalCtx: EvalContext) { when { target.identifier != null -> { diff --git a/examples/test.p8 b/examples/test.p8 index d96456bbf..ec368763b 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -9,19 +9,14 @@ ubyte[100] arr1 ubyte[100] arr2 - _lp: - memcopy(arr1, arr2, len(arr2)) - c64scr.setcc(20,10,65,2) - goto x - c64scr.setcc(20,10,65,2) + word w1 = 1111 + word w2 = 2222 + + swap(w1, w2) + swap(A, Y) + swap(arr1[10], arr2[20]) + swap(arr1[10], Y) + swap(Y, arr2[10]) + swap(@($d020), @($d021)) } - - sub x() { - -derp: - c64scr.print("ey\n") - goto derp - - } - }