more block tests reveal a compiler bug
copy/paste, args twice in switch
This commit is contained in:
parent
ff8b95f21a
commit
3c1137066b
@ -40,7 +40,7 @@ module Risc
|
|||||||
slot_def = [:frame]
|
slot_def = [:frame]
|
||||||
elsif @method.arguments_type.variable_index(name)
|
elsif @method.arguments_type.variable_index(name)
|
||||||
slot_def = [:caller , :arguments ]
|
slot_def = [:caller , :arguments ]
|
||||||
elsif @method.arguments_type.variable_index(name)
|
elsif @method.frame_type.variable_index(name)
|
||||||
slot_def = [:caller , :frame ]
|
slot_def = [:caller , :frame ]
|
||||||
elsif
|
elsif
|
||||||
raise "no variable #{name} , need to resolve at runtime"
|
raise "no variable #{name} , need to resolve at runtime"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestBlockStatement < MiniTest::Test
|
class TestBlockArg < MiniTest::Test
|
||||||
include MomCompile
|
include MomCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -19,7 +19,7 @@ module Vool
|
|||||||
assert @ret.method_compilers.first.get_method.blocks , "No block created"
|
assert @ret.method_compilers.first.get_method.blocks , "No block created"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBlockCreated < MiniTest::Test
|
class TestBlockLocal < MiniTest::Test
|
||||||
include MomCompile
|
include MomCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ -39,15 +39,19 @@ module Vool
|
|||||||
assert_equal 1, @block.frame_type.variable_index(:local)
|
assert_equal 1, @block.frame_type.variable_index(:local)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBlockMethod < MiniTest::Test
|
class TestBlockMethodArg < MiniTest::Test
|
||||||
include MomCompile
|
include MomCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } "))
|
|
||||||
@block = @ret.method_compilers.first.get_method.blocks
|
|
||||||
end
|
end
|
||||||
def test_block_arg_type
|
def test_method_arg_compiles
|
||||||
assert_equal Parfait::Type, @block.arguments_type.class
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -37,8 +37,8 @@ module MomCompile
|
|||||||
assert_equal Risc::MethodCompiler , compiler.class
|
assert_equal Risc::MethodCompiler , compiler.class
|
||||||
@method.source.to_mom( compiler )
|
@method.source.to_mom( compiler )
|
||||||
end
|
end
|
||||||
def compile_first_block( block_input )
|
def compile_first_block( block_input , method_input = "main_local = 5")
|
||||||
source = "main_local = 5 ; self.main{|val| #{block_input}}"
|
source = "#{method_input} ; self.main{|val| #{block_input}}"
|
||||||
vool = RubyX::RubyCompiler.compile( as_test_main(source) ).normalize
|
vool = RubyX::RubyCompiler.compile( as_test_main(source) ).normalize
|
||||||
mom_c = vool.to_mom(nil)
|
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}
|
compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
||||||
|
@ -13,22 +13,22 @@ module VoolBlocks
|
|||||||
def test_block_compiles
|
def test_block_compiles
|
||||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||||
end
|
end
|
||||||
def pest_slot_is_set
|
def test_slot_is_set
|
||||||
assert @ins.left
|
assert @ins.left
|
||||||
end
|
end
|
||||||
def pest_slot_starts_at_message
|
def test_slot_starts_at_message
|
||||||
assert_equal :message , @ins.left.known_object
|
assert_equal :message , @ins.left.known_object
|
||||||
end
|
end
|
||||||
def pest_slot_gets_self
|
def test_slot_gets_self
|
||||||
assert_equal :frame , @ins.left.slots[0]
|
assert_equal :frame , @ins.left.slots[0]
|
||||||
end
|
end
|
||||||
def pest_slot_assigns_to_local
|
def test_slot_assigns_to_local
|
||||||
assert_equal :main_local , @ins.left.slots[-1]
|
assert_equal :local , @ins.left.slots[-1]
|
||||||
end
|
end
|
||||||
def pest_slot_assigns_something
|
def test_slot_assigns_something
|
||||||
assert @ins.right
|
assert @ins.right
|
||||||
end
|
end
|
||||||
def pest_slot_assigns_int
|
def test_slot_assigns_int
|
||||||
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,10 +38,10 @@ module VoolBlocks
|
|||||||
include MomCompile
|
include MomCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ins = compile_first_method( "@a = 5 ; local = @a")
|
@ins = compile_first_block( "local = @a" , "@a = 5")
|
||||||
end
|
end
|
||||||
def pest_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotLoad , @ins.next.class , @ins
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user