diff --git a/Gemfile.lock b/Gemfile.lock index 441d03e6..eb8c4d43 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/salama/salama-arm.git - revision: b0eba7529c37fb5f90e73c1e8e44cc60cb2c6519 + revision: bf9ba364343acd4afbe053a18126b87d73f43e94 specs: salama-arm (0.3.0) diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index 9e538845..6faef909 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -64,6 +64,26 @@ module Arm end end + def translate_OperatorInstruction code + left = code.left + right = code.right + case code.operator.to_s + when "+" + c = ArmMachine.add(left , left , right) + when "-" + c = ArmMachine.sub(left , left , right) + when "&" + c = ArmMachine.and(left , left , right) + when "|" + c = ArmMachine.orr(left , left , right) + when "*" + c = ArmMachine.mul(left , right , left) #arm rule about left not being result, lukily commutative + else + raise "unimplemented '#{code.operator}' #{code}" + end + c + end + # This implements branch logic, which is simply assembler branch # # The only target for a call is a Block, so we just need to get the address for the code diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb index 09ea6423..0bc44159 100644 --- a/test/parfait/test_integer.rb +++ b/test/parfait/test_integer.rb @@ -3,22 +3,26 @@ require_relative 'helper' class TestPutiRT < MiniTest::Test include RuntimeTests - def test_mod - @string_input = "return 5.mod(3)" - check_return 2 + def test_mod4 + [2,3,4,5,10,12].each do |m| + @string_input = "return #{m}.mod4()" + check_return m % 4 + end end - def test_mod2 - @string_input = "return 2.mod(4)" - check_return 2 + def test_mod10 + [2,3,4,5,10,12,55].each do |m| + @string_input = "return #{m}.mod10()" + check_return m % 10 + end end - def test_mod3 - @string_input = "return 2.mod(4)" - check_return 2 - end - def test_div - @string_input = "return 5.div(4)" - check_return 1 + + def test_div10 + [2,5,10,12 , 55 ].each do |m| + @string_input = "return #{m}.div10()" + check_return m / 10 + end end + def test_as_char1 @string_input = "return 5.as_char()" check_return 53