Refactor VM and next instruction and argument reading
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user