fix locals scope in method and blocks

methods used to gobble up any locals of included scope. fixed
Blocks now create frame_type correctly and don't include and locals that are in fact method scope
This commit is contained in:
Torsten Ruger 2018-07-09 17:55:45 +03:00
parent 4ac89ece66
commit 06e78a7326
4 changed files with 24 additions and 7 deletions

View File

@ -23,9 +23,8 @@ module Vool
parfait_block = self.parfait_block(compiler)
block_compiler = Risc::BlockCompiler.new( parfait_block , compiler.method )
compiler.add_block_compiler(block_compiler)
puts "BODY #{body}"
head = body.to_mom( block_compiler )
block_compiler.add_mom(head)
#block_compiler.add_mom(head)
block_compiler
end
@ -42,7 +41,7 @@ module Vool
# to CallableMethod)
def parfait_block(compiler)
return @parfait_block if @parfait_block
@parfait_block = compiler.method.create_block( make_arg_type , make_frame)
@parfait_block = compiler.method.create_block( make_arg_type , make_frame(compiler))
end
private
@ -51,10 +50,11 @@ module Vool
@args.each {|arg| type_hash[arg] = :Object }
Parfait::NamedList.type_for( type_hash )
end
def make_frame
def make_frame(compiler)
type_hash = {}
@body.each do |node|
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
next if compiler.in_scope?(node.name)
type_hash[node.name] = :Object
end
Parfait::NamedList.type_for( type_hash )

View File

@ -47,8 +47,14 @@ module Vool
private
def make_frame
nodes = []
@body.each { |node| nodes << node }
nodes.dup.each do |node|
next unless node.is_a?(BlockStatement)
node.each {|block_scope| nodes.delete(block_scope)}
end
type_hash = {}
@body.each do |node|
nodes.each do |node|
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
type_hash[node.name] = :Object
end

View File

@ -7,7 +7,7 @@ module Vool
def setup
Parfait.boot!
@ret = compile_mom( as_test_main("self.main {|elem| elem } "))
@ret = compile_mom( as_test_main("self.main {|elem| elem = 5 } "))
end
def test_is_compiler
assert_equal Mom::MomCompiler , @ret.class
@ -39,4 +39,15 @@ module Vool
assert_equal 1, @block.frame_type.variable_index(:local)
end
end
class TestBlockMethod < MiniTest::Test
include MomCompile
def setup
Parfait.boot!
@ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } "))
@block = @ret.method_compilers.first.method.blocks
end
def test_block_arg_type
assert_equal Parfait::Type, @block.arguments_type.class
end
end
end

View File

@ -11,7 +11,7 @@ module VoolBlocks
end
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
#assert_equal Mom::SlotLoad , @ins.class , @ins
end
def pest_slot_is_set
assert @ins.left