mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
fix parsing taking really long
This commit is contained in:
@@ -559,8 +559,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
for i, v := range arr {
|
for i, v := range arr {
|
||||||
res, err := runOperation(operationType{
|
res, err := runOperation(operationType{
|
||||||
operation: 8,
|
operation: 8,
|
||||||
value1: v,
|
values: []any{v, args[0].(ArObject).obj["__value__"].([]any)[i]},
|
||||||
value2: args[0].(ArObject).obj["__value__"].([]any)[i],
|
|
||||||
}, stack{}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -584,8 +583,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
res, err := runOperation(operationType{
|
res, err := runOperation(operationType{
|
||||||
operation: 9,
|
operation: 9,
|
||||||
value1: v,
|
values: []any{v, args[0]},
|
||||||
value2: args[0],
|
|
||||||
}, stack{}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -610,8 +608,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
res, err := runOperation(operationType{
|
res, err := runOperation(operationType{
|
||||||
operation: 9,
|
operation: 9,
|
||||||
value1: v,
|
values: []any{v, args[0]},
|
||||||
value2: args[0],
|
|
||||||
}, stack{}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -342,5 +342,16 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return ArString(typeof(a[0])), ArErr{}
|
return ArString(typeof(a[0])), ArErr{}
|
||||||
}}
|
}}
|
||||||
|
vars["sha256"] = builtinFunc{"sha256", func(a ...any) (any, ArErr) {
|
||||||
|
if len(a) != 1 {
|
||||||
|
return nil, ArErr{TYPE: "sha256", message: "sha256 takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
|
}
|
||||||
|
a[0] = ArValidToAny(a[0])
|
||||||
|
switch x := a[0].(type) {
|
||||||
|
case string:
|
||||||
|
return ArString(sha256Hash(x)), ArErr{}
|
||||||
|
}
|
||||||
|
return nil, ArErr{TYPE: "TypeError", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
|
}}
|
||||||
return Map(vars)
|
return Map(vars)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst
|
|||||||
},
|
},
|
||||||
i,
|
i,
|
||||||
codeline,
|
codeline,
|
||||||
0,
|
0)
|
||||||
)
|
|
||||||
if err.EXISTS || !worked {
|
if err.EXISTS || !worked {
|
||||||
if j == 1 {
|
if j == 1 {
|
||||||
return ifstatement{}, worked, err, step
|
return ifstatement{}, worked, err, step
|
||||||
|
|||||||
@@ -285,8 +285,7 @@ func Map(m anymap) ArObject {
|
|||||||
}
|
}
|
||||||
val, err := runOperation(operationType{
|
val, err := runOperation(operationType{
|
||||||
operation: 9,
|
operation: 9,
|
||||||
value1: v,
|
values: []any{v, a[k]},
|
||||||
value2: a[k],
|
|
||||||
}, stack{}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return val, err
|
return val, err
|
||||||
|
|||||||
@@ -7,52 +7,31 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var operations = [][]string{
|
var operations = []string{
|
||||||
{
|
|
||||||
"&&",
|
"&&",
|
||||||
" and ",
|
|
||||||
}, {
|
|
||||||
"||",
|
"||",
|
||||||
" or ",
|
|
||||||
}, {
|
|
||||||
" not in ",
|
" not in ",
|
||||||
}, {
|
|
||||||
" in ",
|
" in ",
|
||||||
}, {
|
|
||||||
"<=",
|
"<=",
|
||||||
}, {
|
|
||||||
">=",
|
">=",
|
||||||
}, {
|
|
||||||
"<",
|
"<",
|
||||||
}, {
|
|
||||||
">",
|
">",
|
||||||
}, {
|
|
||||||
"!=",
|
"!=",
|
||||||
}, {
|
|
||||||
"==",
|
"==",
|
||||||
}, {
|
|
||||||
"+",
|
"+",
|
||||||
}, {
|
|
||||||
"-",
|
"-",
|
||||||
}, {
|
|
||||||
"*",
|
"*",
|
||||||
}, {
|
|
||||||
"%",
|
"%",
|
||||||
}, {
|
|
||||||
"//",
|
"//",
|
||||||
}, {
|
|
||||||
"/",
|
"/",
|
||||||
}, {
|
|
||||||
"^",
|
"^",
|
||||||
"**",
|
}
|
||||||
}}
|
|
||||||
|
|
||||||
var one = newNumber().SetInt64(1)
|
var one = newNumber().SetInt64(1)
|
||||||
|
|
||||||
type operationType struct {
|
type operationType struct {
|
||||||
operation int
|
operation int
|
||||||
value1 any
|
values []any
|
||||||
value2 any
|
|
||||||
line int
|
line int
|
||||||
code string
|
code string
|
||||||
path string
|
path string
|
||||||
@@ -60,66 +39,70 @@ type operationType struct {
|
|||||||
|
|
||||||
func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (operationType, bool, ArErr, int) {
|
func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (operationType, bool, ArErr, int) {
|
||||||
for i := 0; i < len(operations); i++ {
|
for i := 0; i < len(operations); i++ {
|
||||||
for j := 0; j < len(operations[i]); j++ {
|
split := strings.Split(code.code, operations[i])
|
||||||
split := strings.Split(code.code, operations[i][j])
|
if len(split) < 2 {
|
||||||
if len(split) <= 1 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for k := 0; k < len(split)-1; k++ {
|
var values []any
|
||||||
if (len(strings.TrimSpace(split[k])) == 0 || len(strings.TrimSpace(split[k+1])) == 0) && operations[i][j] != "-" {
|
lookingAt := 0
|
||||||
break
|
totalStep := 1
|
||||||
|
for j := 1; j < len(split); j++ {
|
||||||
|
if split[j-1] == "" {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
val1, worked, err, step1 := translateVal(UNPARSEcode{
|
joined := strings.Join(split[lookingAt:j], operations[i])
|
||||||
code: strings.Join(split[:k+1], operations[i][j]),
|
resp, success, err, respindex := translateVal(
|
||||||
|
UNPARSEcode{
|
||||||
|
code: joined,
|
||||||
realcode: code.realcode,
|
realcode: code.realcode,
|
||||||
line: code.line,
|
line: code.line,
|
||||||
path: code.path,
|
path: code.path,
|
||||||
}, index, codelines, 0)
|
}, index, codelines, 0)
|
||||||
if !worked || err.EXISTS {
|
if !success || err.EXISTS {
|
||||||
if k == len(split)-1 {
|
|
||||||
return operationType{}, false, err, 0
|
|
||||||
} else {
|
|
||||||
if len(strings.TrimSpace(split[k])) == 0 || len(strings.TrimSpace(split[k+1])) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
values = append(values, resp)
|
||||||
|
totalStep += respindex - 1
|
||||||
|
lookingAt = j
|
||||||
}
|
}
|
||||||
|
if len(values) > 0 {
|
||||||
val2, worked, err, step2 := translateVal(UNPARSEcode{
|
resp, success, err, respindex := translateVal(
|
||||||
code: strings.Join(split[k+1:], operations[i][j]),
|
UNPARSEcode{
|
||||||
|
code: strings.Join(split[lookingAt:], operations[i]),
|
||||||
realcode: code.realcode,
|
realcode: code.realcode,
|
||||||
line: code.line,
|
line: code.line,
|
||||||
path: code.path,
|
path: code.path,
|
||||||
}, index, codelines, 0)
|
}, index, codelines, 0)
|
||||||
if !worked || err.EXISTS {
|
if !success || err.EXISTS {
|
||||||
if k == len(split)-1 {
|
return operationType{}, success, err, 0
|
||||||
return operationType{}, false, err, 0
|
|
||||||
} else {
|
|
||||||
if len(strings.TrimSpace(split[k])) == 0 || len(strings.TrimSpace(split[k+1])) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
values = append(values, resp)
|
||||||
|
totalStep += respindex - 1
|
||||||
return operationType{
|
return operationType{
|
||||||
i,
|
operation: i,
|
||||||
val1,
|
values: values,
|
||||||
val2,
|
line: code.line,
|
||||||
code.line,
|
code: code.code,
|
||||||
code.code,
|
path: code.path,
|
||||||
code.path,
|
}, true, ArErr{}, totalStep
|
||||||
}, true, ArErr{}, step1 + step2 - 1
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return operationType{}, false, ArErr{}, 0
|
return operationType{}, false, ArErr{}, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||||
|
if len(o.values) != 2 {
|
||||||
|
return false, ArErr{
|
||||||
|
"Runtime Error",
|
||||||
|
"Invalid number of values for comparison",
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
o.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
|
}
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -128,7 +111,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp2, err := runVal(
|
resp2, err := runVal(
|
||||||
o.value2,
|
o.values[1],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -149,21 +132,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return anyToBool(val), ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp2.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{resp},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -191,21 +159,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return anyToBool(val), ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp2.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__LessThanEqual__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{resp},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -233,27 +186,12 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return anyToBool(val), ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp2.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__GreaterThan__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{resp},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return anyToBool(val), ArErr{}
|
return anyToBool(val), ArErr{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false, ArErr{
|
return false, ArErr{
|
||||||
"Runtime Error",
|
"Runtime Error",
|
||||||
"Cannot compare type '" + typeof(resp) + "' with type '" + typeof(resp2) + "' with opperation '<'",
|
"Cannot compare type '" + typeof(resp) + "' with type '" + typeof(resp2) + "' with opperation '<'",
|
||||||
@@ -275,21 +213,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return anyToBool(val), ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp2.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__LessThan__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{resp},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -322,7 +245,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
|
|
||||||
func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -333,8 +256,9 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if isAnyNumber(resp) {
|
if isAnyNumber(resp) {
|
||||||
output = newNumber().Set(resp.(number))
|
output = newNumber().Set(resp.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -342,7 +266,8 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if typeof(output) == "number" && typeof(resp) == "number" {
|
||||||
return output.(number).Sub(output.(number), resp.(number)), ArErr{}
|
output = output.(number).Sub(output.(number), resp.(number))
|
||||||
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Subtract__"]; ok {
|
if y, ok := x.obj["__Subtract__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -353,25 +278,11 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return val, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostSubtract__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return val, ArErr{}
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -382,12 +293,15 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.code,
|
o.code,
|
||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return output, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -398,8 +312,9 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if isAnyNumber(resp) {
|
if isAnyNumber(resp) {
|
||||||
output = newNumber().Set(resp.(number))
|
output = newNumber().Set(resp.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -407,16 +322,8 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var outputErr ArErr = ArErr{
|
|
||||||
"Runtime Error",
|
|
||||||
"Cannot divide type '" + typeof(resp) + "'",
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
o.code,
|
|
||||||
true,
|
|
||||||
}
|
|
||||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
if typeof(resp) == "number" && typeof(output) == "number" {
|
||||||
if resp.(number).Cmp(newNumber()) == 0 {
|
if resp.(number).Cmp(newNumber().SetInt64(0)) == 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"Runtime Error",
|
"Runtime Error",
|
||||||
"Cannot divide by zero",
|
"Cannot divide by zero",
|
||||||
@@ -427,7 +334,7 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
output = output.(number).Quo(output.(number), resp.(number))
|
output = output.(number).Quo(output.(number), resp.(number))
|
||||||
return output, ArErr{}
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Divide__"]; ok {
|
if y, ok := x.obj["__Divide__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -438,36 +345,29 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
return val, ArErr{}
|
|
||||||
}
|
|
||||||
outputErr = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostDivide__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return val, ArErr{}
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, outputErr
|
return nil, ArErr{
|
||||||
|
"Runtime Error",
|
||||||
|
"Cannot divide type '" + typeof(resp) + "'",
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
o.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -478,8 +378,9 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if typeof(output) == "number" {
|
if typeof(output) == "number" {
|
||||||
output = newNumber().Set(output.(number))
|
output = newNumber().Set(output.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -488,7 +389,7 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if typeof(output) == "number" && typeof(resp) == "number" {
|
||||||
output = output.(number).Add(output.(number), resp.(number))
|
output = output.(number).Add(output.(number), resp.(number))
|
||||||
return output, ArErr{}
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Add__"]; ok {
|
if y, ok := x.obj["__Add__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -499,29 +400,13 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
output = val
|
output = val
|
||||||
return output, ArErr{}
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostAdd__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if !err.EXISTS {
|
|
||||||
output = val
|
|
||||||
return output, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"Runtime Error",
|
"Runtime Error",
|
||||||
"Cannot add type '" + typeof(resp) + "' to type '" + typeof(output) + "'",
|
"Cannot add type '" + typeof(resp) + "' to type '" + typeof(output) + "'",
|
||||||
@@ -531,11 +416,13 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (output), ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -546,8 +433,9 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if isAnyNumber(resp) {
|
if isAnyNumber(resp) {
|
||||||
output = newNumber().Set(resp.(number))
|
output = newNumber().Set(resp.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -556,7 +444,7 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if typeof(output) == "number" && typeof(resp) == "number" {
|
||||||
output = output.(number).Mul(output.(number), resp.(number))
|
output = output.(number).Mul(output.(number), resp.(number))
|
||||||
return output, ArErr{}
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Multiply__"]; ok {
|
if y, ok := x.obj["__Multiply__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -567,26 +455,11 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
output = val
|
|
||||||
return output, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostMultiply__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return val, ArErr{}
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -597,62 +470,51 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.code,
|
o.code,
|
||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return output, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcAnd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcAnd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
var output any = false
|
||||||
|
for i := 0; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
|
resp = ArValidToAny(resp)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !anyToBool(resp) {
|
if !anyToBool(resp) {
|
||||||
return resp, ArErr{}
|
return resp, ArErr{}
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
output = resp
|
||||||
o.value2,
|
|
||||||
stack,
|
|
||||||
stacklevel+1,
|
|
||||||
)
|
|
||||||
if err.EXISTS {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if !anyToBool(resp) {
|
return output, ArErr{}
|
||||||
return resp, ArErr{}
|
|
||||||
}
|
|
||||||
return resp, ArErr{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcOr(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcOr(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
var output any = false
|
||||||
|
for i := 0; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
|
resp = ArValidToAny(resp)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if anyToBool(resp) {
|
if anyToBool(resp) {
|
||||||
return resp, ArErr{}
|
return resp, ArErr{}
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
output = resp
|
||||||
o.value2,
|
|
||||||
stack,
|
|
||||||
stacklevel+1,
|
|
||||||
)
|
|
||||||
if err.EXISTS {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if anyToBool(resp) {
|
return output, ArErr{}
|
||||||
return resp, ArErr{}
|
|
||||||
}
|
|
||||||
return resp, ArErr{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InSlice checks if an element is present in a slice of any type.
|
|
||||||
// It returns true if the element is found, false otherwise.
|
|
||||||
func InSlice(a any, list []any) bool {
|
func InSlice(a any, list []any) bool {
|
||||||
for _, b := range list {
|
for _, b := range list {
|
||||||
if b == a {
|
if b == a {
|
||||||
@@ -661,23 +523,29 @@ func InSlice(a any, list []any) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// calcNotIn is a function that calculates the 'not in' operation between two values.
|
|
||||||
// It takes in an operationType 'o', a stack 'stack', and a stack level 'stacklevel'.
|
|
||||||
// It returns an 'any' value and an 'ArErr' error.
|
|
||||||
// The 'o' parameter contains information about the operation to be performed, including the values to be compared, the line of code, and the file path.
|
|
||||||
func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
if len(o.values) != 2 {
|
||||||
|
return false, ArErr{
|
||||||
|
"Runtime Error",
|
||||||
|
"Invalid number of arguments for 'not in'",
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
o.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
|
}
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
|
resp = ArValidToAny(resp)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp2, err := runVal(
|
resp2, err := runVal(
|
||||||
o.value2,
|
o.values[1],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -706,13 +574,19 @@ func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// calcIn is a function that calculates the 'in' operation between two values.
|
|
||||||
// It takes in an operationType 'o', a stack 'stack', and a stack level 'stacklevel'.
|
|
||||||
// It returns an 'any' value and an 'ArErr' error.
|
|
||||||
// The 'o' parameter contains information about the operation to be performed, including the values to be compared, the line of code, and the file path.
|
|
||||||
func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
if len(o.values) != 2 {
|
||||||
|
return false, ArErr{
|
||||||
|
"Runtime Error",
|
||||||
|
"Invalid number of arguments for 'not in'",
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
o.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
|
}
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -721,7 +595,7 @@ func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp2, err := runVal(
|
resp2, err := runVal(
|
||||||
o.value2,
|
o.values[1],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -806,7 +680,7 @@ func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if x, ok := b.(ArObject); ok {
|
if x, ok := b.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Equal__"]; ok {
|
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
y,
|
y,
|
||||||
@@ -826,7 +700,7 @@ func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, A
|
|||||||
|
|
||||||
func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -837,8 +711,9 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if isAnyNumber(resp) {
|
if isAnyNumber(resp) {
|
||||||
output = newNumber().Set(resp.(number))
|
output = newNumber().Set(resp.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -852,7 +727,7 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
x = floor(x)
|
x = floor(x)
|
||||||
x.Mul(x, resp.(number))
|
x.Mul(x, resp.(number))
|
||||||
output.(number).Sub(output.(number), x)
|
output.(number).Sub(output.(number), x)
|
||||||
return output, ArErr{}
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__Modulo__"]; ok {
|
if y, ok := x.obj["__Modulo__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -863,27 +738,11 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
output = val
|
|
||||||
return output, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostModulo__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return val, ArErr{}
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -895,10 +754,12 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return output, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -909,8 +770,9 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if isAnyNumber(resp) {
|
if isAnyNumber(resp) {
|
||||||
output = newNumber().Set(resp.(number))
|
output = newNumber().Set(resp.(number))
|
||||||
}
|
}
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -920,7 +782,7 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
if typeof(resp) == "number" && typeof(output) == "number" {
|
||||||
output = output.(number).Quo(output.(number), resp.(number))
|
output = output.(number).Quo(output.(number), resp.(number))
|
||||||
return output, ArErr{}
|
continue
|
||||||
} else if x, ok := output.(ArObject); ok {
|
} else if x, ok := output.(ArObject); ok {
|
||||||
if y, ok := x.obj["__IntDivide__"]; ok {
|
if y, ok := x.obj["__IntDivide__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
@@ -931,26 +793,11 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if !err.EXISTS {
|
|
||||||
output = val
|
|
||||||
return output, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__PostIntDivide__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return val, ArErr{}
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -962,10 +809,12 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return output, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func calcPower(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.value1,
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -984,8 +833,9 @@ func calcPower(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
output := newNumber().Set(resp.(number))
|
output := newNumber().Set(resp.(number))
|
||||||
resp, err = runVal(
|
for i := 1; i < len(o.values); i++ {
|
||||||
o.value2,
|
resp, err := runVal(
|
||||||
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
@@ -1028,39 +878,16 @@ func calcPower(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
output.Mul(output, calculated)
|
output.Mul(output, calculated)
|
||||||
}
|
}
|
||||||
return output, ArErr{}
|
|
||||||
} else if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Power__"]; ok {
|
|
||||||
val, err := runCall(
|
|
||||||
call{
|
|
||||||
y,
|
|
||||||
[]any{output},
|
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if !err.EXISTS {
|
|
||||||
return val, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if x, ok := resp.(ArObject); ok {
|
/*
|
||||||
if y, ok := x.obj["__PostPower__"]; ok {
|
n1, _ := output.Float64()
|
||||||
val, err := runCall(
|
n2, _ := resp.(number).Float64()
|
||||||
call{
|
output = newNumber().SetFloat64(math.Pow(n1, n2))
|
||||||
y,
|
if output == nil {
|
||||||
[]any{output},
|
output = infinity
|
||||||
o.code,
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
}, stack, stacklevel+1)
|
|
||||||
if err.EXISTS {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return val, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"Runtime Error",
|
"Runtime Error",
|
||||||
"Cannot calculate power of type '" + typeof(resp) + "'",
|
"Cannot calculate power of type '" + typeof(resp) + "'",
|
||||||
@@ -1070,6 +897,9 @@ func calcPower(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return output, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func runOperation(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func runOperation(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
switch o.operation {
|
switch o.operation {
|
||||||
|
|||||||
151
src/translate.go
151
src/translate.go
@@ -11,7 +11,30 @@ type UNPARSEcode struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var knownFailures = []string{}
|
||||||
|
var knownFailuresErrs = []ArErr{}
|
||||||
|
|
||||||
|
func StringExists(arr []string, target string) (bool, ArErr) {
|
||||||
|
for i, str := range arr {
|
||||||
|
if str == target {
|
||||||
|
return true, knownFailuresErrs[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||||
|
known, knownErr := StringExists(knownFailures, code.code)
|
||||||
|
if known {
|
||||||
|
return nil, false, ArErr{
|
||||||
|
knownErr.TYPE,
|
||||||
|
knownErr.message,
|
||||||
|
code.line,
|
||||||
|
code.path,
|
||||||
|
code.realcode,
|
||||||
|
true,
|
||||||
|
}, 1
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
resp any = nil
|
resp any = nil
|
||||||
worked bool = false
|
worked bool = false
|
||||||
@@ -20,36 +43,91 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
)
|
)
|
||||||
if isLine == 2 {
|
if isLine == 2 {
|
||||||
if isDeleteVariable(code) {
|
if isDeleteVariable(code) {
|
||||||
return parseDelete(code, index, codelines)
|
resp, worked, err, i = parseDelete(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isComment(code) {
|
} else if isComment(code) {
|
||||||
resp, worked, err, i = parseComment(code, index, codelines)
|
resp, worked, err, i = parseComment(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isReturn(code) {
|
} else if isReturn(code) {
|
||||||
return parseReturn(code, index, codelines)
|
resp, worked, err, i = parseReturn(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isBreak(code) {
|
} else if isBreak(code) {
|
||||||
return parseBreak(code)
|
resp, worked, err, i = parseBreak(code)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isContinue(code) {
|
} else if isContinue(code) {
|
||||||
return parseContinue(code)
|
resp, worked, err, i = parseContinue(code)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isIfStatement(code) {
|
} else if isIfStatement(code) {
|
||||||
return parseIfStatement(code, index, codelines)
|
resp, worked, err, i = parseIfStatement(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isWhileLoop(code) {
|
} else if isWhileLoop(code) {
|
||||||
return parseWhileLoop(code, index, codelines)
|
resp, worked, err, i = parseWhileLoop(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isForeverLoop(code) {
|
} else if isForeverLoop(code) {
|
||||||
return parseForeverLoop(code, index, codelines)
|
resp, worked, err, i = parseForeverLoop(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isForLoop(code) {
|
} else if isForLoop(code) {
|
||||||
return parseForLoop(code, index, codelines)
|
resp, worked, err, i = parseForLoop(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isGenericImport(code) {
|
} else if isGenericImport(code) {
|
||||||
return parseGenericImport(code, index, codelines)
|
resp, worked, err, i = parseGenericImport(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isTryCatch(code) {
|
} else if isTryCatch(code) {
|
||||||
return parseTryCatch(code, index, codelines)
|
resp, worked, err, i = parseTryCatch(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isLine >= 1 {
|
if isLine >= 1 {
|
||||||
if isDoWrap(code) {
|
if isDoWrap(code) {
|
||||||
return parseDoWrap(code, index, codelines)
|
resp, worked, err, i = parseDoWrap(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +162,19 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isNumber(code) {
|
if isNumber(code) {
|
||||||
return parseNumber(code)
|
resp, worked, err, i = parseNumber(code)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isString(code) {
|
} else if isString(code) {
|
||||||
return parseString(code)
|
resp, worked, err, i = parseString(code)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if issquareroot(code) {
|
} else if issquareroot(code) {
|
||||||
resp, worked, err, i = parseSquareroot(code, index, codelines)
|
resp, worked, err, i = parseSquareroot(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
@@ -100,7 +188,12 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isVariable(code) {
|
if isVariable(code) {
|
||||||
return parseVariable(code)
|
resp, worked, err, i = parseVariable(code)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
if isArray(code) {
|
if isArray(code) {
|
||||||
resp, worked, err, i = parseArray(code, index, codelines)
|
resp, worked, err, i = parseArray(code, index, codelines)
|
||||||
@@ -110,6 +203,12 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
} else if isMap(code) {
|
} else if isMap(code) {
|
||||||
resp, worked, err, i = parseMap(code, index, codelines)
|
resp, worked, err, i = parseMap(code, index, codelines)
|
||||||
}
|
}
|
||||||
|
if isnot(code) {
|
||||||
|
resp, worked, err, i = parseNot(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 {
|
||||||
@@ -118,12 +217,6 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
return nil, worked, err, step
|
return nil, worked, err, step
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isnot(code) {
|
|
||||||
resp, worked, err, i = parseNot(code, index, codelines, isLine)
|
|
||||||
if worked {
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isCall(code) {
|
if isCall(code) {
|
||||||
resp, worked, err, i = parseCall(code, index, codelines)
|
resp, worked, err, i = parseCall(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
@@ -131,15 +224,29 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isNegative(code) {
|
if isNegative(code) {
|
||||||
return parseNegative(code, index, codelines)
|
resp, worked, err, i = parseNegative(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isMapGet(code) {
|
} else if isMapGet(code) {
|
||||||
return mapGetParse(code, index, codelines)
|
resp, worked, err, i = mapGetParse(code, index, codelines)
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
|
return resp, worked, err, i
|
||||||
} else if isIndexGet(code) {
|
} else if isIndexGet(code) {
|
||||||
resp, worked, err, i = indexGetParse(code, index, codelines)
|
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !worked {
|
||||||
|
knownFailures = append(knownFailures, code.code)
|
||||||
|
knownFailuresErrs = append(knownFailuresErrs, err)
|
||||||
|
}
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ let interpret(code) = do
|
|||||||
else loops.pop()
|
else loops.pop()
|
||||||
code_ptr = code_ptr + 1
|
code_ptr = code_ptr + 1
|
||||||
|
|
||||||
term.log("hello worldf")
|
|
||||||
interpret('>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.>++++++++++.')
|
interpret('>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.>++++++++++.')
|
||||||
Reference in New Issue
Block a user