remove unused attributes() boilerplate

This commit is contained in:
Torsten Ruger 2014-08-19 22:54:28 +03:00
parent 4b17a1e58f
commit dd59a2f9c6
9 changed files with 15 additions and 79 deletions

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,7 @@
module Sof
class Volotile
@@mapping = {
Virtual::Block => [:method],
Virtual::MethodDefinition => [:current]
}
def self.attributes clazz

View File

@ -19,10 +19,6 @@ module Virtual
@codes = []
end
def attributes
[:name , :codes , :branch]
end
attr_reader :name , :codes , :method
attr_accessor :branch

View File

@ -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

View File

@ -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

View File

@ -41,9 +41,6 @@ module Virtual
def initialize members
@members = members
end
def attributes
super << :members
end
end
class Class < Object

View File

@ -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

View File

@ -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