summaryrefslogtreecommitdiff
path: root/parser/interpreter.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
committerMarc Vertes <mvertes@free.fr>2024-03-14 14:37:32 +0100
commit378683d25bdae89fa446b2b82f8dda5d6b34ea33 (patch)
treecbf624e4eb38fafe51a12a718b48f43192cfcfac /parser/interpreter.go
parent60170bad25f912e0ba44e4c0095b54f6e26e307e (diff)
feat: initial support of closures
Also detection and automatic execution of main function. Make sure that all debug is output to stderr.
Diffstat (limited to 'parser/interpreter.go')
-rw-r--r--parser/interpreter.go10
1 files changed, 3 insertions, 7 deletions
diff --git a/parser/interpreter.go b/parser/interpreter.go
index c5e463a..3ecbc46 100644
--- a/parser/interpreter.go
+++ b/parser/interpreter.go
@@ -34,6 +34,9 @@ func (i *Interpreter) Eval(src string) (res any, err error) {
}
i.Push(i.Data[dataOffset:]...)
i.PushCode(i.Code[codeOffset:]...)
+ if s, ok := i.symbols["main"]; ok {
+ i.PushCode([]int64{0, vm.Calli, i.Data[s.index].Data.Int()})
+ }
i.PushCode([]int64{0, vm.Exit})
i.SetIP(max(codeOffset, i.Entry))
if debug {
@@ -43,10 +46,3 @@ func (i *Interpreter) Eval(src string) (res any, err error) {
err = i.Run()
return i.Top().Data, err
}
-
-func max(a, b int) int {
- if a > b {
- return a
- }
- return b
-}