From 3071da2e2d988662f5a52359088a7f10badc2d32 Mon Sep 17 00:00:00 2001 From: William Bell Date: Fri, 16 Jun 2023 10:02:16 +0100 Subject: [PATCH] fix getindex and add debug --- build | 2 +- debug | 2 ++ run | 2 +- src/call.go | 2 +- src/getIndex.go | 10 ++++++++-- 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100755 debug diff --git a/build b/build index c9fb28a..a16ee8e 100755 --- a/build +++ b/build @@ -1 +1 @@ -go build -o bin/argon ./src \ No newline at end of file +go build -ldflags "-s -w" -o bin/argon ./src \ No newline at end of file diff --git a/debug b/debug new file mode 100755 index 0000000..2b3c5e1 --- /dev/null +++ b/debug @@ -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 "$@" \ No newline at end of file diff --git a/run b/run index 2b3c5e1..496b1a7 100755 --- a/run +++ b/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 -__ARGON_DEBUG__=true go run ./src "$@" \ No newline at end of file +go run ./src "$@" \ No newline at end of file diff --git a/src/call.go b/src/call.go index 1c9b968..d2fd82a 100644 --- a/src/call.go +++ b/src/call.go @@ -65,7 +65,7 @@ func parseCall(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool, } func runCall(c call, stack stack, stacklevel int) (any, ArErr) { - var callable any + var callable any = c.callable switch x := c.callable.(type) { case builtinFunc: callable = x diff --git a/src/getIndex.go b/src/getIndex.go index 7f992e3..9d56d05 100644 --- a/src/getIndex.go +++ b/src/getIndex.go @@ -28,8 +28,7 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) { } switch m := resp.(type) { case ArObject: - if _, ok := m.obj["__getindex__"]; ok { - callable := m.obj["__getindex__"] + if callable, ok := m.obj["__getindex__"]; ok { resp, err := runCall(call{ callable: callable, 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) if err.EXISTS { return nil, err