Files
monkey/internal/vm/frame.go
Chuck Smith 7a32cce8a1
Some checks failed
Build / build (push) Failing after 6m1s
Publish Image / publish (push) Failing after 38s
Test / build (push) Failing after 6m23s
Refactor VM and next instruction and argument reading
2024-03-31 09:09:04 -04:00

46 lines
797 B
Go

package vm
import (
"monkey/internal/code"
"monkey/internal/object"
)
type Frame struct {
cl *object.Closure
ip int
basePointer int
}
func NewFrame(cl *object.Closure, basePointer int) *Frame {
return &Frame{
cl: cl,
basePointer: basePointer,
}
}
func (f *Frame) ReadNextOp() code.Opcode {
op := code.Opcode(f.cl.Fn.Instructions[f.ip])
f.ip++
return op
}
func (f *Frame) PeekNextOp() code.Opcode {
return code.Opcode(f.cl.Fn.Instructions[f.ip])
}
func (f *Frame) ReadUint8() uint8 {
n := code.ReadUint8(f.cl.Fn.Instructions[f.ip:])
f.ip++
return n
}
func (f *Frame) ReadUint16() uint16 {
n := code.ReadUint16(f.cl.Fn.Instructions[f.ip:])
f.ip += 2
return n
}
func (f *Frame) Instructions() code.Instructions {
return f.cl.Fn.Instructions
}