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:
Torsten Rüger 2019-08-19 14:33:02 +03:00
parent 3ddf2e3837
commit a722a4c285
7 changed files with 13 additions and 12 deletions

View File

@ -34,9 +34,9 @@ module Vool
create_class_object create_class_object
method_compilers = body.statements.collect do |node| method_compilers = body.statements.collect do |node|
case node case node
when MethodStatement when MethodExpression
node.to_mom(@clazz) node.to_mom(@clazz)
when ClassMethodStatement when ClassMethodExpression
node.to_mom(@clazz.meta_class) node.to_mom(@clazz.meta_class)
else else
raise "Only methods for now #{node.class}:#{node}" raise "Only methods for now #{node.class}:#{node}"

View File

@ -13,7 +13,7 @@ module Vool
method = clazz.add_method_for(name , make_arg_type , make_frame , body ) method = clazz.add_method_for(name , make_arg_type , make_frame , body )
#VoolMethod #VoolMethod
compiler = method.compiler_for(clazz.instance_type) 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 compiler
end end

View File

@ -14,14 +14,16 @@ 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 to_slot(compiler) def to_slot(compiler)
compile(compiler) unless @parfait_block
return Mom::SlotDefinition.new(Mom::LambdaConstant.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)
# to the method compiler for further processing # to the method compiler for further processing
def to_mom( compiler ) def compile( compiler )
parfait_block = self.parfait_block(compiler) parfait_block = self.parfait_block(compiler)
block_compiler = Mom::BlockCompiler.new( parfait_block , compiler.get_method ) block_compiler = Mom::BlockCompiler.new( parfait_block , compiler.get_method )
compiler.add_block_compiler(block_compiler)
head = body.to_mom( block_compiler ) head = body.to_mom( block_compiler )
block_compiler.add_code(head) block_compiler.add_code(head)
block_compiler block_compiler

View File

@ -52,7 +52,7 @@ module Vool
nodes = [] nodes = []
@body.each { |node| nodes << node } @body.each { |node| nodes << node }
nodes.dup.each do |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)} node.each {|block_scope| nodes.delete(block_scope)}
end end
type_hash = {} type_hash = {}

View File

@ -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 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) # as that is constant, and function implementations depend on the type (not class)
class SendStatement < CallStatement class SendStatement < CallStatement
attr_reader :block
def block def block
return nil if arguments.empty? return nil if arguments.empty?
bl = arguments.last bl = arguments.last
bl.is_a?(BlockStatement) ? bl : nil bl.is_a?(LambdaExpression) ? bl : nil
end end
def add_block( block ) def add_block( block )

View File

@ -10,10 +10,10 @@ module Vool
@vool = ruby_tree.to_vool @vool = ruby_tree.to_vool
end end
def test_class def test_class
assert_equal ClassStatement , @vool.class assert_equal ClassExpression , @vool.class
end end
def test_method def test_method
assert_equal MethodStatement , @vool.body.first.class assert_equal MethodExpression , @vool.body.first.class
end end
def test_create_class def test_create_class
assert_equal Parfait::Class , @vool.create_class_object.class assert_equal Parfait::Class , @vool.create_class_object.class
@ -33,7 +33,7 @@ module Vool
def assert_type_for(input) def assert_type_for(input)
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) ) ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
vool = ruby_tree.to_vool vool = ruby_tree.to_vool
assert_equal ClassStatement , vool.class assert_equal ClassExpression , vool.class
clazz = vool.create_class_object clazz = vool.create_class_object
assert_equal Parfait::Class , clazz.class assert_equal Parfait::Class , clazz.class
assert_equal :a , clazz.instance_type.names[1] assert_equal :a , clazz.instance_type.names[1]

View File

@ -13,9 +13,9 @@ module Vool
@clazz.body.first @clazz.body.first
end end
def test_setup def test_setup
assert_equal ClassStatement , @clazz.class assert_equal ClassExpression , @clazz.class
assert_equal Statements , @clazz.body.class assert_equal Statements , @clazz.body.class
assert_equal MethodStatement , method.class assert_equal MethodExpression , method.class
end end
def test_class def test_class
assert_equal Parfait::Class , @clazz.create_class_object.class assert_equal Parfait::Class , @clazz.create_class_object.class