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:
Torsten Ruger 2019-02-10 21:00:25 +02:00
parent a89301d623
commit d24b6ee153
3 changed files with 30 additions and 29 deletions

View File

@ -1,9 +1,31 @@
# Parfait is the ruby runtime
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
require_relative "parfait/object"
require_relative "parfait/factory"
require_relative "parfait/data_object"
require_relative "parfait/integer"
require_relative "parfait/behaviour"

View File

@ -1,4 +1,3 @@
module Parfait
# 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)
@ -117,4 +116,3 @@ module Parfait
obj
end
end
end

View File

@ -12,29 +12,10 @@
# The Type also defines the class of the object
# The Type is **always** the first entry (index 0) in an object
module Parfait
TYPE_INDEX = 0
class Object
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
self.object_id == other.object_id
end
@ -52,7 +33,7 @@ module Parfait
# private
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
end
@ -62,7 +43,7 @@ module Parfait
end
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
end
@ -94,15 +75,15 @@ module Parfait
# parfait versions are deliberately called different, so we "relay"
# have to put the "" on the names for rfx to take them off again
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
# name comes in as a ruby var name
def instance_variable_ged name
var = get_instance_variable name.to_s[1 .. -1].to_sym
def instance_variable_ged( name )
#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}"
var
end
end
end