Added Force Quit to intcode processor
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user