Fix forgotten block compiler
Especially on the way down to risc
This commit is contained in:
56
test/mom/blocks/test_block_assign.rb
Normal file
56
test/mom/blocks/test_block_assign.rb
Normal file
@ -0,0 +1,56 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestBlockAssign < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def setup
|
||||
super
|
||||
@input = as_block("return 5")
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4
|
||||
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #9
|
||||
RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg, #14
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #19
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #24
|
||||
SlotToReg, FunctionCall, Label]
|
||||
end
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil(produce_block) , msg
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
def test_load_block
|
||||
produced = produce_body.next(3)
|
||||
assert_load( produced , Parfait::Block)
|
||||
assert_equal :main_block , produced.constant.name
|
||||
end
|
||||
def test_load_method_to_call
|
||||
produced = produce_body.next(6)
|
||||
assert_load( produced , Parfait::CallableMethod)
|
||||
assert_equal :main , produced.constant.name
|
||||
end
|
||||
def test_load_next_message
|
||||
produced = produce_body.next(7)
|
||||
assert_load( produced , Parfait::Factory)
|
||||
assert_equal "Message_Type" , produced.constant.for_type.name
|
||||
end
|
||||
def test_load_return
|
||||
produced = produce_body.next(22)
|
||||
assert_load( produced , Label)
|
||||
assert produced.constant.name.start_with?("continue_")
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(26)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :main , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(27)
|
||||
assert_equal Label , produced.class
|
||||
assert produced.name.start_with?("continue_")
|
||||
end
|
||||
end
|
||||
end
|
32
test/mom/blocks/test_block_compiler.rb
Normal file
32
test/mom/blocks/test_block_compiler.rb
Normal file
@ -0,0 +1,32 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestBlockSetup < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def setup
|
||||
super
|
||||
@input = as_block("return 5")
|
||||
@mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(as_test_main)
|
||||
end
|
||||
def main_risc
|
||||
@mom.to_risc.method_compilers.find{|c| c.callable.name == :main }
|
||||
end
|
||||
def test_mom
|
||||
assert_equal Mom::MomCollection , @mom.class
|
||||
end
|
||||
def test_mom_block_comp
|
||||
assert_equal 1 , @mom.method_compilers.first.block_compilers.length
|
||||
end
|
||||
def test_risc
|
||||
assert_equal Risc::RiscCollection , @mom.to_risc.class
|
||||
end
|
||||
def test_risc_comp
|
||||
assert_equal :main , main_risc.callable.name
|
||||
end
|
||||
def test_risc_block_comp
|
||||
assert_equal 1 , main_risc.block_compilers.length
|
||||
end
|
||||
|
||||
end
|
||||
end
|
57
test/mom/blocks/test_block_setup.rb
Normal file
57
test/mom/blocks/test_block_setup.rb
Normal file
@ -0,0 +1,57 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestBlockSetup < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def setup
|
||||
super
|
||||
@input = as_block("return 5")
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4
|
||||
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #9
|
||||
RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg, #14
|
||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #19
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #24
|
||||
SlotToReg, FunctionCall, Label]
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
def test_load_block
|
||||
produced = produce_body.next(3)
|
||||
assert_load( produced , Parfait::Block)
|
||||
assert_equal :main_block , produced.constant.name
|
||||
end
|
||||
def test_load_method_to_call
|
||||
produced = produce_body.next(6)
|
||||
assert_load( produced , Parfait::CallableMethod)
|
||||
assert_equal :main , produced.constant.name
|
||||
end
|
||||
def test_load_next_message
|
||||
produced = produce_body.next(7)
|
||||
assert_load( produced , Parfait::Factory)
|
||||
assert_equal "Message_Type" , produced.constant.for_type.name
|
||||
end
|
||||
def test_load_return
|
||||
produced = produce_body.next(22)
|
||||
assert_load( produced , Label)
|
||||
assert produced.constant.name.start_with?("continue_")
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(26)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :main , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(27)
|
||||
assert_equal Label , produced.class
|
||||
assert produced.name.start_with?("continue_")
|
||||
end
|
||||
end
|
||||
end
|
@ -24,17 +24,32 @@ module Risc
|
||||
preamble.each{ produced = produced.next }
|
||||
produced
|
||||
end
|
||||
|
||||
def as_block( block_input , method_input = "main_local = 5")
|
||||
"#{method_input} ; self.main{|val| #{block_input}}"
|
||||
end
|
||||
def as_test_main
|
||||
"class Test; def main(arg);#{@input};end;end"
|
||||
end
|
||||
def produce_instructions
|
||||
def to_target
|
||||
assert @expect , "No output given"
|
||||
linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_test_main).translate(:interpreter)
|
||||
compiler = linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
|
||||
compiler.instructions
|
||||
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_target(as_test_main,:interpreter)
|
||||
end
|
||||
def check_nil
|
||||
produced = produce_instructions
|
||||
def find_main
|
||||
assert @expect , "No output given"
|
||||
linker = to_target
|
||||
linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
|
||||
end
|
||||
def produce_instructions
|
||||
find_main.instructions
|
||||
end
|
||||
def produce_block
|
||||
linker = to_target
|
||||
linker.assemblers.each {|c| puts c.callable.name}
|
||||
linker.block_compilers.first.instructions
|
||||
end
|
||||
def check_nil( instructions = nil )
|
||||
produced = instructions || produce_instructions
|
||||
compare_instructions( produced , @expect)
|
||||
end
|
||||
def check_return
|
||||
|
@ -1,85 +1,23 @@
|
||||
require_relative "../helper"
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestBlockCompiler < MiniTest::Test
|
||||
include MomCompile
|
||||
include ScopeHelper
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "local = 5")
|
||||
code = as_test_main_block("return 5" , "a = 1")
|
||||
@risc = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code)
|
||||
end
|
||||
|
||||
def test_block_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
def test_collection
|
||||
assert_equal Risc::RiscCollection, @risc.class
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
def test_main_compiler
|
||||
assert_equal :main , @risc.method_compilers.first.callable.name
|
||||
end
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @ins.left.known_object
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:frame , :local] , @ins.left.slots
|
||||
end
|
||||
def test_slot_assigns_something
|
||||
assert @ins.right
|
||||
end
|
||||
def test_slot_assigns_int
|
||||
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
||||
def test_main_block_compiler
|
||||
assert_equal :main , @risc.method_compilers.first.block_compilers.first.in_method.name
|
||||
assert_equal :main_block , @risc.method_compilers.first.block_compilers.first.callable.name
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignMomInstanceToLocal < MiniTest::Test
|
||||
include MomCompile
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
|
||||
end
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:frame, :local] , @ins.left.slots
|
||||
end
|
||||
def test_slots_right
|
||||
assert_equal [:receiver, :a] , @ins.right.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignToArg < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "arg = 5")
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignMomToInstance < MiniTest::Test
|
||||
include MomCompile
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
end
|
||||
def test_assigns_const
|
||||
@ins = compile_first_block( "@a = 5")
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
assert_equal Mom::IntegerConstant , @ins.right.known_object.class , @ins
|
||||
end
|
||||
def test_assigns_move
|
||||
@ins = compile_first_block( "@a = arg")
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,12 +21,6 @@ module Mom
|
||||
def test_compilers_bare
|
||||
assert_equal 21 , MomCollection.new.compilers.length
|
||||
end
|
||||
def test_returns_constants
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant_before
|
||||
assert_equal [] , @comp.constants
|
||||
end
|
||||
def test_append_class
|
||||
assert_equal MomCollection, (@comp.append @comp).class
|
||||
end
|
||||
|
Reference in New Issue
Block a user