a start on dynamic dispatch (wip)

This commit is contained in:
Torsten Ruger
2017-09-14 16:07:02 +03:00
parent be1481ce34
commit 2739747453
5 changed files with 91 additions and 8 deletions

25
lib/mom/dynamic_call.rb Normal file
View File

@ -0,0 +1,25 @@
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
#
# 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.
#
# 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.
#
class DynamicCall < Instruction
attr_reader :method_var_name
def initialize(method_var_name)
@method_var_name = method_var_name
end
end
end

View File

@ -20,7 +20,9 @@ module Mom
end
require_relative "simple_call"
require_relative "dynamic_call"
require_relative "truth_check"
require_relative "not_same_check"
require_relative "jump"
require_relative "slot_load"
require_relative "return_sequence"

16
lib/mom/not_same_check.rb Normal file
View File

@ -0,0 +1,16 @@
module Mom
# Mom internal check, as the name says to see if two values are not the same
# In other words, we this checks identity, bit-values, pointers
#
# The values that are compared are defined as SlotDefinitions, ie can be anything
# available to the machine through frame message or self
#
class NotSameCheck < Check
attr_reader :left , :right
def initialize(left, right)
@left , @right = left , right
end
end
end