fixes the if test (regs again)
This commit is contained in:
parent
b125a7c5c7
commit
eef6744827
@ -93,11 +93,13 @@ module Arm
|
|||||||
entry
|
entry
|
||||||
end
|
end
|
||||||
|
|
||||||
# assumes string in r0 and r1 and moves them along for the syscall
|
# assumes string in standard receiver reg (r2) and moves them down for the syscall
|
||||||
def write_stdout block
|
def write_stdout function #, string
|
||||||
# TODO save and restore r0
|
# TODO save and restore r0
|
||||||
block.do_add mov( :r0 , 1 ) # 1 == stdout
|
function.mov( :r0 , 1 ) # 1 == stdout
|
||||||
syscall( block , 4 )
|
function.mov( :r1 , :r2 )
|
||||||
|
function.mov( :r2 , :r3 )
|
||||||
|
syscall( function.insertion_point , 4 ) # 4 == write
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -124,12 +126,13 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def syscall block , num
|
def syscall block , num
|
||||||
#small todo, is this actually correct for all (that they return int)
|
# This is very arm specific, syscall number is passed in r7, other arguments like a c call ie 0 and up
|
||||||
sys_and_ret = Vm::Integer.new( Vm::RegisterMachine.instance.return_register )
|
sys = Vm::Integer.new( Vm::RegisterUse.new(:r7) )
|
||||||
block.do_add mov( sys_and_ret , num )
|
ret = Vm::Integer.new( Vm::RegisterUse.new(RETURN_REG) )
|
||||||
|
block.do_add mov( sys , num )
|
||||||
block.do_add swi( 0 )
|
block.do_add swi( 0 )
|
||||||
#todo should write type into r0 according to syscall
|
#todo should write type into r1 according to syscall
|
||||||
sys_and_ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -5,9 +5,9 @@ module Ast
|
|||||||
f = context.function
|
f = context.function
|
||||||
# to execute the logic as the if states it, the blocks are the other way around
|
# 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
|
# 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"
|
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}"
|
puts "compiling if condition #{cond}"
|
||||||
cond_val = cond.compile(context)
|
cond_val = cond.compile(context)
|
||||||
|
@ -5,13 +5,9 @@ module Core
|
|||||||
# We use this module syntax to avoid the (ugly) self (also eases searching).
|
# We use this module syntax to avoid the (ugly) self (also eases searching).
|
||||||
module ClassMethods
|
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
|
def putstring context
|
||||||
function = Vm::Function.new(:putstring , Vm::Integer , [] )
|
function = Vm::Function.new(:putstring , Vm::Integer , [] )
|
||||||
block = function.body
|
ret = Vm::RegisterMachine.instance.write_stdout(function)
|
||||||
# should be another level of indirection, ie write(io,str)
|
|
||||||
ret = Vm::RegisterMachine.instance.write_stdout(block)
|
|
||||||
function.set_return ret
|
function.set_return ret
|
||||||
function
|
function
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user