diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index a968b50c..02d44725 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -86,7 +86,7 @@ module Arm end end - def translate_OperatorInstruction code + def translate_OperatorInstruction( code ) left = code.left right = code.right case code.operator.to_s diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index 787c24aa..ae67f2f6 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -150,7 +150,7 @@ module Risc Dictionary: {keys: :List , values: :List } , CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } , TypedMethod: {name: :Word, source: :Object, risc_instructions: :Object, - cpu_instructions: :Object, binary: :BinaryCode, + cpu_instructions: :Object, binary: :BinaryCode, arguments: :Type , for_type: :Type, frame: :Type } , } end @@ -183,7 +183,7 @@ module Risc end obj = space.get_class_by_name(:Integer) - [ :putint, :mod4, :div10].each do |f| #mod4 is just a forward declaration + [ :putint, :mod4, :div10, :+].each do |f| #mod4 is just a forward declaration obj.instance_type.add_method Builtin::Integer.send(f , nil) end end diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 9f7587a9..bb10b5ae 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -15,7 +15,20 @@ module Risc return compiler.method end + def +( context ) + source = "plus" + compiler = compiler_for(:Integer,:+ ,{other: :int}) + me , other = self_and_int_arg(compiler,source) + # reduce me and other to integers + compiler.add_slot_to_reg( source , me , 1 , me) + compiler.add_slot_to_reg( source , other , 1 , other) + compiler.add_code Risc.op( source , :+ , me , other) + #TODO must get an Integer and put the value there then return the integer (object not value) + # and put it back into the return value + compiler.add_reg_to_slot( source , me , :message , :return_value) + return compiler.method + end def div10( context ) s = "div_10" compiler = compiler_for(:Integer,:div10 ,{}) diff --git a/lib/risc/instructions/function_call.rb b/lib/risc/instructions/function_call.rb index f57b56ba..f7293ac2 100644 --- a/lib/risc/instructions/function_call.rb +++ b/lib/risc/instructions/function_call.rb @@ -20,16 +20,16 @@ module Risc Risc::FunctionCall.new( source , method , register) end - def self.issue_call( compiler , callee ) - callee_name = callee.name - return_label = Risc.label("_return_label #{callee_name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) - ret_tmp = compiler.use_reg(:Label) - compiler.add_load_constant("#{callee_name} load ret", return_label , ret_tmp) - compiler.add_reg_to_slot("#{callee_name} store ret", ret_tmp , :new_message , :return_address) - compiler.add_transfer("#{callee_name} move new message", Risc.new_message_reg , Risc.message_reg ) - compiler.add_function_call( "#{callee_name} call" , callee ) - compiler.add_code return_label - compiler.add_transfer("#{callee_name} remove new message", Risc.message_reg , Risc.new_message_reg ) - compiler.add_slot_to_reg("#{callee_name} restore message" , :new_message , :caller , :message ) - end + # def self.issue_call( compiler , callee ) + # callee_name = callee.name + # return_label = Risc.label("_return_label #{callee_name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) + # ret_tmp = compiler.use_reg(:Label) + # compiler.add_load_constant("#{callee_name} load ret", return_label , ret_tmp) + # compiler.add_reg_to_slot("#{callee_name} store ret", ret_tmp , :new_message , :return_address) + # compiler.add_transfer("#{callee_name} move new message", Risc.new_message_reg , Risc.message_reg ) + # compiler.add_function_call( "#{callee_name} call" , callee ) + # compiler.add_code return_label + # compiler.add_transfer("#{callee_name} remove new message", Risc.message_reg , Risc.new_message_reg ) + # compiler.add_slot_to_reg("#{callee_name} restore message" , :new_message , :caller , :message ) + # end end diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index cef409ca..1f96eb3e 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -27,7 +27,7 @@ class TestSpace < MiniTest::Test def test_integer int = Parfait.object_space.get_class_by_name :Integer - assert_equal 3, int.instance_type.method_names.get_length + assert_equal 4, int.instance_type.method_names.get_length end def test_classes_class diff --git a/test/risc/interpreter/test_plus.rb b/test/risc/interpreter/test_plus.rb index b8cc0730..3c6d498c 100644 --- a/test/risc/interpreter/test_plus.rb +++ b/test/risc/interpreter/test_plus.rb @@ -1,29 +1,28 @@ require_relative "helper" module Risc - class PlusTest < MiniTest::Test + class InterpreterPlusTest < MiniTest::Test include Ticker def setup - @string_input = <