passing compiler to to_mom, not method

To be able to delegate scope (block/method) things later
This commit is contained in:
Torsten Ruger
2018-07-05 14:02:38 +03:00
parent 16d91f24ce
commit 3f80953385
15 changed files with 78 additions and 74 deletions

View File

@ -60,7 +60,7 @@ module Vool
@arguments.each do |arg|
block.call(arg)
end
self.block.each(block) if self.block
self.block.each(&block) if self.block
end
# lazy init this, to keep the dependency (which goes to parfait and booting) at bay
@ -71,62 +71,62 @@ module Vool
# A Send breaks down to 2 steps:
# - Setting up the next message, with receiver, arguments, and (importantly) return address
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
def to_mom( in_method )
@parfait_block = self.block.to_mom(in_method) if self.block
@receiver = SelfExpression.new(in_method.for_type) if @receiver.is_a?(SelfExpression)
def to_mom( compiler )
@parfait_block = self.block.to_mom(compiler) if self.block
@receiver = SelfExpression.new(compiler.method.for_type) if @receiver.is_a?(SelfExpression)
if(@receiver.ct_type)
simple_call(in_method)
simple_call(compiler)
else
cached_call(in_method)
cached_call(compiler)
end
end
# When used as right hand side, this tells what data to move to get the result into
# a varaible. It is (off course) the return value of the message
def slot_definition(in_method)
def slot_definition(compiler)
Mom::SlotDefinition.new(:message ,[ :return_value])
end
def message_setup(in_method,called_method)
def message_setup(compiler,called_method)
setup = Mom::MessageSetup.new( called_method )
mom_receive = @receiver.slot_definition(in_method)
mom_receive = @receiver.slot_definition(compiler)
arg_target = [:message , :next_message , :arguments]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << Mom::SlotLoad.new( arg_target + [index + 1] , arg.slot_definition(in_method))
args << Mom::SlotLoad.new( arg_target + [index + 1] , arg.slot_definition(compiler))
end
setup << Mom::ArgumentTransfer.new( mom_receive , args )
end
def simple_call(in_method)
def simple_call(compiler)
type = @receiver.ct_type
called_method = type.resolve_method(@name)
raise "No method #{@name} for #{type}" unless called_method
message_setup(in_method,called_method) << Mom::SimpleCall.new(called_method)
message_setup(compiler,called_method) << Mom::SimpleCall.new(called_method)
end
# this breaks cleanly into two parts:
# - check the cached type and if neccessary update
# - call the cached method
def cached_call(in_method)
cache_check(in_method) << call_cached_method(in_method)
def cached_call(compiler)
cache_check(compiler) << call_cached_method(compiler)
end
# check that current type is the cached type
# 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
def cache_check(in_method)
def cache_check(compiler)
ok = Mom::Label.new("cache_ok_#{self.object_id}")
check = build_condition(ok, in_method) # if cached_type != current_type
check << Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , receiver_type_definition(in_method))
check = build_condition(ok, compiler) # if cached_type != current_type
check << Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler))
check << Mom::ResolveMethod.new( @name , dynamic_call.cache_entry )
check << ok
end
# to call the method (that we know now to be in the cache), we move the method
# to reg1, do the setup (very similar to static) and call
def call_cached_method(in_method)
message_setup(in_method,dynamic_call.cache_entry) << dynamic_call
def call_cached_method(compiler)
message_setup(compiler,dynamic_call.cache_entry) << dynamic_call
end
def to_s(depth = 0)
@ -135,14 +135,14 @@ module Vool
end
private
def receiver_type_definition(in_method)
defi = @receiver.slot_definition(in_method)
def receiver_type_definition(compiler)
defi = @receiver.slot_definition(compiler)
defi.slots << :type
defi
end
def build_condition(ok_label, in_method)
def build_condition(ok_label, compiler)
cached_type = Mom::SlotDefinition.new(dynamic_call.cache_entry , [:cached_type])
current_type = receiver_type_definition(in_method)
current_type = receiver_type_definition(compiler)
Mom::NotSameCheck.new(cached_type , current_type, ok_label)
end
end