about to start implimentation of if statments, and add not

This commit is contained in:
2023-03-11 15:26:25 +00:00
parent 3a449dec63
commit 27a1abe160
8 changed files with 65 additions and 19 deletions

View File

@@ -4,16 +4,14 @@ import "strings"
var returnCompile = makeRegex(`( *)return( +)(.|\n)+`)
type CallJumpStatment struct {
TYPE string
type CallReturn struct {
value any
line int
code string
path string
}
type PassBackJumpStatment struct {
TYPE string
type Return struct {
value any
line int
code string
@@ -24,15 +22,14 @@ func isReturn(code UNPARSEcode) bool {
return returnCompile.MatchString(code.code)
}
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallJumpStatment, bool, ArErr, int) {
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallReturn, bool, ArErr, int) {
resp, worked, err, i := translateVal(UNPARSEcode{
code: strings.TrimSpace(code.code)[6:],
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codeline, 1)
return CallJumpStatment{
TYPE: "return",
return CallReturn{
value: resp,
line: code.line,
code: code.realcode,
@@ -40,7 +37,7 @@ func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallJumpS
}, worked, err, i
}
func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, ArErr) {
func runReturn(code CallReturn, stack stack, stacklevel int) (any, ArErr) {
var val any
if code.value != nil {
v, err := runVal(code.value, stack, stacklevel+1)
@@ -49,8 +46,7 @@ func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, A
}
val = v
}
return PassBackJumpStatment{
TYPE: code.TYPE,
return Return{
value: val,
line: code.line,
code: code.code,
@@ -60,7 +56,7 @@ func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, A
func openJump(resp any) any {
switch x := resp.(type) {
case PassBackJumpStatment:
case Return:
return x.value
default:
return resp