From 378683d25bdae89fa446b2b82f8dda5d6b34ea33 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 14 Mar 2024 14:37:32 +0100 Subject: feat: initial support of closures Also detection and automatic execution of main function. Make sure that all debug is output to stderr. --- parser/interpreter.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'parser/interpreter.go') 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 -} -- cgit v1.2.3