starting on mom to risc
some docs too
This commit is contained in:
@ -1,4 +1,13 @@
|
||||
module Vool
|
||||
# This represents a class at the vool level. Vool is a syntax tree,
|
||||
# so here the only child (or children) is a body.
|
||||
# Body may either be a MethodStatement, or Statements (either empty or
|
||||
# containing MethodStatement)
|
||||
#
|
||||
# We store the class name and the parfait class
|
||||
#
|
||||
# The Parfait class gets created lazily on the way down to mom, ie the clazz
|
||||
# attribute will only be set after to_mom, or a direct call to create_class
|
||||
class ClassStatement < Statement
|
||||
attr_reader :name, :super_class_name , :body
|
||||
attr_reader :clazz
|
||||
@ -17,6 +26,10 @@ module Vool
|
||||
end
|
||||
end
|
||||
|
||||
# This create the Parfait class, and then transforms every method
|
||||
#
|
||||
# As there is no class equivalnet in code, a MomCollection is returned,
|
||||
# which is just a list of Mom::MethodCompilers
|
||||
def to_mom( _ )
|
||||
create_class_object
|
||||
method_compilers = body.statements.collect do |node|
|
||||
@ -37,6 +50,10 @@ module Vool
|
||||
@body.each(&block) if @body
|
||||
end
|
||||
|
||||
# This creates the Parfait class. But doesn not hadle reopening yet, so only new classes
|
||||
# Creating the class involves creating the instance_type (or an initial version)
|
||||
# which means knowing all used names. So we go through the code looking for
|
||||
# InstanceVariables or InstanceVariable Assignments, to do that.
|
||||
def create_class_object
|
||||
@clazz = Parfait.object_space.get_class_by_name(@name )
|
||||
if(@clazz)
|
||||
@ -53,6 +70,7 @@ module Vool
|
||||
ivar_hash[node.name] = :Object
|
||||
end
|
||||
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
||||
@clazz
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -9,7 +9,7 @@ module Vool
|
||||
|
||||
def to_mom(clazz)
|
||||
raise( "no class in #{self}") unless clazz
|
||||
method = clazz.add_method_for(name , make_arg_type , make_frame , body )
|
||||
method = make_method(clazz)
|
||||
compiler = method.compiler_for(clazz.instance_type)
|
||||
each do |node| ## TODO: must account for nested blocks (someday)
|
||||
next unless node.is_a?(BlockStatement)
|
||||
@ -18,6 +18,15 @@ module Vool
|
||||
compiler
|
||||
end
|
||||
|
||||
# Class to be passed in is a Parfait class
|
||||
# return VoolMethod
|
||||
#
|
||||
# extracted call to create the VoolMethod as this is the place
|
||||
# where we have all the info. Used in testing.
|
||||
def make_method(clazz)
|
||||
clazz.add_method_for(name , make_arg_type , make_frame , body )
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
block.call(self)
|
||||
@body.each(&block)
|
||||
|
Reference in New Issue
Block a user