to_risc for NotSameCheck

which is only used in call cache checking
some fixing, needed to add a abel for the cache check jump
This commit is contained in:
Torsten Ruger 2018-03-21 12:38:28 +05:30
parent 12c71fa394
commit fa797f722d
5 changed files with 30 additions and 13 deletions

View File

@ -9,12 +9,18 @@ module Mom
class NotSameCheck < Check
attr_reader :left , :right
def initialize(left, right)
def initialize(left, right , label)
super(label)
@left , @right = left , right
end
def to_risc(context)
Risc::Label.new(self,"NotSameCheck")
# basically move both left and right values into register and issue a
# risc comparison
def to_risc(compiler)
l_val = left.to_register(compiler, self)
r_val = right.to_register(compiler, self)
check = Risc::NotSame.new(self, l_val.register, r_val.register, false_jump.to_risc(compiler))
l_val << r_val << check
end
end
end

View File

@ -75,6 +75,14 @@ module Risc
end
end
# branch if two registers contain different values
class NotSame < Branch
attr_reader :left , :right
def initialize(source , left , right , label)
super(source , label)
end
end
class Unconditional < Branch
end

View File

@ -95,9 +95,11 @@ module Vool
# if cached_type != current_type
# cached_type = current_type
# cached_method = current_type.resolve_method(method.name)
check = build_condition
ok = Mom::Label.new("cache_ok")
check = build_condition(ok)
check << build_type_cache_update
check << build_method_cache_update(in_method)
check << ok
end
# this may look like a simple_call, but the difference is that we don't know
@ -107,10 +109,10 @@ module Vool
end
private
def build_condition
def build_condition(ok_label)
cached_type = Mom::SlotDefinition.new(dynamic_call.cache_entry , [:cached_type])
current_type = Mom::SlotDefinition.new(:message , [:receiver , :type])
Mom::NotSameCheck.new(cached_type , current_type)
Mom::NotSameCheck.new(cached_type , current_type, ok_label)
end
def build_type_cache_update
Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , [:message , :receiver , :type])

View File

@ -26,7 +26,8 @@ module Vool
end
def test_array
check_array [SlotLoad,NotSameCheck,SlotLoad,MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,MessageSetup,ArgumentTransfer,DynamicCall] , @ins
check_array [SlotLoad, NotSameCheck, SlotLoad, MessageSetup, ArgumentTransfer, SimpleCall ,
SlotLoad, Label, MessageSetup, ArgumentTransfer, DynamicCall] , @ins
end
end

View File

@ -12,19 +12,19 @@ module Vool
end
def test_condition
assert_equal TruthCheck , @ins.next(10).class
assert_equal TruthCheck , @ins.next(11).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(10).condition.class , @ins
assert_equal SlotDefinition , @ins.next(11).condition.class , @ins
end
def test_hoisted_dynamic_call
assert_equal DynamicCall , @ins.next(8).class
assert_equal DynamicCall , @ins.next(9).class
end
def test_array
check_array [NotSameCheck, SlotLoad, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, TruthCheck, Label ,
MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label, MessageSetup ,
ArgumentTransfer, SimpleCall, Label] , @ins
Label, MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, TruthCheck ,
Label, MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label ,
MessageSetup, ArgumentTransfer, SimpleCall, Label] , @ins
end
end