moving vool_method to parfait

This commit is contained in:
Torsten Ruger
2017-12-10 20:47:26 +02:00
parent b7701d0d5e
commit bc5906fb83
10 changed files with 55 additions and 28 deletions

View File

@ -1,4 +1,4 @@
# Class is mainly a list of methods with a name. The methods are untyped.
# Class is mainly a list of methods with a name. The methods are untyped, sis Vool.
# The memory layout of an object is determined by the Type (see there).
# The class carries the "current" type, ie the type an object would be if you created an instance
@ -36,6 +36,7 @@ module Parfait
end
def add_method(method)
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
@methods[method.name] = method
end

View File

@ -1,6 +1,5 @@
# A TypedMethod is static object that primarily holds the executable code.
# It is called typed, because all arguments and variables it uses are typed.
# (Type means basic type, ie integer or reference)
# It's relation to the method a ruby programmer knows (called RubyMethod) is many to one,
# meaning one RubyMethod (untyped) has many TypedMethod implementations.

View File

@ -0,0 +1,40 @@
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 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.
#
class VoolMethod
attr_reader :name , :args_type , :locals_type , :source
def initialize(name , args_type , locals_type , source )
@name , @args_type , @locals_type , @source = name , args_type, locals_type , 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 "locals_type must be type" unless locals_type.is_a?(Parfait::Type)
raise "source must be vool" unless source.is_a?(Vool::Statement)
end
def normalize_source
@source = yield @source
end
def create_parfait_method( type )
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
type.create_method( @name , @args_type )#FIXME, @locals_type)
end
def create_tmp
tmp_name = "tmp_#{@locals_type.instance_length}".to_sym
@locals_type = @locals_type.add_instance_variable( tmp_name , :Object )
tmp_name
end
end
end