This commit is contained in:
Chuck Smith
2024-03-16 20:02:57 -04:00
parent 83ad72a7fc
commit d454572870
3 changed files with 46 additions and 3 deletions

View File

@@ -2,9 +2,11 @@ package vm
import (
"fmt"
"log"
"monkey/code"
"monkey/compiler"
"monkey/object"
"strings"
)
const StackSize = 2048
@@ -16,6 +18,8 @@ var True = &object.Boolean{Value: true}
var False = &object.Boolean{Value: false}
type VM struct {
Debug bool
constants []object.Object
stack []object.Object
@@ -77,6 +81,17 @@ func (vm *VM) Run() error {
var ins code.Instructions
var op code.Opcode
if vm.Debug {
log.Printf(
"%-20s %-20s\n",
strings.Split(ins[ip:].String(), "\n")[0],
fmt.Sprintf(
"[ip=%02d fp=%02d, sp=%02d]",
ip, vm.sp, vm.framesIndex-1,
),
)
}
for vm.currentFrame().ip < len(vm.currentFrame().Instructions())-1 {
vm.currentFrame().ip++