add debug

This commit is contained in:
2023-06-13 23:18:54 +01:00
parent 8443b20949
commit ec53db45d5
9 changed files with 98 additions and 71 deletions

View File

@@ -93,6 +93,7 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
}
switch x := callable.(type) {
case builtinFunc:
debugPrintln(x.name, args)
resp, err := x.FUNC(args...)
resp = AnyToArValid(resp)
if err.EXISTS {
@@ -108,6 +109,7 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
}
return resp, err
case Callable:
debugPrintln(x.name, args)
if len(x.params) != len(args) {
return nil, ArErr{"Runtime Error", "expected " + fmt.Sprint(len(x.params)) + " arguments, got " + fmt.Sprint(len(args)), c.line, c.path, c.code, true}
}
@@ -122,6 +124,7 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
}
func builtinCall(callable any, args []any) (any, ArErr) {
debugPrintln(callable, args)
switch x := callable.(type) {
case builtinFunc:

View File

@@ -1,6 +1,6 @@
package main
var websiteLang = "https://argon.wbell.dev/"
var website = "https://argon.wbell.dev/"
var docs = "https://argon.wbell.dev/docs/"
var mainrepo = "https://github.com/Open-Argon/argon-v3"
var mainissuesPage = "https://github.com/Open-Argon/argon-v3/issues"

21
src/debug.go Normal file
View File

@@ -0,0 +1,21 @@
package main
import (
"fmt"
"os"
)
var debug = os.Getenv("__ARGON_DEBUG__") == "true"
func debugPrintln(a ...interface{}) {
if debug {
go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("debugPrintln: panic:", r)
}
}()
fmt.Println(a...)
}()
}
}

View File

@@ -15,26 +15,32 @@ func newscope() ArObject {
}
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
fmt.Println()
if fork {
fmt.Println("This is a fork of Open-Argon. Please report this to the fork's maintainer.")
fmt.Println("Fork repo:", forkrepo)
fmt.Println("Fork issue page:", forkissuesPage)
debugPrintln("In debug mode...")
if !debug {
defer func() {
if r := recover(); r != nil {
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
fmt.Println()
} else {
fmt.Println("Please report this to the Open-Argon team.")
fmt.Println("Main repo:", mainrepo)
fmt.Println("Issue page:", mainissuesPage)
fmt.Println("website:", website)
fmt.Println("docs:", docs)
fmt.Println()
if fork {
fmt.Println("This is a fork of Open-Argon. Please report this to the fork's maintainer.")
fmt.Println("Fork repo:", forkrepo)
fmt.Println("Fork issue page:", forkissuesPage)
fmt.Println()
} else {
fmt.Println("Please report this to the Open-Argon team.")
fmt.Println("Main repo:", mainrepo)
fmt.Println("Issue page:", mainissuesPage)
fmt.Println()
}
fmt.Println("please include the following information:")
fmt.Println("panic:", r)
os.Exit(1)
}
fmt.Println("please include the following information:")
fmt.Println("panic:", r)
os.Exit(1)
}
}()
}()
}
initRandom()
garbageCollect()
global := makeGlobal()

View File

@@ -22,13 +22,13 @@ func isMap(code UNPARSEcode) bool {
func parseMap(code UNPARSEcode) (any, UNPARSEcode) {
trimmed := strings.Trim(code.code, " ")
trimmed = trimmed[1 : len(trimmed)-1]
fmt.Println(trimmed)
debugPrintln(trimmed)
return nil, UNPARSEcode{}
}
func Map(m anymap) ArObject {
var mutex = sync.RWMutex{}
return ArObject{
obj := ArObject{
obj: anymap{
"__value__": m,
"__name__": "map",
@@ -168,4 +168,47 @@ func Map(m anymap) ArObject {
},
},
}
obj.obj["__Equal__"] = builtinFunc{
"__Equal__",
func(args ...any) (any, ArErr) {
debugPrintln("Equal", args)
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
}
if typeof(args[0]) != "map" {
return false, ArErr{}
}
a := ArValidToAny(args[0]).(anymap)
mutex.RLock()
if len(m) != len(a) {
mutex.RUnlock()
return false, ArErr{}
}
for k, v := range m {
debugPrintln(k, v)
if _, ok := a[k]; !ok {
mutex.RUnlock()
return false, ArErr{}
}
val, err := runOperation(operationType{
operation: 9,
values: []any{v, a[k]},
}, stack{}, 0)
if err.EXISTS {
return val, err
}
if !anyToBool(val) {
mutex.RUnlock()
return false, ArErr{}
}
}
mutex.RUnlock()
return true, ArErr{}
},
}
return obj
}

View File

@@ -129,7 +129,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
stack,
stacklevel+1,
)
resp2 = ArValidToAny(resp2)
if err.EXISTS {
return false, err
}
@@ -557,12 +556,12 @@ func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
if err.EXISTS {
return false, err
}
if x, ok := resp2.(ArObject); ok {
if x, ok := resp.(ArObject); ok {
if y, ok := x.obj["__NotContains__"]; ok {
return runCall(
call{
y,
[]any{resp},
[]any{resp2},
o.code,
o.line,
o.path,
@@ -651,6 +650,7 @@ func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool
}
func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
debugPrintln("equals", a, b)
if typeof(a) == "number" && typeof(b) == "number" {
return a.(number).Cmp(b.(number)) == 0, ArErr{}
} else if x, ok := a.(ArObject); ok {
@@ -678,7 +678,6 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}