2015-09-19 16:28:41 +03:00
|
|
|
module Bosl
|
2015-09-19 18:56:18 +03:00
|
|
|
Compiler.class_eval do
|
2015-05-04 14:22:22 +03:00
|
|
|
|
2015-09-19 18:56:18 +03:00
|
|
|
def on_while expression
|
2015-09-20 17:33:05 +03:00
|
|
|
#puts expression.inspect
|
2015-09-20 16:52:26 +03:00
|
|
|
condition , expressions = *expression
|
|
|
|
condition = condition.first
|
|
|
|
|
2015-07-18 19:02:54 +03: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 16:52:26 +03:00
|
|
|
cond = process(condition)
|
|
|
|
|
|
|
|
method.source.add_code Virtual::IsTrueBranch.new(merge)
|
2015-07-18 19:02:54 +03:00
|
|
|
|
2015-09-20 16:52:26 +03:00
|
|
|
last = process_all(expressions).last
|
2015-07-18 19:02:54 +03:00
|
|
|
|
|
|
|
# unconditionally branch to the start
|
2015-09-20 16:52:26 +03:00
|
|
|
method.source.add_code Virtual::UnconditionalBranch.new(start)
|
2015-07-18 19:02:54 +03:00
|
|
|
|
|
|
|
# continue execution / compiling at the merge block
|
|
|
|
method.source.current merge
|
2014-07-17 16:46:17 +03:00
|
|
|
last
|
2014-07-14 16:19:47 +03:00
|
|
|
end
|
2015-05-08 15:10:30 +03:00
|
|
|
end
|
2015-05-04 14:22:22 +03:00
|
|
|
end
|