still recoving from previous block - function change. no more exceptions at least
This commit is contained in:
@@ -28,7 +28,6 @@ module Ast
|
||||
context.locals = locals
|
||||
context.function = function
|
||||
|
||||
into = function.body
|
||||
last_compiled = nil
|
||||
body.each do |b|
|
||||
puts "compiling in function #{b}"
|
||||
@@ -38,9 +37,9 @@ module Ast
|
||||
|
||||
return_reg = Vm::Integer.new(Vm::RegisterMachine.instance.return_register)
|
||||
if last_compiled.is_a?(Vm::IntegerConstant) or last_compiled.is_a?(Vm::ObjectConstant)
|
||||
return_reg.load into , last_compiled if last_compiled.register_symbol != return_reg.register_symbol
|
||||
return_reg.load function , last_compiled if last_compiled.register_symbol != return_reg.register_symbol
|
||||
else
|
||||
return_reg.move( into, last_compiled ) if last_compiled.register_symbol != return_reg.register_symbol
|
||||
return_reg.move( function, last_compiled ) if last_compiled.register_symbol != return_reg.register_symbol
|
||||
end
|
||||
function.set_return return_reg
|
||||
|
||||
|
@@ -2,6 +2,7 @@ module Ast
|
||||
class ReturnExpression < Expression
|
||||
# attr_reader :expression
|
||||
def compile context
|
||||
into = context.function
|
||||
puts "compiling return expression #{expression}, now return in return_regsiter"
|
||||
expression_value = expression.compile(context)
|
||||
# copied from function expression: TODO make function
|
||||
|
@@ -4,12 +4,13 @@ module Ast
|
||||
def compile context
|
||||
into = context.function
|
||||
while_block = into.new_block "while"
|
||||
ret = while_block.new_block "return"
|
||||
ret = into.new_block "return"
|
||||
into.insert_at while_block
|
||||
|
||||
puts "compiling while condition #{condition}"
|
||||
cond_val = condition.compile(context)
|
||||
while_block.b ret , condition_code: cond_val.not_operator
|
||||
while_block.branch = ret
|
||||
into.b ret , condition_code: cond_val.not_operator
|
||||
into.insertion_point.branch = ret
|
||||
|
||||
last = nil
|
||||
|
||||
@@ -17,7 +18,9 @@ module Ast
|
||||
puts "compiling in while #{part}"
|
||||
last = part.compile(context)
|
||||
end
|
||||
while_block.b while_block
|
||||
into.b while_block
|
||||
into.insertion_point.branch = while_block
|
||||
|
||||
puts "compile while end"
|
||||
into.insert_at ret
|
||||
return last
|
||||
|
Reference in New Issue
Block a user