finish assign test

start ifs
This commit is contained in:
Torsten Ruger 2018-07-18 13:57:38 +03:00
parent 3c1137066b
commit f624e38dbb
4 changed files with 47 additions and 22 deletions

View File

@ -0,0 +1 @@
require_relative "../helper"

View File

@ -19,11 +19,8 @@ module VoolBlocks
def test_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 test_slot_gets_self def test_slots_left
assert_equal :frame , @ins.left.slots[0] assert_equal [:frame , :local] , @ins.left.slots
end
def test_slot_assigns_to_local
assert_equal :local , @ins.left.slots[-1]
end end
def test_slot_assigns_something def test_slot_assigns_something
assert @ins.right assert @ins.right
@ -33,41 +30,39 @@ module VoolBlocks
end end
end end
#otherwise as above, but assigning instance, so should get a SlotLoad
class TestAssignMomInstanceToLocal < MiniTest::Test class TestAssignMomInstanceToLocal < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
Parfait.boot! Parfait.boot!
@ins = compile_first_block( "local = @a" , "@a = 5") @ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
end end
def test_class_compiles def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins assert_equal Mom::SlotLoad , @ins.class , @ins
end 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 end
#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 MomCompile
def setup def setup
Parfait.boot! Parfait.boot!
@ins = compile_first_method( "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_slot_starts_at_message def test_slots_left
assert_equal :message , @ins.left.known_object assert_equal [:caller, :arguments, :arg] , @ins.left.slots
end
def pest_slot_gets_self
assert_equal :arguments , @ins.left.slots[0]
end
def pest_slot_assigns_to_local
assert_equal :arg , @ins.left.slots[-1]
end end
end end
@ -76,12 +71,12 @@ module VoolBlocks
def setup def setup
Parfait.boot! Parfait.boot!
end end
def pest_assigns_const def test_assigns_const
@ins = compile_first_method( "@a = 5") @ins = compile_first_method( "@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_method( "@a = arg") @ins = compile_first_method( "@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

@ -0,0 +1,30 @@
require_relative "helper"
module VoolBlocks
class TestConditionIfMom #< MiniTest::Test
include MomCompile
include Mom
def setup
Parfait.boot!
Risc::Builtin.boot_functions
@ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
end
def test_condition
assert_equal TruthCheck , @ins.next(4).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
end
def test_hoisted_dynamic_call
assert_equal SimpleCall , @ins.next(2).class
assert_equal :div4 , @ins.next(2).method.name
end
def test_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
end
end
end

View File

@ -1,4 +1,3 @@
require_relative "helper" require_relative "helper"
module Vool module Vool