start writing parfait witout the module
Parfait classes must be unscoped. Now we start parsing Parfait, it must be without the module. Luckily module_eval makes this a breeze. Also remove string interpolation that is not yet processed
This commit is contained in:
parent
a89301d623
commit
d24b6ee153
@ -1,9 +1,31 @@
|
|||||||
# Parfait is the ruby runtime
|
# Parfait is the ruby runtime
|
||||||
module Parfait
|
module Parfait
|
||||||
|
TYPE_INDEX = 0
|
||||||
|
|
||||||
|
class Object
|
||||||
|
def self.memory_size
|
||||||
|
8
|
||||||
|
end
|
||||||
|
def self.type_length
|
||||||
|
1
|
||||||
|
end
|
||||||
|
def self.new( *args )
|
||||||
|
object = self.allocate
|
||||||
|
# have to grab the class, because we are in the ruby class not the parfait one
|
||||||
|
cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym)
|
||||||
|
# and have to set the type before we let the object do anything. otherwise boom
|
||||||
|
object.set_type cl.instance_type
|
||||||
|
object.send :initialize , *args
|
||||||
|
object
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
["object" , "factory" ].each do |file_name|
|
||||||
|
path = File.expand_path( "../parfait/#{file_name}.rb" , __FILE__)
|
||||||
|
module_eval( File.read path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "parfait/object"
|
|
||||||
require_relative "parfait/factory"
|
|
||||||
require_relative "parfait/data_object"
|
require_relative "parfait/data_object"
|
||||||
require_relative "parfait/integer"
|
require_relative "parfait/integer"
|
||||||
require_relative "parfait/behaviour"
|
require_relative "parfait/behaviour"
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
module Parfait
|
|
||||||
# A factory has the one job of handing out new instances
|
# A factory has the one job of handing out new instances
|
||||||
#
|
#
|
||||||
# A factory is for a specific type (currently, may change by size at some point)
|
# A factory is for a specific type (currently, may change by size at some point)
|
||||||
@ -117,4 +116,3 @@ module Parfait
|
|||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -12,29 +12,10 @@
|
|||||||
# The Type also defines the class of the object
|
# The Type also defines the class of the object
|
||||||
# The Type is **always** the first entry (index 0) in an object
|
# The Type is **always** the first entry (index 0) in an object
|
||||||
|
|
||||||
module Parfait
|
|
||||||
TYPE_INDEX = 0
|
|
||||||
|
|
||||||
class Object
|
class Object
|
||||||
attr :type
|
attr :type
|
||||||
|
|
||||||
def self.memory_size
|
|
||||||
8
|
|
||||||
end
|
|
||||||
def self.type_length
|
|
||||||
1
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.new( *args )
|
|
||||||
object = self.allocate
|
|
||||||
# have to grab the class, because we are in the ruby class not the parfait one
|
|
||||||
cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym)
|
|
||||||
# and have to set the type before we let the object do anything. otherwise boom
|
|
||||||
object.set_type cl.instance_type
|
|
||||||
object.send :initialize , *args
|
|
||||||
object
|
|
||||||
end
|
|
||||||
|
|
||||||
def == other
|
def == other
|
||||||
self.object_id == other.object_id
|
self.object_id == other.object_id
|
||||||
end
|
end
|
||||||
@ -52,7 +33,7 @@ module Parfait
|
|||||||
|
|
||||||
# private
|
# private
|
||||||
def set_type(typ)
|
def set_type(typ)
|
||||||
raise "not type #{typ.class} in #{object_id.to_s(16)}" unless typ.is_a?(Type)
|
raise "not type" + typ.class.to_s + "in " + object_id.to_s(16) unless typ.is_a?(Type)
|
||||||
self.type = typ
|
self.type = typ
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -62,7 +43,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_type()
|
def get_type()
|
||||||
raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless has_type?
|
raise "No type " + self.object_id.to_s(16) + ":" + self.class.name unless has_type?
|
||||||
type
|
type
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -94,15 +75,15 @@ module Parfait
|
|||||||
# parfait versions are deliberately called different, so we "relay"
|
# parfait versions are deliberately called different, so we "relay"
|
||||||
# have to put the "" on the names for rfx to take them off again
|
# have to put the "" on the names for rfx to take them off again
|
||||||
def instance_variables
|
def instance_variables
|
||||||
get_instance_variables.to_a.collect{ |n| "#{n}".to_sym }
|
get_instance_variables.to_a.collect{ |n| n.to_s.to_sym }
|
||||||
end
|
end
|
||||||
|
|
||||||
# name comes in as a ruby var name
|
# name comes in as a ruby var name
|
||||||
def instance_variable_ged name
|
def instance_variable_ged( name )
|
||||||
var = get_instance_variable name.to_s[1 .. -1].to_sym
|
#TODO the [] shoud be a range, but currenly that is not processed in RubyCompiler
|
||||||
|
var = get_instance_variable name.to_s[1 , name.to_s.length - 1].to_sym
|
||||||
#puts "getting #{name} #{var}"
|
#puts "getting #{name} #{var}"
|
||||||
var
|
var
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user