mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2026-03-03 02:14:34 +00:00
fix built in functions
This commit is contained in:
2
example.ar
Normal file
2
example.ar
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
forever do
|
||||||
|
term.log(random())
|
||||||
@@ -507,9 +507,9 @@ func ArArray(arr []any) ArObject {
|
|||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output = append(output, v.(string))
|
output = append(output, v.(ArObject).obj["__value__"].(string))
|
||||||
}
|
}
|
||||||
return ArString(strings.Join(output, args[0].(string))), ArErr{}
|
return ArString(strings.Join(output, args[0].(ArObject).obj["__value__"].(string))), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
val.obj["concat"] = builtinFunc{
|
val.obj["concat"] = builtinFunc{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func ArgonNumber(args ...any) (any, ArErr) {
|
|||||||
if x {
|
if x {
|
||||||
return newNumber().SetInt64(1), ArErr{}
|
return newNumber().SetInt64(1), ArErr{}
|
||||||
}
|
}
|
||||||
return newNumber().SetInt64(0), ArErr{}
|
return newNumber(), ArErr{}
|
||||||
case nil:
|
case nil:
|
||||||
return newNumber(), ArErr{}
|
return newNumber(), ArErr{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func makeGlobal(allowDocument bool) ArObject {
|
func makeGlobal(allowDocument bool) ArObject {
|
||||||
var vars = Map(anymap{})
|
var vars = Map(anymap{})
|
||||||
vars.obj["global"] = vars
|
vars.obj["global"] = vars
|
||||||
@@ -35,15 +33,15 @@ func makeGlobal(allowDocument bool) ArObject {
|
|||||||
newmap[i] = v
|
newmap[i] = v
|
||||||
}
|
}
|
||||||
return Map(newmap), ArErr{}
|
return Map(newmap), ArErr{}
|
||||||
}
|
} else if x.TYPE == "string" {
|
||||||
return x, ArErr{}
|
|
||||||
case string:
|
|
||||||
newmap := anymap{}
|
newmap := anymap{}
|
||||||
for i, v := range x {
|
for i, v := range x.obj["__value__"].(string) {
|
||||||
newmap[i] = ArString(string(v))
|
newmap[i] = ArString(string(v))
|
||||||
}
|
}
|
||||||
return Map(newmap), ArErr{}
|
return Map(newmap), ArErr{}
|
||||||
}
|
}
|
||||||
|
return x, ArErr{}
|
||||||
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars.obj["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
vars.obj["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
||||||
@@ -51,15 +49,16 @@ func makeGlobal(allowDocument bool) ArObject {
|
|||||||
return ArArray([]any{}), ArErr{}
|
return ArArray([]any{}), ArErr{}
|
||||||
}
|
}
|
||||||
switch x := a[0].(type) {
|
switch x := a[0].(type) {
|
||||||
case string:
|
|
||||||
newarray := []any{}
|
|
||||||
for _, v := range x {
|
|
||||||
newarray = append(newarray, ArString(string(v)))
|
|
||||||
}
|
|
||||||
return ArArray(newarray), ArErr{}
|
|
||||||
case ArObject:
|
case ArObject:
|
||||||
if x.TYPE == "array" {
|
if x.TYPE == "array" {
|
||||||
return x, ArErr{}
|
return x, ArErr{}
|
||||||
|
} else if x.TYPE == "string" {
|
||||||
|
|
||||||
|
newarray := []any{}
|
||||||
|
for _, v := range x.obj["__value__"].(string) {
|
||||||
|
newarray = append(newarray, ArString(string(v)))
|
||||||
|
}
|
||||||
|
return ArArray(newarray), ArErr{}
|
||||||
}
|
}
|
||||||
newarray := []any{}
|
newarray := []any{}
|
||||||
for key, val := range x.obj {
|
for key, val := range x.obj {
|
||||||
@@ -151,7 +150,6 @@ func makeGlobal(allowDocument bool) ArObject {
|
|||||||
vars.obj["torad"] = ArToRad
|
vars.obj["torad"] = ArToRad
|
||||||
vars.obj["abs"] = ArAbs
|
vars.obj["abs"] = ArAbs
|
||||||
vars.obj["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
vars.obj["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
||||||
fmt.Println(a)
|
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return ArArray([]any{}), ArErr{}
|
return ArArray([]any{}), ArErr{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,6 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
switch x := callable.(type) {
|
switch x := callable.(type) {
|
||||||
case builtinFunc:
|
case builtinFunc:
|
||||||
for i := range args {
|
|
||||||
args[i] = ArValidToAny(args[i])
|
|
||||||
}
|
|
||||||
resp, err := x.FUNC(args...)
|
resp, err := x.FUNC(args...)
|
||||||
resp = AnyToArValid(resp)
|
resp = AnyToArValid(resp)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
splitby := a[0].(string)
|
splitby := a[0].(ArObject).obj["__value__"].(string)
|
||||||
output := []any{}
|
output := []any{}
|
||||||
splitted := (strings.Split(str, splitby))
|
splitted := (strings.Split(str, splitby))
|
||||||
for _, v := range splitted {
|
for _, v := range splitted {
|
||||||
@@ -297,7 +297,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[1]) != "string" {
|
if typeof(a[1]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Replace(str, a[0].(string), a[1].(string), -1), ArErr{}
|
return strings.Replace(str, a[0].(ArObject).obj["__value__"].(string), a[1].(string), -1), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["contains"] = builtinFunc{
|
obj.obj["contains"] = builtinFunc{
|
||||||
"contains",
|
"contains",
|
||||||
@@ -308,7 +308,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Contains(str, a[0].(string)), ArErr{}
|
return strings.Contains(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["startswith"] = builtinFunc{
|
obj.obj["startswith"] = builtinFunc{
|
||||||
"startswith",
|
"startswith",
|
||||||
@@ -319,7 +319,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.HasPrefix(str, a[0].(string)), ArErr{}
|
return strings.HasPrefix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["endswith"] = builtinFunc{
|
obj.obj["endswith"] = builtinFunc{
|
||||||
"endswith",
|
"endswith",
|
||||||
@@ -330,7 +330,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.HasSuffix(str, a[0].(string)), ArErr{}
|
return strings.HasSuffix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["index"] = builtinFunc{
|
obj.obj["index"] = builtinFunc{
|
||||||
"index",
|
"index",
|
||||||
@@ -341,7 +341,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Index(str, a[0].(string)), ArErr{}
|
return strings.Index(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["rindex"] = builtinFunc{
|
obj.obj["rindex"] = builtinFunc{
|
||||||
"rindex",
|
"rindex",
|
||||||
@@ -352,7 +352,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.LastIndex(str, a[0].(string)), ArErr{}
|
return strings.LastIndex(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["count"] = builtinFunc{
|
obj.obj["count"] = builtinFunc{
|
||||||
"count",
|
"count",
|
||||||
@@ -364,7 +364,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Count(str, a[0].(string)), ArErr{}
|
return strings.Count(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
obj.obj["sort"] = builtinFunc{
|
obj.obj["sort"] = builtinFunc{
|
||||||
@@ -451,7 +451,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
return strings.Trim(str, cutset), ArErr{}
|
return strings.Trim(str, cutset), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -466,7 +466,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
return strings.TrimLeft(str, cutset), ArErr{}
|
return strings.TrimLeft(str, cutset), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -481,7 +481,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
return strings.TrimRight(str, cutset), ArErr{}
|
return strings.TrimRight(str, cutset), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -494,7 +494,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return str <= a[0].(string), ArErr{}
|
return str <= a[0].(ArObject).obj["__value__"].(string), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__LessThan__"] = builtinFunc{
|
obj.obj["__LessThan__"] = builtinFunc{
|
||||||
"__LessThan__",
|
"__LessThan__",
|
||||||
@@ -505,7 +505,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return str < a[0].(string), ArErr{}
|
return str < a[0].(ArObject).obj["__value__"].(string), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__GreaterThan__"] = builtinFunc{
|
obj.obj["__GreaterThan__"] = builtinFunc{
|
||||||
"__GreaterThan__",
|
"__GreaterThan__",
|
||||||
@@ -516,7 +516,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return str > a[0].(string), ArErr{}
|
return str > a[0].(ArObject).obj["__value__"].(string), ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
obj.obj["__GreaterThanEqual__"] = builtinFunc{
|
obj.obj["__GreaterThanEqual__"] = builtinFunc{
|
||||||
@@ -528,7 +528,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return str >= a[0].(string), ArErr{}
|
return str >= a[0].(ArObject).obj["__value__"].(string), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__Equal__"] = builtinFunc{
|
obj.obj["__Equal__"] = builtinFunc{
|
||||||
"__Equal__",
|
"__Equal__",
|
||||||
@@ -555,7 +555,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot add " + typeof(a[0]) + " to string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot add " + typeof(a[0]) + " to string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Join([]string{str, a[0].(string)}, ""), ArErr{}
|
return strings.Join([]string{str, a[0].(ArObject).obj["__value__"].(string)}, ""), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__Multiply__"] = builtinFunc{
|
obj.obj["__Multiply__"] = builtinFunc{
|
||||||
"__Multiply__",
|
"__Multiply__",
|
||||||
@@ -584,7 +584,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Contains(str, a[0].(string)), ArErr{}
|
return strings.Contains(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__Subtract__"] = builtinFunc{
|
obj.obj["__Subtract__"] = builtinFunc{
|
||||||
"__Subtract__",
|
"__Subtract__",
|
||||||
@@ -595,7 +595,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Replace(str, a[0].(string), "", -1), ArErr{}
|
return strings.Replace(str, a[0].(ArObject).obj["__value__"].(string), "", -1), ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__Divide__"] = builtinFunc{
|
obj.obj["__Divide__"] = builtinFunc{
|
||||||
"__Divide__",
|
"__Divide__",
|
||||||
@@ -606,7 +606,7 @@ func ArString(str string) ArObject {
|
|||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"TypeError", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
splitby := a[0].(string)
|
splitby := a[0].(ArObject).obj["__value__"].(string)
|
||||||
output := []any{}
|
output := []any{}
|
||||||
splitted := (strings.Split(str, splitby))
|
splitted := (strings.Split(str, splitby))
|
||||||
for _, v := range splitted {
|
for _, v := range splitted {
|
||||||
|
|||||||
Reference in New Issue
Block a user