moving from collect to each

when iterating over tree.
Much cleaner, less hokuspukus methods that are noops

Mom is coming back out, but not linked yet
This commit is contained in:
Torsten Ruger
2018-03-15 17:22:56 +05:30
parent 3702411043
commit 3247c2036c
10 changed files with 37 additions and 35 deletions

View File

@ -14,19 +14,17 @@ module Vool
# compilation to the next layer, mom
# context coming in for class is nil, also for methods, henceafter a method is passed down
def to_mom( _ )
methods = @body.statements.collect { |meth| meth.to_mom( nil ) }
Mom::Statements.new(methods)
@body.to_mom(nil)
end
def each()
@body.collect(arr)
super
def each(&block)
block.call(self)
@body.each(&block)
end
def create_objects
create_class_object
body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects
self.each {|node| node.create_objects(@clazz) if node.is_a?(MethodStatement) }
end
def create_class_object
@ -36,10 +34,11 @@ module Vool
#existing class, don't overwrite type (parfait only?)
else
@clazz = Parfait.object_space.create_class(@name , @super_class_name )
vars = []
@body.collect([]).each { |node| node.add_ivar(vars) }
ivar_hash = {}
vars.each { |var| ivar_hash[var] = :Object }
self.each do |node|
next unless node.is_a?(InstanceVariable) or node.is_a?(IvarAssignment)
ivar_hash[node.name] = :Object
end
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end
end

View File

@ -16,16 +16,18 @@ module Vool
@body.to_mom(method)
end
def collect(arr)
@body.collect(arr)
super
def each(&block)
block.call(self)
@body.each(&block)
end
def normalize
MethodStatement.new( @name , @args , @body.normalize)
end
def create_objects
def create_objects(clazz)
@clazz = clazz
raise "no class" unless clazz
args_type = make_type
frame_type = make_frame
method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
@ -46,9 +48,10 @@ module Vool
def make_frame
type_hash = {}
vars = []
@body.each([]).each { |node| node.add_local(vars) }
vars.each { |var| type_hash[var] = :Object }
@body.each do |node|
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
type_hash[node.name] = :Object
end
Parfait::NamedList.type_for( type_hash )
end

View File

@ -18,12 +18,16 @@ module Vool
@dynamic = nil
end
def collect(arr)
@receiver.collect(arr)
def normalize
SendStatement.new(@name, @receiver , @arguments)
end
def each(&block)
block.call(self)
block.call(@receiver)
@arguments.each do |arg|
arg.collect(arr)
block.call(arg)
end
super
end
# A Send breaks down to 2 steps:

View File

@ -12,6 +12,11 @@ module Vool
@statements.each{ |s| s.create_objects }
end
def each(&block)
block.call(self)
@statements.each{|a| a.each(block)}
end
end
class ScopeStatement < Statements