fix a whole bunch of vool to_mom
All but those requiring boot functions
This commit is contained in:
parent
1237e079f7
commit
d5625a70d7
@ -7,6 +7,7 @@ module Mom
|
|||||||
#
|
#
|
||||||
class ReturnJump < Instruction
|
class ReturnJump < Instruction
|
||||||
|
|
||||||
|
# the jump quite simple resolves to an uncondition risc Branch
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
compiler.add_code Risc::Branch.new(self , compiler.return_label)
|
compiler.add_code Risc::Branch.new(self , compiler.return_label)
|
||||||
end
|
end
|
||||||
|
@ -21,9 +21,9 @@ module Vool
|
|||||||
# to the method compiler for further processing
|
# to the method compiler for further processing
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
parfait_block = self.parfait_block(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 )
|
head = body.to_mom( block_compiler )
|
||||||
block_compiler.add_mom(head)
|
block_compiler.add_code(head)
|
||||||
block_compiler
|
block_compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def simple_if(compiler)
|
def simple_if(compiler)
|
||||||
true_label = Mom::Label.new( "true_label_#{object_id.to_s(16)}")
|
true_label = Mom::Label.new( self,"true_label_#{object_id.to_s(16)}")
|
||||||
merge_label = Mom::Label.new( "merge_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 = Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
|
||||||
head << true_label
|
head << true_label
|
||||||
|
@ -6,7 +6,7 @@ module Vool
|
|||||||
slot_def = compiler.slot_type_for(@name)
|
slot_def = compiler.slot_type_for(@name)
|
||||||
to = Mom::SlotDefinition.new(:message ,slot_def)
|
to = Mom::SlotDefinition.new(:message ,slot_def)
|
||||||
from = @value.slot_definition(compiler)
|
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
|
end
|
||||||
|
@ -50,7 +50,7 @@ module Vool
|
|||||||
arg_target = [:message , :next_message , :arguments]
|
arg_target = [:message , :next_message , :arguments]
|
||||||
args = []
|
args = []
|
||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@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
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
||||||
end
|
end
|
||||||
|
@ -10,8 +10,8 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}")
|
merge_label = Mom::Label.new(self, "merge_label_#{object_id.to_s(16)}")
|
||||||
cond_label = Mom::Label.new( "cond_label_#{object_id.to_s(16)}")
|
cond_label = Mom::Label.new(self, "cond_label_#{object_id.to_s(16)}")
|
||||||
codes = cond_label
|
codes = cond_label
|
||||||
codes << @hoisted.to_mom(compiler) if @hoisted
|
codes << @hoisted.to_mom(compiler) if @hoisted
|
||||||
codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
|
codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
|
||||||
|
@ -33,7 +33,7 @@ module Vool
|
|||||||
# this needs run-time variable resolution, which is just not done.
|
# this needs run-time variable resolution, which is just not done.
|
||||||
# we brace ourselves with the check, and exit (later raise) if . . .
|
# we brace ourselves with the check, and exit (later raise) if . . .
|
||||||
def method_check(compiler)
|
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 , [])
|
compile_method = Mom::SlotDefinition.new( compiler.get_method , [])
|
||||||
runtime_method = Mom::SlotDefinition.new( :message , [ :method] )
|
runtime_method = Mom::SlotDefinition.new( :message , [ :method] )
|
||||||
check = Mom::NotSameCheck.new(compile_method , runtime_method, ok_label)
|
check = Mom::NotSameCheck.new(compile_method , runtime_method, ok_label)
|
||||||
@ -53,7 +53,7 @@ module Vool
|
|||||||
arg_target = [:message , :next_message , :arguments]
|
arg_target = [:message , :next_message , :arguments]
|
||||||
args = []
|
args = []
|
||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@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
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
||||||
setup << Mom::BlockYield.new( arg_index )
|
setup << Mom::BlockYield.new( arg_index )
|
||||||
|
@ -2,39 +2,28 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
class TestMethodCompiler < MiniTest::Test
|
class TestMethodCompiler < MiniTest::Test
|
||||||
include MomCompile
|
include ScopeHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
|
||||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class
|
def in_test_vool(str)
|
||||||
assert_equal MomCompiler , @comp.class
|
vool = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(in_Test(str))
|
||||||
|
vool.to_mom(nil)
|
||||||
|
vool
|
||||||
end
|
end
|
||||||
def test_compilers
|
def in_test_mom(str)
|
||||||
assert_equal 23 , @comp.compilers.length
|
FIXMERubyX::RubyXCompiler.new(in_Test(str)).ruby_to_mom()
|
||||||
end
|
end
|
||||||
def test_boot_compilers
|
def create_method(body = "@ivar = 5")
|
||||||
assert_equal 22 , @comp.boot_compilers.length
|
in_test_vool("def meth; #{body};end")
|
||||||
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
|
test.get_method(:meth)
|
||||||
end
|
end
|
||||||
def test_compilers_bare
|
|
||||||
assert_equal 22 , MomCompiler.new.compilers.length
|
def test_method_has_source
|
||||||
end
|
method = create_method
|
||||||
def test_returns_constants
|
assert_equal Vool::IvarAssignment , method.source.class
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,6 +21,11 @@ module VoolCompile
|
|||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include Mom
|
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)
|
def compile_method(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)
|
||||||
@ -33,6 +38,18 @@ module VoolCompile
|
|||||||
assert_equal Mom::MethodCompiler , ret.class
|
assert_equal Mom::MethodCompiler , ret.class
|
||||||
ret
|
ret
|
||||||
end
|
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 )
|
def check_array( should , is )
|
||||||
index = 0
|
index = 0
|
||||||
test = is
|
test = is
|
||||||
|
@ -2,7 +2,7 @@ require_relative "../helper"
|
|||||||
|
|
||||||
module VoolBlocks
|
module VoolBlocks
|
||||||
class TestAssignMom < MiniTest::Test
|
class TestAssignMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ -30,7 +30,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignMomInstanceToLocal < MiniTest::Test
|
class TestAssignMomInstanceToLocal < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
def setup
|
def setup
|
||||||
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
|
||||||
@ -47,7 +47,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignToArg < MiniTest::Test
|
class TestAssignToArg < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ -66,7 +66,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignMomToInstance < MiniTest::Test
|
class TestAssignMomToInstance < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,6 @@ require_relative "../helper"
|
|||||||
|
|
||||||
module VoolBlocks
|
module VoolBlocks
|
||||||
class TestClassAssignMom < MiniTest::Test
|
class TestClassAssignMom < MiniTest::Test
|
||||||
include MomCompile
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ -21,7 +20,7 @@ module VoolBlocks
|
|||||||
end
|
end
|
||||||
def test_assign_compiles
|
def test_assign_compiles
|
||||||
vool = Ruby::RubyCompiler.compile( as_class_method("val = 0") ).to_vool
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,12 +2,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module VoolBlocks
|
module VoolBlocks
|
||||||
class TestSimpleWhileMom < MiniTest::Test
|
class TestSimpleWhileMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
|
|
||||||
def test_compiles_as_while
|
def test_compiles_as_while
|
||||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
|||||||
module Vool
|
module Vool
|
||||||
# relies on @ins and receiver_type method
|
# relies on @ins and receiver_type method
|
||||||
module SimpleSendHarness
|
module SimpleSendHarness
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
|
@ -8,7 +8,8 @@ module Vool
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
@ins = compile_first_method( "a = main(1 + 2)" )
|
@compiler = compile_first_method( "a = main(1 + 2)" )
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_array
|
def test_array
|
||||||
|
@ -7,7 +7,8 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
def test_check_type
|
def test_check_type
|
||||||
assert_equal NotSameCheck , @ins.next.class , @ins
|
assert_equal NotSameCheck , @ins.next.class , @ins
|
||||||
|
@ -2,11 +2,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestAssignMom < MiniTest::Test
|
class TestAssignMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ins = compile_first_method( "local = 5")
|
@compiler = compile_first_method( "local = 5")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
@ -34,10 +35,11 @@ module Vool
|
|||||||
|
|
||||||
#otherwise as above, but assigning instance, so should get a SlotLoad
|
#otherwise as above, but assigning instance, so should get a SlotLoad
|
||||||
class TestAssignMomInstanceToLocal < MiniTest::Test
|
class TestAssignMomInstanceToLocal < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotLoad , @ins.next.class , @ins
|
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
|
#compiling to an argument should result in different second parameter in the slot array
|
||||||
class TestAssignToArg < MiniTest::Test
|
class TestAssignToArg < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ins = compile_first_method( "arg = 5")
|
@compiler = compile_first_method( "arg = 5")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
@ -71,17 +74,19 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TestAssignMomToInstance < MiniTest::Test
|
class TestAssignMomToInstance < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
end
|
end
|
||||||
def test_assigns_const
|
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::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 test_assigns_move
|
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::SlotLoad , @ins.class , @ins
|
||||||
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
|
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,7 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestConditionIfMom < MiniTest::Test
|
class TestConditionIfMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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")
|
@ins = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_condition
|
def pest_condition
|
||||||
assert_equal TruthCheck , @ins.next(4).class
|
assert_equal TruthCheck , @ins.next(4).class
|
||||||
end
|
end
|
||||||
def test_condition_is_slot
|
def pest_condition_is_slot
|
||||||
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
||||||
end
|
end
|
||||||
def test_hoisted_dynamic_call
|
def pest_hoisted_dynamic_call
|
||||||
assert_equal SimpleCall , @ins.next(2).class
|
assert_equal SimpleCall , @ins.next(2).class
|
||||||
assert_equal :div4 , @ins.next(2).method.name
|
assert_equal :div4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
def test_array
|
def pest_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] , @ins
|
||||||
end
|
end
|
||||||
|
@ -3,12 +3,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestIfNoElse < MiniTest::Test
|
class TestIfNoElse < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
|
|
||||||
def test_condition_compiles_to_check
|
def test_condition_compiles_to_check
|
||||||
@ -24,7 +24,8 @@ module Vool
|
|||||||
assert_equal Label , @ins.last.class , @ins
|
assert_equal Label , @ins.last.class , @ins
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [TruthCheck, Label, SlotLoad, Label], @ins
|
check_array [TruthCheck, Label, SlotLoad, Label, Label ,
|
||||||
|
ReturnSequence, Label], @ins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,12 +3,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestSimpleIfMom < MiniTest::Test
|
class TestSimpleIfMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
|
|
||||||
def test_condition_compiles_to_check
|
def test_condition_compiles_to_check
|
||||||
@ -24,8 +24,8 @@ module Vool
|
|||||||
assert_equal Label , @ins.last.class , @ins
|
assert_equal Label , @ins.last.class , @ins
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [TruthCheck, Label, SlotLoad, Jump, Label, SlotLoad ,
|
check_array [TruthCheck, Label, SlotLoad, Jump, Label ,
|
||||||
Label] , @ins
|
SlotLoad, Label, Label, ReturnSequence, Label], @ins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,11 +2,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestIvarMom < MiniTest::Test
|
class TestIvarMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ins = compile_first_method( "@a = 5")
|
@compiler = compile_first_method( "@a = 5")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compiles_not_array
|
def test_compiles_not_array
|
||||||
|
@ -2,11 +2,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestLocalMom < MiniTest::Test
|
class TestLocalMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ins = compile_first_method( "a = 5")
|
@compiler = compile_first_method( "a = 5")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compiles_not_array
|
def test_compiles_not_array
|
||||||
|
@ -2,56 +2,56 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestReturnMom < MiniTest::Test
|
class TestReturnMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@inst = compile_first_method( "return 5")
|
@compiler = compile_first_method( "return 5")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal SlotLoad , @inst.class , @inst
|
assert_equal SlotLoad , @ins.class , @ins
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @inst.left
|
assert @ins.left
|
||||||
end
|
end
|
||||||
def test_two_instructions_are_returned
|
def test_two_instructions_are_returned
|
||||||
assert_equal 2 , @inst.length
|
assert_equal 5 , @ins.length
|
||||||
end
|
|
||||||
def test_second_is_return
|
|
||||||
assert_equal ReturnJump, @inst.last.class
|
|
||||||
end
|
end
|
||||||
def test_slot_starts_at_message
|
def test_slot_starts_at_message
|
||||||
assert_equal :message , @inst.left.known_object
|
assert_equal :message , @ins.left.known_object
|
||||||
end
|
end
|
||||||
def test_slot_gets_return
|
def test_slot_gets_return
|
||||||
assert_equal :return_value , @inst.left.slots[0]
|
assert_equal :return_value , @ins.left.slots[0]
|
||||||
end
|
end
|
||||||
def test_slot_assigns_something
|
def test_slot_assigns_something
|
||||||
assert @inst.right
|
assert @ins.right
|
||||||
end
|
end
|
||||||
def test_slot_assigns_int
|
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
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [SlotLoad,ReturnSequence] , @ins
|
check_array [SlotLoad, ReturnJump, Label, ReturnSequence, Label], @ins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestReturnSendMom < MiniTest::Test
|
class TestReturnSendMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
@ins = compile_first_method( "return 5.div4")
|
@compiler = compile_first_method( "return 5.div4")
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_is_last
|
def pest_return_is_last
|
||||||
assert_equal ReturnJump , @ins.last.class
|
assert_equal ReturnJump , @ins.last.class
|
||||||
end
|
end
|
||||||
def test_array
|
def pest_array
|
||||||
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,SlotLoad,ReturnJump] , @ins
|
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,SlotLoad,ReturnJump] , @ins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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
|
|
@ -2,12 +2,12 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestSimpleWhileMom < MiniTest::Test
|
class TestSimpleWhileMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
|
|
||||||
def test_compiles_as_while
|
def test_compiles_as_while
|
||||||
@ -20,7 +20,8 @@ module Vool
|
|||||||
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
|
@ -3,32 +3,32 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestWhileConditionMom < MiniTest::Test
|
class TestWhileConditionMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc::Builtin.boot_functions
|
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
|
end
|
||||||
|
|
||||||
def test_condition_compiles_to_check
|
def pest_condition_compiles_to_check
|
||||||
assert_equal TruthCheck , @ins.next(5).class
|
assert_equal TruthCheck , @ins.next(5).class
|
||||||
end
|
end
|
||||||
def test_condition_is_slot
|
def pest_condition_is_slot
|
||||||
assert_equal SlotDefinition , @ins.next(5).condition.class , @ins
|
assert_equal SlotDefinition , @ins.next(5).condition.class , @ins
|
||||||
end
|
end
|
||||||
def test_hoisetd
|
def pest_hoisetd
|
||||||
jump = @ins.next(9)
|
jump = @ins.next(9)
|
||||||
assert_kind_of Jump , jump
|
assert_kind_of Jump , jump
|
||||||
assert jump.label.name.start_with?("cond_label") , jump.label.name
|
assert jump.label.name.start_with?("cond_label") , jump.label.name
|
||||||
end
|
end
|
||||||
def test_label
|
def pest_label
|
||||||
label = @ins
|
label = @ins
|
||||||
assert_equal Label , label.class
|
assert_equal Label , label.class
|
||||||
assert label.name.start_with?("cond_label") , label.name
|
assert label.name.start_with?("cond_label") , label.name
|
||||||
end
|
end
|
||||||
def test_array
|
def pest_array
|
||||||
check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
|
check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
|
||||||
TruthCheck, MessageSetup, ArgumentTransfer, SimpleCall, Jump ,
|
TruthCheck, MessageSetup, ArgumentTransfer, SimpleCall, Jump ,
|
||||||
Label] , @ins
|
Label] , @ins
|
@ -55,17 +55,19 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestYieldArgsSendMom < MiniTest::Test
|
class TestYieldArgsSendMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include YieldBasics
|
include YieldBasics
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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
|
end
|
||||||
|
|
||||||
def test_array
|
def test_array
|
||||||
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
|
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
|
||||||
SlotLoad, SlotLoad, ReturnJump] , @ins
|
SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence ,
|
||||||
|
Label] , @ins
|
||||||
end
|
end
|
||||||
def test_transfer
|
def test_transfer
|
||||||
assert_equal ArgumentTransfer, @ins.next(3).class
|
assert_equal ArgumentTransfer, @ins.next(3).class
|
||||||
@ -79,16 +81,17 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestYieldNoArgsSendMom < MiniTest::Test
|
class TestYieldNoArgsSendMom < MiniTest::Test
|
||||||
include MomCompile
|
include VoolCompile
|
||||||
include Mom
|
|
||||||
include YieldBasics
|
include YieldBasics
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@ins = compile_first_method( "return yield" )
|
@compiler = compile_first_method( "return yield" )
|
||||||
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
|
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
|
||||||
SlotLoad, SlotLoad, ReturnJump] , @ins
|
SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence ,
|
||||||
|
Label] , @ins
|
||||||
end
|
end
|
||||||
def test_transfer
|
def test_transfer
|
||||||
assert_equal ArgumentTransfer, @ins.next(3).class
|
assert_equal ArgumentTransfer, @ins.next(3).class
|
||||||
|
Loading…
Reference in New Issue
Block a user