Stop using exceptions for control flow
This commit is contained in:
parent
911855e479
commit
5602e04661
1 changed files with 2 additions and 7 deletions
|
|
@ -49,8 +49,6 @@ module Intcode
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DoneExecuting < StandardError; end
|
|
||||||
|
|
||||||
class Executor
|
class Executor
|
||||||
def initialize(mem)
|
def initialize(mem)
|
||||||
@mem = mem
|
@mem = mem
|
||||||
|
|
@ -59,10 +57,7 @@ module Intcode
|
||||||
|
|
||||||
def run(&user_input)
|
def run(&user_input)
|
||||||
loop do
|
loop do
|
||||||
tick(&user_input)
|
return if tick(&user_input) == :done_executing
|
||||||
rescue DoneExecuting
|
|
||||||
# TODO: Stop using exceptions for control flow
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -85,7 +80,7 @@ module Intcode
|
||||||
when 8
|
when 8
|
||||||
equal!
|
equal!
|
||||||
when 99
|
when 99
|
||||||
raise DoneExecuting
|
:done_executing
|
||||||
else
|
else
|
||||||
raise StandardError, "unexpected opcode: #{opcode}"
|
raise StandardError, "unexpected opcode: #{opcode}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue