Make Next() method on Context failable

refactor peekContext and Peek
This commit is contained in:
BlockChainDev 2019-03-16 21:45:48 +00:00
parent 48413900ca
commit 9eb11d2822
3 changed files with 23 additions and 11 deletions

View file

@ -41,12 +41,12 @@ func (c *Context) Context() (*Context, error) {
}
// Next return the next instruction to execute.
func (c *Context) Next() Instruction {
func (c *Context) Next() (Instruction, error) {
c.ip++
if c.ip >= len(c.prog) {
return RET
return RET, errors.New("program pointer is more than the length of program. RETURNING")
}
return Instruction(c.prog[c.ip])
return Instruction(c.prog[c.ip]), nil
}
// IP returns the absolute instruction without taking 0 into account.