update arm and implement most operators
multiplication wasn’t implemented and division isn’t part if arm neither is rotate by register
This commit is contained in:
parent
787f727974
commit
6f0d6d831e
@ -1,6 +1,6 @@
|
||||
GIT
|
||||
remote: git://github.com/salama/salama-arm.git
|
||||
revision: b0eba7529c37fb5f90e73c1e8e44cc60cb2c6519
|
||||
revision: bf9ba364343acd4afbe053a18126b87d73f43e94
|
||||
specs:
|
||||
salama-arm (0.3.0)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user