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:
parent
3702411043
commit
3247c2036c
@ -28,10 +28,6 @@ module Common
|
||||
@statements << o
|
||||
self
|
||||
end
|
||||
def collect(arr)
|
||||
@statements.each { |s| s.collect(arr) }
|
||||
super
|
||||
end
|
||||
def add_array(a)
|
||||
@statements += a
|
||||
end
|
||||
|
@ -31,10 +31,6 @@ module Vool
|
||||
raise self.class.name
|
||||
end
|
||||
|
||||
def each()
|
||||
yield self
|
||||
end
|
||||
|
||||
def to_mom( _ )
|
||||
# temporary warning to find unimplemented kids
|
||||
raise "Not implemented for #{self}"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ module Vool
|
||||
def self.ruby_to_vool( ruby_source )
|
||||
statements = RubyCompiler.compile( ruby_source )
|
||||
statements = statements.normalize
|
||||
#statements.create_objects
|
||||
statements.create_objects
|
||||
statements
|
||||
end
|
||||
def self.ruby_to_mom(source)
|
||||
|
@ -23,7 +23,7 @@ module MomCompile
|
||||
|
||||
def compile_first_method input
|
||||
lst = Vool::VoolCompiler.ruby_to_vool as_test_main( input )
|
||||
assert_equal Parfait::Class , lst.clazz.class , input
|
||||
assert_equal Parfait::Class , lst.clazz.class , lst
|
||||
@method = lst.clazz.get_method(:main)
|
||||
assert_equal Parfait::VoolMethod , @method.class
|
||||
res = lst.to_mom( nil )
|
||||
|
@ -5,10 +5,10 @@ module Vool
|
||||
assert Array != @stats.class , @stats
|
||||
end
|
||||
def test_class_compiles
|
||||
assert_equal Mom::MessageSetup , @stats.first.class , @stats
|
||||
assert_equal Mom::MessageSetup , @stats.class , @stats
|
||||
end
|
||||
def test_two_instructions_are_returned
|
||||
assert_equal 3 , @stats.length
|
||||
assert_equal 3 , @stats.length , @stats.to_rxf
|
||||
end
|
||||
def test_receiver_move_class
|
||||
assert_equal Mom::ArgumentTransfer, @stats[1].class
|
||||
|
@ -8,8 +8,7 @@ module Vool
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( "'5'.get_internal_byte(1)").first
|
||||
@first = @stats.first
|
||||
@stats = compile_first_method( "'5'.get_internal_byte(1)")
|
||||
end
|
||||
def receiver
|
||||
[Mom::StringConstant , "5"]
|
||||
|
Loading…
Reference in New Issue
Block a user