Make private
This commit is contained in:
42
state.go
42
state.go
@@ -44,24 +44,24 @@ func NewState(byteCodes [][]byte) (*State, error) {
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func (state *State) StackFrame() *StackFrame {
|
||||
return state.stack[len(state.stack)-1]
|
||||
}
|
||||
|
||||
func (state *State) Function() []*Instruction {
|
||||
return state.functions[state.functionIndex]
|
||||
}
|
||||
|
||||
func (state *State) Execute() {
|
||||
state.setHandlers()
|
||||
state.call(0)
|
||||
state.running = true
|
||||
|
||||
for state.running {
|
||||
state.ProcessInstruction()
|
||||
state.processInstruction()
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) stackFrame() *StackFrame {
|
||||
return state.stack[len(state.stack)-1]
|
||||
}
|
||||
|
||||
func (state *State) function() []*Instruction {
|
||||
return state.functions[state.functionIndex]
|
||||
}
|
||||
|
||||
func (state *State) setError(err error) {
|
||||
state.err = err
|
||||
state.running = false
|
||||
@@ -81,14 +81,14 @@ func (state *State) setHandlers() {
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) ProcessInstruction() {
|
||||
fnc := state.Function()
|
||||
func (state *State) processInstruction() {
|
||||
fnc := state.function()
|
||||
instr := fnc[state.instructionIndex]
|
||||
state.instructionIndex += 1
|
||||
instr.opHandler(state, instr)
|
||||
}
|
||||
|
||||
func (state *State) ReadUnsigned(op *Operand) uint64 {
|
||||
func (state *State) readUnsigned(op *Operand) uint64 {
|
||||
switch op.Type {
|
||||
case Literal:
|
||||
return op.Value
|
||||
@@ -98,7 +98,7 @@ func (state *State) ReadUnsigned(op *Operand) uint64 {
|
||||
state.setError(fmt.Errorf("Invalid function memory index: %016x", op.Value))
|
||||
return 0
|
||||
}
|
||||
return state.StackFrame().FunctionMemory[op.Value]
|
||||
return state.stackFrame().FunctionMemory[op.Value]
|
||||
|
||||
case GlobalMemoryIndex:
|
||||
if op.Value >= globalMemoryEntries {
|
||||
@@ -113,11 +113,11 @@ func (state *State) ReadUnsigned(op *Operand) uint64 {
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) ReadSigned(op *Operand) int64 {
|
||||
return int64(state.ReadUnsigned(op))
|
||||
func (state *State) readSigned(op *Operand) int64 {
|
||||
return int64(state.readUnsigned(op))
|
||||
}
|
||||
|
||||
func (state *State) WriteUnsigned(op *Operand, value uint64) {
|
||||
func (state *State) writeUnsigned(op *Operand, value uint64) {
|
||||
switch op.Type {
|
||||
case Literal:
|
||||
state.setError(fmt.Errorf("Write to literal operand"))
|
||||
@@ -127,7 +127,7 @@ func (state *State) WriteUnsigned(op *Operand, value uint64) {
|
||||
state.setError(fmt.Errorf("Invalid function memory index: %016x", op.Value))
|
||||
return
|
||||
}
|
||||
state.StackFrame().FunctionMemory[op.Value] = value
|
||||
state.stackFrame().FunctionMemory[op.Value] = value
|
||||
|
||||
case GlobalMemoryIndex:
|
||||
if op.Value >= globalMemoryEntries {
|
||||
@@ -141,8 +141,8 @@ func (state *State) WriteUnsigned(op *Operand, value uint64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) WriteSigned(op *Operand, value int64) {
|
||||
state.WriteUnsigned(op, uint64(value))
|
||||
func (state *State) writeSigned(op *Operand, value int64) {
|
||||
state.writeUnsigned(op, uint64(value))
|
||||
}
|
||||
|
||||
func (state *State) call(functionOffset int64) {
|
||||
@@ -161,8 +161,8 @@ func (state *State) call(functionOffset int64) {
|
||||
}
|
||||
|
||||
func (state *State) ret() {
|
||||
state.functionIndex = state.StackFrame().PreviousFunctionIndex
|
||||
state.instructionIndex = state.StackFrame().PreviousInstructionIndex
|
||||
state.functionIndex = state.stackFrame().PreviousFunctionIndex
|
||||
state.instructionIndex = state.stackFrame().PreviousInstructionIndex
|
||||
state.stack = state.stack[:len(state.stack)-1]
|
||||
if len(state.stack) == 0 {
|
||||
state.running = false
|
||||
|
||||
Reference in New Issue
Block a user