debug
This commit is contained in:
15
vm/vm.go
15
vm/vm.go
@@ -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++
|
||||
|
||||
|
||||
Reference in New Issue
Block a user