From f5d8eb6d70f508beb37966585914538d8ce31a7a Mon Sep 17 00:00:00 2001 From: William Bell Date: Sat, 11 Mar 2023 02:06:36 +0000 Subject: [PATCH] fix do wrap bugs --- src/call.go | 6 +----- src/dowraps.go | 2 +- src/jumpStatments.go | 11 ++++++++++- src/variable.go | 6 +----- test.ar | 9 +++++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/call.go b/src/call.go index 1fea684..940f190 100644 --- a/src/call.go +++ b/src/call.go @@ -94,11 +94,7 @@ func runCall(c call, stack stack) (any, ArErr) { level[param] = args[i] } resp, err := runVal(x.run, append(x.stack, level)) - switch x := resp.(type) { - case PassBackJumpStatment: - resp = x.value - } - return resp, err + return openJump(resp), err } return nil, ArErr{"Runtime Error", "type '" + typeof(callable) + "' is not callable", c.line, c.path, c.code, true} } diff --git a/src/dowraps.go b/src/dowraps.go index 907b140..bc1fd81 100644 --- a/src/dowraps.go +++ b/src/dowraps.go @@ -18,7 +18,7 @@ func isDoWrap(code UNPARSEcode) bool { } func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool, ArErr, int) { - currentindent := len(code.code) - len(strings.TrimLeft(code.code, " ")) + currentindent := len(code.realcode) - len(strings.TrimLeft(code.realcode, " ")) var setindent int = -1 var i = index + 1 translated := []any{} diff --git a/src/jumpStatments.go b/src/jumpStatments.go index 6467ffa..27689d8 100644 --- a/src/jumpStatments.go +++ b/src/jumpStatments.go @@ -30,7 +30,7 @@ func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallJumpS realcode: code.realcode, line: code.line, path: code.path, - }, index, codeline, 0) + }, index, codeline, 1) return CallJumpStatment{ TYPE: "return", value: resp, @@ -57,3 +57,12 @@ func runJumpStatment(code CallJumpStatment, stack stack) (any, ArErr) { path: code.path, }, ArErr{} } + +func openJump(resp any) any { + switch x := resp.(type) { + case PassBackJumpStatment: + return x.value + default: + return resp + } +} diff --git a/src/variable.go b/src/variable.go index 07d6c74..182168e 100644 --- a/src/variable.go +++ b/src/variable.go @@ -193,11 +193,7 @@ func setVariableValue(v setVariable, stack stack) (any, ArErr) { if err.EXISTS { return nil, err } - switch x := respp.(type) { - case PassBackJumpStatment: - respp = x.value - } - resp = respp + resp = openJump(respp) } if v.TYPE == "let" { diff --git a/test.ar b/test.ar index d3de4c9..276da58 100644 --- a/test.ar +++ b/test.ar @@ -1,5 +1,6 @@ f(x) = do - x = x + 1 - x = x + 1 - return x -term.log(f(1)) \ No newline at end of file + y = number(input("what number? ")) + return (z) = do + return maths.round(z) * y * x + +term.log(f(5)(70)) \ No newline at end of file