From c55b41afaeea3c8d5c4bbd1481c2054d7d5a863a Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 29 May 2018 20:52:58 +0300 Subject: [PATCH] sort objects by class before positioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit since we don’t have pages yet, but want consistent layout --- lib/parfait/integer.rb | 3 +++ lib/risc/machine.rb | 3 ++- test/risc/test_interpreter.rb | 4 ++-- test/risc/test_machine.rb | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 6675e985..0c380725 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -27,6 +27,9 @@ module Parfait type_length end + def to_s + "Integer #{@value}" + end # compile time method to set the actual value. # this should not really be part of parfait, as ints are immutable at runtime. def set_value(value) diff --git a/lib/risc/machine.rb b/lib/risc/machine.rb index e0fbdb35..bf46ec4f 100644 --- a/lib/risc/machine.rb +++ b/lib/risc/machine.rb @@ -84,7 +84,8 @@ module Risc # return final position that is stored in code_start def position_objects(at) # 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 ) before = at Position.set(objekt,at) diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 596e84f1..60772675 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -52,7 +52,7 @@ module Risc end def test_pc1 @interpreter.tick - assert_equal 18392 , @interpreter.pc + assert_equal 17952 , @interpreter.pc end def test_tick2 @interpreter.tick @@ -66,7 +66,7 @@ module Risc def test_pc2 @interpreter.tick @interpreter.tick - assert_equal 18396 , @interpreter.pc + assert_equal 17956 , @interpreter.pc end def test_tick_14_jump 14.times {@interpreter.tick} diff --git a/test/risc/test_machine.rb b/test/risc/test_machine.rb index b5d31418..fc8176d8 100644 --- a/test/risc/test_machine.rb +++ b/test/risc/test_machine.rb @@ -29,10 +29,10 @@ module Risc assert_equal 0 , Position.get(@machine.cpu_init).at end 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 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 def test_cpu_label assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class