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

View File

@ -6,51 +6,16 @@ module Risc
def setup def setup
super super
@input = as_block("return 5") @input = as_block("a = 5")
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4 @expect = [LoadConstant, SlotToReg, RegToSlot]
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 end
def test_send_instructions def test_send_instructions
assert_nil msg = check_nil(produce_block) , msg assert_nil msg = check_nil(produce_block) , msg
end end
def test_load_5 def test_load_5
produced = produce_body produced = produce_block.next
assert_load( produced , Parfait::Integer) assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end 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
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,8 @@ module VoolBlocks
end end
def test_array def test_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label , 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
end end

View File

@ -19,7 +19,8 @@ module VoolBlocks
assert_equal SlotDefinition , @ins.next.condition.class , @ins assert_equal SlotDefinition , @ins.next.condition.class , @ins
end end
def test_array 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 end
end end