update to use new ast

soml was updated to have a typed ast layer to make programatic creation
easier
this brings LOTS of syntax change with it, that does not really mean
anything at all
All tests pass again so back to the same
This commit is contained in:
Torsten Ruger
2016-03-07 11:55:28 +02:00
parent d7b210d63a
commit 229f5896c6
22 changed files with 126 additions and 118 deletions

View File

@ -1,27 +1,26 @@
module Soml
Compiler.class_eval do
def on_while_statement statement
def on_WhileStatement statement
#puts statement.inspect
branch_type , condition , statements = *statement
condition = condition.first
#branch_type , condition , statements = *statement
condition_label = Register::Label.new(statement , "condition_label")
condition_label = Register::Label.new(statement.condition , "condition_label")
# unconditionally branch to the condition upon entering the loop
add_code Register::Branch.new(statement,condition_label)
add_code Register::Branch.new(statement.condition,condition_label)
add_code start = Register::Label.new(statement , "while_start" )
reset_regs
process_all(statements)
process(statement.statements)
# This is where the loop starts, though in subsequent iterations it's in the middle
add_code condition_label
reset_regs
process(condition)
process(statement.condition)
branch_class = Object.const_get "Register::Is#{branch_type.capitalize}"
branch_class = Object.const_get "Register::Is#{statement.branch_type.capitalize}"
# this is where the while ends and both branches meet
add_code branch_class.new( condition , start )
add_code branch_class.new( statement.condition , start )
nil # statements don't return anything
end