move wip tests
This commit is contained in:
67
test/risc/interpreter/wip/test_byte_to_reg.rb
Normal file
67
test/risc/interpreter/wip/test_byte_to_reg.rb
Normal file
@ -0,0 +1,67 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestInterpretRegToByte < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
"Hello".set_internal_byte(1,104)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:call,
|
||||
:set_internal_byte ,
|
||||
s(:arguments, s(:int, 1), s(:int, 104)),
|
||||
s(:receiver, s(:string, "Hello"))))
|
||||
super
|
||||
end
|
||||
|
||||
def pest_chain
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
|
||||
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
|
||||
Transfer, FunctionCall, Label, LoadConstant, SlotToReg,
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
||||
SlotToReg, RegToByte, Label, FunctionReturn, Transfer,
|
||||
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
|
||||
Label, FunctionReturn, Transfer, Syscall, NilClass]
|
||||
end
|
||||
|
||||
def pest_branch
|
||||
was = @interpreter.instruction
|
||||
assert_equal Branch , ticks(1).class
|
||||
assert was != @interpreter.instruction
|
||||
assert @interpreter.instruction , "should have gone to next instruction"
|
||||
end
|
||||
def pest_load
|
||||
assert_equal LoadConstant , ticks(3).class
|
||||
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
|
||||
assert_equal :r2, @interpreter.instruction.array.symbol
|
||||
end
|
||||
def pest_get
|
||||
assert_equal SlotToReg , ticks(4).class
|
||||
assert @interpreter.get_register( :r1 )
|
||||
assert Integer , @interpreter.get_register( :r1 ).class
|
||||
end
|
||||
def pest_call
|
||||
assert_equal FunctionCall , ticks(8).class
|
||||
end
|
||||
def pest_exit
|
||||
done = ticks(50)
|
||||
assert_equal NilClass , done.class
|
||||
end
|
||||
|
||||
def pest_reg_to_byte
|
||||
done = ticks(37)
|
||||
assert_equal RegToByte , done.class
|
||||
assert_equal "h".ord , @interpreter.get_register(done.register)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
55
test/risc/interpreter/wip/test_called_if.rb
Normal file
55
test/risc/interpreter/wip/test_called_if.rb
Normal file
@ -0,0 +1,55 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class IfCalledTest < MiniTest::Test
|
||||
include Ticker
|
||||
include CleanCompile
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int itest(int n)
|
||||
if_zero( n - 12)
|
||||
"then".putstring()
|
||||
else
|
||||
"else".putstring()
|
||||
end
|
||||
end
|
||||
|
||||
int main()
|
||||
itest(20)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:call, :itest , s(:arguments, s(:int, 20))))
|
||||
super
|
||||
end
|
||||
|
||||
# must be after boot, but before main compile, to define method
|
||||
def do_clean_compile
|
||||
clean_compile :Space , :itest , {:n => :Integer} ,
|
||||
s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:arg, :n), s(:int, 12))),
|
||||
s(:true_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "then")))),
|
||||
s(:false_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "else"))))))
|
||||
end
|
||||
def pest_if
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
|
||||
SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, Transfer, FunctionCall, Label,
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
|
||||
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, LoadConstant, RegToSlot, Transfer, FunctionCall,
|
||||
Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
||||
SlotToReg, Transfer, Syscall, Transfer, Transfer,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, SlotToReg,
|
||||
SlotToReg, Branch, Label, Label, FunctionReturn,
|
||||
Transfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
end
|
||||
end
|
||||
end
|
48
test/risc/interpreter/wip/test_change.rb
Normal file
48
test/risc/interpreter/wip/test_change.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class AddChange < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))
|
||||
@state_events = {}
|
||||
@instruction_events = []
|
||||
super
|
||||
end
|
||||
|
||||
def state_changed( a , b)
|
||||
@state_events[:state_changed] = [a , b]
|
||||
end
|
||||
|
||||
def instruction_changed(was , is )
|
||||
@instruction_events << was
|
||||
end
|
||||
|
||||
def pest_state_change
|
||||
@interpreter.register_event :state_changed , self
|
||||
ticks 30
|
||||
assert @state_events[:state_changed]
|
||||
assert_equal 2 , @state_events[:state_changed].length
|
||||
assert_equal :running, @state_events[:state_changed][0]
|
||||
@interpreter.unregister_event :state_changed , self
|
||||
end
|
||||
|
||||
def pest_instruction_events
|
||||
@interpreter.register_event :instruction_changed , self
|
||||
ticks 30
|
||||
assert_equal 20 , @instruction_events.length
|
||||
@interpreter.unregister_event :instruction_changed , self
|
||||
end
|
||||
|
||||
def pest_chain
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
40
test/risc/interpreter/wip/test_mult.rb
Normal file
40
test/risc/interpreter/wip/test_mult.rb
Normal file
@ -0,0 +1,40 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class MultTest < MiniTest::Test
|
||||
include Ticker
|
||||
include AST::Sexp
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
return #{2**31} * #{2**31}
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:return, s(:operator_value, :*, s(:int, 2147483648), s(:int, 2147483648))))
|
||||
super
|
||||
end
|
||||
|
||||
def pest_mult
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
check_return 0
|
||||
end
|
||||
def pest_overflow
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:overflow]
|
||||
end
|
||||
|
||||
def pest_zero
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:zero]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
71
test/risc/interpreter/wip/test_puts.rb
Normal file
71
test/risc/interpreter/wip/test_puts.rb
Normal file
@ -0,0 +1,71 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestPuts < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
"Hello again".putstring()
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "Hello again"))))
|
||||
super
|
||||
end
|
||||
|
||||
def pest_chain
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
|
||||
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, LoadConstant, RegToSlot, Transfer,
|
||||
FunctionCall, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
SlotToReg, SlotToReg, Transfer, Syscall, Transfer,
|
||||
Transfer, RegToSlot, Label, FunctionReturn, Transfer,
|
||||
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
|
||||
Label, FunctionReturn, Transfer, Syscall, NilClass]
|
||||
end
|
||||
|
||||
def pest_branch
|
||||
was = @interpreter.instruction
|
||||
assert_equal Branch , ticks(1).class
|
||||
assert was != @interpreter.instruction
|
||||
assert @interpreter.instruction , "should have gone to next instruction"
|
||||
end
|
||||
def pest_load
|
||||
assert_equal LoadConstant , ticks(3).class
|
||||
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
|
||||
assert_equal :r2, @interpreter.instruction.array.symbol
|
||||
end
|
||||
def pest_get
|
||||
assert_equal SlotToReg , ticks(4).class
|
||||
assert @interpreter.get_register( :r1 )
|
||||
assert Integer , @interpreter.get_register( :r1 ).class
|
||||
end
|
||||
def pest_call
|
||||
assert_equal FunctionCall , ticks(8).class
|
||||
end
|
||||
|
||||
def pest_putstring
|
||||
done = ticks(29)
|
||||
assert_equal Syscall , done.class
|
||||
assert_equal "Hello again" , @interpreter.stdout
|
||||
end
|
||||
|
||||
def pest_return
|
||||
done = ticks(34)
|
||||
assert_equal FunctionReturn , done.class
|
||||
assert Label , @interpreter.instruction.class
|
||||
assert @interpreter.instruction.is_a?(Instruction) , "not instruction #{@interpreter.instruction}"
|
||||
end
|
||||
|
||||
def pest_exit
|
||||
done = ticks(45)
|
||||
assert_equal NilClass , done.class
|
||||
assert_equal "Hello again" , @interpreter.stdout
|
||||
end
|
||||
end
|
||||
end
|
67
test/risc/interpreter/wip/test_reg_to_byte.rb
Normal file
67
test/risc/interpreter/wip/test_reg_to_byte.rb
Normal file
@ -0,0 +1,67 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestInterpretByteToReg < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
"Hello".get_internal_byte(1)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:call,
|
||||
:get_internal_byte,
|
||||
s(:arguments, s(:int, 1)),
|
||||
s(:receiver, s(:string, "Hello"))))
|
||||
super
|
||||
end
|
||||
|
||||
def pest_chain
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
|
||||
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, Transfer, FunctionCall, Label,
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, ByteToReg, RegToSlot, Label, FunctionReturn,
|
||||
Transfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
end
|
||||
|
||||
def pest_branch
|
||||
was = @interpreter.instruction
|
||||
assert_equal Branch , ticks(1).class
|
||||
assert was != @interpreter.instruction
|
||||
assert @interpreter.instruction , "should have gone to next instruction"
|
||||
end
|
||||
def pest_load
|
||||
assert_equal LoadConstant , ticks(3).class
|
||||
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
|
||||
assert_equal :r2, @interpreter.instruction.array.symbol
|
||||
end
|
||||
def pest_get
|
||||
assert_equal SlotToReg , ticks(4).class
|
||||
assert @interpreter.get_register( :r1 )
|
||||
assert Integer , @interpreter.get_register( :r1 ).class
|
||||
end
|
||||
def pest_call
|
||||
assert_equal FunctionCall , ticks(8).class
|
||||
end
|
||||
def pest_exit
|
||||
done = ticks(46)
|
||||
assert_equal NilClass , done.class
|
||||
end
|
||||
|
||||
def pest_byte_to_reg
|
||||
done = ticks(32)
|
||||
assert_equal ByteToReg , done.class
|
||||
assert_equal "H".ord , @interpreter.get_register(done.register)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
42
test/risc/interpreter/wip/test_simple_if.rb
Normal file
42
test/risc/interpreter/wip/test_simple_if.rb
Normal file
@ -0,0 +1,42 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class IfSimpleTest < MiniTest::Test
|
||||
include Ticker
|
||||
include CleanCompile
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
if_zero( 10 - 12)
|
||||
"then".putstring()
|
||||
else
|
||||
"else".putstring()
|
||||
end
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))),
|
||||
s(:true_statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "then")))),
|
||||
s(:false_statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "else"))))))
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def pest_if
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
|
||||
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, LoadConstant, RegToSlot, Transfer, FunctionCall,
|
||||
Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
||||
SlotToReg, Transfer, Syscall, Transfer, Transfer,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, SlotToReg,
|
||||
SlotToReg, Branch, Label, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user