cvsuser 03/12/02 09:45:16
Modified: include/parrot pmc.h
src global_setup.c objects.c pmc.c
Log:
Objects should be in, at least in a simple form
Revision Changes Path
1.63 +2 -1 parrot/include/parrot/pmc.h
Index: pmc.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/pmc.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -w -r1.62 -r1.63
--- pmc.h 1 Dec 2003 18:54:32 -0000 1.62
+++ pmc.h 2 Dec 2003 17:45:12 -0000 1.63
@@ -1,7 +1,7 @@
/* pmc.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: pmc.h,v 1.62 2003/12/01 18:54:32 dan Exp $
+ * $Id: pmc.h,v 1.63 2003/12/02 17:45:12 dan Exp $
* Overview:
* This is the api header for the pmc subsystem
* Data Structure and Algorithms:
@@ -19,6 +19,7 @@
#define PARROT_MAX_CLASSES 100
VAR_SCOPE VTABLE **Parrot_base_vtables;/*[PARROT_MAX_CLASSES];*/
+VAR_SCOPE INTVAL class_table_size;
VAR_SCOPE INTVAL enum_class_max;
VAR_SCOPE Parrot_mutex class_count_mutex;
1.49 +4 -6 parrot/src/global_setup.c
Index: global_setup.c
===================================================================
RCS file: /cvs/public/parrot/src/global_setup.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -w -r1.48 -r1.49
--- global_setup.c 1 Dec 2003 18:54:34 -0000 1.48
+++ global_setup.c 2 Dec 2003 17:45:16 -0000 1.49
@@ -1,7 +1,7 @@
/* global_setup.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: global_setup.c,v 1.48 2003/12/01 18:54:34 dan Exp $
+ * $Id: global_setup.c,v 1.49 2003/12/02 17:45:16 dan Exp $
* Overview:
* Performs all the global setting up of things. This includes the
* (very few) global variables that Parrot totes around
@@ -33,13 +33,11 @@
string_init(); /* Set up the string subsystem */
- /* allocate core vtable */
-#if 1
- /* no - we can't move existing vtables */
+ /* allocate core vtable table */
Parrot_base_vtables =
- mem_sys_allocate_zeroed(sizeof(VTABLE *) * enum_class_core_max);
-#endif
+ mem_sys_allocate_zeroed(sizeof(VTABLE *) * PARROT_MAX_CLASSES);
enum_class_max = enum_class_core_max;
+ class_table_size = PARROT_MAX_CLASSES;
/* Call base vtable class constructor methods */
Parrot_initialize_core_pmcs(interpreter);
1.17 +12 -4 parrot/src/objects.c
Index: objects.c
===================================================================
RCS file: /cvs/public/parrot/src/objects.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -w -r1.16 -r1.17
--- objects.c 1 Dec 2003 18:54:38 -0000 1.16
+++ objects.c 2 Dec 2003 17:45:16 -0000 1.17
@@ -1,7 +1,7 @@
/* objects.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: objects.c,v 1.16 2003/12/01 18:54:38 dan Exp $
+ * $Id: objects.c,v 1.17 2003/12/02 17:45:16 dan Exp $
* Overview:
* Handles class and object manipulation
* Data Structure and Algorithms:
@@ -158,13 +158,18 @@
return PMCNULL;
}
+/* This is the method to register a new Parrot class as an
+ instantiatable type. Doing this invoves putting it in the class
+ hash, setting its vtable so that the init method inits objects of
+ the class rather than the class itself, and adding it to the
+ interpreter's base type table so you can "new Px, foo" the things.
+*/
void
Parrot_class_register(Parrot_Interp interpreter, STRING *class_name, PMC *new_class)
{
VTABLE_set_pmc_keyed(interpreter, interpreter->class_hash,
key_new_string(interpreter,class_name), new_class);
- return;
/* Now build a new vtable for this class and register it in the
global registry */
{
@@ -176,10 +181,13 @@
/* Set the vtable's type to the newly allocated type */
Parrot_vtable_set_type(interpreter, new_vtable, new_type);
- /* Reset the init method */
- new_vtable->init = NULL;
+ /* Reset the init method to our instantiation method */
+ new_vtable->init = Parrot_instantiate_object;
new_class->vtable = new_vtable;
+ /* Put our new vtable in the global table */
+ Parrot_base_vtables[new_type] = new_vtable;
+
}
}
1.57 +16 -1 parrot/src/pmc.c
Index: pmc.c
===================================================================
RCS file: /cvs/public/parrot/src/pmc.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -w -r1.56 -r1.57
--- pmc.c 28 Oct 2003 16:08:29 -0000 1.56
+++ pmc.c 2 Dec 2003 17:45:16 -0000 1.57
@@ -1,7 +1,7 @@
/* pmc.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: pmc.c,v 1.56 2003/10/28 16:08:29 dan Exp $
+ * $Id: pmc.c,v 1.57 2003/12/02 17:45:16 dan Exp $
* Overview:
* The base vtable calling functions.
* Data Structure and Algorithms:
@@ -226,6 +226,21 @@
key = key_new_string(interp, name);
type = enum_class_max++;
+ /* Have we overflowed the table? */
+ if (enum_class_max > class_table_size - 1) {
+ VTABLE **new_vtable_table;
+ /* 10 bigger seems reasonable, though it's only a pointer
+ table and we could get bigger without blowing much memory
+ */
+ INTVAL new_max = class_table_size + 10;
+ INTVAL new_size = new_max * sizeof(VTABLE *);
+ new_vtable_table = mem_sys_realloc(Parrot_base_vtables, new_size);
+ /* XXX Should set all the empty slots to the null PMC's
+ vtable pointer */
+ Parrot_base_vtables = new_vtable_table;
+ class_table_size = new_max;
+ }
+
VTABLE_set_integer_keyed(interp, classname_hash, key, type);
UNLOCK(class_count_mutex);