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 # assumes string in standard receiver reg (r2) and moves them down for the syscall
def write_stdout function #, string def write_stdout function #, string
# TODO save and restore r0 # TODO save and restore r0
function.mov( :r0 , 1 ) # 1 == stdout function.mov( :r0 , 1 ) # 1 == stdout
function.mov( :r1 , :r2 ) function.mov( :r1 , RECEIVER_REG )
function.mov( :r2 , :r3 ) function.mov( RECEIVER_REG , :r3 )
syscall( function.insertion_point , 4 ) # 4 == write syscall( function.insertion_point , 4 ) # 4 == write
end 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) index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
get_function.push( [me] ) get_function.push( [me] )
get_function.call( index_function ) 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.insert_at after_body
get_function.pop([me]) get_function.pop([me])

View File

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

View File

@ -75,10 +75,10 @@ module Vm
end end
def new_local type = Vm::Integer def new_local type = Vm::Integer
register = args.length + 1 + @locals.length # one for the receiver implicit arg register = args.length + 3 + @locals.length # three for the receiver, return and type regs
l = type.new(register + 1) # one for the type register 0, TODO add type as arg0 implicitly l = type.new(register) #so start at r3
puts "new local #{l.register_symbol}" 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 @locals << l
l l
end end

View File

@ -44,7 +44,7 @@ module Fragments
function.assemble io function.assemble io
assembly = io.string assembly = io.string
# use this for getting the bytes to compare to : # use this for getting the bytes to compare to :
#puts bytes(assembly) puts bytes(assembly)
assembly.bytes.each_with_index do |byte , index| assembly.bytes.each_with_index do |byte , index|
is = @should[index] is = @should[index]
assert_equal Fixnum , is.class , "@#{index.to_s(16)} = #{is}" assert_equal Fixnum , is.class , "@#{index.to_s(16)} = #{is}"

View File

@ -10,7 +10,7 @@ def foo(x)
end end
3.foo( 4 ) 3.foo( 4 )
HERE HERE
@should = [0x0,0x40,0x2d,0xe9,0x5,0x20,0xa0,0xe3,0x2,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x5,0x20,0xa0,0xe3,0x2,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8] @should = [0x0,0x40,0x2d,0xe9,0x5,0x0,0xa0,0xe3,0x0,0x80,0xbd,0xe8]
@output = "" @output = ""
parse parse
@target = [:Object , :foo] @target = [:Object , :foo]

View File

@ -7,7 +7,7 @@ class TestHello < MiniTest::Test
@string_input = <<HERE @string_input = <<HERE
"Hello Raisa, I am crystal".putstring() "Hello Raisa, I am crystal".putstring()
HERE HERE
@should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8] @should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0xa0,0xe3,0x2,0x10,0xa0,0xe1,0x3,0x20,0xa0,0xe1,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8]
@output = "Hello Raisa, I am crystal " @output = "Hello Raisa, I am crystal "
@target = [:Object , :putstring] @target = [:Object , :putstring]
parse parse

View File

@ -15,7 +15,7 @@ end
itest(20) itest(20)
HERE HERE
@should = [0x0,0x40,0x2d,0xe9,0xc,0x0,0x51,0xe3,0x5,0x0,0x0,0xba,0x2,0x0,0x2d,0xe9,0x3c,0x10,0x8f,0xe2,0x8,0x20,0xa0,0xe3,0x7,0x0,0x0,0xeb,0x2,0x0,0xbd,0xe8,0x4,0x0,0x0,0xea,0x2,0x0,0x2d,0xe9,0x2c,0x10,0x8f,0xe2,0x8,0x20,0xa0,0xe3,0x1,0x0,0x0,0xeb,0x2,0x0,0xbd,0xe8,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0xc,0x0,0x51,0xe3,0x5,0x0,0x0,0xba,0x2,0x0,0x2d,0xe9,0x3c,0x10,0x8f,0xe2,0x8,0x20,0xa0,0xe3,0x7,0x0,0x0,0xeb,0x2,0x0,0xbd,0xe8,0x4,0x0,0x0,0xea,0x2,0x0,0x2d,0xe9,0x2c,0x10,0x8f,0xe2,0x8,0x20,0xa0,0xe3,0x1,0x0,0x0,0xeb,0x2,0x0,0xbd,0xe8,0x0,0x80,0xbd,0xe8] @should = [0x0,0x40,0x2d,0xe9,0xc,0x0,0x53,0xe3,0x3,0x0,0x0,0xba,0x44,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0x4,0x0,0x0,0xeb,0x2,0x0,0x0,0xea,0x3c,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0x0,0x0,0x0,0xeb,0x0,0x80,0xbd,0xe8]
@output = "else " @output = "else "
@target = [:Object , :itest] @target = [:Object , :itest]
parse parse