sort objects by class before positioning

since we don’t have pages yet, but want consistent layout
This commit is contained in:
Torsten Ruger 2018-05-29 20:52:58 +03:00
parent e94c9ea37b
commit c55b41afae
4 changed files with 9 additions and 5 deletions

View File

@ -27,6 +27,9 @@ module Parfait
type_length type_length
end end
def to_s
"Integer #{@value}"
end
# compile time method to set the actual value. # compile time method to set the actual value.
# this should not really be part of parfait, as ints are immutable at runtime. # this should not really be part of parfait, as ints are immutable at runtime.
def set_value(value) def set_value(value)

View File

@ -84,7 +84,8 @@ module Risc
# return final position that is stored in code_start # return final position that is stored in code_start
def position_objects(at) def position_objects(at)
# want to have the objects first in the executable # want to have the objects first in the executable
objects.each do | id , objekt| sorted = objects.values.sort{|left,right| left.class.name <=> right.class.name}
sorted.each do | objekt|
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label ) next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
before = at before = at
Position.set(objekt,at) Position.set(objekt,at)

View File

@ -52,7 +52,7 @@ module Risc
end end
def test_pc1 def test_pc1
@interpreter.tick @interpreter.tick
assert_equal 18392 , @interpreter.pc assert_equal 17952 , @interpreter.pc
end end
def test_tick2 def test_tick2
@interpreter.tick @interpreter.tick
@ -66,7 +66,7 @@ module Risc
def test_pc2 def test_pc2
@interpreter.tick @interpreter.tick
@interpreter.tick @interpreter.tick
assert_equal 18396 , @interpreter.pc assert_equal 17956 , @interpreter.pc
end end
def test_tick_14_jump def test_tick_14_jump
14.times {@interpreter.tick} 14.times {@interpreter.tick}

View File

@ -29,10 +29,10 @@ module Risc
assert_equal 0 , Position.get(@machine.cpu_init).at assert_equal 0 , Position.get(@machine.cpu_init).at
end end
def test_cpu_at def test_cpu_at
assert_equal "0x5714" , Position.get(@machine.cpu_init.first).to_s assert_equal "0x555c" , Position.get(@machine.cpu_init.first).to_s
end end
def test_cpu_bin def test_cpu_bin
assert_equal "0x570c" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s assert_equal "0x5554" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
end end
def test_cpu_label def test_cpu_label
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class