diff --git a/lib/common/statements.rb b/lib/common/statements.rb index 8ee86e21..10a4fb37 100644 --- a/lib/common/statements.rb +++ b/lib/common/statements.rb @@ -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 diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index 4dbf6f02..caab098e 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -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}" diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index cb1e8d3f..6aaa04f2 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -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 diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index b62f1c59..2dabf704 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -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 diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index 8677f8fa..34dc90f1 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -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: diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index d2dfcadf..8828b75f 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -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 diff --git a/lib/vool/vool_compiler.rb b/lib/vool/vool_compiler.rb index ab5cee34..1c00f536 100644 --- a/lib/vool/vool_compiler.rb +++ b/lib/vool/vool_compiler.rb @@ -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) diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 7e19451f..bff51501 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -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 ) diff --git a/test/vool/to_mom/send/simple_send_harness.rb b/test/vool/to_mom/send/simple_send_harness.rb index a258a8e3..56bd0504 100644 --- a/test/vool/to_mom/send/simple_send_harness.rb +++ b/test/vool/to_mom/send/simple_send_harness.rb @@ -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 diff --git a/test/vool/to_mom/send/test_send_simple_string.rb b/test/vool/to_mom/send/test_send_simple_string.rb index 04bb6dad..2d41e2a9 100644 --- a/test/vool/to_mom/send/test_send_simple_string.rb +++ b/test/vool/to_mom/send/test_send_simple_string.rb @@ -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"]