// Read a register address from the file input. func NextOpcode(fileInput io.Reader) (result opcode.Opcode, err error) { num, err := NextCodepoint(fileInput) if err == nil { result = opcode.Opcode(num) } return result, err }
func (m *Machine) ExecuteNextInstruction() { op := opcode.Opcode(m.Memory[m.InstrPtr]) m.InstrPtr += 1 switch op { case opcode.Halt: panic(EXIT_HALT) case opcode.Set: m.DoSet() case opcode.Push: m.DoPush() case opcode.Pop: m.DoPop() case opcode.Eq: m.DoEq() case opcode.Gt: m.DoGt() case opcode.Jmp: m.DoJmp() case opcode.Jt: m.DoJt() case opcode.Jf: m.DoJf() case opcode.Add: m.DoAdd() case opcode.Mult: m.DoMult() case opcode.Mod: m.DoMod() case opcode.And: m.DoAnd() case opcode.Or: m.DoOr() case opcode.Not: m.DoNot() case opcode.Rmem: m.DoRmem() case opcode.Wmem: m.DoWmem() case opcode.Call: m.DoCall() case opcode.Ret: m.DoRet() case opcode.Out: m.DoOut() case opcode.In: m.DoIn() case opcode.Noop: // nothing default: panic(EXIT_UNRECOGNIZED_INSTR) } }