diff --git a/stackframe.go b/stackframe.go index 259eae1..006cce3 100644 --- a/stackframe.go +++ b/stackframe.go @@ -1,9 +1,9 @@ package vm -const FunctionMemoryEntries = 16 +const functionMemoryEntries = 16 -type StackFrame struct { - PreviousFunctionIndex int64 - PreviousInstructionIndex int64 - FunctionMemory [FunctionMemoryEntries]uint64 +type stackFrame struct { + previousFunctionIndex int64 + previousInstructionIndex int64 + functionMemory [functionMemoryEntries]uint64 } diff --git a/state.go b/state.go index 9c024e2..89c0ae3 100644 --- a/state.go +++ b/state.go @@ -16,7 +16,7 @@ type State struct { comparisonResult bool globalMemory [globalMemoryEntries]uint64 - stack []*StackFrame + stack []*stackFrame } func NewState(functions [][]*Instruction) (*State, error) { @@ -50,7 +50,7 @@ func (state *State) Execute() { } } -func (state *State) stackFrame() *StackFrame { +func (state *State) stackFrame() *stackFrame { return state.stack[len(state.stack)-1] } @@ -90,11 +90,11 @@ func (state *State) readUnsigned(op *Operand) uint64 { return op.Value case FunctionMemoryIndex: - if op.Value >= FunctionMemoryEntries { + if op.Value >= functionMemoryEntries { 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 { @@ -119,11 +119,11 @@ func (state *State) writeUnsigned(op *Operand, value uint64) { state.setError(fmt.Errorf("Write to literal operand")) case FunctionMemoryIndex: - if op.Value >= FunctionMemoryEntries { + if op.Value >= functionMemoryEntries { 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 { @@ -147,9 +147,9 @@ func (state *State) call(functionOffset int64) { return } - stackFrame := &StackFrame{ - PreviousFunctionIndex: state.functionIndex, - PreviousInstructionIndex: state.instructionIndex, + stackFrame := &stackFrame{ + previousFunctionIndex: state.functionIndex, + previousInstructionIndex: state.instructionIndex, } state.stack = append(state.stack, stackFrame) state.functionIndex += functionOffset @@ -157,8 +157,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