fix dynamic call

which had the method in the regsiter, not the binary.
Single SlotToReg added (and some tests)
Which amazingly fixed all broken binary tests
This commit is contained in:
Torsten Ruger 2018-06-25 00:19:43 +03:00
parent 068bda492c
commit b804be5f70
3 changed files with 29 additions and 10 deletions

View File

@ -3,6 +3,7 @@ module Arm
# Implemented: immediate offset with offset=0 # Implemented: immediate offset with offset=0
class MemoryInstruction < Instruction class MemoryInstruction < Instruction
attr_reader :left , :right , :result
def initialize result , left , right = nil , attributes = {} def initialize result , left , right = nil , attributes = {}
super(nil) super(nil)

View File

@ -68,7 +68,12 @@ module Arm
def translate_FunctionReturn( code ) def translate_FunctionReturn( code )
ArmMachine.mov( :pc , code.register) ArmMachine.mov( :pc , code.register)
end end
alias :translate_DynamicJump :translate_FunctionReturn def translate_DynamicJump(code)
index = Parfait.object_space.get_class_by_name(:TypedMethod).instance_type.variable_index(:binary)
codes = ArmMachine.ldr( code.register , code.register , arm_index(index) )
codes << ArmMachine.mov( :pc , code.register)
codes
end
def translate_LoadConstant( code ) def translate_LoadConstant( code )
constant = code.constant constant = code.constant

View File

@ -1,17 +1,30 @@
require_relative 'helper' require_relative 'helper'
module Arm module Arm
class TestStack < MiniTest::Test class TestTranslator < MiniTest::Test
def test_init def setup
assert Translator.new Risc.machine.boot
@jump = Risc::DynamicJump.new("" , :r1)
@codes = Translator.new.translate @jump
end end
def test_slot_class
def test_dynamic assert_equal MemoryInstruction , @codes.class
trans = Translator.new end
jump = Risc::DynamicJump.new("" , :r1) def test_slot_left
res = trans.translate jump assert_equal :r1 , @codes.left
assert :r1 , res.from end
def test_slot_result
assert_equal :r1 , @codes.left
end
def test_slot_right
assert_equal 16 , @codes.right
end
def test_next_from
assert_equal :r1 , @codes.next.from.symbol
end
def test_next_class
assert_equal MoveInstruction , @codes.next.class
end end
end end
end end