mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
fix not equal
This commit is contained in:
@@ -48,6 +48,22 @@ func makeGlobal() ArObject {
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["hex"] = builtinFunc{"hex", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case number:
|
||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert non-integer to hex", EXISTS: true}
|
||||
}
|
||||
n := x.Num().Int64()
|
||||
return ArString(fmt.Sprintf("%x", n)), ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
|
||||
}}
|
||||
vars["throwError"] = builtinFunc{"throwError", ArThrowError}
|
||||
vars["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
||||
if len(a) == 0 {
|
||||
return ArArray([]any{}), ArErr{}
|
||||
@@ -241,5 +257,19 @@ func makeGlobal() ArObject {
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||
}}
|
||||
vars["ord"] = builtinFunc{"ord", func(a ...any) (any, ArErr) {
|
||||
if len(a) != 1 {
|
||||
return nil, ArErr{TYPE: "ord", message: "ord takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
switch x := a[0].(type) {
|
||||
case string:
|
||||
if len(x) != 1 {
|
||||
return nil, ArErr{TYPE: "ord", message: "ord takes a string with only one character, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||
}
|
||||
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||
}}
|
||||
return Map(vars)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo
|
||||
break
|
||||
}
|
||||
if indent != setindent {
|
||||
return nil, false, ArErr{"Syntax Error", "invalid indent", code.line, code.path, code.realcode, true}, 1
|
||||
return nil, false, ArErr{"Syntax Error", "invalid indent", i, code.path, codelines[i].code, true}, 1
|
||||
}
|
||||
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 2)
|
||||
@@ -56,9 +56,7 @@ func runDoWrap(d dowrap, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
switch x := val.(type) {
|
||||
case Return:
|
||||
return x, ArErr{}
|
||||
case Break:
|
||||
case Return, Break, Continue:
|
||||
return x, ArErr{}
|
||||
}
|
||||
}
|
||||
|
||||
27
src/error.go
27
src/error.go
@@ -13,6 +13,33 @@ type ArErr struct {
|
||||
EXISTS bool
|
||||
}
|
||||
|
||||
func ArThrowError(a ...any) (any, ArErr) {
|
||||
if len(a) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError takes 2 arguments, " + fmt.Sprint(len(a)) + " given",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError type must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
} else if typeof(a[1]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "TypeError",
|
||||
message: "throwError message must be a string",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: ArValidToAny(a[0]).(string),
|
||||
message: ArValidToAny(a[1]).(string),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
|
||||
func panicErr(err ArErr) {
|
||||
if err.code != "" && err.line != 0 && err.path != "" {
|
||||
fmt.Println(" File:", err.path+":"+fmt.Sprint(err.line))
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var returnCompile = makeRegex(`( *)return( +)(.|\n)+`)
|
||||
var returnCompile = makeRegex(`( *)return(( +)(.|\n)+)?`)
|
||||
var breakCompile = makeRegex(`( *)break( *)`)
|
||||
var continueCompile = makeRegex(`( *)continue( *)`)
|
||||
|
||||
@@ -45,12 +45,17 @@ func isContinue(code UNPARSEcode) bool {
|
||||
}
|
||||
|
||||
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallReturn, bool, ArErr, int) {
|
||||
resp, worked, err, i := translateVal(UNPARSEcode{
|
||||
code: strings.TrimSpace(code.code)[6:],
|
||||
val := strings.TrimSpace(code.code)[6:]
|
||||
var resp any
|
||||
var worked, err, i = true, ArErr{}, 1
|
||||
if val != "" {
|
||||
resp, worked, err, i = translateVal(UNPARSEcode{
|
||||
code: val,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 1)
|
||||
}
|
||||
return CallReturn{
|
||||
value: resp,
|
||||
line: code.line,
|
||||
|
||||
@@ -44,7 +44,7 @@ func runCreateMap(m createMap, stack stack, stacklevel int) (any, ArErr) {
|
||||
true,
|
||||
}
|
||||
}
|
||||
newmap[key] = valVal
|
||||
newmap[keyVal] = valVal
|
||||
}
|
||||
return newmap, ArErr{}
|
||||
}
|
||||
|
||||
@@ -763,7 +763,7 @@ func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool
|
||||
o.path,
|
||||
}, stack, stacklevel+1)
|
||||
if !err.EXISTS {
|
||||
return !anyToBool(val), ArErr{}
|
||||
return anyToBool(val), ArErr{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,32 @@ func ArSocket(args ...any) (any, ArErr) {
|
||||
return ArString(string(buf[:n])), ArErr{}
|
||||
},
|
||||
},
|
||||
"writeData": builtinFunc{
|
||||
"writeData",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.writeData() takes exactly 1 argument",
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
data := ArValidToAny(args[0])
|
||||
switch x := data.(type) {
|
||||
case []any:
|
||||
bytes := []byte{}
|
||||
for _, v := range x {
|
||||
bytes = append(bytes, byte(v.(number).Num().Int64()))
|
||||
}
|
||||
conn.Write(bytes)
|
||||
return nil, ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "SocketError",
|
||||
message: "Socket.writeData() argument must be a array of numbers",
|
||||
}
|
||||
},
|
||||
},
|
||||
"write": builtinFunc{
|
||||
"write",
|
||||
func(args ...any) (any, ArErr) {
|
||||
@@ -118,6 +144,18 @@ func ArSocket(args ...any) (any, ArErr) {
|
||||
return conn == nil, ArErr{}
|
||||
},
|
||||
},
|
||||
"RemoteAddr": builtinFunc{
|
||||
"RemoteAddr",
|
||||
func(args ...any) (any, ArErr) {
|
||||
return ArString(conn.RemoteAddr().String()), ArErr{}
|
||||
},
|
||||
},
|
||||
"LocalAddr": builtinFunc{
|
||||
"LocalAddr",
|
||||
func(args ...any) (any, ArErr) {
|
||||
return ArString(conn.LocalAddr().String()), ArErr{}
|
||||
},
|
||||
},
|
||||
}), ArErr{}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -254,7 +254,7 @@ func ArString(str string) ArObject {
|
||||
if typeof(a[0]) != "string" {
|
||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||
}
|
||||
splitby := a[0].(ArObject).obj["__value__"].(string)
|
||||
splitby := ArValidToAny(a[0]).(string)
|
||||
output := []any{}
|
||||
splitted := (strings.Split(str, splitby))
|
||||
for _, v := range splitted {
|
||||
@@ -553,6 +553,7 @@ func ArString(str string) ArObject {
|
||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||
}
|
||||
a[0] = ArValidToAny(a[0])
|
||||
fmt.Println(str, a[0])
|
||||
return str != a[0], ArErr{}
|
||||
}}
|
||||
obj.obj["__Add__"] = builtinFunc{
|
||||
|
||||
Reference in New Issue
Block a user