From 5b3045e42ad82607b7165127f241836a40633e09 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 8 Jun 2015 11:37:20 +0200 Subject: [PATCH] remove positioned copy paste --- lib/virtual/parfait_adapter.rb | 18 +----------------- lib/virtual/positioned.rb | 7 ++++--- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index d4d81e7d..67e7c86e 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -22,23 +22,6 @@ module FakeMem raise "Layout not set #{vm_name}" unless clazz.object_layout self.set_layout clazz.object_layout end - #TODO, this is copied from module Positioned, maybe avoid duplication ? - def position - if @position.nil? - str = "IN machine #{Virtual.machine.objects.include?(self)}\n" - raise str + "position not set for #{self.class} at #{word_length} for #{self.inspect[0...100]}" - end - @position - end - def set_position pos - raise "Setting of nil not allowed" if pos.nil? - # resetting of position used to be error, but since relink and dynamic instruction size it is ok. - # in measures (of 32) - if @position != nil and ((@position - pos).abs > 32) - raise "position set again #{pos}!=#{@position} for #{self.class}" - end - @position = pos - end end module Virtual def self.new_list array @@ -99,6 +82,7 @@ module Parfait class Object include FakeMem include Padding + include Positioned # these internal functions are _really_ internal # they respresent the smallest code needed to build larger functionality diff --git a/lib/virtual/positioned.rb b/lib/virtual/positioned.rb index 234192fd..fee12094 100644 --- a/lib/virtual/positioned.rb +++ b/lib/virtual/positioned.rb @@ -2,12 +2,14 @@ require_relative "type" module Positioned def position - if @position == nil - raise "position accessed but not set at #{word_length} for #{self.inspect[0...500]}" + if @position.nil? + str = "IN machine #{Virtual.machine.objects.include?(self)}\n" + raise str + "position not set for #{self.class} at #{word_length} for #{self.inspect[0...100]}" end @position end def set_position pos + raise "Setting of nil not allowed" if pos.nil? # resetting of position used to be error, but since relink and dynamic instruction size it is ok. # in measures (of 32) if @position != nil and ((@position - pos).abs > 32) @@ -15,5 +17,4 @@ module Positioned end @position = pos end - end