2017-12-10 19:47:26 +01:00
|
|
|
module Parfait
|
2016-12-20 19:02:20 +01:00
|
|
|
|
2017-12-10 19:47:26 +01:00
|
|
|
# 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 TypedMethod
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-29 20:03:06 +02:00
|
|
|
class VoolMethod < Object
|
2016-12-20 19:02:20 +01:00
|
|
|
|
2018-03-14 13:09:04 +01:00
|
|
|
attr_reader :name , :args_type , :frame_type , :source
|
2016-12-21 10:30:35 +01:00
|
|
|
|
2018-03-14 15:54:47 +01:00
|
|
|
def initialize(name , args_type , frame_type , source )
|
|
|
|
@name , @args_type , @frame_type , @source = name , args_type, frame_type , source
|
2017-01-16 16:44:34 +01:00
|
|
|
raise "Name must be symbol" unless name.is_a?(Symbol)
|
|
|
|
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
2018-03-14 15:54:47 +01:00
|
|
|
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
|
2017-12-10 19:47:26 +01:00
|
|
|
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
2018-06-30 18:20:17 +02:00
|
|
|
raise "Empty bod" if(source.is_a?(Vool::Statements) and source.empty?)
|
2016-12-20 19:02:20 +01:00
|
|
|
end
|
|
|
|
|
2018-06-26 19:46:58 +02:00
|
|
|
def create_typed_method( type )
|
2017-01-15 11:10:37 +01:00
|
|
|
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
2018-03-18 17:39:27 +01:00
|
|
|
type.create_method( @name , @args_type , @frame_type)
|
2017-01-15 11:10:37 +01:00
|
|
|
end
|
|
|
|
|
2018-07-01 10:57:17 +02:00
|
|
|
def compiler_for(for_type)
|
2018-06-27 16:09:50 +02:00
|
|
|
typed_method = create_typed_method(for_type)
|
|
|
|
head = source.to_mom( typed_method )
|
2018-06-30 22:26:28 +02:00
|
|
|
compiler = Risc::MethodCompiler.new( typed_method )
|
2018-06-27 16:09:50 +02:00
|
|
|
compiler.add_mom(head)
|
2018-07-01 10:57:17 +02:00
|
|
|
compiler
|
2018-06-27 16:09:50 +02:00
|
|
|
end
|
2016-12-20 19:02:20 +01:00
|
|
|
end
|
|
|
|
end
|