Move vool block compilation into constant generation
When the lambda is passed as argument, it must be moved. This triggers the generation of a corresponding parfait object (as before, and as for other constants) but now also triggers the code build. The code being the constant as it were Also some more name fixes from renames
This commit is contained in:
parent
3ddf2e3837
commit
a722a4c285
@ -34,9 +34,9 @@ module Vool
|
||||
create_class_object
|
||||
method_compilers = body.statements.collect do |node|
|
||||
case node
|
||||
when MethodStatement
|
||||
when MethodExpression
|
||||
node.to_mom(@clazz)
|
||||
when ClassMethodStatement
|
||||
when ClassMethodExpression
|
||||
node.to_mom(@clazz.meta_class)
|
||||
else
|
||||
raise "Only methods for now #{node.class}:#{node}"
|
||||
|
@ -13,7 +13,7 @@ module Vool
|
||||
method = clazz.add_method_for(name , make_arg_type , make_frame , body )
|
||||
#VoolMethod
|
||||
compiler = method.compiler_for(clazz.instance_type)
|
||||
each {|node| raise "Blocks not implemented" if node.is_a?(BlockStatement)}
|
||||
each {|node| raise "Blocks not implemented" if node.is_a?(LambdaExpression)}
|
||||
compiler
|
||||
end
|
||||
|
||||
|
@ -14,14 +14,16 @@ module Vool
|
||||
# This means we do the compiler here (rather than to_mom, which is in
|
||||
# fact never called)
|
||||
def to_slot(compiler)
|
||||
compile(compiler) unless @parfait_block
|
||||
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)
|
||||
# to the method compiler for further processing
|
||||
def to_mom( compiler )
|
||||
def compile( compiler )
|
||||
parfait_block = self.parfait_block(compiler)
|
||||
block_compiler = Mom::BlockCompiler.new( parfait_block , compiler.get_method )
|
||||
compiler.add_block_compiler(block_compiler)
|
||||
head = body.to_mom( block_compiler )
|
||||
block_compiler.add_code(head)
|
||||
block_compiler
|
||||
|
@ -52,7 +52,7 @@ module Vool
|
||||
nodes = []
|
||||
@body.each { |node| nodes << node }
|
||||
nodes.dup.each do |node|
|
||||
next unless node.is_a?(BlockStatement)
|
||||
next unless node.is_a?(LambdaExpression)
|
||||
node.each {|block_scope| nodes.delete(block_scope)}
|
||||
end
|
||||
type_hash = {}
|
||||
|
@ -10,12 +10,11 @@ module Vool
|
||||
# As cache key we must use the type of the object (which is the first word of _every_ object)
|
||||
# as that is constant, and function implementations depend on the type (not class)
|
||||
class SendStatement < CallStatement
|
||||
attr_reader :block
|
||||
|
||||
def block
|
||||
return nil if arguments.empty?
|
||||
bl = arguments.last
|
||||
bl.is_a?(BlockStatement) ? bl : nil
|
||||
bl.is_a?(LambdaExpression) ? bl : nil
|
||||
end
|
||||
|
||||
def add_block( block )
|
||||
|
@ -10,10 +10,10 @@ module Vool
|
||||
@vool = ruby_tree.to_vool
|
||||
end
|
||||
def test_class
|
||||
assert_equal ClassStatement , @vool.class
|
||||
assert_equal ClassExpression , @vool.class
|
||||
end
|
||||
def test_method
|
||||
assert_equal MethodStatement , @vool.body.first.class
|
||||
assert_equal MethodExpression , @vool.body.first.class
|
||||
end
|
||||
def test_create_class
|
||||
assert_equal Parfait::Class , @vool.create_class_object.class
|
||||
@ -33,7 +33,7 @@ module Vool
|
||||
def assert_type_for(input)
|
||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
||||
vool = ruby_tree.to_vool
|
||||
assert_equal ClassStatement , vool.class
|
||||
assert_equal ClassExpression , vool.class
|
||||
clazz = vool.create_class_object
|
||||
assert_equal Parfait::Class , clazz.class
|
||||
assert_equal :a , clazz.instance_type.names[1]
|
||||
|
@ -13,9 +13,9 @@ module Vool
|
||||
@clazz.body.first
|
||||
end
|
||||
def test_setup
|
||||
assert_equal ClassStatement , @clazz.class
|
||||
assert_equal ClassExpression , @clazz.class
|
||||
assert_equal Statements , @clazz.body.class
|
||||
assert_equal MethodStatement , method.class
|
||||
assert_equal MethodExpression , method.class
|
||||
end
|
||||
def test_class
|
||||
assert_equal Parfait::Class , @clazz.create_class_object.class
|
||||
|
Loading…
Reference in New Issue
Block a user