diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 19061535..ea87c804 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -23,8 +23,7 @@ module Risc compiler.add_slot_to_reg( source + "2" , me , Parfait::Integer.integer_index , me) compiler.add_slot_to_reg( source + "3", other , Parfait::Integer.integer_index , other) compiler.add_code Risc.op( source + "4", :+ , me , other) - compiler.add_new_int(other) - compiler.add_reg_to_slot( source + "5" , me , other , Parfait::Integer.integer_index) + compiler.add_new_int(me , other) compiler.add_reg_to_slot( source + "5" , other , :message , :return_value) return compiler.method @@ -80,6 +79,10 @@ module Risc compiler.add_code Risc.op( s , :>> , tmp , const ) # return q + tmp compiler.add_code Risc.op( s , :+ , q , tmp ) + + compiler.add_new_int(me , other) + compiler.add_reg_to_slot( source + "5" , other , :message , :return_value) + compiler.add_reg_to_slot( s , q , :message , :return_value) compiler.add_mom( Mom::ReturnSequence.new) return compiler.method diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 77a6abe2..4da45ecb 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -132,17 +132,18 @@ module Risc @regs.clear end - # grab an integer from space and stick it in the register. - def add_new_int( register ) + # move a machine int from register "from" to a Parfait::Integer in register "to" + # have to grab an integer from space and stick it in the "to" register first. + def add_new_int( from, to ) source = "add_new_int " space = use_reg(:Space) int = use_reg(:Integer) space_i = Risc.resolve_to_index(:Space, :next_integer) add_load_constant( source + "space" , Parfait.object_space , space ) add_slot_to_reg( source + "next_i1" , space , space_i , register) - add_slot_to_reg( source + "next_i2" , register , Risc.resolve_to_index(:Integer, :next_integer) , int) + add_slot_to_reg( source + "next_i2" , to , Risc.resolve_to_index(:Integer, :next_integer) , int) add_reg_to_slot( source + "store link" , int , space , space_i ) - # store 2nd next_i to spce next_i + add_reg_to_slot( source + "store value" , from , to , Parfait::Integer.integer_index) end def add_constant(const) Risc.machine.add_constant(const) diff --git a/test/risc/interpreter/test_return_call.rb b/test/risc/interpreter/test_div10.rb similarity index 94% rename from test/risc/interpreter/test_return_call.rb rename to test/risc/interpreter/test_div10.rb index aef9ddb5..cf2a43b3 100644 --- a/test/risc/interpreter/test_return_call.rb +++ b/test/risc/interpreter/test_div10.rb @@ -1,7 +1,7 @@ require_relative "helper" module Risc - class InterpreterReturnCall < MiniTest::Test + class InterpreterDiv10 < MiniTest::Test include Ticker def setup @@ -33,7 +33,8 @@ module Risc SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall, NilClass] - #assert_equal 1 , get_return + assert_equal Parfait::Integer , get_return.class + #assert_equal 1 , get_return end def test_call_main diff --git a/test/risc/interpreter/test_plus.rb b/test/risc/interpreter/test_plus.rb index 114f4724..1526511f 100644 --- a/test/risc/interpreter/test_plus.rb +++ b/test/risc/interpreter/test_plus.rb @@ -5,7 +5,7 @@ module Risc include Ticker def setup - @string_input = as_main("a = 5 + 5;return a") + @string_input = as_main("return 5 + 5") super end diff --git a/test/risc/interpreter/test_byte_to_reg.rb b/test/risc/interpreter/wip/test_byte_to_reg.rb similarity index 98% rename from test/risc/interpreter/test_byte_to_reg.rb rename to test/risc/interpreter/wip/test_byte_to_reg.rb index efaab7b5..f3cd8b48 100644 --- a/test/risc/interpreter/test_byte_to_reg.rb +++ b/test/risc/interpreter/wip/test_byte_to_reg.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class TestInterpretRegToByte < MiniTest::Test diff --git a/test/risc/interpreter/test_called_if.rb b/test/risc/interpreter/wip/test_called_if.rb similarity index 98% rename from test/risc/interpreter/test_called_if.rb rename to test/risc/interpreter/wip/test_called_if.rb index 7c67b813..93c2e071 100644 --- a/test/risc/interpreter/test_called_if.rb +++ b/test/risc/interpreter/wip/test_called_if.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class IfCalledTest < MiniTest::Test diff --git a/test/risc/interpreter/test_change.rb b/test/risc/interpreter/wip/test_change.rb similarity index 97% rename from test/risc/interpreter/test_change.rb rename to test/risc/interpreter/wip/test_change.rb index 04375da4..b8ed6f3a 100644 --- a/test/risc/interpreter/test_change.rb +++ b/test/risc/interpreter/wip/test_change.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class AddChange < MiniTest::Test diff --git a/test/risc/interpreter/test_mult.rb b/test/risc/interpreter/wip/test_mult.rb similarity index 96% rename from test/risc/interpreter/test_mult.rb rename to test/risc/interpreter/wip/test_mult.rb index 9a8d056e..53dcb84a 100644 --- a/test/risc/interpreter/test_mult.rb +++ b/test/risc/interpreter/wip/test_mult.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class MultTest < MiniTest::Test diff --git a/test/risc/interpreter/test_puts.rb b/test/risc/interpreter/wip/test_puts.rb similarity index 98% rename from test/risc/interpreter/test_puts.rb rename to test/risc/interpreter/wip/test_puts.rb index 62e4cbe4..1950792d 100644 --- a/test/risc/interpreter/test_puts.rb +++ b/test/risc/interpreter/wip/test_puts.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class TestPuts < MiniTest::Test diff --git a/test/risc/interpreter/test_reg_to_byte.rb b/test/risc/interpreter/wip/test_reg_to_byte.rb similarity index 98% rename from test/risc/interpreter/test_reg_to_byte.rb rename to test/risc/interpreter/wip/test_reg_to_byte.rb index ab382295..5f8ea429 100644 --- a/test/risc/interpreter/test_reg_to_byte.rb +++ b/test/risc/interpreter/wip/test_reg_to_byte.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class TestInterpretByteToReg < MiniTest::Test diff --git a/test/risc/interpreter/test_simple_if.rb b/test/risc/interpreter/wip/test_simple_if.rb similarity index 98% rename from test/risc/interpreter/test_simple_if.rb rename to test/risc/interpreter/wip/test_simple_if.rb index ebd699cc..d7aaab67 100644 --- a/test/risc/interpreter/test_simple_if.rb +++ b/test/risc/interpreter/wip/test_simple_if.rb @@ -1,4 +1,4 @@ -require_relative "helper" +require_relative "../helper" module Risc class IfSimpleTest < MiniTest::Test