Rename Vool Block to Lambda

Making the distinction clearer
Some fixing of previous (wip)
This commit is contained in:
Torsten Rüger 2019-08-19 10:40:22 +03:00
parent 02807cf6f9
commit ae16551ed0
8 changed files with 12 additions and 12 deletions

View File

@ -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"

View File

@ -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}"

View File

@ -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}"

View File

@ -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))

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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