about summary refs log tree commit diff
path: root/pkg/lang
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-05-18 02:19:35 +0200
committerMel <einebeere@gmail.com>2022-05-18 02:19:35 +0200
commit0a7927ed8257857c8d114387f12844312f6da51c (patch)
tree5fa9829606be6dc1c0f0d4b092a4bc29a96e24a0 /pkg/lang
parent3abe18ffca484efc3553aa4ec9cb677eb19cdaf4 (diff)
downloadjinx-0a7927ed8257857c8d114387f12844312f6da51c.tar.zst
jinx-0a7927ed8257857c8d114387f12844312f6da51c.zip
Start call stack with at least one frame
Diffstat (limited to 'pkg/lang')
-rw-r--r--pkg/lang/vm/stack.go4
-rw-r--r--pkg/lang/vm/vm.go5
2 files changed, 7 insertions, 2 deletions
diff --git a/pkg/lang/vm/stack.go b/pkg/lang/vm/stack.go
index 433c0b7..1d028e5 100644
--- a/pkg/lang/vm/stack.go
+++ b/pkg/lang/vm/stack.go
@@ -4,6 +4,10 @@ import "jinx/pkg/lang/vm/value"
 
 type CallStack []*LocalStack
 
+func NewCallStack() CallStack {
+	return []*LocalStack{{}}
+}
+
 func (cs *CallStack) Push() {
 	*cs = append(*cs, &LocalStack{})
 }
diff --git a/pkg/lang/vm/vm.go b/pkg/lang/vm/vm.go
index 434eae3..a6e1fb8 100644
--- a/pkg/lang/vm/vm.go
+++ b/pkg/lang/vm/vm.go
@@ -13,8 +13,9 @@ type VM struct {
 
 func New(code *code.Code) *VM {
 	return &VM{
-		code: code,
-		pc:   0,
+		code:  code,
+		pc:    0,
+		stack: NewCallStack(),
 	}
 }