remove unused attributes() boilerplate
This commit is contained in:
parent
4b17a1e58f
commit
dd59a2f9c6
@ -13,9 +13,6 @@ module Boot
|
|||||||
@meta_class = MetaClass.new(self)
|
@meta_class = MetaClass.new(self)
|
||||||
end
|
end
|
||||||
attr_reader :name , :methods , :meta_class , :context , :super_class_name
|
attr_reader :name , :methods , :meta_class , :context , :super_class_name
|
||||||
def attributes
|
|
||||||
[:name , :super_class_name]
|
|
||||||
end
|
|
||||||
def add_method_definition method
|
def add_method_definition method
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
|
||||||
raise "syserr " unless method.name.is_a? Symbol
|
raise "syserr " unless method.name.is_a? Symbol
|
||||||
|
@ -17,10 +17,6 @@ module Boot
|
|||||||
@me_self = object
|
@me_self = object
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
# in a non-booting version this should map to _add_singleton_method
|
# in a non-booting version this should map to _add_singleton_method
|
||||||
def add_function function
|
def add_function function
|
||||||
raise "not a function #{function}" unless function.is_a? Virtual::Function
|
raise "not a function #{function}" unless function.is_a? Virtual::Function
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module Sof
|
module Sof
|
||||||
class Volotile
|
class Volotile
|
||||||
@@mapping = {
|
@@mapping = {
|
||||||
|
Virtual::Block => [:method],
|
||||||
Virtual::MethodDefinition => [:current]
|
Virtual::MethodDefinition => [:current]
|
||||||
}
|
}
|
||||||
def self.attributes clazz
|
def self.attributes clazz
|
||||||
|
@ -19,10 +19,6 @@ module Virtual
|
|||||||
@codes = []
|
@codes = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes
|
|
||||||
[:name , :codes , :branch]
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :name , :codes , :method
|
attr_reader :name , :codes , :method
|
||||||
attr_accessor :branch
|
attr_accessor :branch
|
||||||
|
|
||||||
|
@ -3,13 +3,10 @@ module Virtual
|
|||||||
class Constant < ::Virtual::Value
|
class Constant < ::Virtual::Value
|
||||||
end
|
end
|
||||||
class TrueValue < Constant
|
class TrueValue < Constant
|
||||||
def attributes ; [] ; end
|
|
||||||
end
|
end
|
||||||
class FalseValue < Constant
|
class FalseValue < Constant
|
||||||
def attributes ; [] ; end
|
|
||||||
end
|
end
|
||||||
class NilValue < Constant
|
class NilValue < Constant
|
||||||
def attributes ; [] ; end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# another abstract "marker" class (so we can check for it)
|
# another abstract "marker" class (so we can check for it)
|
||||||
@ -22,12 +19,6 @@ module Virtual
|
|||||||
@integer = int
|
@integer = int
|
||||||
end
|
end
|
||||||
attr_reader :integer
|
attr_reader :integer
|
||||||
def attributes
|
|
||||||
[:integer]
|
|
||||||
end
|
|
||||||
def inspect
|
|
||||||
self.class.name + ".new(#{@integer})"
|
|
||||||
end
|
|
||||||
def type
|
def type
|
||||||
Virtual::Integer
|
Virtual::Integer
|
||||||
end
|
end
|
||||||
@ -39,20 +30,14 @@ module Virtual
|
|||||||
# Mainly because that works an i aint no elf expert.
|
# Mainly because that works an i aint no elf expert.
|
||||||
|
|
||||||
class StringConstant < ObjectConstant
|
class StringConstant < ObjectConstant
|
||||||
attr_reader :string
|
|
||||||
def attributes
|
|
||||||
[:string]
|
|
||||||
end
|
|
||||||
def initialize str
|
def initialize str
|
||||||
@string = str
|
@string = str
|
||||||
end
|
end
|
||||||
|
attr_reader :string
|
||||||
|
|
||||||
def result= value
|
def result= value
|
||||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||||
end
|
end
|
||||||
def inspect
|
|
||||||
self.class.name + ".new('#{@string}')"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -27,9 +27,6 @@ module Virtual
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Named
|
module Named
|
||||||
@ -37,9 +34,6 @@ module Virtual
|
|||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
def attributes
|
|
||||||
[:name ]
|
|
||||||
end
|
|
||||||
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
|
# 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
|
@to = to
|
||||||
end
|
end
|
||||||
attr_reader :to
|
attr_reader :to
|
||||||
def attributes
|
|
||||||
[:to]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# implicit means there is no explcit test involved.
|
# implicit means there is no explcit test involved.
|
||||||
@ -87,9 +78,6 @@ module Virtual
|
|||||||
@args = args
|
@args = args
|
||||||
end
|
end
|
||||||
attr_reader :name , :args
|
attr_reader :name , :args
|
||||||
def attributes
|
|
||||||
[:name , :args ]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class FrameSet < Instruction
|
class FrameSet < Instruction
|
||||||
@ -98,9 +86,6 @@ module Virtual
|
|||||||
@value = val
|
@value = val
|
||||||
end
|
end
|
||||||
attr_reader :name , :value
|
attr_reader :name , :value
|
||||||
def attributes
|
|
||||||
[:name , :value]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class MessageSet < Instruction
|
class MessageSet < Instruction
|
||||||
@ -109,9 +94,6 @@ module Virtual
|
|||||||
@value = val
|
@value = val
|
||||||
end
|
end
|
||||||
attr_reader :name , :value
|
attr_reader :name , :value
|
||||||
def attributes
|
|
||||||
[:name , :value]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class LoadSelf < Instruction
|
class LoadSelf < Instruction
|
||||||
@ -119,9 +101,6 @@ module Virtual
|
|||||||
@value = val
|
@value = val
|
||||||
end
|
end
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def attributes
|
|
||||||
[:value]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ObjectGet < Instruction
|
class ObjectGet < Instruction
|
||||||
|
@ -41,9 +41,6 @@ module Virtual
|
|||||||
def initialize members
|
def initialize members
|
||||||
@members = members
|
@members = members
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
super << :members
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Class < Object
|
class Class < Object
|
||||||
|
@ -33,9 +33,7 @@ module Virtual
|
|||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
end
|
end
|
||||||
attr_accessor :clazz
|
attr_accessor :clazz
|
||||||
def attributes
|
|
||||||
[:clazz]
|
|
||||||
end
|
|
||||||
def at_index block , left , right
|
def at_index block , left , right
|
||||||
block.ldr( self , left , right )
|
block.ldr( self , left , right )
|
||||||
self
|
self
|
||||||
@ -48,9 +46,6 @@ module Virtual
|
|||||||
class Mystery < Type
|
class Mystery < Type
|
||||||
def initialize
|
def initialize
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
def as type
|
def as type
|
||||||
type.new
|
type.new
|
||||||
end
|
end
|
||||||
|
@ -6,28 +6,27 @@ module Virtual
|
|||||||
# Values must really be Constants or Variables, ie have a storage space
|
# Values must really be Constants or Variables, ie have a storage space
|
||||||
|
|
||||||
class Value
|
class Value
|
||||||
def == other
|
|
||||||
other.class == self.class
|
|
||||||
end
|
|
||||||
def type
|
def type
|
||||||
raise "abstract called for #{self.class}"
|
raise "abstract called for #{self.class}"
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
raise "abstract called for #{self.class}"
|
|
||||||
end
|
|
||||||
def == other
|
def == other
|
||||||
return false unless other.class == self.class
|
return false unless other.class == self.class
|
||||||
attributes.each do |a|
|
Sof::Util.attributes(self).each do |a|
|
||||||
left = send(a)
|
begin
|
||||||
right = other.send(a)
|
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.class == right.class
|
||||||
return false unless left == right
|
return false unless left == right
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
def inspect
|
|
||||||
self.class.name + ".new(" + attributes.collect{|a| send(a).inspect }.join(",")+ ")"
|
|
||||||
end
|
|
||||||
private
|
private
|
||||||
def initialize
|
def initialize
|
||||||
end
|
end
|
||||||
@ -40,9 +39,6 @@ module Virtual
|
|||||||
@type = type
|
@type = type
|
||||||
end
|
end
|
||||||
attr_accessor :name , :type
|
attr_accessor :name , :type
|
||||||
def attributes
|
|
||||||
[:name , :type]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# The subclasses are not strictly speaking neccessary at this def point
|
# The subclasses are not strictly speaking neccessary at this def point
|
||||||
# i just don't want to destroy the information for later optimizations
|
# i just don't want to destroy the information for later optimizations
|
||||||
@ -52,17 +48,11 @@ module Virtual
|
|||||||
def initialize type
|
def initialize type
|
||||||
super(:return , type)
|
super(:return , type)
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
[:type]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class Self < Variable
|
class Self < Variable
|
||||||
def initialize type
|
def initialize type
|
||||||
super(:self , type)
|
super(:self , type)
|
||||||
end
|
end
|
||||||
def attributes
|
|
||||||
[:type]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class Argument < Variable
|
class Argument < Variable
|
||||||
end
|
end
|
||||||
@ -70,4 +60,4 @@ module Virtual
|
|||||||
end
|
end
|
||||||
class Temp < Variable
|
class Temp < Variable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user