fixes the if test (regs again)
This commit is contained in:
parent
b125a7c5c7
commit
eef6744827
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user