all of mom and vool

with working block tests this time
This commit is contained in:
Torsten Rüger 2019-08-13 20:35:27 +03:00
parent 155c042009
commit c13a8ceb11
10 changed files with 35 additions and 68 deletions

View File

@ -4,7 +4,6 @@ module Mom
# and to instantiate the methods correctly.
class MethodCompiler < CallableCompiler
alias :callable :method
def initialize( method )
super(method)
@ -29,7 +28,6 @@ module Mom
risc_compiler = Risc::MethodCompiler.new(@callable , mom_instructions)
instructions_to_risc(risc_compiler)
block_compilers.each do |m_comp|
puts "BLOCK #{m_comp}"
risc_compiler.block_compilers << m_comp.to_risc(@callable)
end
risc_compiler

View File

@ -6,51 +6,16 @@ module Risc
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]
@input = as_block("a = 5")
@expect = [LoadConstant, SlotToReg, RegToSlot]
end
def test_send_instructions
assert_nil msg = check_nil(produce_block) , msg
end
def test_load_5
produced = produce_body
produced = produce_block.next
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

View File

@ -1,7 +1,7 @@
require_relative "../helper"
module Risc
class TestBlockSetup < MiniTest::Test
class TestBlockSetupBlock < MiniTest::Test
include Statements
def setup

View File

@ -8,8 +8,7 @@ module Mom
@functions = Builtin.boot_functions
end
def get_compiler( name )
@functions.each.find{|meth|
meth.callable.name == name}
@functions.each.find{|meth| meth.callable.name == name}
end
end
end

View File

@ -45,12 +45,13 @@ module Risc
end
def produce_block
linker = to_target
linker.assemblers.each {|c| puts c.callable.name}
linker.block_compilers.first.instructions
block = linker.assemblers.find {|c| c.callable.name == :main_block}
assert_equal Risc::Assembler , block.class
block.instructions
end
def check_nil( instructions = nil )
produced = instructions || produce_instructions
compare_instructions( produced , @expect)
compare_instructions( produced , @expect )
end
def check_return
was = check_nil

View File

@ -33,6 +33,7 @@ module RubyX
compiler = RubyXCompiler.new(RubyX.default_test_options)
compiler.ruby_to_vool(space_source_for("main"))
compiler.ruby_to_vool(space_source_for("twain"))
assert_equal 2 , compiler.vool.length
linker = compiler.to_binary(:interpreter)
assert_equal Risc::Linker , linker.class
assert_equal 23 , linker.assemblers.length

View File

@ -28,19 +28,21 @@ module VoolCompile
def compile_first_method( input )
inut = as_test_main( input )
input = as_test_main( input )
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
assert collection.is_a?(Mom::MomCollection)
assert collection.is_a?(Mom::MomCollection) , collection.class.name
compiler = collection.compilers.first
assert compiler.is_a?(Mom::MethodCompiler)
assert_equal Mom::MethodCompiler , compiler.class
compiler
end
def compile_first_block( block_input , method_input = "main_local = 5")
source = "#{method_input} ; self.main{|val| #{block_input}}"
risc_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc( as_test_main(source) )
compiler = risc_col.method_compilers.find{|c| c.get_method.name.to_s.start_with?("implicit") }
assert_equal 1 , compiler.class
source = as_test_main("#{method_input} ; self.main{|val| #{block_input}}")
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom( source )
compiler = mom_col.method_compilers.find{|c| c.get_method.name.to_s.start_with?("main") }
block = compiler.block_compilers.first
assert block
block.mom_instructions.next
end
def check_array( should , is )
index = 0

View File

@ -8,23 +8,22 @@ module VoolBlocks
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_block( "local = 5" )
end
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_slots_left
def test_slots_left
assert_equal [:frame , :local] , @ins.left.slots
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
@ -35,13 +34,13 @@ module VoolBlocks
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
end
def pest_class_compiles
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
end
def pest_slots_left
def test_slots_left
assert_equal [:frame, :local] , @ins.left.slots
end
def pest_slots_right
def test_slots_right
assert_equal [:receiver, :a] , @ins.right.slots
end
end
@ -54,13 +53,13 @@ module VoolBlocks
@ins = compile_first_block( "arg = 5")
end
def pest_class_compiles
def test_class_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_slots_left
def test_slots_left
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
end
end
@ -70,12 +69,12 @@ module VoolBlocks
def setup
Parfait.boot!(Parfait.default_test_options)
end
def pest_assigns_const
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 pest_assigns_move
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

View File

@ -22,7 +22,8 @@ module VoolBlocks
end
def test_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
SlotLoad, Jump, Label, SlotLoad, Label,
Label, ReturnSequence, Label] , @ins
end
end

View File

@ -19,7 +19,8 @@ module VoolBlocks
assert_equal SlotDefinition , @ins.next.condition.class , @ins
end
def test_array
check_array [Label, TruthCheck, SlotLoad, Jump, Label], @ins
check_array [Label, TruthCheck, SlotLoad, Jump, Label,
Label, ReturnSequence, Label], @ins
end
end
end