rubyx/lib/parfait/vool_method.rb
Torsten Ruger b0aefe31fe make all instances attr read writers
unfortunately the writers have to have self.var =
otherwise it is just a local var
Also need to make the type explicit for all
Protocol included memory_length on the class for now
2018-08-11 19:15:34 +03:00

43 lines
1.5 KiB
Ruby

module Parfait
# This represents the method at source code level (sis vool)
#
# Type objects are already created for args and locals, but the main attribute
# is the source, which is a Vool::Statement
#
# Classes store VoolMethods, while Types store CallableMethod
# A Type referes to a Class , but a Class (interface) is implemented by many types
# as it changes during the course of it's life. Types do not change. Objects have
# type, and so only indirectly a class.
#
class VoolMethod < Object
attr :type, :name , :args_type , :frame_type , :source
def initialize(name , args_type , frame_type , source )
self.name = name
self.args_type = args_type
self.frame_type = frame_type
self.source = source
raise "Name must be symbol" unless name.is_a?(Symbol)
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
raise "source must be vool" unless source.is_a?(Vool::Statement)
raise "Empty bod" if(source.is_a?(Vool::Statements) and source.empty?)
end
def create_callable_method( type )
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
type.create_method( name , args_type , frame_type)
end
def compiler_for(self_type)
callable_method = create_callable_method(self_type)
compiler = Risc::MethodCompiler.new( callable_method )
head = source.to_mom( compiler )
compiler.add_mom(head)
compiler
end
end
end