fix getindex and add debug

This commit is contained in:
2023-06-16 10:02:16 +01:00
parent ec53db45d5
commit 3071da2e2d
5 changed files with 13 additions and 5 deletions

2
build
View File

@@ -1 +1 @@
go build -o bin/argon ./src go build -ldflags "-s -w" -o bin/argon ./src

2
debug Executable file
View File

@@ -0,0 +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
__ARGON_DEBUG__=true go run ./src "$@"

2
run
View File

@@ -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
__ARGON_DEBUG__=true go run ./src "$@" go run ./src "$@"

View File

@@ -65,7 +65,7 @@ func parseCall(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool,
} }
func runCall(c call, stack stack, stacklevel int) (any, ArErr) { func runCall(c call, stack stack, stacklevel int) (any, ArErr) {
var callable any var callable any = c.callable
switch x := c.callable.(type) { switch x := c.callable.(type) {
case builtinFunc: case builtinFunc:
callable = x callable = x

View File

@@ -28,8 +28,7 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
} }
switch m := resp.(type) { switch m := resp.(type) {
case ArObject: case ArObject:
if _, ok := m.obj["__getindex__"]; ok { if callable, ok := m.obj["__getindex__"]; ok {
callable := m.obj["__getindex__"]
resp, err := runCall(call{ resp, err := runCall(call{
callable: callable, callable: callable,
args: r.args, args: r.args,
@@ -48,6 +47,13 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
} }
} }
switch m := resp.(type) {
case ArObject:
if obj, ok := m.obj[r.args[0]]; ok {
return obj, ArErr{}
}
}
key, err := runVal(r.args[0], stack, stacklevel+1) key, err := runVal(r.args[0], stack, stacklevel+1)
if err.EXISTS { if err.EXISTS {
return nil, err return nil, err