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
|
GIT
|
||||||
remote: git://github.com/salama/salama-arm.git
|
remote: git://github.com/salama/salama-arm.git
|
||||||
revision: b0eba7529c37fb5f90e73c1e8e44cc60cb2c6519
|
revision: bf9ba364343acd4afbe053a18126b87d73f43e94
|
||||||
specs:
|
specs:
|
||||||
salama-arm (0.3.0)
|
salama-arm (0.3.0)
|
||||||
|
|
||||||
|
@ -64,6 +64,26 @@ module Arm
|
|||||||
end
|
end
|
||||||
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
|
# 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
|
# 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
|
class TestPutiRT < MiniTest::Test
|
||||||
include RuntimeTests
|
include RuntimeTests
|
||||||
|
|
||||||
def test_mod
|
def test_mod4
|
||||||
@string_input = "return 5.mod(3)"
|
[2,3,4,5,10,12].each do |m|
|
||||||
check_return 2
|
@string_input = "return #{m}.mod4()"
|
||||||
|
check_return m % 4
|
||||||
end
|
end
|
||||||
def test_mod2
|
|
||||||
@string_input = "return 2.mod(4)"
|
|
||||||
check_return 2
|
|
||||||
end
|
end
|
||||||
def test_mod3
|
def test_mod10
|
||||||
@string_input = "return 2.mod(4)"
|
[2,3,4,5,10,12,55].each do |m|
|
||||||
check_return 2
|
@string_input = "return #{m}.mod10()"
|
||||||
|
check_return m % 10
|
||||||
end
|
end
|
||||||
def test_div
|
|
||||||
@string_input = "return 5.div(4)"
|
|
||||||
check_return 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
def test_as_char1
|
||||||
@string_input = "return 5.as_char()"
|
@string_input = "return 5.as_char()"
|
||||||
check_return 53
|
check_return 53
|
||||||
|
Loading…
Reference in New Issue
Block a user