first interpreter tests
This commit is contained in:
parent
c16ed5ab3a
commit
1378745907
@ -106,7 +106,7 @@ module Risc
|
||||
ins.register.set_compiler(self)
|
||||
add_code ins
|
||||
# todo for constants (not objects)
|
||||
add_constant( object) if object.is_a?(Parfait::Object)
|
||||
add_constant( object) if object.is_a?(Parfait::Object)
|
||||
# add_constant(right) if compiler
|
||||
ins.register
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ module Risc
|
||||
# return the number of registers the platform supports
|
||||
def num_registers
|
||||
end
|
||||
|
||||
|
||||
# Factory method to create a Platform object according to the platform
|
||||
# string given.
|
||||
# Currently only "Arm" and "Interpreter"
|
||||
|
@ -11,37 +11,36 @@ module Risc
|
||||
|
||||
def test_chain
|
||||
#show_main_ticks # get output of what is
|
||||
check_main_chain [LoadConstant, RegToSlot, SlotToReg, RegToSlot, Branch, #5
|
||||
check_main_chain [LoadConstant, RegToSlot, SlotToReg, RegToSlot, Branch, #5
|
||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #10
|
||||
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg, #15
|
||||
Syscall, NilClass,] #20
|
||||
assert_equal 15 , get_return
|
||||
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, #15
|
||||
NilClass,] #20
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 15 , get_return.value
|
||||
end
|
||||
|
||||
def test_call_main
|
||||
call_ins = ticks(main_at)
|
||||
assert_equal FunctionCall , call_ins.class
|
||||
assert :main , call_ins.method.name
|
||||
end
|
||||
def test_load_15
|
||||
load_ins = main_ticks(1)
|
||||
assert_equal LoadConstant , load_ins.class
|
||||
assert_equal Parfait::Integer , @interpreter.get_register(load_ins.register).class
|
||||
assert_equal 15 , @interpreter.get_register(load_ins.register).value
|
||||
assert_load 1 , Parfait::Integer , "id_integer_"
|
||||
assert_equal 15 , @interpreter.get_register(@interpreter.instruction.register).value
|
||||
end
|
||||
def test_branch
|
||||
assert_branch 5 , "return_label"
|
||||
end
|
||||
def test_return
|
||||
ret = main_ticks(12)
|
||||
ret = main_ticks(11)
|
||||
assert_equal FunctionReturn , ret.class
|
||||
link = @interpreter.get_register( ret.register )
|
||||
assert_equal ::Integer , link.class
|
||||
assert_equal Parfait::ReturnAddress , link.class
|
||||
end
|
||||
def test_transfer
|
||||
transfer = main_ticks(13)
|
||||
assert_equal Transfer , transfer.class
|
||||
assert_transfer 12 , :message , :saved_message
|
||||
end
|
||||
def test_sys
|
||||
sys = main_ticks(16)
|
||||
assert_equal Syscall , sys.class
|
||||
assert_syscall 15 , :exit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ module Risc
|
||||
end
|
||||
|
||||
def test_chain
|
||||
#show_main_ticks # get output of what is
|
||||
show_main_ticks # get output of what is
|
||||
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #10
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||
@ -31,12 +31,12 @@ module Risc
|
||||
assert_equal ::Integer , get_return.class
|
||||
assert_equal 1 , get_return
|
||||
end
|
||||
def test_load_entry
|
||||
def est_load_entry
|
||||
call_ins = main_ticks(3)
|
||||
assert_equal LoadConstant , call_ins.class
|
||||
assert_equal Parfait::CacheEntry , call_ins.constant.class
|
||||
end
|
||||
def test_dyn
|
||||
def est_dyn
|
||||
cal = main_ticks(38)
|
||||
assert_equal DynamicJump , cal.class
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module Risc
|
||||
@instruction_events << was
|
||||
end
|
||||
def length
|
||||
28
|
||||
27
|
||||
end
|
||||
def test_state_change
|
||||
@interpreter.register_event :state_changed , self
|
||||
@ -43,10 +43,10 @@ module Risc
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #10
|
||||
RegToSlot, LoadConstant, RegToSlot, FunctionCall, LoadConstant, #15
|
||||
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #20
|
||||
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, #25
|
||||
SlotToReg, SlotToReg, Syscall, NilClass,] #30
|
||||
assert_equal ::Integer , get_return.class
|
||||
assert_equal 5 , get_return
|
||||
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #25
|
||||
SlotToReg, Syscall, NilClass,] #30
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 5 , get_return.value
|
||||
end
|
||||
def test_length
|
||||
run_all
|
||||
|
@ -10,23 +10,21 @@ module Risc
|
||||
end
|
||||
|
||||
def test_chain
|
||||
#show_main_ticks # get output of what is
|
||||
# show_main_ticks # get output of what is
|
||||
check_main_chain [LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg, #5
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, #10
|
||||
Transfer, SlotToReg, SlotToReg, Syscall, NilClass,] #15
|
||||
assert_equal 5 , get_return
|
||||
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, Transfer, #10
|
||||
SlotToReg, SlotToReg, Syscall, NilClass,] #15
|
||||
assert_equal 5 , get_return.value
|
||||
end
|
||||
|
||||
def test_call_main
|
||||
call_ins = ticks(main_at)
|
||||
assert_equal FunctionCall , call_ins.class
|
||||
assert :main , call_ins.method.name
|
||||
assert_function_call 0 , :main
|
||||
end
|
||||
def test_function_return
|
||||
ret = main_ticks(10)
|
||||
ret = main_ticks(9)
|
||||
assert_equal FunctionReturn , ret.class
|
||||
link = @interpreter.get_register( ret.register )
|
||||
assert_equal ::Integer , link.class
|
||||
assert_equal Parfait::ReturnAddress , link.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,8 +48,8 @@ module Risc
|
||||
end
|
||||
|
||||
def get_return
|
||||
assert_equal Parfait::Message , @interpreter.get_register(:r8).class
|
||||
@interpreter.get_register(:r0)
|
||||
assert_equal Parfait::Message , @interpreter.get_register(:saved_message).class
|
||||
@interpreter.get_register(:message)
|
||||
end
|
||||
|
||||
# do as many as given ticks in the main, ie main_at more
|
||||
@ -66,6 +66,7 @@ module Risc
|
||||
end
|
||||
return last
|
||||
end
|
||||
alias :risc :main_ticks
|
||||
|
||||
# collect the classes of all executed istructions
|
||||
def all_classes(max = 300)
|
||||
|
Loading…
Reference in New Issue
Block a user