fix bug in slot_load and definition
move parfait helper for reuse
This commit is contained in:
parent
253d2fead8
commit
f85fe8a2cb
@ -65,8 +65,8 @@ module Mom
|
||||
compiler.add_code const
|
||||
raise "Can't have slots into Constants" if slots.length > 0
|
||||
when Parfait::Object , Risc::Label
|
||||
const = Risc::SlotToReg.new( source , right ,index, right)
|
||||
compiler.add_code const Risc.load_constant(source, known_object , right)
|
||||
const = const = Risc.load_constant(source, known_object , right)
|
||||
compiler.add_code const
|
||||
if slots.length > 0
|
||||
# desctructively replace the existing value to be loaded if more slots
|
||||
compiler.add_code Risc.slot_to_reg( source , right ,slots[0], right)
|
||||
|
@ -39,7 +39,6 @@ module Mom
|
||||
end
|
||||
|
||||
def to_risc(compiler)
|
||||
#puts "RISC #{self}"
|
||||
const_reg = @right.to_register(compiler , original_source)
|
||||
left_slots = @left.slots
|
||||
case @left.known_object
|
||||
@ -48,7 +47,7 @@ module Mom
|
||||
when Parfait::CacheEntry
|
||||
left = compiler.use_reg( :CacheEntry )
|
||||
compiler.add_code Risc.load_constant(original_source, @left.known_object , left)
|
||||
compiler.add_code Risc.reg_to_slot(original_source, const.register , left, left_slots.first)
|
||||
compiler.add_code Risc.reg_to_slot(original_source, const_reg , left, left_slots.first)
|
||||
else
|
||||
raise "We have left #{@left.known_object}"
|
||||
end
|
||||
|
@ -21,10 +21,9 @@ module Risc
|
||||
@register = register
|
||||
@array = array
|
||||
@index = index
|
||||
# raise "index 0 " if index < 0
|
||||
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
|
||||
raise "Not integer or reg index #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
|
||||
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
|
||||
raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
|
||||
raise "Not slot/register #{array}" unless RegisterValue.look_like_reg(array)
|
||||
end
|
||||
attr_accessor :register , :array , :index
|
||||
|
||||
|
@ -11,12 +11,14 @@ module Mom
|
||||
@instructions = @compiler.instructions
|
||||
end
|
||||
|
||||
def test_ins_next_class
|
||||
def test_ins_next_classes
|
||||
assert_equal Risc::SlotToReg , @instructions[0].class
|
||||
assert_equal Risc::SlotToReg , @instructions[1].class
|
||||
assert_equal Risc::SlotToReg , @instructions[2].class
|
||||
end
|
||||
def test_ins_next_next_class
|
||||
assert_equal Risc::RegToSlot , @instructions[3].class
|
||||
assert_equal NilClass , @instructions[4].class
|
||||
end
|
||||
|
||||
def test_ins_next_reg
|
||||
|
50
test/mom/instruction/test_slot_load3.rb
Normal file
50
test/mom/instruction/test_slot_load3.rb
Normal file
@ -0,0 +1,50 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestSlotLoad3 < Parfait::ParfaitTest
|
||||
|
||||
def setup
|
||||
super
|
||||
method = make_method
|
||||
@compiler = Risc::FakeCompiler.new
|
||||
@cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
|
||||
load = SlotLoad.new( [@cache_entry , :cached_type] , [:message, :type] )
|
||||
load.to_risc(@compiler)
|
||||
@instructions = @compiler.instructions
|
||||
end
|
||||
def test_ins_next_class
|
||||
assert_equal Risc::SlotToReg , @instructions[0].class
|
||||
assert_equal Risc::LoadConstant, @instructions[1].class
|
||||
end
|
||||
|
||||
def test_ins_next_class
|
||||
assert_equal Risc::RegToSlot , @instructions[2].class
|
||||
assert_equal NilClass , @instructions[3].class
|
||||
end
|
||||
def test_ins_load
|
||||
assert_equal :r1 , @instructions[1].register.symbol
|
||||
assert_equal Parfait::CacheEntry , @instructions[1].constant.class
|
||||
end
|
||||
|
||||
def test_ins_next_reg
|
||||
assert_equal :r1 , @instructions[0].register.symbol
|
||||
end
|
||||
def test_ins_next_arr
|
||||
assert_equal :r0 , @instructions[0].array.symbol
|
||||
end
|
||||
def test_ins_next_index
|
||||
assert_equal 0 , @instructions[0].index
|
||||
end
|
||||
|
||||
def test_ins_next_2_reg
|
||||
assert_equal :r1 , @instructions[2].register.symbol
|
||||
end
|
||||
def test_ins_next_2_arr
|
||||
assert_equal :r1 , @instructions[2].array.symbol
|
||||
end
|
||||
def test_ins_next_2_index
|
||||
assert_equal 1 , @instructions[2].index
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,17 +1 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Parfait
|
||||
class ParfaitTest < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@space = Parfait.object_space
|
||||
end
|
||||
def make_method
|
||||
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
||||
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||
@method = Parfait::CallableMethod.new( :meth , @obj , @args , @frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
15
test/support/parfait_test.rb
Normal file
15
test/support/parfait_test.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module Parfait
|
||||
class ParfaitTest < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@space = Parfait.object_space
|
||||
end
|
||||
def make_method
|
||||
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
||||
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||
@method = Parfait::CallableMethod.new( :meth , @obj , @args , @frame)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user