make frame and message indexed

also auto generate a replacement for previous offset class method (dry)
This commit is contained in:
Torsten Ruger 2015-10-27 16:04:36 +02:00
parent fdc7f8b39c
commit 50029711ff
4 changed files with 18 additions and 12 deletions

View File

@ -19,9 +19,8 @@ module Parfait
class Frame < Object class Frame < Object
attribute :next_frame attribute :next_frame
def self.offset include Indexed
1 + Space.object_space.get_class_by_name(:Frame).object_layout.instance_length self.offset(2) # 1 == the next_frame attributes above + layout. (indexed_length gets added)
end
end end
end end

View File

@ -139,6 +139,14 @@ module Parfait
def offset( offset ) def offset( offset )
offset += 1 # for the attribute we add (indexed_length) offset += 1 # for the attribute we add (indexed_length)
# define methods on the class that includes.
# weird syntax, but at least it's possible
(class << self;self;end).send :define_method , :get_length_index do
offset
end
(class << self;self;end).send :define_method , :get_indexed do |index|
offset + index
end
define_method :get_offset do define_method :get_offset do
offset offset
end end

View File

@ -9,8 +9,11 @@
module Parfait module Parfait
class Message < Object class Message < Object
attributes [:next_message , :frame, :caller] attributes [:next_message , :receiver , :frame , :return_address ]
attributes [:receiver , :return_address , :return_value , :name] attributes [:return_value, :caller , :name ]
include Indexed
self.offset(8) # 8 == the seven attributes above + layout. (indexed_length gets added)
def initialize next_m def initialize next_m
self.next_message = next_m self.next_message = next_m
@ -28,9 +31,5 @@ module Parfait
index = @layout.get_index(name) index = @layout.get_index(name)
get_at(index) get_at(index)
end end
def self.offset
1 + Space.object_space.get_class_by_name(:Message).object_layout.instance_length
end
end end
end end

View File

@ -115,15 +115,15 @@ module Register
{ :Word => [:char_length] , { :Word => [:char_length] ,
:List => [:indexed_length] , :List => [:indexed_length] ,
# Assumtion is that name is the last of message # Assumtion is that name is the last of message
:Message => [:next_message , :receiver , :frame , :return_address , :return_value, :Message => [ :next_message , :receiver , :frame , :return_address ,
:caller , :name ], :return_value, :caller , :name , :indexed_length ],
:MetaClass => [:me], :MetaClass => [:me],
:Integer => [], :Integer => [],
:Object => [], :Object => [],
:Kernel => [], #fix, kernel is a class, but should be a module :Kernel => [], #fix, kernel is a class, but should be a module
:BinaryCode => [], :BinaryCode => [],
:Space => [:classes , :first_message ], :Space => [:classes , :first_message ],
:Frame => [:next_frame ], :Frame => [:next_frame , :indexed_length],
:Layout => [:object_class,:instance_methods,:indexed_length] , :Layout => [:object_class,:instance_methods,:indexed_length] ,
:Class => [:object_layout , :name , :instance_methods , :super_class_name ], :Class => [:object_layout , :name , :instance_methods , :super_class_name ],
:Dictionary => [:keys , :values ] , :Dictionary => [:keys , :values ] ,