tests for mom check instructions
This commit is contained in:
parent
5ab021de5a
commit
b46512a1b8
@ -13,7 +13,6 @@ module Mom
|
||||
|
||||
def initialize(left, right , label)
|
||||
super(label)
|
||||
raise right.to_s if right.to_s.include?("arguments")
|
||||
@left , @right = left , right
|
||||
end
|
||||
|
||||
|
@ -71,4 +71,5 @@ require_relative "instructions/function_return"
|
||||
require_relative "instructions/transfer"
|
||||
require_relative "instructions/label"
|
||||
require_relative "instructions/branch"
|
||||
require_relative "instructions/dynamic_jump"
|
||||
require_relative "instructions/operator_instruction"
|
||||
|
@ -31,32 +31,6 @@ module Risc
|
||||
end
|
||||
end
|
||||
|
||||
# dynamic version of an Branch that jumps to the contents
|
||||
# of a register instead of a hardcoded address
|
||||
# As Branches jump to Labels, this is not derived from Branch
|
||||
# PS: to conditionally jump to a dynamic adddress we do a normal branch
|
||||
# over the dynamic one and then a dynamic one. Save us having all types of branches
|
||||
# in two versions
|
||||
class DynamicJump < Instruction
|
||||
def initialize( source , register )
|
||||
super(source)
|
||||
@register = register
|
||||
end
|
||||
attr_reader :register
|
||||
|
||||
def to_s
|
||||
class_source( register.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
# A Dynamic yield is very much like a DynamicJump, especially in it's idea
|
||||
#
|
||||
# The implentation differes slightly, as we use a chache entry in the DynamicJump
|
||||
# but a block in the DynamicYield.
|
||||
# Using means that we assume the register to be ready loaded with a Block
|
||||
class DynamicYield < DynamicJump
|
||||
end
|
||||
|
||||
class IsZero < Branch
|
||||
end
|
||||
|
||||
|
27
lib/risc/instructions/dynamic_jump.rb
Normal file
27
lib/risc/instructions/dynamic_jump.rb
Normal file
@ -0,0 +1,27 @@
|
||||
module Risc
|
||||
# dynamic version of an Branch that jumps to the contents
|
||||
# of a register instead of a hardcoded address
|
||||
# As Branches jump to Labels, this is not derived from Branch
|
||||
# PS: to conditionally jump to a dynamic adddress we do a normal branch
|
||||
# over the dynamic one and then a dynamic one. Save us having all types of branches
|
||||
# in two versions
|
||||
class DynamicJump < Instruction
|
||||
def initialize( source , register )
|
||||
super(source)
|
||||
@register = register
|
||||
end
|
||||
attr_reader :register
|
||||
|
||||
def to_s
|
||||
class_source( register.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
# A Dynamic yield is very much like a DynamicJump, especially in it's idea
|
||||
#
|
||||
# The implentation differes slightly, as we use a chache entry in the DynamicJump
|
||||
# but a block in the DynamicYield.
|
||||
# Using means that we assume the register to be ready loaded with a Block
|
||||
class DynamicYield < DynamicJump
|
||||
end
|
||||
end
|
46
test/mom/instruction/test_check.rb
Normal file
46
test/mom/instruction/test_check.rb
Normal file
@ -0,0 +1,46 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestNotSameCheck < MomInstructionTest
|
||||
def instruction
|
||||
target = SlotDefinition.new(:message , :caller)
|
||||
NotSameCheck.new(target , target , Label.new("ok" , "land"))
|
||||
end
|
||||
def test_len
|
||||
assert_equal 5 , all.length , all_str
|
||||
end
|
||||
def test_2_slot
|
||||
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
|
||||
end
|
||||
end
|
||||
# [Label, SlotToReg, SlotToReg, OperatorInstruction, IsZero,] #5
|
||||
end
|
||||
module X
|
||||
class Y
|
||||
def test_1_load
|
||||
assert_load risc(1) , Risc::Label , :r1
|
||||
assert_label risc(1).constant , "continue_"
|
||||
end
|
||||
def test_2_slot
|
||||
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
|
||||
end
|
||||
def test_3_reg
|
||||
assert_reg_to_slot risc(3) , :r1 , :r2 , 4
|
||||
end
|
||||
def test_4_slot
|
||||
assert_slot_to_reg risc(4) ,:r0 , 1 , :r0
|
||||
end
|
||||
def test_5_load
|
||||
assert_load risc(5) , Parfait::CacheEntry , :r3
|
||||
end
|
||||
def test_6_slot
|
||||
assert_slot_to_reg risc(6) ,:r3 , 2 , :r3
|
||||
end
|
||||
def test_7_jump
|
||||
assert_equal Risc::DynamicJump , risc(7).class
|
||||
end
|
||||
def test_8_label
|
||||
assert_label risc(8) , "continue_"
|
||||
end
|
||||
end
|
||||
end
|
29
test/mom/instruction/test_not_same_check.rb
Normal file
29
test/mom/instruction/test_not_same_check.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestNotSameCheck < MomInstructionTest
|
||||
def instruction
|
||||
target = SlotDefinition.new(:message , :caller)
|
||||
NotSameCheck.new(target , target , Label.new("ok" , "target"))
|
||||
end
|
||||
def test_len
|
||||
assert_equal 5 , all.length , all_str
|
||||
end
|
||||
def test_1_slot
|
||||
assert_slot_to_reg risc(1) ,:r0 , 6 , :r2
|
||||
end
|
||||
def test_2_slot
|
||||
assert_slot_to_reg risc(2) ,:r0 , 6 , :r4
|
||||
end
|
||||
def test_3_op
|
||||
assert_equal Risc::OperatorInstruction , risc(3).class
|
||||
assert_equal :r2 , risc(3).left.symbol
|
||||
assert_equal :r4 , risc(3).right.symbol
|
||||
assert_equal :- , risc(3).operator
|
||||
end
|
||||
def test_4_zero
|
||||
assert_equal Risc::IsZero , risc(4).class
|
||||
assert_label risc(4).label , "target"
|
||||
end
|
||||
end
|
||||
end
|
42
test/mom/instruction/test_truth_check.rb
Normal file
42
test/mom/instruction/test_truth_check.rb
Normal file
@ -0,0 +1,42 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestSameCheck < MomInstructionTest
|
||||
def instruction
|
||||
target = SlotDefinition.new(:message , :caller)
|
||||
TruthCheck.new(target , Label.new("ok" , "target"))
|
||||
end
|
||||
def test_len
|
||||
assert_equal 8 , all.length , all_str
|
||||
end
|
||||
def test_1_slot
|
||||
assert_slot_to_reg risc(1) ,:r0 , 6 , :r2
|
||||
end
|
||||
def test_2_load
|
||||
assert_load risc(2) , Parfait::FalseClass , :r3
|
||||
end
|
||||
def test_3_op
|
||||
assert_equal Risc::OperatorInstruction , risc(3).class
|
||||
assert_equal :r3 , risc(3).left.symbol
|
||||
assert_equal :r2 , risc(3).right.symbol
|
||||
assert_equal :- , risc(3).operator
|
||||
end
|
||||
def test_4_zero
|
||||
assert_equal Risc::IsZero , risc(4).class
|
||||
assert_label risc(4).label , "target"
|
||||
end
|
||||
def test_5_load
|
||||
assert_load risc(5) , Parfait::NilClass , :r3
|
||||
end
|
||||
def test_6_op
|
||||
assert_equal Risc::OperatorInstruction , risc(6).class
|
||||
assert_equal :r3 , risc(6).left.symbol
|
||||
assert_equal :r2 , risc(6).right.symbol
|
||||
assert_equal :- , risc(6).operator
|
||||
end
|
||||
def test_7_zero
|
||||
assert_equal Risc::IsZero , risc(7).class
|
||||
assert_label risc(7).label , "target"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user