add while interpreter test
This commit is contained in:
parent
1849522a54
commit
13d8a65e07
@ -33,16 +33,25 @@ module Vool
|
|||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:True).instance_type
|
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||||
end
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class FalseConstant < Constant
|
class FalseConstant < Constant
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:False).instance_type
|
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||||
end
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class NilConstant < Constant
|
class NilConstant < Constant
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||||
end
|
end
|
||||||
|
def slot_definition(method)
|
||||||
|
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class SelfExpression < Expression
|
class SelfExpression < Expression
|
||||||
attr_reader :my_type
|
attr_reader :my_type
|
||||||
|
33
test/mom/assign/test_assign_local_false.rb
Normal file
33
test/mom/assign/test_assign_local_false.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
require_relative '../helper'
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestAssignLocalFalse < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "r = false"
|
||||||
|
@expect = [LoadConstant,SlotToReg, RegToSlot]
|
||||||
|
end
|
||||||
|
def test_local_assign_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_constant_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal Parfait::FalseClass , produced.constant.class
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_frame_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal :Message , produced.next(1).array.type
|
||||||
|
assert_equal 4 , produced.next(1).index # 4 is frame
|
||||||
|
end
|
||||||
|
def test_value_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(2).register , produced.register
|
||||||
|
assert_equal 2 , produced.next(2).index #type == 1 , r == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,7 +1,7 @@
|
|||||||
require_relative '../helper'
|
require_relative '../helper'
|
||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
class TestAssignLocalConst < MiniTest::Test
|
class TestAssignLocalInt < MiniTest::Test
|
||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
59
test/risc/interpreter/test_while_simple.rb
Normal file
59
test/risc/interpreter/test_while_simple.rb
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class InterpreterWhileSimle < MiniTest::Test
|
||||||
|
include Ticker
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@string_input = as_main 'a = true; while( a ); a = false;end;return a'
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_if
|
||||||
|
#show_main_ticks # get output of what is in main
|
||||||
|
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, Label,
|
||||||
|
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
|
||||||
|
LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg,
|
||||||
|
RegToSlot, Branch, Label, SlotToReg, SlotToReg,
|
||||||
|
LoadConstant, OperatorInstruction, IsZero, Label, SlotToReg,
|
||||||
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
||||||
|
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
|
||||||
|
NilClass]
|
||||||
|
assert_kind_of Parfait::FalseClass , get_return
|
||||||
|
end
|
||||||
|
def test_load_false_const
|
||||||
|
load = main_ticks(2)
|
||||||
|
assert_equal LoadConstant , load.class
|
||||||
|
assert_kind_of Parfait::TrueClass , load.constant
|
||||||
|
end
|
||||||
|
def test_load_false
|
||||||
|
load = main_ticks(8)
|
||||||
|
assert_equal LoadConstant , load.class
|
||||||
|
assert_equal Parfait::FalseClass , load.constant.class
|
||||||
|
end
|
||||||
|
def test_compare
|
||||||
|
op = main_ticks(9)
|
||||||
|
assert_equal OperatorInstruction , op.class
|
||||||
|
assert_equal :- , op.operator
|
||||||
|
end
|
||||||
|
def test_not_zero
|
||||||
|
check = main_ticks(10)
|
||||||
|
assert_equal IsZero , check.class
|
||||||
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
||||||
|
end
|
||||||
|
def test_compare2
|
||||||
|
op = main_ticks(12)
|
||||||
|
assert_equal OperatorInstruction , op.class
|
||||||
|
assert_equal :- , op.operator
|
||||||
|
end
|
||||||
|
def test_not_zero2
|
||||||
|
check = main_ticks(13)
|
||||||
|
assert_equal IsZero , check.class
|
||||||
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
||||||
|
end
|
||||||
|
def test_exit
|
||||||
|
done = main_ticks(35)
|
||||||
|
assert_equal Syscall , done.class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user