From 506f98da5a3ffac4785775c4a465c5a47f96e7fb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 12 Jun 2014 09:07:03 +0300 Subject: [PATCH] fixed foo and hello, next putint --- lib/arm/arm_machine.rb | 6 +++--- lib/boot/object.rb | 2 +- lib/core/kernel.rb | 12 +++++------- lib/vm/function.rb | 6 +++--- test/fragments/helper.rb | 2 +- test/fragments/test_foo.rb | 2 +- test/fragments/test_hello.rb | 2 +- test/fragments/test_if.rb | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 4f943045..7f49b58a 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -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 diff --git a/lib/boot/object.rb b/lib/boot/object.rb index 46b523c8..7100381b 100644 --- a/lib/boot/object.rb +++ b/lib/boot/object.rb @@ -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]) diff --git a/lib/core/kernel.rb b/lib/core/kernel.rb index 3efbfda8..7206a746 100644 --- a/lib/core/kernel.rb +++ b/lib/core/kernel.rb @@ -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 diff --git a/lib/vm/function.rb b/lib/vm/function.rb index 53b37367..4afddd13 100644 --- a/lib/vm/function.rb +++ b/lib/vm/function.rb @@ -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 diff --git a/test/fragments/helper.rb b/test/fragments/helper.rb index 625bfacc..209fe202 100644 --- a/test/fragments/helper.rb +++ b/test/fragments/helper.rb @@ -44,7 +44,7 @@ module Fragments function.assemble io assembly = io.string # use this for getting the bytes to compare to : - #puts bytes(assembly) + puts bytes(assembly) assembly.bytes.each_with_index do |byte , index| is = @should[index] assert_equal Fixnum , is.class , "@#{index.to_s(16)} = #{is}" diff --git a/test/fragments/test_foo.rb b/test/fragments/test_foo.rb index a04ce48e..b9f542db 100644 --- a/test/fragments/test_foo.rb +++ b/test/fragments/test_foo.rb @@ -10,7 +10,7 @@ def foo(x) end 3.foo( 4 ) 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 = "" parse @target = [:Object , :foo] diff --git a/test/fragments/test_hello.rb b/test/fragments/test_hello.rb index 78491085..57ebfd71 100644 --- a/test/fragments/test_hello.rb +++ b/test/fragments/test_hello.rb @@ -7,7 +7,7 @@ class TestHello < MiniTest::Test @string_input = <