Private members

This commit is contained in:
Ian Gulliver
2021-11-16 15:39:12 -10:00
parent f2d552e076
commit 1fdeaaf4cc
2 changed files with 16 additions and 16 deletions

View File

@@ -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