bit of refactoring
This commit is contained in:
@ -25,7 +25,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def add_instance_method( method )
|
||||
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? RubyMethod
|
||||
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? VoolMethod
|
||||
method
|
||||
end
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
# Class is mainly a list of methods with a name. The methods are untyped, sis Vool.
|
||||
# Class is mainly a list of methods with a name.
|
||||
# The methods are untyped, sis VoolMethod.
|
||||
|
||||
# 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
|
||||
# of the class. Note that this changes over time and so many types share the same class.
|
||||
# The class carries the "current" type, ie the type an object would be if you
|
||||
# created an instance of the class.
|
||||
# Note that this changes over time and so many types share the same class.
|
||||
|
||||
# For dynamic OO it is essential that the class (the object defining the class)
|
||||
# can carry methods. It does so as instance variables.
|
||||
# In fact this property is implemented in the Type, as methods
|
||||
# may be added to any object at run-time.
|
||||
# can carry methods. It does so in an instance variable methods.
|
||||
|
||||
# An Object carries the data for the instance variables it has.
|
||||
# The Type lists the names of the instance variables
|
||||
# The Class keeps a list of instance methods, these have a name and code
|
||||
# The Class keeps a list of instance methods, these have a name and (vool) code
|
||||
# Each type in turn has a list of TypedMethods that hold binary code
|
||||
|
||||
module Parfait
|
||||
class Class < Object
|
||||
@ -35,6 +36,12 @@ module Parfait
|
||||
"Class(#{name})"
|
||||
end
|
||||
|
||||
def add_method_for(name , type , frame , body )
|
||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||
add_method( method )
|
||||
method
|
||||
end
|
||||
|
||||
def add_method(method)
|
||||
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||
@methods[method.name] = method
|
||||
|
@ -1,19 +1,22 @@
|
||||
# A TypedMethod is static object that primarily holds the executable code.
|
||||
# It is called typed, because all arguments and variables it uses are typed.
|
||||
# It is called typed, because all arguments and variables it uses are "typed",
|
||||
# that is to say the names are known and form a type (not that the types of the
|
||||
# variables are known). The objects type is known too, which means all instances
|
||||
# variable names are known (not their respective type).
|
||||
|
||||
# It's relation to the method a ruby programmer knows (called RubyMethod) is many to one,
|
||||
# meaning one RubyMethod (untyped) has many TypedMethod implementations.
|
||||
# The RubyMethod only holds ruby code, no binary.
|
||||
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
|
||||
# meaning one VoolMethod (untyped) has many TypedMethod implementations.
|
||||
# The VoolMethod only holds vool code, no binary.
|
||||
|
||||
# The Typed method has the following instance variables
|
||||
# - name : This is the same as the ruby method name it implements
|
||||
# - source: is currently the ast (or string) that represents the "code". This is historic
|
||||
# and will change to the RubyMethod that it implements
|
||||
# - instructions: The sequence of instructions the source (ast) was compiled to
|
||||
# - risc_instructions: The sequence of risc level instructions that mom was compiled to
|
||||
# - cpu_instructions: The sequence of cpu specific instructions that the
|
||||
# risc_instructions was compiled to
|
||||
# Instructions derive from class Instruction and form a linked list
|
||||
# - binary: The binary (jumpable) code that the instructions get assembled into
|
||||
# - arguments: A type object describing the arguments (name+types) to be passed
|
||||
# - frame: A type object describing the local variables that the method has
|
||||
# - arguments_type: A type object describing the arguments (name+types) to be passed
|
||||
# - frame_type: A type object describing the local variables that the method has
|
||||
# - for_type: The Type the Method is for
|
||||
|
||||
|
||||
@ -24,8 +27,6 @@ module Parfait
|
||||
attr_reader :name , :risc_instructions , :for_type , :cpu_instructions
|
||||
attr_reader :arguments_type , :frame_type , :binary , :next_method
|
||||
|
||||
attr_accessor :source
|
||||
|
||||
def initialize( type , name , arguments_type , frame_type)
|
||||
super()
|
||||
raise "No class #{name}" unless type
|
||||
|
@ -27,5 +27,12 @@ module Parfait
|
||||
type.create_method( @name , @args_type , @frame_type)
|
||||
end
|
||||
|
||||
def compile_to_risc(for_type)
|
||||
typed_method = create_typed_method(for_type)
|
||||
head = source.to_mom( typed_method )
|
||||
compiler = Risc::MethodCompiler.new( typed_method )
|
||||
compiler.add_mom(head)
|
||||
head # return for testing
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user