diff --git a/lib/ruby.rb b/lib/ruby.rb index e9de51ba..f5936588 100644 --- a/lib/ruby.rb +++ b/lib/ruby.rb @@ -11,7 +11,7 @@ require_relative "ruby/statement" require_relative "ruby/statements" require_relative "ruby/assignment" require_relative "ruby/array_statement" -require_relative "ruby/block_statement" +require_relative "ruby/ruby_block_statement" require_relative "ruby/if_statement" require_relative "ruby/normalizer" require_relative "ruby/class_statement" diff --git a/lib/ruby/assignment.rb b/lib/ruby/assignment.rb index 03556b1e..bde8a60d 100644 --- a/lib/ruby/assignment.rb +++ b/lib/ruby/assignment.rb @@ -13,7 +13,7 @@ module Ruby return self.vool_brother.new(name,@value.to_vool) when SendStatement , YieldStatement return normalize_send - when BlockStatement + when RubyBlockStatement return normalize_block else raise "unsupported right #{value}" diff --git a/lib/ruby/method_statement.rb b/lib/ruby/method_statement.rb index 9b60937c..e95b0ec3 100644 --- a/lib/ruby/method_statement.rb +++ b/lib/ruby/method_statement.rb @@ -27,7 +27,7 @@ module Ruby when LocalAssignment ret = ReturnStatement.new( LocalVariable.new(statement.name) ) return Statements.new([statement , ret]) - when ReturnStatement , IfStatement , WhileStatement ,BlockStatement + when ReturnStatement , IfStatement , WhileStatement ,RubyBlockStatement return statement else raise "Not implemented implicit return #{statement.class}" diff --git a/lib/ruby/ruby_block_statement.rb b/lib/ruby/ruby_block_statement.rb index aea499ed..8947dde0 100644 --- a/lib/ruby/ruby_block_statement.rb +++ b/lib/ruby/ruby_block_statement.rb @@ -20,7 +20,7 @@ module Ruby # def to_vool block_name = "implicit_block_#{object_id}".to_sym - block = Vool::BlockStatement.new( @args.dup , @body.to_vool) + block = Vool::LambdaStatement.new( @args.dup , @body.to_vool) assign = Vool::LocalAssignment.new( block_name , block) sendd = @send.to_vool if(sendd.is_a?(Vool::Statements)) diff --git a/lib/vool/block_statement.rb b/lib/vool/lambda_statement.rb similarity index 90% rename from lib/vool/block_statement.rb rename to lib/vool/lambda_statement.rb index d2ea16f6..a91c26cd 100644 --- a/lib/vool/block_statement.rb +++ b/lib/vool/lambda_statement.rb @@ -1,5 +1,5 @@ module Vool - class BlockStatement < Statement + class LambdaStatement < Statement attr_reader :args , :body , :clazz def initialize( args , body , clazz = nil) @@ -14,7 +14,7 @@ module Vool # This means we do the compiler here (rather than to_mom, which is in # fact never called) def slot_definition(compiler) - return Mom::SlotDefinition.new(Mom::BlockConstant.new(parfait_block(compiler)) , []) + return Mom::SlotDefinition.new(Mom::LambdaConstant.new(parfait_block(compiler)) , []) end # create a block, a compiler for it, comile the bock and add the compiler(code) @@ -32,6 +32,9 @@ module Vool @body.each(&block) end + def to_s(depth=0) + "Block #{args} #{body}" + end # create the parfait block (parfait representation of the block, a Callable similar # to CallableMethod) def parfait_block(compiler) diff --git a/lib/vool/method_statement.rb b/lib/vool/method_statement.rb index b5ae2bf2..bc2b3fd0 100644 --- a/lib/vool/method_statement.rb +++ b/lib/vool/method_statement.rb @@ -5,16 +5,13 @@ module Vool def initialize( name , args , body ) @name , @args , @body = name , args , body raise "no bod" unless @body + raise "Not Vool #{@body}" unless @body.is_a?(Statement) end def to_mom(clazz) raise( "no class in #{self}") unless clazz 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) - compiler.block_compilers << node.to_mom(compiler) - end compiler end diff --git a/test/ruby/test_ruby_block_statement.rb b/test/ruby/test_ruby_block_statement.rb index 5912e7f9..50172fba 100644 --- a/test/ruby/test_ruby_block_statement.rb +++ b/test/ruby/test_ruby_block_statement.rb @@ -38,7 +38,7 @@ module Ruby def test_first assert_equal Vool::LocalAssignment , @lst.first.class assert @lst.first.name.to_s.start_with?("implicit_block_") - assert_equal Vool::BlockStatement , @lst.first.value.class + assert_equal Vool::LambdaStatement , @lst.first.value.class end def test_last_send assert_equal 2 , @lst.length diff --git a/test/ruby/test_ruby_block_statement1.rb b/test/ruby/test_ruby_block_statement1.rb index 9d5cc746..125672ab 100644 --- a/test/ruby/test_ruby_block_statement1.rb +++ b/test/ruby/test_ruby_block_statement1.rb @@ -41,7 +41,7 @@ module Ruby assert @lst.first.first.name.to_s.start_with?("implicit_block") end def test_block_assign_right - assert_equal Vool::BlockStatement , @lst.first.first.value.class + assert_equal Vool::LambdaStatement , @lst.first.first.value.class end def test_a_assign assert_equal Vool::LocalAssignment , @lst.first.last.class