Files
monkey/internal/vm/frame.go
Chuck Smith 88e3330856
Some checks failed
Build / build (push) Successful in 9m47s
Publish Image / publish (push) Failing after 49s
Test / build (push) Failing after 6m19s
optimizations
2024-04-02 14:32:03 -04:00

58 lines
981 B
Go

package vm
import (
"monkey/internal/code"
"monkey/internal/object"
)
type frame struct {
ip uint16
basePointer int
cl *object.Closure
}
func newFrame(cl *object.Closure, basePointer int) frame {
return frame{
cl: cl,
basePointer: basePointer,
}
}
func (f *frame) Closure() *object.Closure {
return f.cl
}
func (f *frame) GetFree(idx uint8) object.Object {
return f.cl.Free[idx]
}
func (f *frame) SetFree(idx uint8, obj object.Object) {
f.cl.Free[idx] = obj
}
func (f *frame) SetIP(ip uint16) {
f.ip = ip
}
func (f frame) PeekNextOp() code.Opcode {
return code.Opcode(f.cl.Fn.Instructions[f.ip])
}
func (f *frame) ReadNextOp() code.Opcode {
op := code.Opcode(f.cl.Fn.Instructions[f.ip])
f.ip++
return op
}
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
}