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
attribute :next_frame
def self.offset
1 + Space.object_space.get_class_by_name(:Frame).object_layout.instance_length
end
include Indexed
self.offset(2) # 1 == the next_frame attributes above + layout. (indexed_length gets added)
end
end

View File

@ -139,6 +139,14 @@ module Parfait
def offset( offset )
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
offset
end

View File

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

View File

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