Refactor VM and next instruction and argument reading
Some checks failed
Build / build (push) Failing after 6m1s
Publish Image / publish (push) Failing after 38s
Test / build (push) Failing after 6m23s

This commit is contained in:
Chuck Smith
2024-03-31 09:09:04 -04:00
parent c8de195ac8
commit 7a32cce8a1
2 changed files with 173 additions and 110 deletions

View File

@@ -14,18 +14,30 @@ type Frame struct {
func NewFrame(cl *object.Closure, basePointer int) *Frame {
return &Frame{
cl: cl,
ip: -1,
basePointer: basePointer,
}
}
// NextOp ...
func (f *Frame) NextOp() code.Opcode {
return code.Opcode(f.Instructions()[f.ip+1])
func (f *Frame) ReadNextOp() code.Opcode {
op := code.Opcode(f.cl.Fn.Instructions[f.ip])
f.ip++
return op
}
func (f *Frame) Reset() {
f.ip = -1
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 {