get conditions to work for while
This commit is contained in:
@ -20,13 +20,13 @@ module Ast
|
||||
|
||||
def save_locals context , into
|
||||
into.instance_eval do
|
||||
push [:r1 , :r2 , :r3]
|
||||
push [:r0,:r1 , :r2 , :r3]
|
||||
end
|
||||
end
|
||||
|
||||
def restore_locals context , into
|
||||
into.instance_eval do
|
||||
pop [:r1, :r2 , :r3]
|
||||
pop [:r0,:r1, :r2 , :r3]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Ast
|
||||
body.each do |b|
|
||||
compiled = b.compile(context , into)
|
||||
function.return_type = compiled
|
||||
puts "compiled in function #{compiled.class}"
|
||||
puts "compiled in function #{compiled.inspect}"
|
||||
raise "alarm #{compiled} \n #{b}" unless compiled.is_a? Vm::Word
|
||||
end
|
||||
context.locals = parent_locals
|
||||
|
@ -36,7 +36,7 @@ module Ast
|
||||
|
||||
case operator
|
||||
when ">"
|
||||
code = l_val.less_or_equal into , r_val
|
||||
code = l_val.greater_than into , r_val
|
||||
when "+"
|
||||
res = context.function.new_local
|
||||
into.res = l_val + r_val
|
||||
|
@ -14,16 +14,18 @@ module Ast
|
||||
[:condition, :body]
|
||||
end
|
||||
def compile context , into
|
||||
ret = into.new_block "#{into.name}_return_#{hash}"
|
||||
while_block = into.new_block "#{into.name}_while_#{hash}"
|
||||
ret = while_block.new_block "#{into.name}_return_#{hash}"
|
||||
cond_val = condition.compile(context , while_block)
|
||||
while_block.bne ret
|
||||
puts "compiled while condition #{cond_val.inspect}"
|
||||
while_block.b ret , condition_code: cond_val.not_operator
|
||||
last = nil
|
||||
body.each do |part|
|
||||
last = part.compile(context , while_block )
|
||||
puts "compiled in while #{last.inspect}"
|
||||
end
|
||||
while_block.b while_block
|
||||
puts "compile while end"
|
||||
into.insert_at_end
|
||||
return last
|
||||
end
|
||||
|
Reference in New Issue
Block a user