split compiled_method into method and compiled_method_info
This commit is contained in:
70
lib/parfait/method.rb
Normal file
70
lib/parfait/method.rb
Normal file
@ -0,0 +1,70 @@
|
||||
# A Method (at runtime , sis in Parfait) is static object that primarily holds the executable
|
||||
# code.
|
||||
|
||||
# For reflection also holds arguments and such
|
||||
|
||||
#
|
||||
|
||||
module Parfait
|
||||
|
||||
# static description of a method
|
||||
# name
|
||||
# arg_names
|
||||
# known local variable names
|
||||
# temp variables (numbered)
|
||||
# executable code
|
||||
|
||||
# ps, the compiler injects its own info, see virtual::compiled_method_info
|
||||
|
||||
|
||||
class Method < Object
|
||||
|
||||
def initialize name , arg_names
|
||||
@name = name
|
||||
@arg_names = arg_names
|
||||
@locals = []
|
||||
@tmps = []
|
||||
end
|
||||
attr_reader :name , :arg_names
|
||||
attr_accessor :for_class
|
||||
|
||||
|
||||
# determine whether this method has a variable by the given name
|
||||
# variables are locals and and arguments
|
||||
# used to determine if a send must be issued
|
||||
# return index of the name into the message if so
|
||||
def has_var name
|
||||
name = name.to_sym
|
||||
index = has_arg(name)
|
||||
return index if index
|
||||
has_local(name)
|
||||
end
|
||||
|
||||
# determine whether this method has an argument by the name
|
||||
def has_arg name
|
||||
@arg_names.index_of name.to_sym
|
||||
end
|
||||
|
||||
# determine if method has a local variable or tmp (anonymous local) by given name
|
||||
def has_local name
|
||||
name = name.to_sym
|
||||
index = @locals.index(name)
|
||||
index = @tmps.index(name) unless index
|
||||
index
|
||||
end
|
||||
|
||||
def ensure_local name
|
||||
index = has_local name
|
||||
return index if index
|
||||
@locals << name
|
||||
@locals.length
|
||||
end
|
||||
|
||||
def get_var name
|
||||
var = has_var name
|
||||
raise "no var #{name} in method #{self.name} , #{@locals} #{@arg_names}" unless var
|
||||
var
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -15,15 +15,21 @@ module Parfait
|
||||
class Module < Object
|
||||
def initialize name , superclass
|
||||
@instance_methods = []
|
||||
@name = name.to_sym
|
||||
@name = name
|
||||
@super_class = superclass
|
||||
@meta_class = Virtual::MetaClass.new(self)
|
||||
end
|
||||
|
||||
def add_instance_method method
|
||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod
|
||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
||||
raise "syserr " unless method.name.is_a? Symbol
|
||||
method.for_class = self
|
||||
@instance_methods << method
|
||||
method
|
||||
end
|
||||
|
||||
def create_instance_method name , arg_names
|
||||
add_instance_method Method.new( name , arg_names )
|
||||
end
|
||||
|
||||
# this needs to be done during booting as we can't have all the classes and superclassses
|
||||
|
Reference in New Issue
Block a user