From dd59a2f9c6f80deac2b0d9256c2fb933228d14ca Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 19 Aug 2014 22:54:28 +0300 Subject: [PATCH] remove unused attributes() boilerplate --- lib/boot/boot_class.rb | 3 --- lib/boot/meta_class.rb | 4 ---- lib/sof/volotile.rb | 1 + lib/virtual/block.rb | 4 ---- lib/virtual/constants.rb | 17 +---------------- lib/virtual/instruction.rb | 21 --------------------- lib/virtual/object.rb | 3 --- lib/virtual/type.rb | 7 +------ lib/virtual/value.rb | 34 ++++++++++++---------------------- 9 files changed, 15 insertions(+), 79 deletions(-) diff --git a/lib/boot/boot_class.rb b/lib/boot/boot_class.rb index 4b3c78c1..fd793794 100644 --- a/lib/boot/boot_class.rb +++ b/lib/boot/boot_class.rb @@ -13,9 +13,6 @@ module Boot @meta_class = MetaClass.new(self) end attr_reader :name , :methods , :meta_class , :context , :super_class_name - def attributes - [:name , :super_class_name] - end def add_method_definition method raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition raise "syserr " unless method.name.is_a? Symbol diff --git a/lib/boot/meta_class.rb b/lib/boot/meta_class.rb index 88bca2f5..45b74785 100644 --- a/lib/boot/meta_class.rb +++ b/lib/boot/meta_class.rb @@ -17,10 +17,6 @@ module Boot @me_self = object end - def attributes - [] - end - # in a non-booting version this should map to _add_singleton_method def add_function function raise "not a function #{function}" unless function.is_a? Virtual::Function diff --git a/lib/sof/volotile.rb b/lib/sof/volotile.rb index f685276f..e57935f5 100644 --- a/lib/sof/volotile.rb +++ b/lib/sof/volotile.rb @@ -1,6 +1,7 @@ module Sof class Volotile @@mapping = { + Virtual::Block => [:method], Virtual::MethodDefinition => [:current] } def self.attributes clazz diff --git a/lib/virtual/block.rb b/lib/virtual/block.rb index b92d0f17..632fceab 100644 --- a/lib/virtual/block.rb +++ b/lib/virtual/block.rb @@ -19,10 +19,6 @@ module Virtual @codes = [] end - def attributes - [:name , :codes , :branch] - end - attr_reader :name , :codes , :method attr_accessor :branch diff --git a/lib/virtual/constants.rb b/lib/virtual/constants.rb index 8aea60fa..0319cd67 100644 --- a/lib/virtual/constants.rb +++ b/lib/virtual/constants.rb @@ -3,13 +3,10 @@ module Virtual class Constant < ::Virtual::Value end class TrueValue < Constant - def attributes ; [] ; end end class FalseValue < Constant - def attributes ; [] ; end end class NilValue < Constant - def attributes ; [] ; end end # another abstract "marker" class (so we can check for it) @@ -22,12 +19,6 @@ module Virtual @integer = int end attr_reader :integer - def attributes - [:integer] - end - def inspect - self.class.name + ".new(#{@integer})" - end def type Virtual::Integer end @@ -39,20 +30,14 @@ module Virtual # Mainly because that works an i aint no elf expert. class StringConstant < ObjectConstant - attr_reader :string - def attributes - [:string] - end def initialize str @string = str end + attr_reader :string def result= value class_for(MoveInstruction).new(value , self , :opcode => :mov) end - def inspect - self.class.name + ".new('#{@string}')" - end end end \ No newline at end of file diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index afb7dd81..eddee016 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -27,9 +27,6 @@ module Virtual end return true end - def attributes - [] - end end module Named @@ -37,9 +34,6 @@ module Virtual @name = name end attr_reader :name - def attributes - [:name ] - end end # the first instruction we need is to stop. Off course in a real machine this would be a syscall, but that is just @@ -61,9 +55,6 @@ module Virtual @to = to end attr_reader :to - def attributes - [:to] - end end # implicit means there is no explcit test involved. @@ -87,9 +78,6 @@ module Virtual @args = args end attr_reader :name , :args - def attributes - [:name , :args ] - end end class FrameSet < Instruction @@ -98,9 +86,6 @@ module Virtual @value = val end attr_reader :name , :value - def attributes - [:name , :value] - end end class MessageSet < Instruction @@ -109,9 +94,6 @@ module Virtual @value = val end attr_reader :name , :value - def attributes - [:name , :value] - end end class LoadSelf < Instruction @@ -119,9 +101,6 @@ module Virtual @value = val end attr_reader :value - def attributes - [:value] - end end class ObjectGet < Instruction diff --git a/lib/virtual/object.rb b/lib/virtual/object.rb index 65b3269d..f0bb7764 100644 --- a/lib/virtual/object.rb +++ b/lib/virtual/object.rb @@ -41,9 +41,6 @@ module Virtual def initialize members @members = members end - def attributes - super << :members - end end class Class < Object diff --git a/lib/virtual/type.rb b/lib/virtual/type.rb index 8f7352b3..9aff43bf 100644 --- a/lib/virtual/type.rb +++ b/lib/virtual/type.rb @@ -33,9 +33,7 @@ module Virtual @clazz = clazz end attr_accessor :clazz - def attributes - [:clazz] - end + def at_index block , left , right block.ldr( self , left , right ) self @@ -48,9 +46,6 @@ module Virtual class Mystery < Type def initialize end - def attributes - [] - end def as type type.new end diff --git a/lib/virtual/value.rb b/lib/virtual/value.rb index 5c89b975..509f59b6 100644 --- a/lib/virtual/value.rb +++ b/lib/virtual/value.rb @@ -6,28 +6,27 @@ module Virtual # Values must really be Constants or Variables, ie have a storage space class Value - def == other - other.class == self.class - end def type raise "abstract called for #{self.class}" end - def attributes - raise "abstract called for #{self.class}" - end def == other return false unless other.class == self.class - attributes.each do |a| - left = send(a) - right = other.send(a) + Sof::Util.attributes(self).each do |a| + begin + left = send(a) + rescue NoMethodError + next # not using instance variables that are not defined as attr_readers for equality + end + begin + right = other.send(a) + rescue NoMethodError + return false + end return false unless left.class == right.class return false unless left == right end return true end - def inspect - self.class.name + ".new(" + attributes.collect{|a| send(a).inspect }.join(",")+ ")" - end private def initialize end @@ -40,9 +39,6 @@ module Virtual @type = type end attr_accessor :name , :type - def attributes - [:name , :type] - end end # The subclasses are not strictly speaking neccessary at this def point # i just don't want to destroy the information for later optimizations @@ -52,17 +48,11 @@ module Virtual def initialize type super(:return , type) end - def attributes - [:type] - end end class Self < Variable def initialize type super(:self , type) end - def attributes - [:type] - end end class Argument < Variable end @@ -70,4 +60,4 @@ module Virtual end class Temp < Variable end -end \ No newline at end of file +end