fixed foo and hello, next putint

This commit is contained in:
Torsten Ruger
2014-06-12 09:07:03 +03:00
parent eef6744827
commit 506f98da5a
8 changed files with 16 additions and 18 deletions

View File

@ -96,9 +96,9 @@ module Arm
# assumes string in standard receiver reg (r2) and moves them down for the syscall
def write_stdout function #, string
# TODO save and restore r0
function.mov( :r0 , 1 ) # 1 == stdout
function.mov( :r1 , :r2 )
function.mov( :r2 , :r3 )
function.mov( :r0 , 1 ) # 1 == stdout
function.mov( :r1 , RECEIVER_REG )
function.mov( RECEIVER_REG , :r3 )
syscall( function.insertion_point , 4 ) # 4 == write
end

View File

@ -25,7 +25,7 @@ module Boot
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
get_function.push( [me] )
get_function.call( index_function )
after_body = get_function.new_block("#{get_function.insertion_point.name}_a")
after_body = get_function.new_block("after_index")
get_function.insert_at after_body
get_function.pop([me])

View File

@ -20,19 +20,17 @@ module Core
moved_int = putint_function.new_local
utoa = context.object_space.get_or_create_class(:Object).get_or_create_function(:utoa)
putint_function.instance_eval do
mov( moved_int , int ) #move arg up
#body.a buffer => int # string to write to
add( int , buffer ,nil ) # string to write to
add(int , int , buffer.length - 3)
mov( moved_int , int ) # move arg up
add( int , buffer ,nil ) # string to write to (add string address to pc)
add( int , int , buffer.length - 3) # 3 for good measure , ahem.
call( utoa )
after = new_block("#{body.name}_a")
after = new_block("after_call")
insert_at after
# And now we "just" have to print it, using the write_stdout
add( int , buffer , nil ) # string to write to
mov( moved_int , buffer.length )
Vm::RegisterMachine.instance.write_stdout(after)
end
Vm::RegisterMachine.instance.write_stdout(putint_function)
putint_function
end

View File

@ -75,10 +75,10 @@ module Vm
end
def new_local type = Vm::Integer
register = args.length + 1 + @locals.length # one for the receiver implicit arg
l = type.new(register + 1) # one for the type register 0, TODO add type as arg0 implicitly
register = args.length + 3 + @locals.length # three for the receiver, return and type regs
l = type.new(register) #so start at r3
puts "new local #{l.register_symbol}"
# raise "Register overflow in function #{name}" if l.register > 6
raise "Register overflow in function #{name}" if register >= 13 # yep, 13 is bad luck
@locals << l
l
end