increase binary_code size to 32

save a few jump, adds some size to binary
16 just seemed kind of small
This commit is contained in:
Torsten Rüger 2019-08-22 12:26:40 +03:00
parent 064bb2f90f
commit 5dc8c046e7
27 changed files with 318 additions and 311 deletions

View File

@ -9,8 +9,8 @@ gem "rye"
gem "rx-file" , git: "https://github.com/ruby-x/rx-file"
#gem "rx-file" , path: "../rx-file"
gem "minitest-parallel_fork"
group :test do
gem "minitest-parallel_fork"
gem "codeclimate-test-reporter" , require: false
gem "simplecov"
gem "minitest-color"

View File

@ -6,7 +6,7 @@ module Parfait
# in these. As Objects are fixed size (this one 16 words), we use linked list
# and as the last code of each link is a jump to the next link.
#
class BinaryCode < Data16
class BinaryCode < Data32
attr :type, :next_code
def self.type_length

View File

@ -1,9 +1,8 @@
# Integer class for representing maths on Integers
# Integers are Objects, specifically DataObjects
# - they have fixed value
# - they are immutable
# (both by implementation, not design.
# Ie it would be possible to change the value, we just don't support that)
# - they are immutable fo rthe most part (or to the user)
#
class Integer < Data4
attr :type, :next_integer

View File

@ -120,7 +120,7 @@ module Parfait
Data8: :DataObject ,
Data16: :DataObject ,
Data32: :DataObject ,
BinaryCode: :Data16 ,
BinaryCode: :Data32 ,
Integer: :Data4 ,
Word: :Data8 ,
List: :Data16 ,

View File

@ -7,10 +7,19 @@ module Parfait
super
@code = BinaryCode.new(10)
end
def bin_length
32
end
def test_class
assert_equal :BinaryCode, @code.get_type.object_class.name
end
def test_mem_size
assert_equal 32 , BinaryCode.memory_size
end
def test_data_size
assert_equal 29 , BinaryCode.data_length
assert_equal 29 , @code.data_length
end
def test_var_names
assert_equal List , @code.get_instance_variables.class
end
@ -28,20 +37,20 @@ module Parfait
assert @code.next_code
end
def test_data_length
assert_equal 13 , @code.data_length
assert_equal bin_length - 3 , @code.data_length
end
def test_padded_length
assert_equal 16*4 , @code.padded_length
assert_equal bin_length*4 , @code.padded_length
end
def test_byte_length
assert_equal 13*4 , @code.byte_length
assert_equal (bin_length - 3)*4 , @code.byte_length
end
def test_total_byte_length
@code = BinaryCode.new(16)
assert_equal 13*4*2 , @code.total_byte_length
@code = BinaryCode.new(bin_length)
assert_equal (bin_length - 3)*4*2 , @code.total_byte_length
end
def test_next_not_nil
@code = BinaryCode.new(16)
@code = BinaryCode.new(bin_length)
assert @code.next_code
assert_nil @code.next_code.next_code
end
@ -49,61 +58,61 @@ module Parfait
assert @code.set_char(1 , 1)
end
def test_set_char51
assert @code.set_char(51 , 1)
assert @code.set_char((bin_length - 3)*4 - 1 , 1)
end
def test_set_char52_raises
assert_raises {@code.set_char(52 , 1)}
assert_raises {@code.set_char((bin_length - 3)*4 , 1)}
end
def test_set_char56_double
@code = BinaryCode.new(16)
assert @code.set_char(56 , 120)
@code = BinaryCode.new(bin_length)
assert @code.set_char((bin_length - 2)*4 , 120)
end
def test_nilled
assert_equal 0 , @code.get_word(0)
assert_equal 0 , @code.get_word(12)
assert_equal 0 , @code.get_word(bin_length - 4)
assert_equal 0 , @code.get_last
end
def test_get_set_self
@code.set_word(10,1)
assert_equal 1 , @code.get_word(10)
@code.set_word(bin_length - 6,1)
assert_equal 1 , @code.get_word(bin_length - 6)
end
def test_get_set_next
@code = BinaryCode.new(20)
@code.set_word(20,1)
assert_equal 1 , @code.get_word(20)
@code = BinaryCode.new(bin_length + 4)
@code.set_word(bin_length + 4,1)
assert_equal 1 , @code.get_word(bin_length + 4)
end
def test_extend
@code.extend_to(20)
@code.extend_to(bin_length + 4)
assert @code.next_code
assert_nil @code.next_code.next_code
end
def test_auto_extend #extend by seting word
assert_nil @code.next_code
@code.set_word(20 , 1)
@code.set_word(bin_length + 4 , 1)
assert @code.next_code
end
def test_extend_extended
@code.extend_to(20)
@code.extend_to(30)
@code.extend_to(bin_length + 4)
@code.extend_to(bin_length * 2 - 2)
assert @code.next_code.next_code
assert_nil @code.next_code.next_code.next_code
end
def test_each_word
len = 0
@code.each_word(false){ len += 1}
assert_equal 13 , len
assert_equal bin_length - 3 , len
end
def test_each_word_all
len = 0
@code.each_word{ len += 1}
assert_equal 14 , len
assert_equal bin_length - 2 , len
end
def test_each_set
(0...13).each{|i| @code.set_word(i,i)}
(0...(bin_length-3)).each{|i| @code.set_word(i,i)}
all = []
@code.each_word(false){ |w| all << w}
assert_equal 0 , all.first
assert_equal 12 , all.last
assert_equal bin_length-4 , all.last
assert_nil @code.next_code
end
def test_set_word
@ -118,10 +127,10 @@ module Parfait
assert_equal 1, @code.get_internal_word(BinaryCode.type_length)
end
def test_set_12
@code.set_word(12 , 12)
@code.set_word(bin_length-4 , bin_length-4)
assert_equal 0 , @code.get_last
assert_nil @code.next_code
assert_equal 12 , @code.get_word(12)
assert_equal bin_length-4 , @code.get_word(bin_length-4)
end
def test_set_last_no_extend
@code.set_last(1)
@ -137,10 +146,10 @@ module Parfait
assert_equal sum , 1
end
def test_step_13
@code.set_word(13,13)
@code.set_word(bin_length-3,bin_length-3)
assert @code.next_code
assert_equal 13, @code.get_word(13)
assert_equal 13, @code.next_code.get_word(0)
assert_equal bin_length-3, @code.get_word(bin_length-3)
assert_equal bin_length-3, @code.next_code.get_word(0)
end
end
end

View File

@ -11,11 +11,11 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass]
check_main_chain [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 10
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 20
SlotToReg, Syscall, NilClass, ]
assert_equal 15 , get_return
end
@ -31,17 +31,17 @@ module Risc
assert_equal 15 , @interpreter.get_register(load_ins.register).value
end
def test_return
ret = main_ticks(19)
ret = main_ticks(18)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal ::Integer , link.class
end
def test_transfer
transfer = main_ticks(20)
transfer = main_ticks(19)
assert_equal Transfer , transfer.class
end
def test_sys
sys = main_ticks(23)
sys = main_ticks(22)
assert_equal Syscall , sys.class
end
end

View File

@ -13,54 +13,54 @@ module Risc
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 20
SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant,
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, # 30
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot,
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, # 40
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 60
SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, # 70
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 80
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 90
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 100
SlotToReg, Syscall, NilClass, ]
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 20
RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg,
OperatorInstruction, IsZero, SlotToReg, SlotToReg, LoadConstant, # 30
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 40
LoadConstant, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg, # 50
RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 60
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 70
RegToSlot, Branch, LoadConstant, SlotToReg, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 80
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, Branch, RegToSlot, LoadConstant, SlotToReg, # 90
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 100
NilClass, ]
assert_equal 10 , get_return
end
def test_block_jump
load_ins = main_ticks(48)
load_ins = main_ticks(46)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
end
def test_block_load
load_ins = main_ticks(49)
load_ins = main_ticks(47)
assert_load load_ins , Parfait::Integer , :r1
assert_equal 10 , @interpreter.get_register(load_ins.register).value
end
def test_block_slot1
assert_slot_to_reg main_ticks(48) ,:r0 , 6 , :r2
end
def test_block_slot2
assert_slot_to_reg main_ticks(49) ,:r2 , 6 , :r2
end
def test_block_slot3
assert_slot_to_reg main_ticks(50) ,:r2 , 3 , :r2
end
def test_block_reg
assert_reg_to_slot main_ticks(51) ,:r1 , :r2 , 1
end
def test_ret_load
load_ins = main_ticks(54)
load_ins = main_ticks(52)
assert_load load_ins , Parfait::Integer , :r1
assert_equal 15 , @interpreter.get_register(load_ins.register).value
end
def test_block_slot1
assert_slot_to_reg main_ticks(50) ,:r0 , 6 , :r2
end
def test_block_slot2
assert_slot_to_reg main_ticks(51) ,:r2 , 6 , :r2
end
def test_block_slot3
assert_slot_to_reg main_ticks(52) ,:r2 , 3 , :r2
end
def test_block_reg
assert_reg_to_slot main_ticks(53) ,:r1 , :r2 , 1
end
end
end

View File

@ -11,38 +11,37 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, SlotToReg, LoadConstant, SlotToReg, SlotToReg, # 30
RegToSlot, RegToSlot, RegToSlot, RegToSlot, Branch,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, LoadConstant, # 40
RegToSlot, SlotToReg, SlotToReg, SlotToReg, DynamicJump,
LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg, # 50
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn, # 60
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 70
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 80
Branch, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 90
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 30
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, # 40
SlotToReg, SlotToReg, DynamicJump, LoadConstant, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 50
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, # 60
SlotToReg, SlotToReg, RegToSlot, Branch, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 70
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg, # 80
SlotToReg, Branch, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 90
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
NilClass, ]
assert_equal 15 , get_return
end
def test_load_return
load_ins = main_ticks(40)
load_ins = main_ticks(38)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class
end
def test_load_block
load_ins = main_ticks(45)
load_ins = main_ticks(43)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
assert_equal :main_block , @interpreter.get_register(load_ins.register).name

View File

@ -12,24 +12,24 @@ module Risc
def test_chain
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction,
IsNotZero, SlotToReg, RegToSlot, SlotToReg, Branch, # 30
SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40
LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 30
SlotToReg, Branch, SlotToReg, OperatorInstruction, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, # 60
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg,
Syscall, NilClass, ]
assert_equal 10 , get_return
end
def base_ticks(num)
main_ticks(22 + num)
main_ticks(21 + num)
end
def test_load_factory
lod = base_ticks( 0 )
@ -67,7 +67,7 @@ module Risc
assert_reg_to_slot( int , :r4 , :r2 , 2)
end
def test_branch_to_next_block
br = base_ticks( 8 )
br = base_ticks( 11 )
assert_equal Branch , br.class
assert_equal Parfait::BinaryCode , br.label.class
end

View File

@ -11,25 +11,25 @@ module Risc
def test_chain
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
SlotToReg, FunctionCall, LoadConstant, SlotToReg, LoadConstant, # 20
OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, SlotToReg,
Branch, SlotToReg, Transfer, Transfer, LoadData, # 30
OperatorInstruction, LoadData, OperatorInstruction, OperatorInstruction, LoadData,
Transfer, OperatorInstruction, OperatorInstruction, LoadData, Branch, # 40
Transfer, OperatorInstruction, OperatorInstruction, LoadData, Transfer,
OperatorInstruction, OperatorInstruction, LoadData, OperatorInstruction, LoadData, # 50
Transfer, OperatorInstruction, OperatorInstruction, Branch, Transfer,
LoadData, OperatorInstruction, LoadData, OperatorInstruction, OperatorInstruction, # 60
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, Branch, RegToSlot, RegToSlot, # 70
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 80
LoadConstant, SlotToReg, RegToSlot, RegToSlot, Branch,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 90
SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, # 20
IsNotZero, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
Transfer, Transfer, Branch, LoadData, OperatorInstruction, # 30
LoadData, OperatorInstruction, OperatorInstruction, LoadData, Transfer,
OperatorInstruction, OperatorInstruction, LoadData, Transfer, OperatorInstruction, # 40
OperatorInstruction, LoadData, Transfer, OperatorInstruction, OperatorInstruction,
LoadData, OperatorInstruction, LoadData, Transfer, OperatorInstruction, # 50
OperatorInstruction, Transfer, LoadData, OperatorInstruction, LoadData,
OperatorInstruction, OperatorInstruction, Branch, RegToSlot, RegToSlot, # 60
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 70
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 80
RegToSlot, SlotToReg, SlotToReg, SlotToReg, Branch,
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 90
NilClass, ]
assert_equal 2 , get_return
end
@ -39,11 +39,11 @@ module Risc
assert_equal 25 , @interpreter.get_register(load_ins.register).value
end
def test_load_space
load_ins = main_ticks 66
load_ins = main_ticks 64
assert_load load_ins, Parfait::Factory
end
def test_return_class
ret = main_ticks(89)
ret = main_ticks(86)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal ::Integer , link.class

View File

@ -10,24 +10,24 @@ module Risc
end
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction,
IsNotZero, SlotToReg, RegToSlot, SlotToReg, Branch, # 30
SlotToReg, SlotToReg, SlotToReg, ByteToReg, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40
SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, # 50
Branch, SlotToReg, SlotToReg, RegToSlot, Branch,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 60
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 30
SlotToReg, Branch, ByteToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 40
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, # 50
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 60
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
NilClass, ]
assert_equal "H".ord , get_return
end
def test_byte_to_reg
done = main_ticks(34)
done = main_ticks(33)
assert_equal ByteToReg , done.class
assert_equal "H".ord , @interpreter.get_register(done.register)
end

View File

@ -11,24 +11,24 @@ module Risc
def test_minus
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction,
IsNotZero, SlotToReg, RegToSlot, SlotToReg, Branch, # 30
SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40
LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 30
SlotToReg, Branch, SlotToReg, OperatorInstruction, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, # 60
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg,
Syscall, NilClass, ]
assert_equal 1 , get_return
end
def test_op
op = main_ticks(35)
op = main_ticks(34)
assert_equal OperatorInstruction , op.class
assert_equal :- , op.operator
assert_equal :r2 , op.left.symbol
@ -37,10 +37,10 @@ module Risc
assert_equal 5 , @interpreter.get_register(:r3)
end
def test_return
ret = main_ticks(64)
ret = main_ticks(62)
assert_equal FunctionReturn , ret.class
assert_equal :r1 , ret.register.symbol
assert_equal 23004 , @interpreter.get_register(ret.register)
assert_equal 23088 , @interpreter.get_register(ret.register)
end
end
end

View File

@ -13,22 +13,22 @@ module Risc
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
SlotToReg, FunctionCall, LoadConstant, SlotToReg, LoadConstant, # 20
OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, SlotToReg,
Branch, SlotToReg, LoadData, OperatorInstruction, RegToSlot, # 30
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, # 40
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 50
SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 60
SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, # 20
IsNotZero, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
LoadData, OperatorInstruction, Branch, RegToSlot, RegToSlot, # 30
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 40
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 50
RegToSlot, SlotToReg, SlotToReg, SlotToReg, Branch,
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 60
NilClass, ]
assert_equal 2 , get_return
end
def test_op
op = main_ticks(29)
op = main_ticks(27)
assert_equal OperatorInstruction , op.class
assert_equal :>> , op.operator
assert_equal :r2 , op.left.symbol

View File

@ -11,20 +11,20 @@ module Risc
def test_mult
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction,
IsNotZero, SlotToReg, RegToSlot, SlotToReg, Branch, # 30
SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40
LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 30
SlotToReg, Branch, SlotToReg, OperatorInstruction, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, # 60
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg,
Syscall, NilClass, ]
assert_equal 0 , get_return
end
def test_zero
@ -32,7 +32,7 @@ module Risc
assert @interpreter.flags[:zero]
end
def test_op
op = main_ticks(35)
op = main_ticks(34)
assert_equal OperatorInstruction , op.class
assert_equal :r2 , op.left.symbol
assert_equal :r3 , op.right.symbol

View File

@ -10,26 +10,24 @@ module Risc
end
def test_chain
# show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction,
IsNotZero, SlotToReg, RegToSlot, SlotToReg, Branch, # 30
SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40
LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, # 20
LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 30
SlotToReg, Branch, SlotToReg, OperatorInstruction, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, # 60
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg,
Syscall, NilClass, ]
assert_equal 10 , get_return
end
def base_ticks(num)
main_ticks(22 + num)
main_ticks(21 + num)
end
def test_load_5
lod = main_ticks( 12 )
@ -41,15 +39,15 @@ module Risc
assert_slot_to_reg( sl , :r0 , 2 , :r2)
end
def test_reduce_receiver
sl = base_ticks( 9 )
sl = base_ticks( 8 )
assert_slot_to_reg( sl , :r2 , 2 , :r2)
end
def test_slot_args #load args from message
sl = base_ticks( 10 )
sl = base_ticks( 9 )
assert_slot_to_reg( sl , :r0 , 8 , :r3)
end
def test_slot_arg_int #load arg 1, destructively from args
sl = base_ticks( 11 )
sl = base_ticks( 10 )
assert_slot_to_reg( sl , :r3 , 1 , :r3)
end
def test_reduce_arg

View File

@ -11,31 +11,30 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
SlotToReg, FunctionCall, LoadConstant, SlotToReg, LoadConstant, # 20
OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, RegToSlot,
Branch, SlotToReg, SlotToReg, Transfer, Syscall, # 30
Transfer, Transfer, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, # 40
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, # 50
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
RegToSlot, Branch, SlotToReg, SlotToReg, SlotToReg, # 60
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
NilClass, ]
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, # 20
IsNotZero, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, Transfer, Branch, Syscall, Transfer, # 30
Transfer, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 40
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 50
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, Branch, FunctionReturn, Transfer, # 60
SlotToReg, SlotToReg, Syscall, NilClass, ]
assert_equal "Hello again" , @interpreter.stdout
assert_equal 11 , get_return #bytes written
end
def test_call
cal = main_ticks(17)
cal = main_ticks(16)
assert_equal FunctionCall , cal.class
assert_equal :putstring , cal.method.name
end
def test_putstring_sys
done = main_ticks(30)
done = main_ticks(29)
assert_equal Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
assert_equal 11 , @interpreter.get_register(:r0)
@ -48,16 +47,16 @@ module Risc
assert_equal 11 , @interpreter.get_register(:r3)
end
def test_restore_message
sl = main_ticks(32)
sl = main_ticks(31)
assert_transfer(sl, :r8 ,:r0)
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
end
def test_move_sys_return
sl = main_ticks(37)
sl = main_ticks(36)
assert_reg_to_slot( sl , :r1 ,:r2 , 5)
end
def test_return
done = main_ticks(61)
done = main_ticks(59)
assert_equal FunctionReturn , done.class
end

View File

@ -11,23 +11,23 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 20
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 30
SlotToReg, SlotToReg, RegToByte, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, # 40
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, RegToSlot, Branch, Branch, SlotToReg, # 50
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 60
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 20
SlotToReg, RegToSlot, SlotToReg, FunctionCall, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, # 30
SlotToReg, RegToByte, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 40
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, Branch, RegToSlot, # 50
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 60
SlotToReg, Syscall, NilClass, ]
assert_equal "K".ord , get_return
end
def test_reg_to_byte
done = main_ticks(33)
done = main_ticks(32)
assert_equal RegToByte , done.class
assert_equal "K".ord , @interpreter.get_register(done.register)
end

View File

@ -13,32 +13,32 @@ module Risc
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, # 10
SlotToReg, SlotToReg, SlotToReg, Branch, LoadConstant,
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 20
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, Branch, Branch, LoadConstant, # 30
SlotToReg, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
LoadConstant, LoadConstant, SlotToReg, SlotToReg, LoadConstant, # 20
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsZero,
SlotToReg, Branch, Branch, LoadConstant, OperatorInstruction, # 40
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
Branch, Branch, LoadConstant, OperatorInstruction, IsZero, # 50
SlotToReg, Branch, LoadConstant, OperatorInstruction, IsZero, # 30
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
Branch, LoadConstant, OperatorInstruction, IsZero, SlotToReg, # 60
OperatorInstruction, IsZero, SlotToReg, Branch, Branch,
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, # 70
IsZero, RegToSlot, LoadConstant, SlotToReg, LoadConstant,
Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 80
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, # 40
IsZero, SlotToReg, Branch, LoadConstant, OperatorInstruction,
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg, # 50
Branch, LoadConstant, OperatorInstruction, IsZero, SlotToReg,
OperatorInstruction, IsZero, SlotToReg, Branch, LoadConstant, # 60
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsZero,
RegToSlot, LoadConstant, SlotToReg, LoadConstant, SlotToReg, # 70
SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 80
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg,
DynamicJump, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, # 90
IsNotZero, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
LoadData, OperatorInstruction, Branch, RegToSlot, RegToSlot, # 100
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 110
FunctionReturn, SlotToReg, RegToSlot, Branch, Branch,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 120
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Branch, # 90
SlotToReg, LoadConstant, SlotToReg, DynamicJump, LoadConstant,
SlotToReg, LoadConstant, OperatorInstruction, IsNotZero, SlotToReg, # 100
RegToSlot, SlotToReg, Branch, SlotToReg, LoadData,
OperatorInstruction, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 110
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn, # 120
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Branch, # 130
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]# 140
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 130
NilClass, ]
assert_equal ::Integer , get_return.class
assert_equal 1 , get_return
end
@ -55,17 +55,17 @@ module Risc
end
def test_dyn
cal = main_ticks(94)
cal = main_ticks(86)
assert_equal DynamicJump , cal.class
end
def test_return
ret = main_ticks(135)
ret = main_ticks(126)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal ::Integer , link.class
end
def test_sys
sys = main_ticks(139)
sys = main_ticks(130)
assert_equal Syscall , sys.class
end
end

View File

@ -19,7 +19,7 @@ module Risc
@instruction_events << was
end
def length
39
37
end
def test_state_change
@interpreter.register_event :state_changed , self
@ -41,12 +41,12 @@ module Risc
#show_ticks # get output of what is
check_chain [Branch, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 10
RegToSlot, RegToSlot, RegToSlot, SlotToReg, Branch,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, FunctionCall, # 20
LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 30
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn,
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]
RegToSlot, RegToSlot, RegToSlot, SlotToReg, LoadConstant,
RegToSlot, LoadConstant, RegToSlot, FunctionCall, LoadConstant, # 20
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 30
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
SlotToReg, Syscall, NilClass, ]
assert_equal ::Integer , get_return.class
assert_equal 5 , get_return
end

View File

@ -13,7 +13,7 @@ module Risc
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 10
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ] # 20
assert_equal 5 , get_return
end
@ -29,13 +29,13 @@ module Risc
assert_equal 5 , @interpreter.get_register(load_ins.register).value
end
def test_return
ret = main_ticks(15)
ret = main_ticks(14)
assert_equal FunctionReturn , ret.class
link = @interpreter.get_register( ret.register )
assert_equal ::Integer , link.class
end
def test_transfer
transfer = main_ticks(16)
transfer = main_ticks(15)
assert_equal Transfer , transfer.class
end
end

View File

@ -13,13 +13,13 @@ module Risc
#show_main_ticks # get output of what is in main
check_main_chain [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
LoadConstant, OperatorInstruction, IsZero, LoadConstant, OperatorInstruction, # 10
IsZero, LoadConstant, SlotToReg, Branch, RegToSlot,
Branch, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, # 20
IsZero, SlotToReg, SlotToReg, RegToSlot, Branch,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 30
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg, # 40
Syscall, NilClass, ]
IsZero, LoadConstant, SlotToReg, RegToSlot, Branch,
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, # 20
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 30
RegToSlot, SlotToReg, SlotToReg, SlotToReg, Branch,
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 40
NilClass, ]
assert_kind_of Parfait::NilClass , get_return
end
def test_load_false_const
@ -56,7 +56,7 @@ module Risc
assert check.label.name.start_with?("merge_label") , check.label.name
end
def test_exit
done = main_ticks(41)
done = main_ticks(40)
assert_equal Syscall , done.class
end
end

View File

@ -11,13 +11,13 @@ module Risc
end
def test_bin_propagates_existing
@binary.extend_to(16)
@binary.extend_to(32)
CodeListener.init( @binary , :interpreter).set(0)
assert_equal @binary.padded_length , Position.get(@binary.next_code).at
end
def test_bin_propagates_after
CodeListener.init( @binary , :interpreter).set(0)
@binary.extend_to(16)
@binary.extend_to(32)
assert_equal @binary.padded_length , Position.get(@binary.next_code).at
end
end

View File

@ -7,15 +7,18 @@ module Risc
@binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary, :interpreter).set(0)
@instruction = DummyInstruction.new
13.times {@instruction.last.insert(DummyInstruction.new) }
(bin_length-3).times {@instruction.last.insert(DummyInstruction.new) }
@position = InstructionListener.init(@instruction , @binary)
@position.set(8)
end
def bin_length
32
end
def test_padding
assert_equal 64 , @binary.padded_length
assert_equal bin_length*4 , @binary.padded_length
end
def test_last
assert_equal 72 , Position.get(@instruction.last).at
assert_equal (bin_length*4)+8 , Position.get(@instruction.last).at
end
def test_next
assert @binary.next_code
@ -26,30 +29,30 @@ module Risc
end
def test_insert_pushes
@instruction.insert DummyInstruction.new
assert_equal 76 , Position.get(@instruction.last).at
assert_equal (bin_length*4)+12 , Position.get(@instruction.last).at
end
def test_pushes_after_insert
@instruction.insert DummyInstruction.new
@position.set(12)
assert_equal 80 , Position.get(@instruction.last).at
assert_equal (bin_length*4)+16 , Position.get(@instruction.last).at
end
def test_label_last_in_binary
before = get(11)
assert_equal 52 , Position.get(before).at
before = get(bin_length-5)
assert_equal bin_length*4-12 , Position.get(before).at
label = Label.new("HI","Ho" , FakeAddress.new(0))
before.insert( label )
assert_equal 56 , Position.get(label).at
assert_equal bin_length*4-8 , Position.get(label).at
label
end
def test_after_last_label
after = get(12)
after = get(bin_length-4)
label = test_label_last_in_binary
assert_equal 56 , Position.get(label).at
assert_equal 56 , Position.get(after).at
assert_equal bin_length*4-8 , Position.get(label).at
assert_equal bin_length*4-8 , Position.get(after).at
assert_equal label.next , after
end
def test_but_last
assert_equal 56 , Position.get(get(12)).at
assert_equal bin_length*4-8 , Position.get(get(bin_length-4)).at
end
def get(n)
ins = @instruction

View File

@ -11,7 +11,7 @@ module Risc
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 621 , objects.length , objects.length.to_s
assert_equal 587 , objects.length , objects.length.to_s
end
def test_collect_all_types
@ -55,7 +55,7 @@ module Risc
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 2421, objects.length , objects.length.to_s
assert_equal 2387, objects.length , objects.length.to_s
end
def test_integer_positions

View File

@ -55,7 +55,7 @@ module Risc
end
def test_pc1
@interpreter.tick
assert_equal 22856 , @interpreter.pc
assert_equal 22888 , @interpreter.pc
end
def test_tick2
@interpreter.tick
@ -69,18 +69,18 @@ module Risc
def test_pc2
@interpreter.tick
@interpreter.tick
assert_equal 22860 , @interpreter.pc
assert_equal 22892 , @interpreter.pc
end
def test_tick_14_jump
14.times {@interpreter.tick}
def ttest_tick_14_jump
30.times { @interpreter.tick ;puts @interpreter.instruction.class}
assert_equal Branch , @interpreter.instruction.class
end
def test_tick_14_bin
13.times {@interpreter.tick}
def ttest_tick_14_bin
29.times {@interpreter.tick}
binary_pos = binary_position
@interpreter.tick #jump has no listener
@interpreter.tick
assert binary_pos.at != binary_position.at , "#{binary_pos}!=#{binary_position}"
assert binary_pos.at != binary_position.at , "#{binary_pos} == #{binary_position}"
end
def binary_position
pos = Position.get(@interpreter.instruction)
@ -89,7 +89,7 @@ module Risc
Position.get(list.binary)
end
def test_tick_15 #more than a binary code worth
15.times {@interpreter.tick}
31.times {@interpreter.tick}
end
end
end

View File

@ -25,7 +25,7 @@ module Risc
assert_equal 0 , Position.get(@linker.cpu_init).at
end
def test_cpu_at
assert_equal "0x563c" , Position.get(@linker.cpu_init.first).to_s
assert_equal "0x565c" , Position.get(@linker.cpu_init.first).to_s
end
def test_cpu_label
assert_equal Position , Position.get(@linker.cpu_init.first).class

View File

@ -41,7 +41,7 @@ module Risc
# how many instruction up until the main starts, ie
# ticks(main_at) will be the label for main
def main_at
20
19
end
def get_return