more block tests reveal a compiler bug

copy/paste, args twice in switch
This commit is contained in:
Torsten Ruger 2018-07-18 10:13:19 +03:00
parent ff8b95f21a
commit 3c1137066b
4 changed files with 24 additions and 20 deletions

View File

@ -40,7 +40,7 @@ module Risc
slot_def = [:frame]
elsif @method.arguments_type.variable_index(name)
slot_def = [:caller , :arguments ]
elsif @method.arguments_type.variable_index(name)
elsif @method.frame_type.variable_index(name)
slot_def = [:caller , :frame ]
elsif
raise "no variable #{name} , need to resolve at runtime"

View File

@ -2,7 +2,7 @@
require_relative "helper"
module Vool
class TestBlockStatement < MiniTest::Test
class TestBlockArg < MiniTest::Test
include MomCompile
def setup
@ -19,7 +19,7 @@ module Vool
assert @ret.method_compilers.first.get_method.blocks , "No block created"
end
end
class TestBlockCreated < MiniTest::Test
class TestBlockLocal < MiniTest::Test
include MomCompile
def setup
Parfait.boot!
@ -39,15 +39,19 @@ module Vool
assert_equal 1, @block.frame_type.variable_index(:local)
end
end
class TestBlockMethod < MiniTest::Test
class TestBlockMethodArg < MiniTest::Test
include MomCompile
def setup
Parfait.boot!
@ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } "))
@block = @ret.method_compilers.first.get_method.blocks
end
def test_block_arg_type
assert_equal Parfait::Type, @block.arguments_type.class
def test_method_arg_compiles
ret = compile_mom( as_test_main("self.main {|elem| arg = 5 } "))
assert ret
end
def test_method_local_compiles
ret = compile_mom( as_test_main("local = 5 ; self.main {|elem| local = 10 } "))
assert ret
end
end
end

View File

@ -37,8 +37,8 @@ module MomCompile
assert_equal Risc::MethodCompiler , compiler.class
@method.source.to_mom( compiler )
end
def compile_first_block( block_input )
source = "main_local = 5 ; self.main{|val| #{block_input}}"
def compile_first_block( block_input , method_input = "main_local = 5")
source = "#{method_input} ; self.main{|val| #{block_input}}"
vool = RubyX::RubyCompiler.compile( as_test_main(source) ).normalize
mom_c = vool.to_mom(nil)
compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}

View File

@ -13,22 +13,22 @@ module VoolBlocks
def test_block_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
end
def pest_slot_is_set
def test_slot_is_set
assert @ins.left
end
def pest_slot_starts_at_message
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
end
def pest_slot_gets_self
def test_slot_gets_self
assert_equal :frame , @ins.left.slots[0]
end
def pest_slot_assigns_to_local
assert_equal :main_local , @ins.left.slots[-1]
def test_slot_assigns_to_local
assert_equal :local , @ins.left.slots[-1]
end
def pest_slot_assigns_something
def test_slot_assigns_something
assert @ins.right
end
def pest_slot_assigns_int
def test_slot_assigns_int
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
end
end
@ -38,10 +38,10 @@ module VoolBlocks
include MomCompile
def setup
Parfait.boot!
@ins = compile_first_method( "@a = 5 ; local = @a")
@ins = compile_first_block( "local = @a" , "@a = 5")
end
def pest_class_compiles
assert_equal Mom::SlotLoad , @ins.next.class , @ins
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
end
end