mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add class function and remove debug prints
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:]
|
||||
|
||||
Reference in New Issue
Block a user