diff --git a/src/built-ins.go b/src/built-ins.go index 5962964..eae2367 100644 --- a/src/built-ins.go +++ b/src/built-ins.go @@ -16,13 +16,15 @@ func makeGlobal() ArObject { if x.TYPE == "array" { newmap := anymap{} for i, v := range x.obj["__value__"].([]any) { + v := ArValidToAny(v) switch y := v.(type) { case []any: if len(y) == 2 { if isUnhashable(y[0]) { return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true} } - newmap[y[0]] = y[1] + key := ArValidToAny(y[0]) + newmap[key] = y[1] continue } } @@ -161,5 +163,22 @@ func makeGlobal() ArObject { return ArArray([]any{}), ArErr{} }} vars.obj["subprocess"] = builtinFunc{"subprocess", ArSubprocess} + vars.obj["class"] = builtinFunc{"class", func(a ...any) (any, ArErr) { + if len(a) == 0 { + return nil, ArErr{TYPE: "TypeError", message: "Cannot create class from '" + typeof(a[0]) + "'", EXISTS: true} + } + switch x := a[0].(type) { + case ArObject: + if x.TYPE == "class" { + return x, ArErr{} + } + newclass := ArObject{TYPE: "class", obj: anymap{}} + for key, val := range x.obj { + newclass.obj[key] = val + } + return newclass, ArErr{} + } + return nil, ArErr{TYPE: "TypeError", message: "Cannot create class from '" + typeof(a[0]) + "'", EXISTS: true} + }} return vars } diff --git a/src/subprocess.go b/src/subprocess.go index c8573ff..ad1215a 100644 --- a/src/subprocess.go +++ b/src/subprocess.go @@ -14,13 +14,14 @@ func ArSubprocess(args ...any) (any, ArErr) { EXISTS: true, } } else if typeof(args[0]) != "array" { - fmt.Println(args[0]) return nil, ArErr{ TYPE: "TypeError", message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])), EXISTS: true, } - } else if len(args[0].([]any)) == 0 { + } + args[0] = ArValidToAny(args[0]) + if len(args[0].([]any)) == 0 { return nil, ArErr{ TYPE: "RuntimeError", message: "subprocess() argument must be an array of strings, not an empty array", diff --git a/src/translate.go b/src/translate.go index be99262..76efead 100644 --- a/src/translate.go +++ b/src/translate.go @@ -80,12 +80,6 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i return resp, worked, err, i } } - if isAutoAsignVariable(code) { - resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine) - if worked { - return resp, worked, err, i - } - } if isNumber(code) { return parseNumber(code) } else if isString(code) { @@ -104,6 +98,12 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i return resp, worked, err, i } } + if isAutoAsignVariable(code) { + resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine) + if worked { + return resp, worked, err, i + } + } { operation, worked, err, step := parseOperations(code, index, codelines) if worked { diff --git a/src/trycatch.go b/src/trycatch.go index bd4a9db..0866139 100644 --- a/src/trycatch.go +++ b/src/trycatch.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "strings" ) @@ -31,7 +30,6 @@ func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCat totalIndex += i catchtrimmed := strings.TrimSpace(codelines[index+totalIndex].code) if !catchCompiled.MatchString(catchtrimmed) { - fmt.Println(catchtrimmed) return TryCatch{}, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, i } catchtrimmed = catchtrimmed[6:]