mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add debug
This commit is contained in:
46
app.py
46
app.py
@@ -1,46 +0,0 @@
|
|||||||
def interpret(code):
|
|
||||||
memory = {}
|
|
||||||
pointer = 0
|
|
||||||
code_ptr = 0
|
|
||||||
loops = []
|
|
||||||
|
|
||||||
while code_ptr < len(code):
|
|
||||||
command = code[code_ptr]
|
|
||||||
|
|
||||||
if command == '>':
|
|
||||||
pointer += 1
|
|
||||||
elif command == '<':
|
|
||||||
pointer -= 1
|
|
||||||
elif command == '+':
|
|
||||||
if pointer not in memory:
|
|
||||||
memory[pointer] = 0
|
|
||||||
memory[pointer] += 1
|
|
||||||
elif command == '-':
|
|
||||||
if pointer not in memory:
|
|
||||||
memory[pointer] = 0
|
|
||||||
memory[pointer] -= 1
|
|
||||||
elif command == '.':
|
|
||||||
print(chr(memory.get(pointer, 0)), end='')
|
|
||||||
elif command == ',':
|
|
||||||
memory[pointer] = ord(input())
|
|
||||||
elif command == '[':
|
|
||||||
if memory.get(pointer, 0) == 0:
|
|
||||||
loop_depth = 1
|
|
||||||
while loop_depth > 0:
|
|
||||||
code_ptr += 1
|
|
||||||
if code[code_ptr] == '[':
|
|
||||||
loop_depth += 1
|
|
||||||
elif code[code_ptr] == ']':
|
|
||||||
loop_depth -= 1
|
|
||||||
else:
|
|
||||||
loops.append(code_ptr)
|
|
||||||
elif command == ']':
|
|
||||||
if memory.get(pointer, 0) != 0:
|
|
||||||
code_ptr = loops[-1]
|
|
||||||
else:
|
|
||||||
loops.pop()
|
|
||||||
code_ptr += 1
|
|
||||||
|
|
||||||
# Example usage
|
|
||||||
interpret("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
|
|
||||||
# Output: Hello World!
|
|
||||||
2
run
2
run
@@ -1,2 +1,2 @@
|
|||||||
# run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
# run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
|
||||||
go run ./src "$@"
|
__ARGON_DEBUG__=true go run ./src "$@"
|
||||||
@@ -93,6 +93,7 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
switch x := callable.(type) {
|
switch x := callable.(type) {
|
||||||
case builtinFunc:
|
case builtinFunc:
|
||||||
|
debugPrintln(x.name, args)
|
||||||
resp, err := x.FUNC(args...)
|
resp, err := x.FUNC(args...)
|
||||||
resp = AnyToArValid(resp)
|
resp = AnyToArValid(resp)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
@@ -108,6 +109,7 @@ func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
return resp, err
|
return resp, err
|
||||||
case Callable:
|
case Callable:
|
||||||
|
debugPrintln(x.name, args)
|
||||||
if len(x.params) != len(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}
|
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) {
|
func builtinCall(callable any, args []any) (any, ArErr) {
|
||||||
|
debugPrintln(callable, args)
|
||||||
|
|
||||||
switch x := callable.(type) {
|
switch x := callable.(type) {
|
||||||
case builtinFunc:
|
case builtinFunc:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var websiteLang = "https://argon.wbell.dev/"
|
var website = "https://argon.wbell.dev/"
|
||||||
var docs = "https://argon.wbell.dev/docs/"
|
var docs = "https://argon.wbell.dev/docs/"
|
||||||
var mainrepo = "https://github.com/Open-Argon/argon-v3"
|
var mainrepo = "https://github.com/Open-Argon/argon-v3"
|
||||||
var mainissuesPage = "https://github.com/Open-Argon/argon-v3/issues"
|
var mainissuesPage = "https://github.com/Open-Argon/argon-v3/issues"
|
||||||
|
|||||||
21
src/debug.go
Normal file
21
src/debug.go
Normal 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...)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main.go
40
src/main.go
@@ -15,26 +15,32 @@ func newscope() ArObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer func() {
|
debugPrintln("In debug mode...")
|
||||||
if r := recover(); r != nil {
|
if !debug {
|
||||||
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
|
defer func() {
|
||||||
fmt.Println()
|
if r := recover(); r != nil {
|
||||||
if fork {
|
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
|
||||||
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()
|
fmt.Println()
|
||||||
} else {
|
fmt.Println("website:", website)
|
||||||
fmt.Println("Please report this to the Open-Argon team.")
|
fmt.Println("docs:", docs)
|
||||||
fmt.Println("Main repo:", mainrepo)
|
|
||||||
fmt.Println("Issue page:", mainissuesPage)
|
|
||||||
fmt.Println()
|
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()
|
initRandom()
|
||||||
garbageCollect()
|
garbageCollect()
|
||||||
global := makeGlobal()
|
global := makeGlobal()
|
||||||
|
|||||||
47
src/map.go
47
src/map.go
@@ -22,13 +22,13 @@ func isMap(code UNPARSEcode) bool {
|
|||||||
func parseMap(code UNPARSEcode) (any, UNPARSEcode) {
|
func parseMap(code UNPARSEcode) (any, UNPARSEcode) {
|
||||||
trimmed := strings.Trim(code.code, " ")
|
trimmed := strings.Trim(code.code, " ")
|
||||||
trimmed = trimmed[1 : len(trimmed)-1]
|
trimmed = trimmed[1 : len(trimmed)-1]
|
||||||
fmt.Println(trimmed)
|
debugPrintln(trimmed)
|
||||||
return nil, UNPARSEcode{}
|
return nil, UNPARSEcode{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Map(m anymap) ArObject {
|
func Map(m anymap) ArObject {
|
||||||
var mutex = sync.RWMutex{}
|
var mutex = sync.RWMutex{}
|
||||||
return ArObject{
|
obj := ArObject{
|
||||||
obj: anymap{
|
obj: anymap{
|
||||||
"__value__": m,
|
"__value__": m,
|
||||||
"__name__": "map",
|
"__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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp2 = ArValidToAny(resp2)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -557,12 +556,12 @@ func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if x, ok := resp2.(ArObject); ok {
|
if x, ok := resp.(ArObject); ok {
|
||||||
if y, ok := x.obj["__NotContains__"]; ok {
|
if y, ok := x.obj["__NotContains__"]; ok {
|
||||||
return runCall(
|
return runCall(
|
||||||
call{
|
call{
|
||||||
y,
|
y,
|
||||||
[]any{resp},
|
[]any{resp2},
|
||||||
o.code,
|
o.code,
|
||||||
o.line,
|
o.line,
|
||||||
o.path,
|
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) {
|
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" {
|
if typeof(a) == "number" && typeof(b) == "number" {
|
||||||
return a.(number).Cmp(b.(number)) == 0, ArErr{}
|
return a.(number).Cmp(b.(number)) == 0, ArErr{}
|
||||||
} else if x, ok := a.(ArObject); ok {
|
} else if x, ok := a.(ArObject); ok {
|
||||||
@@ -678,7 +678,6 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user