Added Force Quit to intcode processor

This commit is contained in:
2019-12-16 17:31:11 -06:00
parent 11019fa77e
commit 0e315631dd
4 changed files with 238 additions and 21 deletions

View File

@@ -44,6 +44,7 @@ type Program struct {
state int
error error
bail bool
waitingForInput bool
input chan int
waitingForOutput bool
@@ -113,6 +114,12 @@ func (p *Program) Error() error {
return p.error
}
func (p *Program) ForceQuit() {
p.bail = true
close(p.input)
close(p.output)
}
func (p *Program) Run() int {
for {
p.state = p.Step()
@@ -123,6 +130,10 @@ func (p *Program) Run() int {
}
func (p *Program) Step() int {
if p.bail {
p.error = errors.New("Force Quit")
return RET_ERR
}
if len(p.code) < p.ptr {
p.error = errors.New("Pointer Exception")
return RET_ERR