From eef6744827406ec3fc016b41db06c788c1c4efe4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 12 Jun 2014 08:34:46 +0300 Subject: [PATCH] fixes the if test (regs again) --- lib/arm/arm_machine.rb | 21 ++++++++++++--------- lib/ast/if_expression.rb | 4 ++-- lib/core/kernel.rb | 6 +----- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 06e96081..4f943045 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -93,11 +93,13 @@ module Arm entry end - # assumes string in r0 and r1 and moves them along for the syscall - def write_stdout block + # assumes string in standard receiver reg (r2) and moves them down for the syscall + def write_stdout function #, string # TODO save and restore r0 - block.do_add mov( :r0 , 1 ) # 1 == stdout - syscall( block , 4 ) + function.mov( :r0 , 1 ) # 1 == stdout + function.mov( :r1 , :r2 ) + function.mov( :r2 , :r3 ) + syscall( function.insertion_point , 4 ) # 4 == write end @@ -124,12 +126,13 @@ module Arm end def syscall block , num - #small todo, is this actually correct for all (that they return int) - sys_and_ret = Vm::Integer.new( Vm::RegisterMachine.instance.return_register ) - block.do_add mov( sys_and_ret , num ) + # This is very arm specific, syscall number is passed in r7, other arguments like a c call ie 0 and up + sys = Vm::Integer.new( Vm::RegisterUse.new(:r7) ) + ret = Vm::Integer.new( Vm::RegisterUse.new(RETURN_REG) ) + block.do_add mov( sys , num ) block.do_add swi( 0 ) - #todo should write type into r0 according to syscall - sys_and_ret + #todo should write type into r1 according to syscall + ret end end diff --git a/lib/ast/if_expression.rb b/lib/ast/if_expression.rb index 0699a709..9a94ff1d 100644 --- a/lib/ast/if_expression.rb +++ b/lib/ast/if_expression.rb @@ -5,9 +5,9 @@ module Ast f = context.function # to execute the logic as the if states it, the blocks are the other way around # so we can the jump over the else if true ,and the else joins unconditionally after the true_block - false_block = f.new_block "if_false" - true_block = f.new_block "if_true" merge_block = f.new_block "if_merge" + true_block = f.new_block "if_true" + false_block = f.new_block "if_false" puts "compiling if condition #{cond}" cond_val = cond.compile(context) diff --git a/lib/core/kernel.rb b/lib/core/kernel.rb index 85787986..3efbfda8 100644 --- a/lib/core/kernel.rb +++ b/lib/core/kernel.rb @@ -5,13 +5,9 @@ module Core # We use this module syntax to avoid the (ugly) self (also eases searching). module ClassMethods - #TODO this is in the wrong place. It is a function that returns a function object - # while all other methods add their code into some block. --> kernel def putstring context function = Vm::Function.new(:putstring , Vm::Integer , [] ) - block = function.body - # should be another level of indirection, ie write(io,str) - ret = Vm::RegisterMachine.instance.write_stdout(block) + ret = Vm::RegisterMachine.instance.write_stdout(function) function.set_return ret function end