# New Ticket Created by Mattia Barbon
# Please include the string: [perl #24817]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=24817 >
Hello,
this patch
* renames Parrot_INTERP and Parrot_STRING to Parrot_Interp and Parrot_String,
which matches the rest of Parrot types, as well as the embedding interface
* Adds Parrot_PMC_get/set_vtable
* makes the extending interface compilable with a C++ compiler
(removed typedef struct Parrot_Interp* Parrot_Interp)
(note: only *compiles*, it probably does not link yet)
* changes typedefs in extend.h from
typedef void* <type>
to
typedef struct type_* type
which allows for slightly better type safety
Regards
Mattia
Index: include/parrot/dynext.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/dynext.h,v
retrieving revision 1.4
diff -u -2 -r1.4 dynext.h
--- include/parrot/dynext.h 30 Sep 2003 09:29:41 -0000 1.4
+++ include/parrot/dynext.h 5 Jan 2004 20:52:34 -0000
@@ -11,5 +11,5 @@
/* dynamic lib/oplib/PMC loading */
-PMC *Parrot_load_lib(Interp *interpreter, STRING *lib, PMC *initializer);
+Parrot_PMC Parrot_load_lib(Parrot_Interp interpreter, Parrot_String lib, Parrot_PMC
initializer);
#endif
Index: include/parrot/extend.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/extend.h,v
retrieving revision 1.12
diff -u -2 -r1.12 extend.h
--- include/parrot/extend.h 31 Dec 2003 11:54:32 -0000 1.12
+++ include/parrot/extend.h 5 Jan 2004 20:52:35 -0000
@@ -16,4 +16,6 @@
#define PARROT_EXTEND_H_GUARD
+#include <stddef.h> /* size_t */
+
#include "parrot/config.h" /* PARROT_VERSION, PARROT_JIT_CAPABLE... */
#include "parrot/interpreter.h" /* give us the interpreter flags */
@@ -24,67 +26,67 @@
we'll split this into two pieces and not install the core version,
but that would be really annoying */
-#if defined(PARROT_IN_CORE)
+#if !defined(PARROT_IN_CORE)
-#define Parrot_INTERP struct Parrot_Interp *
-#define Parrot_STRING STRING *
-#define Parrot_PMC PMC *
-#define Parrot_Language Parrot_Int
-
-#else
-
-typedef void * Parrot_INTERP;
-typedef void * Parrot_STRING;
-typedef void * Parrot_PMC;
+typedef struct Parrot_String_* Parrot_String;
+typedef struct Parrot_PMC_* Parrot_PMC;
typedef Parrot_Int Parrot_Language;
-typedef void * Parrot_Encoding;
-typedef void * Parrot_CharType;
-typedef const void * Parrot_Const_Encoding;
-typedef const void * Parrot_Const_CharType;
+typedef struct Parrot_Encoding_* Parrot_Encoding;
+typedef struct Parrot_Chartype_* Parrot_CharType;
+typedef const struct Parrot_Encoding_* Parrot_Const_Encoding;
+typedef const struct Parrot_Chartype_* Parrot_Const_CharType;
+typedef struct _vtable* Parrot_Vtable;
+/* XXX for vtables */
+typedef void BIGNUM;
+typedef void visit_info;
#endif
-Parrot_STRING Parrot_PMC_get_string(Parrot_INTERP, Parrot_PMC);
-void *Parrot_PMC_get_pointer(Parrot_INTERP, Parrot_PMC);
-Parrot_Int Parrot_PMC_get_intval(Parrot_INTERP, Parrot_PMC);
-Parrot_Int Parrot_PMC_get_intval_intkey(Parrot_INTERP, Parrot_PMC, Parrot_Int);
-Parrot_Float Parrot_PMC_get_numval(Parrot_INTERP, Parrot_PMC);
-char *Parrot_PMC_get_cstring(Parrot_INTERP, Parrot_PMC);
-char *Parrot_PMC_get_cstringn(Parrot_INTERP, Parrot_PMC, Parrot_Int *);
-
-void Parrot_PMC_set_string(Parrot_INTERP, Parrot_PMC, Parrot_STRING);
-void Parrot_PMC_set_pointer(Parrot_INTERP, Parrot_PMC, void *);
-void Parrot_PMC_set_cstring(Parrot_INTERP, Parrot_PMC, const char *);
-void Parrot_PMC_set_cstringn(Parrot_INTERP, Parrot_PMC, const char *, Parrot_Int);
-void Parrot_PMC_set_intval(Parrot_INTERP, Parrot_PMC, Parrot_Int);
-void Parrot_PMC_set_intval_intkey(Parrot_INTERP, Parrot_PMC, Parrot_Int, Parrot_Int);
-void Parrot_PMC_set_numval(Parrot_INTERP, Parrot_PMC, Parrot_Float);
+#include "parrot/vtable.h" /* Parrot_Vtable */
+
+Parrot_String Parrot_PMC_get_string(Parrot_Interp, Parrot_PMC);
+void *Parrot_PMC_get_pointer(Parrot_Interp, Parrot_PMC);
+Parrot_Int Parrot_PMC_get_intval(Parrot_Interp, Parrot_PMC);
+Parrot_Int Parrot_PMC_get_intval_intkey(Parrot_Interp, Parrot_PMC, Parrot_Int);
+Parrot_Float Parrot_PMC_get_numval(Parrot_Interp, Parrot_PMC);
+char *Parrot_PMC_get_cstring(Parrot_Interp, Parrot_PMC);
+char *Parrot_PMC_get_cstringn(Parrot_Interp, Parrot_PMC, Parrot_Int *);
+Parrot_Vtable Parrot_PMC_get_vtable(Parrot_Interp, Parrot_PMC);
+
+void Parrot_PMC_set_string(Parrot_Interp, Parrot_PMC, Parrot_String);
+void Parrot_PMC_set_pointer(Parrot_Interp, Parrot_PMC, void *);
+void Parrot_PMC_set_cstring(Parrot_Interp, Parrot_PMC, const char *);
+void Parrot_PMC_set_cstringn(Parrot_Interp, Parrot_PMC, const char *, Parrot_Int);
+void Parrot_PMC_set_intval(Parrot_Interp, Parrot_PMC, Parrot_Int);
+void Parrot_PMC_set_intval_intkey(Parrot_Interp, Parrot_PMC, Parrot_Int, Parrot_Int);
+void Parrot_PMC_set_numval(Parrot_Interp, Parrot_PMC, Parrot_Float);
+void Parrot_PMC_set_vtable(Parrot_Interp, Parrot_PMC, Parrot_Vtable);
-Parrot_PMC Parrot_PMC_new(Parrot_INTERP, Parrot_Int);
+Parrot_PMC Parrot_PMC_new(Parrot_Interp, Parrot_Int);
Parrot_PMC Parrot_PMC_null(void);
-Parrot_Int Parrot_PMC_typenum(Parrot_INTERP, const char *);
+Parrot_Int Parrot_PMC_typenum(Parrot_Interp, const char *);
void Parrot_free_cstring(char *);
-void Parrot_call(Parrot_INTERP, Parrot_PMC, Parrot_Int, ...);
-void Parrot_call_method(Parrot_INTERP, Parrot_PMC, Parrot_STRING, Parrot_Int, ...);
+void Parrot_call(Parrot_Interp, Parrot_PMC, Parrot_Int, ...);
+void Parrot_call_method(Parrot_Interp, Parrot_PMC, Parrot_String, Parrot_Int, ...);
-Parrot_Int Parrot_get_intreg(Parrot_INTERP, Parrot_Int);
-Parrot_Float Parrot_get_numreg(Parrot_INTERP, Parrot_Int);
-Parrot_STRING Parrot_get_strreg(Parrot_INTERP, Parrot_Int);
-Parrot_PMC Parrot_get_pmcreg(Parrot_INTERP, Parrot_Int);
-
-void Parrot_set_intreg(Parrot_INTERP, Parrot_Int, Parrot_Int);
-void Parrot_set_numreg(Parrot_INTERP, Parrot_Int, Parrot_Float);
-void Parrot_set_strreg(Parrot_INTERP, Parrot_Int, Parrot_STRING);
-void Parrot_set_pmcreg(Parrot_INTERP, Parrot_Int, Parrot_PMC);
-
-Parrot_STRING Parrot_new_string(Parrot_INTERP, char *, int, Parrot_Encoding,
Parrot_CharType, Parrot_Language, Parrot_Int);
-
-Parrot_Const_CharType Parrot_find_chartype(Parrot_INTERP, char*);
-Parrot_Language Parrot_find_language(Parrot_INTERP, char*);
-Parrot_Const_Encoding Parrot_find_encoding(Parrot_INTERP, char*);
+Parrot_Int Parrot_get_intreg(Parrot_Interp, Parrot_Int);
+Parrot_Float Parrot_get_numreg(Parrot_Interp, Parrot_Int);
+Parrot_String Parrot_get_strreg(Parrot_Interp, Parrot_Int);
+Parrot_PMC Parrot_get_pmcreg(Parrot_Interp, Parrot_Int);
+
+void Parrot_set_intreg(Parrot_Interp, Parrot_Int, Parrot_Int);
+void Parrot_set_numreg(Parrot_Interp, Parrot_Int, Parrot_Float);
+void Parrot_set_strreg(Parrot_Interp, Parrot_Int, Parrot_String);
+void Parrot_set_pmcreg(Parrot_Interp, Parrot_Int, Parrot_PMC);
+
+Parrot_String Parrot_new_string(Parrot_Interp, const char *, int, Parrot_Encoding,
Parrot_CharType, Parrot_Language, Parrot_Int);
+
+Parrot_Const_CharType Parrot_find_chartype(Parrot_Interp, char*);
+Parrot_Language Parrot_find_language(Parrot_Interp, char*);
+Parrot_Const_Encoding Parrot_find_encoding(Parrot_Interp, char*);
-void Parrot_register_pmc(Parrot_INTERP, Parrot_PMC);
-void Parrot_unregister_pmc(Parrot_INTERP, Parrot_PMC);
+void Parrot_register_pmc(Parrot_Interp, Parrot_PMC);
+void Parrot_unregister_pmc(Parrot_Interp, Parrot_PMC);
#endif
Index: include/parrot/interpreter.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/interpreter.h,v
retrieving revision 1.114
diff -u -2 -r1.114 interpreter.h
--- include/parrot/interpreter.h 2 Jan 2004 14:09:32 -0000 1.114
+++ include/parrot/interpreter.h 5 Jan 2004 20:52:37 -0000
@@ -55,9 +55,13 @@
/* &end_gen */
-struct Parrot_Interp;
-
-typedef struct Parrot_Interp *Parrot_Interp;
#if defined(PARROT_IN_CORE)
+#define Parrot_String STRING *
+#define Parrot_PMC PMC *
+#define Parrot_Language Parrot_Int
+#define Parrot_Vtable struct _vtable*
+
+struct Parrot_Interp;
+typedef struct Parrot_Interp *Parrot_Interp;
typedef Parrot_Interp_flag Interp_flags;
@@ -353,6 +357,8 @@
void *func, const char *name, const char *proto);
#else
+struct Parrot_Interp_;
+typedef struct Parrot_Interp_ *Parrot_Interp;
-typedef void * *(*native_func_t)(struct Parrot_Interp *interpreter,
+typedef void * *(*native_func_t)(Parrot_Interp interpreter,
void *cur_opcode,
void *start_code);
Index: src/extend.c
===================================================================
RCS file: /cvs/public/parrot/src/extend.c,v
retrieving revision 1.16
diff -u -2 -r1.16 extend.c
--- src/extend.c 31 Dec 2003 11:54:41 -0000 1.16
+++ src/extend.c 5 Jan 2004 20:52:42 -0000
@@ -31,5 +31,5 @@
*/
-Parrot_STRING Parrot_PMC_get_string(Parrot_INTERP interp, Parrot_PMC pmc) {
+Parrot_String Parrot_PMC_get_string(Parrot_Interp interp, Parrot_PMC pmc) {
return VTABLE_get_string(interp, pmc);
}
@@ -41,5 +41,5 @@
*/
-void *Parrot_PMC_get_pointer(Parrot_INTERP interp, Parrot_PMC pmc) {
+void *Parrot_PMC_get_pointer(Parrot_Interp interp, Parrot_PMC pmc) {
return VTABLE_get_pointer(interp, pmc);
}
@@ -50,5 +50,5 @@
*/
-Parrot_Int Parrot_PMC_get_intval(Parrot_INTERP interp, Parrot_PMC pmc) {
+Parrot_Int Parrot_PMC_get_intval(Parrot_Interp interp, Parrot_PMC pmc) {
return VTABLE_get_integer(interp, pmc);
}
@@ -59,5 +59,5 @@
*/
-Parrot_Int Parrot_PMC_get_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
Parrot_Int key) {
+Parrot_Int Parrot_PMC_get_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
Parrot_Int key) {
return VTABLE_get_integer_keyed_int(interp, pmc, key);
}
@@ -68,5 +68,5 @@
*/
-Parrot_Float Parrot_PMC_get_numval(Parrot_INTERP interp, Parrot_PMC pmc) {
+Parrot_Float Parrot_PMC_get_numval(Parrot_Interp interp, Parrot_PMC pmc) {
return VTABLE_get_number(interp, pmc);
}
@@ -77,5 +77,5 @@
* the PMC.
*/
-char *Parrot_PMC_get_cstring(Parrot_INTERP interp, Parrot_PMC pmc) {
+char *Parrot_PMC_get_cstring(Parrot_Interp interp, Parrot_PMC pmc) {
STRING *retval;
retval = VTABLE_get_string(interp, pmc);
@@ -91,5 +91,5 @@
* without disturbing the interface.
*/
-char *Parrot_PMC_get_cstringn(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int
*length) {
+char *Parrot_PMC_get_cstringn(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int
*length) {
char *retval;
retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
@@ -98,9 +98,17 @@
}
+/*=for api extend Parrot_PMC_get_vtable
+ *
+ * Return a pointer to the vtable of the passed-in PMC
+ */
+Parrot_Vtable Parrot_PMC_get_vtable(Parrot_Interp interp, Parrot_PMC pmc) {
+ return pmc->vtable;
+}
+
/*=for api extend Parrot_PMC_set_string
*
* Assign the passed-in parrot string to the passed-in PMC
*/
-void Parrot_PMC_set_string(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_STRING value)
{
+void Parrot_PMC_set_string(Parrot_Interp interp, Parrot_PMC pmc, Parrot_String value)
{
VTABLE_set_string_native(interp, pmc, value);
}
@@ -110,5 +118,5 @@
* Assign the passed-in pointer to the passed-in PMC
*/
-void Parrot_PMC_set_pointer(Parrot_INTERP interp, Parrot_PMC pmc, void *value) {
+void Parrot_PMC_set_pointer(Parrot_Interp interp, Parrot_PMC pmc, void *value) {
VTABLE_set_pointer(interp, pmc, value);
}
@@ -118,5 +126,5 @@
* Assign the passed-in parrot integer to the passed-in PMC
*/
-void Parrot_PMC_set_intval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int value) {
+void Parrot_PMC_set_intval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int value) {
VTABLE_set_integer_native(interp, pmc, value);
}
@@ -126,5 +134,5 @@
* Assign the passed-in parrot integer to the passed-in PMC
*/
-void Parrot_PMC_set_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int
value, Parrot_Int key) {
+void Parrot_PMC_set_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int
value, Parrot_Int key) {
VTABLE_set_integer_keyed_int(interp, pmc, key, value);
}
@@ -134,5 +142,5 @@
* Assign the passed-in parrot number to the passed-in PMC
*/
-void Parrot_PMC_set_numval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Float value) {
+void Parrot_PMC_set_numval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Float value) {
VTABLE_set_number_native(interp, pmc, value);
}
@@ -142,5 +150,5 @@
* Assign the passed-in null-terminated C string to the passed-in PMC
*/
-void Parrot_PMC_set_cstring(Parrot_INTERP interp, Parrot_PMC pmc, const char *value) {
+void Parrot_PMC_set_cstring(Parrot_Interp interp, Parrot_PMC pmc, const char *value) {
VTABLE_set_string_native(interp, pmc, string_from_cstring(interp, value, 0));
}
@@ -150,13 +158,21 @@
* Assign the passed-in length-noted string to the passed-in PMC
*/
-void Parrot_PMC_set_cstringn(Parrot_INTERP interp, Parrot_PMC pmc, const char *value,
Parrot_Int length) {
+void Parrot_PMC_set_cstringn(Parrot_Interp interp, Parrot_PMC pmc, const char *value,
Parrot_Int length) {
VTABLE_set_string_native(interp, pmc, string_from_cstring(interp, value, length));
}
+/*=for api extend Parrot_PMC_get_vtable
+ *
+ * Set the vtable of the PMC to the passed-in vtable
+ */
+void Parrot_PMC_set_vtable(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Vtable
vtable) {
+ pmc->vtable = vtable;
+}
+
/*=for api extend Parrot_PMC_new
*
* Create and return a new PMC
*/
-Parrot_PMC Parrot_PMC_new(Parrot_INTERP interp, Parrot_Int type) {
+Parrot_PMC Parrot_PMC_new(Parrot_Interp interp, Parrot_Int type) {
Parrot_PMC newpmc;
newpmc = pmc_new_noinit(interp, type);
@@ -169,5 +185,5 @@
* Returns the internal identifier that represents the named class
*/
-Parrot_Int Parrot_PMC_typenum(Parrot_INTERP interp, const char *class) {
+Parrot_Int Parrot_PMC_typenum(Parrot_Interp interp, const char *class) {
return pmc_type(interp, string_from_cstring(interp, class, 0));
}
@@ -190,5 +206,5 @@
* Call a parrot subroutine, with PMC parameters
*/
-void Parrot_call(Parrot_INTERP interpreter, Parrot_PMC sub,
+void Parrot_call(Parrot_Interp interpreter, Parrot_PMC sub,
Parrot_Int argcount, ...) {
Parrot_Int inreg = 0;
@@ -228,6 +244,6 @@
* Call a parrot method, with PMC parameters
*/
-void Parrot_call_method(Parrot_INTERP interp, Parrot_PMC sub,
- Parrot_STRING method, Parrot_Int argcount, ...) {
+void Parrot_call_method(Parrot_Interp interp, Parrot_PMC sub,
+ Parrot_String method, Parrot_Int argcount, ...) {
}
@@ -237,5 +253,5 @@
* Return the value of an integer register
*/
-Parrot_Int Parrot_get_intreg(Parrot_INTERP interpreter, Parrot_Int regnum) {
+Parrot_Int Parrot_get_intreg(Parrot_Interp interpreter, Parrot_Int regnum) {
return REG_INT(regnum);
}
@@ -245,5 +261,5 @@
* Return the value of a numeric register
*/
-Parrot_Float Parrot_get_numreg(Parrot_INTERP interpreter, Parrot_Int regnum) {
+Parrot_Float Parrot_get_numreg(Parrot_Interp interpreter, Parrot_Int regnum) {
return REG_NUM(regnum);
}
@@ -253,5 +269,5 @@
* Return the value of a string register
*/
-Parrot_STRING Parrot_get_strreg(Parrot_INTERP interpreter, Parrot_Int regnum) {
+Parrot_String Parrot_get_strreg(Parrot_Interp interpreter, Parrot_Int regnum) {
return REG_STR(regnum);
}
@@ -261,5 +277,5 @@
* Return the value of a PMC register
*/
-Parrot_PMC Parrot_get_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum) {
+Parrot_PMC Parrot_get_pmcreg(Parrot_Interp interpreter, Parrot_Int regnum) {
return REG_PMC(regnum);
}
@@ -269,5 +285,5 @@
* Set the value of an I register
*/
-void Parrot_set_intreg(Parrot_INTERP interpreter, Parrot_Int regnum, Parrot_Int
value) {
+void Parrot_set_intreg(Parrot_Interp interpreter, Parrot_Int regnum, Parrot_Int
value) {
REG_INT(regnum) = value;
}
@@ -277,5 +293,5 @@
* Set the value of an N register
*/
-void Parrot_set_numreg(Parrot_INTERP interpreter, Parrot_Int regnum, Parrot_Float
value) {
+void Parrot_set_numreg(Parrot_Interp interpreter, Parrot_Int regnum, Parrot_Float
value) {
REG_NUM(regnum) = value;
}
@@ -285,5 +301,5 @@
* Set the value of an S register
*/
-void Parrot_set_strreg(Parrot_INTERP interpreter, Parrot_Int regnum, Parrot_STRING
value) {
+void Parrot_set_strreg(Parrot_Interp interpreter, Parrot_Int regnum, Parrot_String
value) {
REG_STR(regnum) = value;
}
@@ -293,5 +309,5 @@
* Set the value of a P register
*/
-void Parrot_set_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum, Parrot_PMC
value) {
+void Parrot_set_pmcreg(Parrot_Interp interpreter, Parrot_Int regnum, Parrot_PMC
value) {
REG_PMC(regnum) = value;
}
@@ -306,6 +322,6 @@
*
*/
-Parrot_STRING Parrot_new_string(Parrot_INTERP interpreter,
- char *buffer, int length,
+Parrot_String Parrot_new_string(Parrot_Interp interpreter,
+ const char *buffer, int length,
Parrot_Encoding encoding,
Parrot_CharType charset,
@@ -319,5 +335,5 @@
* Find the magic token for an encoding, by name
*/
-Parrot_Const_Encoding Parrot_find_encoding(Parrot_INTERP interpreter, char
*encoding_name) {
+Parrot_Const_Encoding Parrot_find_encoding(Parrot_Interp interpreter, char
*encoding_name) {
return Parrot_encoding_lookup(encoding_name);
}
@@ -328,5 +344,5 @@
*
*/
-Parrot_Language Parrot_find_language(Parrot_INTERP interpreter, char *langauge) {
+Parrot_Language Parrot_find_language(Parrot_Interp interpreter, char *langauge) {
return 0;
}
@@ -337,5 +353,5 @@
*
*/
-Parrot_Const_CharType Parrot_find_chartype(Parrot_INTERP interpreter, char *chartype)
{
+Parrot_Const_CharType Parrot_find_chartype(Parrot_Interp interpreter, char *chartype)
{
return Parrot_chartype_lookup(chartype);
}
@@ -350,5 +366,5 @@
void
-Parrot_register_pmc(Parrot_INTERP interpreter, Parrot_PMC pmc)
+Parrot_register_pmc(Parrot_Interp interpreter, Parrot_PMC pmc)
{
dod_register_pmc(interpreter, pmc);
@@ -364,5 +380,5 @@
void
-Parrot_unregister_pmc(Parrot_INTERP interpreter, Parrot_PMC pmc)
+Parrot_unregister_pmc(Parrot_Interp interpreter, Parrot_PMC pmc)
{
dod_unregister_pmc(interpreter, pmc);