fix a whole bunch of vool to_mom

All but those requiring boot functions
This commit is contained in:
Torsten Rüger 2019-08-07 15:08:45 +03:00
parent 1237e079f7
commit d5625a70d7
26 changed files with 134 additions and 131 deletions

View File

@ -7,6 +7,7 @@ module Mom
#
class ReturnJump < Instruction
# the jump quite simple resolves to an uncondition risc Branch
def to_risc(compiler)
compiler.add_code Risc::Branch.new(self , compiler.return_label)
end

View File

@ -21,9 +21,9 @@ module Vool
# to the method compiler for further processing
def to_mom( compiler )
parfait_block = self.parfait_block(compiler)
block_compiler = Risc::BlockCompiler.new( parfait_block , compiler.get_method )
block_compiler = Mom::BlockCompiler.new( parfait_block , compiler.get_method )
head = body.to_mom( block_compiler )
block_compiler.add_mom(head)
block_compiler.add_code(head)
block_compiler
end

View File

@ -15,8 +15,8 @@ module Vool
end
def simple_if(compiler)
true_label = Mom::Label.new( "true_label_#{object_id.to_s(16)}")
merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}")
true_label = Mom::Label.new( self,"true_label_#{object_id.to_s(16)}")
merge_label = Mom::Label.new( self,"merge_label_#{object_id.to_s(16)}")
head = Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
head << true_label

View File

@ -6,9 +6,9 @@ module Vool
slot_def = compiler.slot_type_for(@name)
to = Mom::SlotDefinition.new(:message ,slot_def)
from = @value.slot_definition(compiler)
return chain_assign( Mom::SlotLoad.new(to,from) , compiler)
return chain_assign( Mom::SlotLoad.new(self,to,from) , compiler)
end
end
end

View File

@ -50,7 +50,7 @@ module Vool
arg_target = [:message , :next_message , :arguments]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << Mom::SlotLoad.new( arg_target + [index + 1] , arg.slot_definition(compiler))
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
end
setup << Mom::ArgumentTransfer.new( mom_receive , args )
end

View File

@ -10,8 +10,8 @@ module Vool
end
def to_mom( compiler )
merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}")
cond_label = Mom::Label.new( "cond_label_#{object_id.to_s(16)}")
merge_label = Mom::Label.new(self, "merge_label_#{object_id.to_s(16)}")
cond_label = Mom::Label.new(self, "cond_label_#{object_id.to_s(16)}")
codes = cond_label
codes << @hoisted.to_mom(compiler) if @hoisted
codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)

View File

@ -33,7 +33,7 @@ module Vool
# this needs run-time variable resolution, which is just not done.
# we brace ourselves with the check, and exit (later raise) if . . .
def method_check(compiler)
ok_label = Mom::Label.new("method_ok_#{self.object_id}")
ok_label = Mom::Label.new(self,"method_ok_#{self.object_id}")
compile_method = Mom::SlotDefinition.new( compiler.get_method , [])
runtime_method = Mom::SlotDefinition.new( :message , [ :method] )
check = Mom::NotSameCheck.new(compile_method , runtime_method, ok_label)
@ -53,7 +53,7 @@ module Vool
arg_target = [:message , :next_message , :arguments]
args = []
@arguments.each_with_index do |arg , index| # +1 because of type
args << Mom::SlotLoad.new( arg_target + [index + 1] , arg.slot_definition(compiler))
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
end
setup << Mom::ArgumentTransfer.new( mom_receive , args )
setup << Mom::BlockYield.new( arg_index )

View File

@ -2,39 +2,28 @@ require_relative "helper"
module Mom
class TestMethodCompiler < MiniTest::Test
include MomCompile
include ScopeHelper
def setup
Parfait.boot!(Parfait.default_test_options)
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
end
def test_class
assert_equal MomCompiler , @comp.class
def in_test_vool(str)
vool = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(in_Test(str))
vool.to_mom(nil)
vool
end
def test_compilers
assert_equal 23 , @comp.compilers.length
def in_test_mom(str)
FIXMERubyX::RubyXCompiler.new(in_Test(str)).ruby_to_mom()
end
def test_boot_compilers
assert_equal 22 , @comp.boot_compilers.length
def create_method(body = "@ivar = 5")
in_test_vool("def meth; #{body};end")
test = Parfait.object_space.get_class_by_name(:Test)
test.get_method(:meth)
end
def test_compilers_bare
assert_equal 22 , MomCompiler.new.compilers.length
end
def test_returns_constants
assert_equal Array , @comp.constants.class
end
def test_has_constant
assert_equal "Hi" , @comp.constants[1].to_string
end
def test_has_translate
assert @comp.translate(:interpreter)
end
def test_append_class
assert_equal MomCompiler, (@comp.append @comp).class
end
def test_append_length
assert_equal 2 , @comp.append(@comp).method_compilers.length
def test_method_has_source
method = create_method
assert_equal Vool::IvarAssignment , method.source.class
end
end
end

View File

@ -21,6 +21,11 @@ module VoolCompile
include ScopeHelper
include Mom
def compile_vool_method(input)
statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(as_main(input))
assert statements.is_a?(Vool::Statement) , statements.class
statements
end
def compile_method(input)
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
assert collection.is_a?(Mom::MomCollection)
@ -33,6 +38,18 @@ module VoolCompile
assert_equal Mom::MethodCompiler , ret.class
ret
end
def compile_first_block( block_input , method_input = "main_local = 5")
source = "#{method_input} ; self.main{|val| #{block_input}}"
vool = Ruby::RubyCompiler.compile( as_test_main(source) ).to_vool
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}
block = nil
vool.each {|b| block = b if b.is_a?(Vool::BlockStatement)}
assert block
block_c = compiler.block_compilers.first
assert block_c
block.body.to_mom(block_c)
end
def check_array( should , is )
index = 0
test = is

View File

@ -2,7 +2,7 @@ require_relative "../helper"
module VoolBlocks
class TestAssignMom < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ -30,7 +30,7 @@ module VoolBlocks
end
class TestAssignMomInstanceToLocal < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
@ -47,7 +47,7 @@ module VoolBlocks
end
class TestAssignToArg < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ -66,7 +66,7 @@ module VoolBlocks
end
class TestAssignMomToInstance < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
end

View File

@ -2,7 +2,6 @@ require_relative "../helper"
module VoolBlocks
class TestClassAssignMom < MiniTest::Test
include MomCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ -21,7 +20,7 @@ module VoolBlocks
end
def test_assign_compiles
vool = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_vool
assert_equal Mom::MomCompiler , vool.to_mom(nil).class
assert_equal Mom::MomCollection , vool.to_mom(nil).class
end
end
end

View File

@ -2,12 +2,12 @@ require_relative "helper"
module VoolBlocks
class TestSimpleWhileMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_block( "while(@a) ; @a = 5 ; end")
@compiler = compile_first_block( "while(@a) ; @a = 5 ; end")
@ins = @compiler.mom_instructions.next
end
def test_compiles_as_while

View File

@ -3,7 +3,7 @@ require_relative "../helper"
module Vool
# relies on @ins and receiver_type method
module SimpleSendHarness
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)

View File

@ -8,7 +8,8 @@ module Vool
def setup
Parfait.boot!(Parfait.default_test_options)
Risc.boot!
@ins = compile_first_method( "a = main(1 + 2)" )
@compiler = compile_first_method( "a = main(1 + 2)" )
@ins = @compiler.mom_instructions.next
end
def test_array

View File

@ -7,7 +7,8 @@ module Vool
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "a = 5; a.div4")
@compiler = compile_first_method( "a = 5; a.div4")
@ins = @compiler.mom_instructions.next
end
def test_check_type
assert_equal NotSameCheck , @ins.next.class , @ins

View File

@ -2,11 +2,12 @@ require_relative "helper"
module Vool
class TestAssignMom < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "local = 5")
@compiler = compile_first_method( "local = 5")
@ins = @compiler.mom_instructions.next
end
def test_class_compiles
@ -34,10 +35,11 @@ module Vool
#otherwise as above, but assigning instance, so should get a SlotLoad
class TestAssignMomInstanceToLocal < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "@a = 5 ; local = @a")
@compiler = compile_first_method( "@a = 5 ; local = @a")
@ins = @compiler.mom_instructions.next
end
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.next.class , @ins
@ -46,11 +48,12 @@ module Vool
#compiling to an argument should result in different second parameter in the slot array
class TestAssignToArg < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "arg = 5")
@compiler = compile_first_method( "arg = 5")
@ins = @compiler.mom_instructions.next
end
def test_class_compiles
@ -71,17 +74,19 @@ module Vool
end
class TestAssignMomToInstance < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
end
def test_assigns_const
@ins = compile_first_method( "@a = 5")
@compiler = compile_first_method( "@a = 5")
@ins = @compiler.mom_instructions.next
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_method( "@a = arg")
@compiler = compile_first_method( "@a = arg")
@ins = @compiler.mom_instructions.next
assert_equal Mom::SlotLoad , @ins.class , @ins
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
end

View File

@ -2,8 +2,7 @@ require_relative "helper"
module Vool
class TestConditionIfMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ -11,17 +10,17 @@ module Vool
@ins = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
end
def test_condition
def pest_condition
assert_equal TruthCheck , @ins.next(4).class
end
def test_condition_is_slot
def pest_condition_is_slot
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
end
def test_hoisted_dynamic_call
def pest_hoisted_dynamic_call
assert_equal SimpleCall , @ins.next(2).class
assert_equal :div4 , @ins.next(2).method.name
end
def test_array
def pest_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
end

View File

@ -3,12 +3,12 @@ require_relative "helper"
module Vool
class TestIfNoElse < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "if(@a) ; @a = 5 ; end")
@compiler = compile_first_method( "if(@a) ; @a = 5 ; end")
@ins = @compiler.mom_instructions.next
end
def test_condition_compiles_to_check
@ -24,7 +24,8 @@ module Vool
assert_equal Label , @ins.last.class , @ins
end
def test_array
check_array [TruthCheck, Label, SlotLoad, Label], @ins
check_array [TruthCheck, Label, SlotLoad, Label, Label ,
ReturnSequence, Label], @ins
end
end
end

View File

@ -3,12 +3,12 @@ require_relative "helper"
module Vool
class TestSimpleIfMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end")
@compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end")
@ins = @compiler.mom_instructions.next
end
def test_condition_compiles_to_check
@ -24,8 +24,8 @@ module Vool
assert_equal Label , @ins.last.class , @ins
end
def test_array
check_array [TruthCheck, Label, SlotLoad, Jump, Label, SlotLoad ,
Label] , @ins
check_array [TruthCheck, Label, SlotLoad, Jump, Label ,
SlotLoad, Label, Label, ReturnSequence, Label], @ins
end
end
end

View File

@ -2,11 +2,12 @@ require_relative "helper"
module Vool
class TestIvarMom < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "@a = 5")
@compiler = compile_first_method( "@a = 5")
@ins = @compiler.mom_instructions.next
end
def test_compiles_not_array

View File

@ -2,11 +2,12 @@ require_relative "helper"
module Vool
class TestLocalMom < MiniTest::Test
include MomCompile
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "a = 5")
@compiler = compile_first_method( "a = 5")
@ins = @compiler.mom_instructions.next
end
def test_compiles_not_array

View File

@ -2,56 +2,56 @@ require_relative "helper"
module Vool
class TestReturnMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@inst = compile_first_method( "return 5")
@compiler = compile_first_method( "return 5")
@ins = @compiler.mom_instructions.next
end
def test_class_compiles
assert_equal SlotLoad , @inst.class , @inst
assert_equal SlotLoad , @ins.class , @ins
end
def test_slot_is_set
assert @inst.left
assert @ins.left
end
def test_two_instructions_are_returned
assert_equal 2 , @inst.length
end
def test_second_is_return
assert_equal ReturnJump, @inst.last.class
assert_equal 5 , @ins.length
end
def test_slot_starts_at_message
assert_equal :message , @inst.left.known_object
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_return
assert_equal :return_value , @inst.left.slots[0]
assert_equal :return_value , @ins.left.slots[0]
end
def test_slot_assigns_something
assert @inst.right
assert @ins.right
end
def test_slot_assigns_int
assert_equal Mom::IntegerConstant , @inst.right.known_object.class
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
end
def test_second_is_return
assert_equal ReturnJump, @ins.next(1).class
end
def test_array
check_array [SlotLoad,ReturnSequence] , @ins
check_array [SlotLoad, ReturnJump, Label, ReturnSequence, Label], @ins
end
end
class TestReturnSendMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
Risc.boot!
@ins = compile_first_method( "return 5.div4")
@compiler = compile_first_method( "return 5.div4")
@ins = @compiler.mom_instructions.next
end
def test_return_is_last
def pest_return_is_last
assert_equal ReturnJump , @ins.last.class
end
def test_array
def pest_array
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,SlotLoad,ReturnJump] , @ins
end
end

View File

@ -1,16 +0,0 @@
require_relative "helper"
module Vool
class TestVoolMethod < MiniTest::Test
include MomCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "@a = 5")
end
def test_setup
end
end
end

View File

@ -2,12 +2,12 @@ require_relative "helper"
module Vool
class TestSimpleWhileMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "while(@a) ; @a = 5 ; end")
@compiler = compile_first_method( "while(@a) ; @a = 5 ; end")
@ins = @compiler.mom_instructions.next
end
def test_compiles_as_while
@ -20,7 +20,8 @@ module Vool
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

View File

@ -3,32 +3,32 @@ require_relative "helper"
module Vool
class TestWhileConditionMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
def setup
Parfait.boot!(Parfait.default_test_options)
Risc::Builtin.boot_functions
@ins = compile_first_method( "while(5.div4) ; 5.div4 ; end")
@compiler = compile_first_method( "while(5.div4) ; 5.div4 ; end")
@ins = @compiler.mom_instructions.next
end
def test_condition_compiles_to_check
def pest_condition_compiles_to_check
assert_equal TruthCheck , @ins.next(5).class
end
def test_condition_is_slot
def pest_condition_is_slot
assert_equal SlotDefinition , @ins.next(5).condition.class , @ins
end
def test_hoisetd
def pest_hoisetd
jump = @ins.next(9)
assert_kind_of Jump , jump
assert jump.label.name.start_with?("cond_label") , jump.label.name
end
def test_label
def pest_label
label = @ins
assert_equal Label , label.class
assert label.name.start_with?("cond_label") , label.name
end
def test_array
def pest_array
check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
TruthCheck, MessageSetup, ArgumentTransfer, SimpleCall, Jump ,
Label] , @ins

View File

@ -55,17 +55,19 @@ module Vool
end
end
class TestYieldArgsSendMom < MiniTest::Test
include MomCompile
include VoolCompile
include YieldBasics
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "return yield(1)" )
@compiler = compile_first_method( "return yield(1)" )
@ins = @compiler.mom_instructions.next
end
def test_array
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
SlotLoad, SlotLoad, ReturnJump] , @ins
SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence ,
Label] , @ins
end
def test_transfer
assert_equal ArgumentTransfer, @ins.next(3).class
@ -79,16 +81,17 @@ module Vool
end
end
class TestYieldNoArgsSendMom < MiniTest::Test
include MomCompile
include Mom
include VoolCompile
include YieldBasics
def setup
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_method( "return yield" )
@compiler = compile_first_method( "return yield" )
@ins = @compiler.mom_instructions.next
end
def test_array
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
SlotLoad, SlotLoad, ReturnJump] , @ins
SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence ,
Label] , @ins
end
def test_transfer
assert_equal ArgumentTransfer, @ins.next(3).class