start on dynamic call

This commit is contained in:
Torsten Ruger 2017-12-05 21:46:37 +02:00
parent ba304f51df
commit b7701d0d5e
2 changed files with 30 additions and 11 deletions

View File

@ -70,6 +70,7 @@ module Vool
def flatten def flatten
raise "flat" raise "flat"
end end
# check that current type is the cached type # check that current type is the cached type
# if not, change and find method for the type (simple_call to resolve_method) # if not, change and find method for the type (simple_call to resolve_method)
# conceptually easy in ruby, but we have to compile that "easy" ruby # conceptually easy in ruby, but we have to compile that "easy" ruby
@ -77,14 +78,15 @@ module Vool
# if cached_type != current_type # if cached_type != current_type
# cached_type = current_type # cached_type = current_type
# cached_method = current_type.resolve_method(method.name) # cached_method = current_type.resolve_method(method.name)
if_true = [build_type_cache_update , build_method_cache_update] #@if_true.to_mom( in_method ) #find and assign if_true = [build_type_cache_update , build_method_cache_update]
#@if_true.to_mom( in_method ) #find and assign
[Mom::IfStatement.new( build_condition , if_true )] [Mom::IfStatement.new( build_condition , if_true )]
end end
# this may look like a simple_call, but the difference is that we don't know # this may look like a simple_call, but the difference is that we don't know
# the method until run-time. Alas the setup is the same # the method until run-time. Alas the setup is the same
def call_cached_method(in_method) def call_cached_method(in_method)
message_setup(in_method) << Mom::DynamicCall.new( method_var_name) message_setup(in_method) << Mom::DynamicCall.new(method_var_name)
end end
private private
# cached type and method are stored in the frame as local variables. # cached type and method are stored in the frame as local variables.
@ -92,6 +94,7 @@ module Vool
def create_tmps(in_method) def create_tmps(in_method)
in_method.create_tmp in_method.create_tmp
end end
# we store the (one!) cached mathod in the frame, under the name that this # we store the (one!) cached mathod in the frame, under the name that this
# method returns # method returns
def method_var_name def method_var_name
@ -107,10 +110,10 @@ module Vool
Mom::NotSameCheck.new(cached_type , current_type) Mom::NotSameCheck.new(cached_type , current_type)
end end
def build_type_cache_update def build_type_cache_update
1
end end
def build_method_cache_update def build_method_cache_update
1
end end
end end
end end

View File

@ -7,12 +7,15 @@ module Vool
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( "arg.mod4").first @stats = compile_first_method( "arg.mod4").first
@first = @stats.first @first, @second , @third ,@fourth= @stats[0],@stats[1],@stats[2],@stats[3]
end end
def test_compiles_not_array def test_compiles_not_array
assert Array != @stats.class , @stats assert Array != @stats.class , @stats
end end
def test_four_instructions_are_returned
assert_equal 4 , @stats.length
end
def test_if_first def test_if_first
assert_equal Mom::IfStatement , @first.class , @first assert_equal Mom::IfStatement , @first.class , @first
end end
@ -23,14 +26,27 @@ module Vool
assert @first.if_true , @first assert @first.if_true , @first
end end
def test_if_true_not_empty def test_if_true_not_empty
assert @first.if_true.first , @first assert @first.if_true.first , @first.to_rxf
end end
def test_slot_is_set def test_if_true_not_empty
assert_equal 1 , @stats , @stats.to_rxf assert @first.if_true.first , @first.to_rxf
end end
def est_two_instructions_are_returned def test_setup_second
assert_equal 2 , @stats.length assert_equal Mom::MessageSetup , @second.class , @second.to_rxf
end end
def test_transfer_third
assert_equal Mom::ArgumentTransfer , @third.class , @third.to_rxf
end
def test_call_third
assert_equal Mom::DynamicCall , @fourth.class , @fourth.to_rxf
end
def test_call_third
assert @fourth.method_var_name.start_with?("cached_") , @fourth.to_rxf
end
def est_receiver_move_class def est_receiver_move_class
assert_equal Mom::SlotConstant, @first.class assert_equal Mom::SlotConstant, @first.class
end end