2015-10-07 14:22:47 +02:00
|
|
|
module Phisol
|
2015-09-19 17:56:18 +02:00
|
|
|
Compiler.class_eval do
|
2015-05-04 13:22:22 +02:00
|
|
|
|
2015-09-19 17:56:18 +02:00
|
|
|
def on_while expression
|
2015-09-20 16:33:05 +02:00
|
|
|
#puts expression.inspect
|
2015-09-20 15:52:26 +02:00
|
|
|
condition , expressions = *expression
|
|
|
|
condition = condition.first
|
|
|
|
|
2015-07-18 18:02:54 +02:00
|
|
|
# this is where the while ends and both branches meet
|
2015-10-05 23:27:13 +02:00
|
|
|
merge = @method.source.new_block("while merge")
|
2015-07-18 18:02:54 +02:00
|
|
|
# this comes after the current and beofre the merge
|
2015-10-05 23:27:13 +02:00
|
|
|
start = @method.source.new_block("while_start" )
|
|
|
|
@method.source.current start
|
2015-07-18 18:02:54 +02:00
|
|
|
|
2015-09-20 15:52:26 +02:00
|
|
|
cond = process(condition)
|
|
|
|
|
2015-10-07 09:02:51 +02:00
|
|
|
@method.source.add_code Register::IsZeroBranch.new(condition,merge)
|
2015-07-18 18:02:54 +02:00
|
|
|
|
2015-09-20 15:52:26 +02:00
|
|
|
last = process_all(expressions).last
|
2015-07-18 18:02:54 +02:00
|
|
|
|
|
|
|
# unconditionally branch to the start
|
2015-10-07 09:02:51 +02:00
|
|
|
@method.source.add_code Register::AlwaysBranch.new(expression,start)
|
2015-07-18 18:02:54 +02:00
|
|
|
|
|
|
|
# continue execution / compiling at the merge block
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.current merge
|
2014-07-17 15:46:17 +02:00
|
|
|
last
|
2014-07-14 15:19:47 +02:00
|
|
|
end
|
2015-05-08 14:10:30 +02:00
|
|
|
end
|
2015-05-04 13:22:22 +02:00
|
|
|
end
|