setup to resolve method dynamically

This commit is contained in:
Torsten Ruger
2018-03-10 18:47:36 +05:30
parent dae17e0c18
commit 3a365c779a
3 changed files with 40 additions and 56 deletions

View File

@ -2,23 +2,22 @@ module Mom
# A dynamic call calls a method at runtime. This off course implies that we don't know the
# method at compile time and so must "find" it. Resolving, or finding the method, is a
# a seperate step though, and here we assume there is a Method instance in some variable
# a seperate step though, and here we assume that we know this Method instance.
#
# The only argument given is the variable's name.
# The instruction thus load the variable, finds the jump address from it and jumps there
# (ie calls). Calls are after all just jumps with the intent to return. Return addresses
# are setup in the preamble.
# Both (to be called) Method instance and the type of receiver are stored as
# variables here. The type is used to check before calling.
#
# As a side note: All argument setup/handling is outside the scope of this Instruction
# and assumed to be done beforehand.
# Also, in an ideal world we would check that the variable actually holds a Method
# but at the momeent we just assume it.
# Setting up the method is not part of the instructions scope. That setup
# includes the type check and any necccessay method resolution.
# See vool send statement
#
class DynamicCall < Instruction
attr_reader :method_var_name
attr :cached_type
attr :cached_method
def initialize(method_var_name)
@method_var_name = method_var_name
def initialize(type = nil, method = nil)
@cached_type = type
@cached_method = method
end
end