rubyx/lib/bosl/compiler/while_expression.rb

30 lines
811 B
Ruby
Raw Normal View History

module Bosl
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")
# this comes after the current and beofre the merge
start = method.source.new_block("while_start" )
method.source.current start
2015-09-20 15:52:26 +02:00
cond = process(condition)
method.source.add_code Virtual::IsTrueBranch.new(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-09-20 15:52:26 +02:00
method.source.add_code Virtual::UnconditionalBranch.new(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