From d6b5d461651809b6fa3557cc8eb5de4c0a9672fb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 14 May 2014 12:02:54 +0300 Subject: [PATCH] while compiles. jo --- lib/arm/arm_machine.rb | 9 +++++++-- lib/ast/call_site_expression.rb | 1 - lib/vm/call_site.rb | 3 +-- lib/vm/values.rb | 5 +++++ test/test_runner.rb | 11 +++++------ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 1ecd9664..d953c713 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -26,10 +26,15 @@ module Arm end def integer_load block , left , right - reg = "r#{left.register}".to_sym - block.add_code mov( :left => reg , :right => right ) + block.add_code mov( :left => left , :right => right ) left end + + def integer_move block , left , right + block.add_code mov( :left => left , :right => right ) + left + end + def string_load block , str_lit , reg block.add_code add( :left => "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit #second arg is a hack to get the stringlength without coding diff --git a/lib/ast/call_site_expression.rb b/lib/ast/call_site_expression.rb index 343bc7c8..5edd6adc 100644 --- a/lib/ast/call_site_expression.rb +++ b/lib/ast/call_site_expression.rb @@ -13,7 +13,6 @@ module Ast call = Vm::CallSite.new( name , params , function) call.load_args into call.do_call into - call end def inspect diff --git a/lib/vm/call_site.rb b/lib/vm/call_site.rb index 6c9958ec..17499556 100644 --- a/lib/vm/call_site.rb +++ b/lib/vm/call_site.rb @@ -16,8 +16,7 @@ module Vm if arg.is_a? IntegerConstant Vm::Integer.new(index).load into , arg else - raise "no #{arg.inspect}" if arg.register != index - #arg.load( into , index ) + arg.move( into , index ) if arg.register != index end end end diff --git a/lib/vm/values.rb b/lib/vm/values.rb index 4a4ae3f1..55390eb0 100644 --- a/lib/vm/values.rb +++ b/lib/vm/values.rb @@ -73,6 +73,11 @@ module Vm def load block , right CMachine.instance.integer_load block , self , right end + + def move block , right + CMachine.instance.integer_move block , self , right + end + end end require_relative "constants" \ No newline at end of file diff --git a/test/test_runner.rb b/test/test_runner.rb index 2b2e70c1..711f63e6 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -23,15 +23,14 @@ class TestRunner < MiniTest::Test program = Vm::Program.new "Arm" syntax = parser.parse_with_debug(string) parts = Parser::Transform.new.apply(syntax) - # file is a list of expressions, al but the last must be a function + # file is a list of expressions, all but the last must be a function # and the last is wrapped as a main parts.each_with_index do |part,index| - if index = parts.length - expr = part.compile( program.context , nil ) - program.main = expr - else + if index == (parts.length - 1) expr = part.compile( program.context , program.main ) - raise "should be function definition for now" unless expr.is_a? Function + else + expr = part.compile( program.context , nil ) + raise "should be function definition for now" unless expr.is_a? Vm::Function program.add_function expr end end