Skip to content

Commit e7ea534

Browse files
committed
Pre allocate stack
1 parent fbcab60 commit e7ea534

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

vm/vm.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type VM struct {
4343

4444
func NewVM(debug bool) *VM {
4545
vm := &VM{
46+
stack: make([]interface{}, 0, 2),
4647
debug: debug,
4748
}
4849
if vm.debug {
@@ -61,27 +62,6 @@ func (vm *VM) SetEnv(env interface{}) {
6162
vm.env = env
6263
}
6364

64-
func (vm *VM) Stack() []interface{} {
65-
return vm.stack
66-
}
67-
68-
func (vm *VM) Scope() Scope {
69-
if len(vm.scopes) > 0 {
70-
return vm.scopes[len(vm.scopes)-1]
71-
}
72-
return nil
73-
}
74-
75-
func (vm *VM) Step() {
76-
if vm.ip < len(vm.bytecode) {
77-
vm.step <- struct{}{}
78-
}
79-
}
80-
81-
func (vm *VM) Position() chan int {
82-
return vm.curr
83-
}
84-
8565
func (vm *VM) Run() interface{} {
8666
for vm.ip < len(vm.bytecode) {
8767

@@ -355,3 +335,24 @@ func (vm *VM) arg() uint16 {
355335
vm.ip += 2
356336
return arg
357337
}
338+
339+
func (vm *VM) Stack() []interface{} {
340+
return vm.stack
341+
}
342+
343+
func (vm *VM) Scope() Scope {
344+
if len(vm.scopes) > 0 {
345+
return vm.scopes[len(vm.scopes)-1]
346+
}
347+
return nil
348+
}
349+
350+
func (vm *VM) Step() {
351+
if vm.ip < len(vm.bytecode) {
352+
vm.step <- struct{}{}
353+
}
354+
}
355+
356+
func (vm *VM) Position() chan int {
357+
return vm.curr
358+
}

0 commit comments

Comments
 (0)