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" , git: "https://github.com/ruby-x/rx-file"
#gem "rx-file" , path: "../rx-file" #gem "rx-file" , path: "../rx-file"
gem "minitest-parallel_fork"
group :test do group :test do
gem "minitest-parallel_fork"
gem "codeclimate-test-reporter" , require: false gem "codeclimate-test-reporter" , require: false
gem "simplecov" gem "simplecov"
gem "minitest-color" 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 # 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. # 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 attr :type, :next_code
def self.type_length def self.type_length

View File

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

View File

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

View File

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

View File

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

View File

@ -13,54 +13,54 @@ module Risc
# show_main_ticks # get output of what is # show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10 SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 20 SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 20
SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg,
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, # 30 OperatorInstruction, IsZero, SlotToReg, SlotToReg, LoadConstant, # 30
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, # 40 RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 40
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg, # 50 DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg, # 50
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg,
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 60 SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 60
SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, # 70 SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 70
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 80 RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 80
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 90 SlotToReg, Branch, RegToSlot, LoadConstant, SlotToReg, # 90
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 100 FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 100
SlotToReg, Syscall, NilClass, ] NilClass, ]
assert_equal 10 , get_return assert_equal 10 , get_return
end end
def test_block_jump def test_block_jump
load_ins = main_ticks(48) load_ins = main_ticks(46)
assert_equal DynamicJump , load_ins.class assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
end end
def test_block_load def test_block_load
load_ins = main_ticks(49) load_ins = main_ticks(47)
assert_load load_ins , Parfait::Integer , :r1 assert_load load_ins , Parfait::Integer , :r1
assert_equal 10 , @interpreter.get_register(load_ins.register).value assert_equal 10 , @interpreter.get_register(load_ins.register).value
end 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 def test_ret_load
load_ins = main_ticks(54) load_ins = main_ticks(52)
assert_load load_ins , Parfait::Integer , :r1 assert_load load_ins , Parfait::Integer , :r1
assert_equal 15 , @interpreter.get_register(load_ins.register).value assert_equal 15 , @interpreter.get_register(load_ins.register).value
end 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
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,21 +13,21 @@ module Risc
#show_main_ticks # get output of what is #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, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 20 LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 20
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, SlotToReg, RegToSlot, SlotToReg, FunctionCall, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 30 SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, # 30
SlotToReg, SlotToReg, RegToByte, SlotToReg, SlotToReg, SlotToReg, RegToByte, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, # 40 LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 40
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, Branch, Branch, SlotToReg, # 50 Branch, SlotToReg, SlotToReg, Branch, RegToSlot, # 50
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 60 SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 60
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ] SlotToReg, Syscall, NilClass, ]
assert_equal "K".ord , get_return assert_equal "K".ord , get_return
end end
def test_reg_to_byte def test_reg_to_byte
done = main_ticks(33) done = main_ticks(32)
assert_equal RegToByte , done.class assert_equal RegToByte , done.class
assert_equal "K".ord , @interpreter.get_register(done.register) assert_equal "K".ord , @interpreter.get_register(done.register)
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ module Risc
assert_equal 0 , Position.get(@linker.cpu_init).at assert_equal 0 , Position.get(@linker.cpu_init).at
end end
def test_cpu_at 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 end
def test_cpu_label def test_cpu_label
assert_equal Position , Position.get(@linker.cpu_init.first).class 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 # how many instruction up until the main starts, ie
# ticks(main_at) will be the label for main # ticks(main_at) will be the label for main
def main_at def main_at
20 19
end end
def get_return def get_return