mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56: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" {
|
if x.TYPE == "array" {
|
||||||
newmap := anymap{}
|
newmap := anymap{}
|
||||||
for i, v := range x.obj["__value__"].([]any) {
|
for i, v := range x.obj["__value__"].([]any) {
|
||||||
|
v := ArValidToAny(v)
|
||||||
switch y := v.(type) {
|
switch y := v.(type) {
|
||||||
case []any:
|
case []any:
|
||||||
if len(y) == 2 {
|
if len(y) == 2 {
|
||||||
if isUnhashable(y[0]) {
|
if isUnhashable(y[0]) {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true}
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,5 +163,22 @@ func makeGlobal() ArObject {
|
|||||||
return ArArray([]any{}), ArErr{}
|
return ArArray([]any{}), ArErr{}
|
||||||
}}
|
}}
|
||||||
vars.obj["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
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
|
return vars
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,14 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(args[0]) != "array" {
|
} else if typeof(args[0]) != "array" {
|
||||||
fmt.Println(args[0])
|
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "TypeError",
|
||||||
message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])),
|
message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if len(args[0].([]any)) == 0 {
|
}
|
||||||
|
args[0] = ArValidToAny(args[0])
|
||||||
|
if len(args[0].([]any)) == 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "RuntimeError",
|
TYPE: "RuntimeError",
|
||||||
message: "subprocess() argument must be an array of strings, not an empty array",
|
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
|
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) {
|
if isNumber(code) {
|
||||||
return parseNumber(code)
|
return parseNumber(code)
|
||||||
} else if isString(code) {
|
} else if isString(code) {
|
||||||
@@ -104,6 +98,12 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
return resp, worked, err, 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)
|
operation, worked, err, step := parseOperations(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCat
|
|||||||
totalIndex += i
|
totalIndex += i
|
||||||
catchtrimmed := strings.TrimSpace(codelines[index+totalIndex].code)
|
catchtrimmed := strings.TrimSpace(codelines[index+totalIndex].code)
|
||||||
if !catchCompiled.MatchString(catchtrimmed) {
|
if !catchCompiled.MatchString(catchtrimmed) {
|
||||||
fmt.Println(catchtrimmed)
|
|
||||||
return TryCatch{}, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, i
|
return TryCatch{}, false, ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}, i
|
||||||
}
|
}
|
||||||
catchtrimmed = catchtrimmed[6:]
|
catchtrimmed = catchtrimmed[6:]
|
||||||
|
|||||||
Reference in New Issue
Block a user