Rename Vool Block to Lambda
Making the distinction clearer Some fixing of previous (wip)
This commit is contained in:
parent
02807cf6f9
commit
ae16551ed0
@ -11,7 +11,7 @@ require_relative "ruby/statement"
|
|||||||
require_relative "ruby/statements"
|
require_relative "ruby/statements"
|
||||||
require_relative "ruby/assignment"
|
require_relative "ruby/assignment"
|
||||||
require_relative "ruby/array_statement"
|
require_relative "ruby/array_statement"
|
||||||
require_relative "ruby/block_statement"
|
require_relative "ruby/ruby_block_statement"
|
||||||
require_relative "ruby/if_statement"
|
require_relative "ruby/if_statement"
|
||||||
require_relative "ruby/normalizer"
|
require_relative "ruby/normalizer"
|
||||||
require_relative "ruby/class_statement"
|
require_relative "ruby/class_statement"
|
||||||
|
@ -13,7 +13,7 @@ module Ruby
|
|||||||
return self.vool_brother.new(name,@value.to_vool)
|
return self.vool_brother.new(name,@value.to_vool)
|
||||||
when SendStatement , YieldStatement
|
when SendStatement , YieldStatement
|
||||||
return normalize_send
|
return normalize_send
|
||||||
when BlockStatement
|
when RubyBlockStatement
|
||||||
return normalize_block
|
return normalize_block
|
||||||
else
|
else
|
||||||
raise "unsupported right #{value}"
|
raise "unsupported right #{value}"
|
||||||
|
@ -27,7 +27,7 @@ module Ruby
|
|||||||
when LocalAssignment
|
when LocalAssignment
|
||||||
ret = ReturnStatement.new( LocalVariable.new(statement.name) )
|
ret = ReturnStatement.new( LocalVariable.new(statement.name) )
|
||||||
return Statements.new([statement , ret])
|
return Statements.new([statement , ret])
|
||||||
when ReturnStatement , IfStatement , WhileStatement ,BlockStatement
|
when ReturnStatement , IfStatement , WhileStatement ,RubyBlockStatement
|
||||||
return statement
|
return statement
|
||||||
else
|
else
|
||||||
raise "Not implemented implicit return #{statement.class}"
|
raise "Not implemented implicit return #{statement.class}"
|
||||||
|
@ -20,7 +20,7 @@ module Ruby
|
|||||||
#
|
#
|
||||||
def to_vool
|
def to_vool
|
||||||
block_name = "implicit_block_#{object_id}".to_sym
|
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)
|
assign = Vool::LocalAssignment.new( block_name , block)
|
||||||
sendd = @send.to_vool
|
sendd = @send.to_vool
|
||||||
if(sendd.is_a?(Vool::Statements))
|
if(sendd.is_a?(Vool::Statements))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class BlockStatement < Statement
|
class LambdaStatement < Statement
|
||||||
attr_reader :args , :body , :clazz
|
attr_reader :args , :body , :clazz
|
||||||
|
|
||||||
def initialize( args , body , clazz = nil)
|
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
|
# This means we do the compiler here (rather than to_mom, which is in
|
||||||
# fact never called)
|
# fact never called)
|
||||||
def slot_definition(compiler)
|
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
|
end
|
||||||
|
|
||||||
# create a block, a compiler for it, comile the bock and add the compiler(code)
|
# create a block, a compiler for it, comile the bock and add the compiler(code)
|
||||||
@ -32,6 +32,9 @@ module Vool
|
|||||||
@body.each(&block)
|
@body.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s(depth=0)
|
||||||
|
"Block #{args} #{body}"
|
||||||
|
end
|
||||||
# create the parfait block (parfait representation of the block, a Callable similar
|
# create the parfait block (parfait representation of the block, a Callable similar
|
||||||
# to CallableMethod)
|
# to CallableMethod)
|
||||||
def parfait_block(compiler)
|
def parfait_block(compiler)
|
@ -5,16 +5,13 @@ module Vool
|
|||||||
def initialize( name , args , body )
|
def initialize( name , args , body )
|
||||||
@name , @args , @body = name , args , body
|
@name , @args , @body = name , args , body
|
||||||
raise "no bod" unless @body
|
raise "no bod" unless @body
|
||||||
|
raise "Not Vool #{@body}" unless @body.is_a?(Statement)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_mom(clazz)
|
def to_mom(clazz)
|
||||||
raise( "no class in #{self}") unless clazz
|
raise( "no class in #{self}") unless clazz
|
||||||
method = make_method(clazz)
|
method = make_method(clazz)
|
||||||
compiler = method.compiler_for(clazz.instance_type)
|
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
|
compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ module Ruby
|
|||||||
def test_first
|
def test_first
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||||
assert @lst.first.name.to_s.start_with?("implicit_block_")
|
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
|
end
|
||||||
def test_last_send
|
def test_last_send
|
||||||
assert_equal 2 , @lst.length
|
assert_equal 2 , @lst.length
|
||||||
|
@ -41,7 +41,7 @@ module Ruby
|
|||||||
assert @lst.first.first.name.to_s.start_with?("implicit_block")
|
assert @lst.first.first.name.to_s.start_with?("implicit_block")
|
||||||
end
|
end
|
||||||
def test_block_assign_right
|
def test_block_assign_right
|
||||||
assert_equal Vool::BlockStatement , @lst.first.first.value.class
|
assert_equal Vool::LambdaStatement , @lst.first.first.value.class
|
||||||
end
|
end
|
||||||
def test_a_assign
|
def test_a_assign
|
||||||
assert_equal Vool::LocalAssignment , @lst.first.last.class
|
assert_equal Vool::LocalAssignment , @lst.first.last.class
|
||||||
|
Loading…
Reference in New Issue
Block a user