Author: paultcochrane
Date: Fri Mar 9 01:05:27 2007
New Revision: 17402
Modified:
trunk/src/pmc/metaattribute.pmc
trunk/src/pmc/metaclass.pmc
trunk/src/pmc/object.pmc
Log:
[src] Removed dos-specific line endings (had inconsistent line endings)
Modified: trunk/src/pmc/metaattribute.pmc
==============================================================================
--- trunk/src/pmc/metaattribute.pmc (original)
+++ trunk/src/pmc/metaattribute.pmc Fri Mar 9 01:05:27 2007
@@ -44,15 +44,15 @@
*/
- void init() {
- Parrot_MetaAttribute *attr = NULL;
-
- /* Custom DOD mark and destory. */
- PObj_custom_mark_SET(SELF);
- PObj_active_destroy_SET(SELF);
-
- /* Set up the attribute. */
- attr = mem_sys_allocate_zeroed(sizeof(Parrot_MetaAttribute));
+ void init() {
+ Parrot_MetaAttribute *attr = NULL;
+
+ /* Custom DOD mark and destory. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* Set up the attribute. */
+ attr = mem_sys_allocate_zeroed(sizeof(Parrot_MetaAttribute));
PMC_data(SELF) = attr;
}
@@ -73,22 +73,22 @@
mem_sys_free(PMC_data(SELF));
}
-/*
-
-=item C<void destroy()>
-
-Mark any referenced strings and PMCs.
-
-=cut
-
-*/
- void mark() {
- Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
- if (attr->name)
- pobject_lives(interp, (PObj*)attr->name);
- if (attr->type)
- pobject_lives(interp, (PObj*)attr->type);
- }
+/*
+
+=item C<void destroy()>
+
+Mark any referenced strings and PMCs.
+
+=cut
+
+*/
+ void mark() {
+ Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
+ if (attr->name)
+ pobject_lives(interp, (PObj*)attr->name);
+ if (attr->type)
+ pobject_lives(interp, (PObj*)attr->type);
+ }
/*
@@ -100,17 +100,17 @@
*/
PMETHOD void name(STRING *name :optional, int got_name :opt_flag) {
- Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
- STRING *name_attr = NULL;
+ Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
+ STRING *name_attr = NULL;
if (got_name) {
attr->name = name;
- }
+ }
name_attr = attr->name;
preturn(STRING *name_attr);
}
-
+
/*
=item C<void type(PMC *type)>
@@ -121,12 +121,12 @@
*/
PMETHOD void type(STRING *type :optional, int got_type :opt_flag) {
- Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
- STRING *type_string = NULL;
+ Parrot_MetaAttribute *attr = PARROT_METAATTRIBUTE(SELF);
+ STRING *type_string = NULL;
if (got_type) {
attr->type = type;
- }
+ }
type_string = attr->type;
preturn(STRING *type_string);
Modified: trunk/src/pmc/metaclass.pmc
==============================================================================
--- trunk/src/pmc/metaclass.pmc (original)
+++ trunk/src/pmc/metaclass.pmc Fri Mar 9 01:05:27 2007
@@ -8,7 +8,7 @@
=head1 DESCRIPTION
-This class implements the basic Parrot metaclass, used for describing a
+This class implements the basic Parrot metaclass, used for describing a
class.
=head2 Functions
@@ -25,65 +25,65 @@
typedef struct Parrot_MetaClass {
STRING *name; /* The name of the class. */
PMC *namespace; /* The namespace it's linked to, if any. */
- int instantiated; /* Any instantiations since last modification? */
+ int instantiated; /* Any instantiations since last modification? */
PMC *parents; /* Immediate parent classes. */
- PMC *all_parents; /* Cached list of ourself and all parents, in MRO
order. */
+ PMC *all_parents; /* Cached list of ourself and all parents, in MRO
order. */
PMC *roles; /* An array of roles. */
- PMC *methods; /* Hash of method names to methods in this class. */
- PMC *vtable_methods; /* Hash of Parrot v-table methods we override. */
- PMC *attrib_metadata; /* Hash of attributes in this class to metadata. */
- PMC *attrib_index; /* Lookup table for attributes in this and parents.
*/
+ PMC *methods; /* Hash of method names to methods in this class. */
+ PMC *vtable_methods; /* Hash of Parrot v-table methods we override. */
+ PMC *attrib_metadata; /* Hash of attributes in this class to metadata. */
+ PMC *attrib_index; /* Lookup table for attributes in this and parents.
*/
PMC *attrib_cache; /* Cache of visible attrib names to indexes. */
} Parrot_MetaClass;
-
-pmclass MetaClass need_ext {
- /* This functions builds the attribute index (table to map class name and
- * attribute name to an index) for the current class. Note: we have to
- * make this a method so we can use PMINVOKE for now. XXX Fix that. */
- METHOD void build_attrib_index() {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- int num_classes = VTABLE_elements(interp, class->all_parents);
- int i;
- int cur_index = 0;
- PMC *table = pmc_new(interp, enum_class_Hash);
-
- /* We will go over the list of all parents to construct the table. */
- for (i = 0; i < num_classes; i++) {
- /* Get the class and its attribute metadata hash. */
- PMC *cur_class = VTABLE_get_pmc_keyed_int(interp,
class->all_parents, i);
- Parrot_MetaClass *class_info = PARROT_METACLASS(cur_class);
- PMC *attribs = class_info->attrib_metadata;
- PMC *iter = VTABLE_get_iter(interp, attribs);
-
- /* Iterate over the attributes. */
- while (VTABLE_get_bool(interp, iter)) {
- /* Get attribute. */
- PMC *cur_attrib = VTABLE_get_pmc_keyed(interp, attribs,
- VTABLE_shift_pmc(interp, iter));
- STRING *attrib_name;
-
- /* Get fully qualified class name. */
- /* XXX BAD AND WRONG! Need to call method properly! */
- PMC *fq_name;
- if (!PMC_IS_NULL(class_info->namespace))
- fq_name = Parrot_NameSpace_get_name(interp,
class_info->namespace);
- else
- fq_name = pmc_new(interp, enum_class_ResizableStringArray);
-
- /* Get attribute name and append it. */
- (STRING *attrib_name) = PMINVOKE(interp, cur_attrib, "name");
- printf("arg %s\n", string_to_cstring(interp, attrib_name));
- VTABLE_push_string(interp, fq_name, attrib_name);
-
- /* Insert into hash, along with index. */
- VTABLE_set_integer_keyed(interp, table, fq_name, cur_index);
- cur_index++;
- }
- }
-
- /* Store built table and invalidate cache. */
- class->attrib_index = table;
- class->attrib_cache = pmc_new(interp, enum_class_Hash);
+
+pmclass MetaClass need_ext {
+ /* This functions builds the attribute index (table to map class name and
+ * attribute name to an index) for the current class. Note: we have to
+ * make this a method so we can use PMINVOKE for now. XXX Fix that. */
+ METHOD void build_attrib_index() {
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ int num_classes = VTABLE_elements(interp, class->all_parents);
+ int i;
+ int cur_index = 0;
+ PMC *table = pmc_new(interp, enum_class_Hash);
+
+ /* We will go over the list of all parents to construct the table. */
+ for (i = 0; i < num_classes; i++) {
+ /* Get the class and its attribute metadata hash. */
+ PMC *cur_class = VTABLE_get_pmc_keyed_int(interp,
class->all_parents, i);
+ Parrot_MetaClass *class_info = PARROT_METACLASS(cur_class);
+ PMC *attribs = class_info->attrib_metadata;
+ PMC *iter = VTABLE_get_iter(interp, attribs);
+
+ /* Iterate over the attributes. */
+ while (VTABLE_get_bool(interp, iter)) {
+ /* Get attribute. */
+ PMC *cur_attrib = VTABLE_get_pmc_keyed(interp, attribs,
+ VTABLE_shift_pmc(interp, iter));
+ STRING *attrib_name;
+
+ /* Get fully qualified class name. */
+ /* XXX BAD AND WRONG! Need to call method properly! */
+ PMC *fq_name;
+ if (!PMC_IS_NULL(class_info->namespace))
+ fq_name = Parrot_NameSpace_get_name(interp,
class_info->namespace);
+ else
+ fq_name = pmc_new(interp, enum_class_ResizableStringArray);
+
+ /* Get attribute name and append it. */
+ (STRING *attrib_name) = PMINVOKE(interp, cur_attrib, "name");
+ printf("arg %s\n", string_to_cstring(interp, attrib_name));
+ VTABLE_push_string(interp, fq_name, attrib_name);
+
+ /* Insert into hash, along with index. */
+ VTABLE_set_integer_keyed(interp, table, fq_name, cur_index);
+ cur_index++;
+ }
+ }
+
+ /* Store built table and invalidate cache. */
+ class->attrib_index = table;
+ class->attrib_cache = pmc_new(interp, enum_class_Hash);
}
/*
@@ -103,30 +103,30 @@
*/
void init() {
- Parrot_MetaClass *class = NULL;
-
- /* Custom DOD mark and destory. */
- PObj_custom_mark_SET(SELF);
- PObj_active_destroy_SET(SELF);
-
- /* We are a class. */
- PObj_is_class_SET(SELF);
-
- /* Init the class object. */
- class = mem_sys_allocate_zeroed(sizeof(Parrot_MetaClass));
- class->namespace = PMCNULL;
- class->parents = pmc_new(interp, enum_class_ResizablePMCArray);
- class->all_parents = pmc_new(interp, enum_class_ResizablePMCArray);
- class->roles = pmc_new(interp, enum_class_ResizablePMCArray);
- class->methods = pmc_new(interp, enum_class_Hash);
- class->vtable_methods = pmc_new(interp, enum_class_Hash);
- class->attrib_metadata = pmc_new(interp, enum_class_Hash);
- class->attrib_index = PMCNULL;
- class->attrib_cache = PMCNULL;
-
- /* We put ourself on the all parents list. */
- VTABLE_push_pmc(interp, class->all_parents, SELF);
-
+ Parrot_MetaClass *class = NULL;
+
+ /* Custom DOD mark and destory. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* We are a class. */
+ PObj_is_class_SET(SELF);
+
+ /* Init the class object. */
+ class = mem_sys_allocate_zeroed(sizeof(Parrot_MetaClass));
+ class->namespace = PMCNULL;
+ class->parents = pmc_new(interp, enum_class_ResizablePMCArray);
+ class->all_parents = pmc_new(interp, enum_class_ResizablePMCArray);
+ class->roles = pmc_new(interp, enum_class_ResizablePMCArray);
+ class->methods = pmc_new(interp, enum_class_Hash);
+ class->vtable_methods = pmc_new(interp, enum_class_Hash);
+ class->attrib_metadata = pmc_new(interp, enum_class_Hash);
+ class->attrib_index = PMCNULL;
+ class->attrib_cache = PMCNULL;
+
+ /* We put ourself on the all parents list. */
+ VTABLE_push_pmc(interp, class->all_parents, SELF);
+
PMC_data(SELF) = class;
}
@@ -153,155 +153,155 @@
*/
void destroy() {
mem_sys_free(PMC_data(SELF));
- }
-
-/*
-
-=item C<void mark()>
-
-Mark any referenced strings and PMCs.
-
-=cut
-
-*/
- void mark() {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- if (class->namespace)
- pobject_lives(interp, (PObj*)class->namespace);
- if (class->parents)
- pobject_lives(interp, (PObj*)class->parents);
- if (class->all_parents)
- pobject_lives(interp, (PObj*)class->all_parents);
- if (class->roles)
- pobject_lives(interp, (PObj*)class->roles);
- if (class->methods)
- pobject_lives(interp, (PObj*)class->methods);
- if (class->vtable_methods)
- pobject_lives(interp, (PObj*)class->vtable_methods);
- if (class->attrib_metadata)
- pobject_lives(interp, (PObj*)class->attrib_metadata);
- if (class->attrib_index)
- pobject_lives(interp, (PObj*)class->attrib_index);
- if (class->attrib_cache)
- pobject_lives(interp, (PObj*)class->attrib_cache);
- }
-
-/*
-
-=item C<void add_attribute()>
-
-Add an attribute to the class. Requires a name and, optionally, a type.
-
-=cut
-
-*/
- PMETHOD void add_attribute(STRING *attribute_name, STRING* attribute_type
:optional, int got_type :opt_flag) {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- PMC *new_attribute = pmc_new(interp, enum_class_MetaAttribute);
-
- /* Set name and type. */
- PMINVOKE(interp, new_attribute, "name", STRING* attribute_name);
- if (got_type) {
- PMINVOKE(interp, new_attribute, "type", STRING* attribute_type);
- }
-
- /* If we've been instantiated already, need a new class. */
- /* if (class->instantiated) ... */
-
- /* Enter the attribute in the attributes array. */
- VTABLE_set_pmc_keyed_str(interp, class->attrib_metadata,
attribute_name, new_attribute);
- }
-
-/*
-
-=item C<void name()>
-
-Sets the name of the class.
-
-=cut
-
+ }
+
+/*
+
+=item C<void mark()>
+
+Mark any referenced strings and PMCs.
+
+=cut
+
+*/
+ void mark() {
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ if (class->namespace)
+ pobject_lives(interp, (PObj*)class->namespace);
+ if (class->parents)
+ pobject_lives(interp, (PObj*)class->parents);
+ if (class->all_parents)
+ pobject_lives(interp, (PObj*)class->all_parents);
+ if (class->roles)
+ pobject_lives(interp, (PObj*)class->roles);
+ if (class->methods)
+ pobject_lives(interp, (PObj*)class->methods);
+ if (class->vtable_methods)
+ pobject_lives(interp, (PObj*)class->vtable_methods);
+ if (class->attrib_metadata)
+ pobject_lives(interp, (PObj*)class->attrib_metadata);
+ if (class->attrib_index)
+ pobject_lives(interp, (PObj*)class->attrib_index);
+ if (class->attrib_cache)
+ pobject_lives(interp, (PObj*)class->attrib_cache);
+ }
+
+/*
+
+=item C<void add_attribute()>
+
+Add an attribute to the class. Requires a name and, optionally, a type.
+
+=cut
+
+*/
+ PMETHOD void add_attribute(STRING *attribute_name, STRING* attribute_type
:optional, int got_type :opt_flag) {
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ PMC *new_attribute = pmc_new(interp, enum_class_MetaAttribute);
+
+ /* Set name and type. */
+ PMINVOKE(interp, new_attribute, "name", STRING* attribute_name);
+ if (got_type) {
+ PMINVOKE(interp, new_attribute, "type", STRING* attribute_type);
+ }
+
+ /* If we've been instantiated already, need a new class. */
+ /* if (class->instantiated) ... */
+
+ /* Enter the attribute in the attributes array. */
+ VTABLE_set_pmc_keyed_str(interp, class->attrib_metadata,
attribute_name, new_attribute);
+ }
+
+/*
+
+=item C<void name()>
+
+Sets the name of the class.
+
+=cut
+
*/
PMETHOD void name(STRING *name :optional, int got_name :opt_flag) {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- STRING *ret_name = NULL;
-
- if (got_name) {
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ STRING *ret_name = NULL;
+
+ if (got_name) {
/* Set class name. */
class->name = name;
- }
-
- ret_name = class->name;
+ }
+
+ ret_name = class->name;
preturn(STRING *ret_name);
- }
-
-/*
-
-=item C<void namespace()>
-
-With a parameter, sets the namespace for the class. Expects a fully
-qualified namespace to be specified as a key. If you already have linked
another
-namespace with this class, this link will be broken and the new namespace
-specified will be linked to this class.
-
-=cut
-
-*/
- PMETHOD void namespace(PMC *namespace :optional, int got_name :opt_flag) {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- PMC *ret_namespace = NULL;
-
- if (got_name) {
- /* Check namespace is a key. */
- if (namespace->vtable->base_type != enum_class_Key)
- {
- real_exception(interp, NULL, E_NameError, "Namespace must be a
key");
- return;
- }
-
- /* If we already have a namespace, it shouldn't refer to the
- class any more. */
- if (class->namespace)
- {
- /* XXX */
- }
-
- /* Set namespace. */
- class->namespace = Parrot_get_namespace_keyed(interp,
- interp->HLL_namespace, namespace);
-
- /* XXX Link namespace to this class; currently missing slot for
that. */
- }
-
- ret_namespace = class->namespace;
- preturn(PMC *ret_namespace);
}
-
-/*
-
-=item C<void new()>
-
-Creates an instance of the object.
-
-=cut
-
+
+/*
+
+=item C<void namespace()>
+
+With a parameter, sets the namespace for the class. Expects a fully
+qualified namespace to be specified as a key. If you already have linked
another
+namespace with this class, this link will be broken and the new namespace
+specified will be linked to this class.
+
+=cut
+
+*/
+ PMETHOD void namespace(PMC *namespace :optional, int got_name :opt_flag) {
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ PMC *ret_namespace = NULL;
+
+ if (got_name) {
+ /* Check namespace is a key. */
+ if (namespace->vtable->base_type != enum_class_Key)
+ {
+ real_exception(interp, NULL, E_NameError, "Namespace must be a
key");
+ return;
+ }
+
+ /* If we already have a namespace, it shouldn't refer to the
+ class any more. */
+ if (class->namespace)
+ {
+ /* XXX */
+ }
+
+ /* Set namespace. */
+ class->namespace = Parrot_get_namespace_keyed(interp,
+ interp->HLL_namespace, namespace);
+
+ /* XXX Link namespace to this class; currently missing slot for
that. */
+ }
+
+ ret_namespace = class->namespace;
+ preturn(PMC *ret_namespace);
+ }
+
+/*
+
+=item C<void new()>
+
+Creates an instance of the object.
+
+=cut
+
*/
PMETHOD void new(PMC *args :slurpy :named) {
- Parrot_MetaClass *class = PARROT_METACLASS(SELF);
- PMC *obj;
-
- /* Ensure we've built attributes list. */
- if (PMC_IS_NULL(class->attrib_index))
- Parrot_MetaClass_build_attrib_index(interp, SELF);
-
- /* Set instantiated flag. */
- class->instantiated = 1;
-
- /* Create object. */
- obj = pmc_new_init(interp, enum_class_Object, SELF);
-
- /* XXX Call constructor with the supplied arguments? */
-
- preturn(PMC *obj)
+ Parrot_MetaClass *class = PARROT_METACLASS(SELF);
+ PMC *obj;
+
+ /* Ensure we've built attributes list. */
+ if (PMC_IS_NULL(class->attrib_index))
+ Parrot_MetaClass_build_attrib_index(interp, SELF);
+
+ /* Set instantiated flag. */
+ class->instantiated = 1;
+
+ /* Create object. */
+ obj = pmc_new_init(interp, enum_class_Object, SELF);
+
+ /* XXX Call constructor with the supplied arguments? */
+
+ preturn(PMC *obj)
}
}
Modified: trunk/src/pmc/object.pmc
==============================================================================
--- trunk/src/pmc/object.pmc (original)
+++ trunk/src/pmc/object.pmc Fri Mar 9 01:05:27 2007
@@ -43,15 +43,15 @@
*/
- void init() {
- Parrot_Object *obj = NULL;
-
- /* Custom DOD mark and destory. */
- PObj_custom_mark_SET(SELF);
- PObj_active_destroy_SET(SELF);
-
- /* Set up the object. */
- obj = mem_sys_allocate_zeroed(sizeof(Parrot_Object));
+ void init() {
+ Parrot_Object *obj = NULL;
+
+ /* Custom DOD mark and destory. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* Set up the object. */
+ obj = mem_sys_allocate_zeroed(sizeof(Parrot_Object));
PMC_data(SELF) = obj;
}
@@ -72,22 +72,22 @@
mem_sys_free(PMC_data(SELF));
}
-/*
-
-=item C<void destroy()>
-
-Mark any referenced strings and PMCs.
-
-=cut
-
-*/
- void mark() {
- Parrot_Object *obj = PARROT_OBJECT(SELF);
- if (obj->class)
- pobject_lives(interp, (PObj*)obj->class);
- if (obj->attrib_store)
- pobject_lives(interp, (PObj*)obj->attrib_store);
- }
+/*
+
+=item C<void destroy()>
+
+Mark any referenced strings and PMCs.
+
+=cut
+
+*/
+ void mark() {
+ Parrot_Object *obj = PARROT_OBJECT(SELF);
+ if (obj->class)
+ pobject_lives(interp, (PObj*)obj->class);
+ if (obj->attrib_store)
+ pobject_lives(interp, (PObj*)obj->attrib_store);
+ }
}