start to compile send

still very hacked version of simple call, but a start
This commit is contained in:
Torsten Ruger
2017-04-15 20:58:39 +03:00
parent 265b25d5f4
commit 0d43987005
8 changed files with 130 additions and 43 deletions

View File

@ -6,5 +6,6 @@ module Mom
end
require_relative "simple_call"
require_relative "slot_load"
require_relative "return_sequence"

18
lib/mom/simple_call.rb Normal file
View File

@ -0,0 +1,18 @@
module Mom
# A SimpleCall is just that, a simple call. This could be called a function call too,
# meaning we managed to resolve the function at compile time and all we have to do is
# actually call it.
#
# As the call setup is done beforehand (for both simple and cached call), the
# calling really means just jumping to the address. Simple.
#
class SimpleCall < Instruction
attr_reader :method
def initialize(method)
@method = method
end
end
end

View File

@ -1,6 +1,6 @@
# A message is what is sent when you invoke a method. Args and stuff are packed up in to a Message
# and the Message is sent to the receiver.
# A message is what is created when a message is sent. Args and stuff are packed up in to a
# Message and the Message is activated (by swapping it into the machine).
# Part of the housekeeping (see attributes) makes messages a double linked list (next_message and
# caller) , and maybe surprisingly this means that we can create all messages at runtime

View File

@ -167,7 +167,7 @@ module Vool
# this is a call to super without args (z = zero arity)
def on_zsuper exp
SendStatement.new( nil , SuperStatement.new )
SendStatement.new( nil , SuperStatement.new , nil)
end
# this is a call to super with args and

View File

@ -2,15 +2,71 @@ module Vool
class SendStatement < Statement
attr_reader :name , :receiver , :arguments
def initialize(name , receiver , arguments = [])
def initialize(name , receiver , arguments )
@name , @receiver , @arguments = name , receiver , arguments
@arguments ||= []
end
def collect(arr)
@receiver.collect(arr)
@arguments.collect(arr)
@arguments.each do |arg|
puts "ARG#{arg}"
arg.collect(arr)
end
super
end
# Sending in a dynamic language is off course not as simple as just calling.
# The function that needs to be called depends after all on the receiver,
# and no guarantees can be made on what that is.
#
# It helps to know that usually (>99%) the class of the receiver does not change.
# Our stategy then is to cache the functions and only dynamically determine it in
# case of a miss (the 1%, and first invocation)
#
# As cache key we must use the type of the object (which is the first word of _every_ object)
# as that is constant, and function implementations depend on the type (not class)
#
# 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 weather the receiver type can be determined
#
# FIXME: we now presume direct (assignable) values for the arguments and receiver.
# in a not so distant future, temporary variables will have to be created
# and complex statements hoisted to assign to them. pps: same as in conditions
def to_mom( method )
message_setup + call_instruction
end
def message_setup
pops = [Mom::SlotConstant.new([:message , :next_message , :receiver] , @receiver) ]
@arguments.each_with_index do |arg , index|
arg_target = [:message , :next_message , :arguments]
pops << Mom::SlotConstant.new( arg_target + index , @arg)
end
pops
end
def call_instruction
if(receiver_type)
simple_call
else
cached_call
end
end
def receiver_type
Parfait.object_space.get_class_by_name(:Integer).instance_type
end
def simple_call
type = receiver_type
method = type.get_method(@name)
[Mom::SimpleCall.new( method) ]
end
def cached_call
[Mom::SlotConstant.new([:message , :next_message , :receiver] , @receiver) ]
end
end
end