rubyx/lib/phisol/compiler/while_expression.rb

30 lines
835 B
Ruby
Raw Normal View History

2015-10-07 14:22:47 +02:00
module Phisol
Compiler.class_eval do
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
merge = @method.source.new_block("while merge")
2015-07-18 18:02:54 +02:00
# this comes after the current and beofre the merge
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)
@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
@method.source.add_code Register::AlwaysBranch.new(expression,start)
2015-07-18 18:02:54 +02:00
# continue execution / compiling at the merge block
@method.source.current merge
last
2014-07-14 15:19:47 +02:00
end
end
end