Author: leo
Date: Fri Apr 22 03:00:01 2005
New Revision: 7905
Modified:
trunk/dynclasses/pybuiltin.pmc
trunk/dynclasses/pyint.pmc
trunk/dynclasses/pyobject.pmc
trunk/imcc/parser_util.c
trunk/src/mmd.c
Log:
MMD 35 - cleanup 2: use mmd_dispatch_p_ppp in python
* dynclasses/py* __add__ and friends use now the mmd_dispatch_p_
functions that return new values
* add 2 comments WRT these METHODS
* the old mmd_dispatch_v_* functions are now unused and spit
out a message, if there is still some accidental usage
* add concat and repeat to the list of known MMDs in parser_util.c
Modified: trunk/dynclasses/pybuiltin.pmc
==============================================================================
--- trunk/dynclasses/pybuiltin.pmc (original)
+++ trunk/dynclasses/pybuiltin.pmc Fri Apr 22 03:00:01 2005
@@ -453,12 +453,11 @@
ret = pmc_new(INTERP, PyBuiltin_PyTuple);
VTABLE_set_integer_native(INTERP, ret, 2);
- temp = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, value1, value2, temp, MMD_FLOOR_DIVIDE);
+ temp = mmd_dispatch_p_ppp(INTERP, value1, value2, NULL,
+ MMD_FLOOR_DIVIDE);
VTABLE_set_pmc_keyed_int(INTERP, ret, 0, temp);
- temp = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, value1, value2, temp, MMD_MOD);
+ temp = mmd_dispatch_p_ppp(INTERP, value1, value2, NULL, MMD_MOD);
VTABLE_set_pmc_keyed_int(INTERP, ret, 1, temp);
return ret;
}
Modified: trunk/dynclasses/pyint.pmc
==============================================================================
--- trunk/dynclasses/pyint.pmc (original)
+++ trunk/dynclasses/pyint.pmc Fri Apr 22 03:00:01 2005
@@ -21,34 +21,6 @@
#include "parrot/parrot.h"
#include "pyconsts.h"
-static void
-overflow(Interp *interpreter, PMC *self, INTVAL b, PMC *dest, int mmd)
-{
- PMC *temp;
- INTVAL a = PMC_int_val(self);
-
- if (self == dest) {
- VTABLE_morph(interpreter, self, PyBuiltin_PyLong);
- VTABLE_set_integer_native(interpreter, self, a);
- mmd_dispatch_v_pip(interpreter, self, b, dest, mmd);
- }
- else {
- temp = pmc_new(interpreter, PyBuiltin_PyLong);
- VTABLE_set_integer_native(interpreter, temp, a);
- mmd_dispatch_v_pip(interpreter, temp, b, dest, mmd);
- }
-}
-
-static void
-promote(Interp *interpreter, PMC *self, PMC *b, PMC *dest, int mmd)
-{
- PMC *temp;
- INTVAL a = PMC_int_val(self);
- temp = pmc_new(interpreter, PyBuiltin_PyLong);
- VTABLE_set_integer_native(interpreter, temp, a);
- mmd_dispatch_v_ppp(interpreter, temp, b, dest, mmd);
-}
-
pmclass PyInt extends PyObject extends Integer dynpmc group python_group {
void class_init() {
@@ -372,7 +344,7 @@
VTABLE_morph(INTERP, ret, PyBuiltin_PyLong);
VTABLE_set_string_keyed_int(INTERP, ret, key,
VTABLE_get_string(INTERP, source));
- mmd_dispatch_v_pip(INTERP, ret, 1, ret, MMD_DIVIDE);
+ mmd_dispatch_p_pip(INTERP, ret, 1, ret, MMD_DIVIDE);
}
else {
INTVAL ivalue = VTABLE_get_integer(INTERP, source);
Modified: trunk/dynclasses/pyobject.pmc
==============================================================================
--- trunk/dynclasses/pyobject.pmc (original)
+++ trunk/dynclasses/pyobject.pmc Fri Apr 22 03:00:01 2005
@@ -80,14 +80,18 @@
Adds C<*value> to C<self> and returns the result.
+TODO: install this method directly as ans alias to the existing
+NCI method. This can be done for all similar methods.
+
+Additional note: get rid of the extra self argument. SELF is already there.
+MMD infix functions are not methods (no "P2" object is used in the signature).
+
=cut
*/
METHOD PMC* __add__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_ADD);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_ADD);
}
/*
@@ -101,9 +105,7 @@
*/
METHOD PMC* __and__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_BAND);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_BAND);
}
/*
@@ -148,9 +150,7 @@
*/
METHOD PMC* __div__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_DIVIDE);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_DIVIDE);
}
/*
@@ -164,9 +164,7 @@
*/
METHOD PMC* __divmod__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_MOD);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_MOD);
}
/*
@@ -197,9 +195,7 @@
*/
METHOD PMC* __floordiv__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_DIVIDE);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_FLOOR_DIVIDE);
}
/*
@@ -264,9 +260,7 @@
*/
METHOD PMC* __lshift__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_BSL);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_BSL);
}
/*
@@ -280,9 +274,7 @@
*/
METHOD PMC* __mod__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_MOD);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_MOD);
}
/*
@@ -296,9 +288,7 @@
*/
METHOD PMC* __mul__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_MULTIPLY);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_MULTIPLY);
}
/*
@@ -345,9 +335,7 @@
*/
METHOD PMC* __or__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_BOR);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_BOR);
}
/*
@@ -361,9 +349,7 @@
*/
METHOD PMC* __pow__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_POW);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_POW);
}
/*
@@ -537,9 +523,7 @@
*/
METHOD PMC* __rshift__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_BSR);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_BSR);
}
/*
@@ -598,9 +582,7 @@
*/
METHOD PMC* __sub__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_SUBTRACT);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_SUBTRACT);
}
/*
@@ -614,9 +596,7 @@
*/
METHOD PMC* __xor__(PMC *self, PMC *value) {
- PMC * ret = pmc_new(INTERP, PyBuiltin_PyObject);
- mmd_dispatch_v_ppp(INTERP, self, value, ret, MMD_BXOR);
- return ret;
+ return mmd_dispatch_p_ppp(INTERP, self, value, NULL, MMD_BXOR);
}
/*
Modified: trunk/imcc/parser_util.c
==============================================================================
--- trunk/imcc/parser_util.c (original)
+++ trunk/imcc/parser_util.c Fri Apr 22 03:00:01 2005
@@ -369,7 +369,9 @@
{
if (n < 2 || r[0]->set != 'P')
return -1;
-
+ /* TODO use a generic Parrot interface function,
+ * which handles user infix extensions too
+ */
if (strcmp(name, "add") == 0)
return MMD_ADD;
if (strcmp(name, "sub") == 0)
@@ -407,6 +409,11 @@
if (strcmp(name, "lsr") == 0)
return MMD_LSR;
+ if (strcmp(name, "concat") == 0)
+ return MMD_CONCAT;
+ if (strcmp(name, "repeat") == 0)
+ return MMD_REPEAT;
+
if (strcmp(name, "or") == 0)
return MMD_LOR;
if (strcmp(name, "and") == 0)
Modified: trunk/src/mmd.c
==============================================================================
--- trunk/src/mmd.c (original)
+++ trunk/src/mmd.c Fri Apr 22 03:00:01 2005
@@ -244,6 +244,7 @@
real_function = (mmd_f_v_ppp)get_mmd_dispatcher(interpreter,
left, right, function, &is_pmc);
+ printf("************* unused\n");
if (is_pmc) {
sub = (PMC*)real_function;
Parrot_runops_fromc_args(interpreter, sub, "vPPP",
@@ -263,6 +264,7 @@
int is_pmc;
UINTVAL left_type;
+ printf("************* unused\n");
left_type = left->vtable->base_type;
real_function = (mmd_f_v_pip)get_mmd_dispatch_type(interpreter,
function, left_type, enum_type_INTVAL, &is_pmc);
@@ -285,6 +287,7 @@
int is_pmc;
UINTVAL left_type;
+ printf("************* unused\n");
left_type = left->vtable->base_type;
real_function = (mmd_f_v_pnp)get_mmd_dispatch_type(interpreter,
function, left_type, enum_type_FLOATVAL, &is_pmc);
@@ -307,6 +310,7 @@
int is_pmc;
UINTVAL left_type;
+ printf("************* unused\n");
left_type = left->vtable->base_type;
real_function = (mmd_f_v_psp)get_mmd_dispatch_type(interpreter,
function, left_type, enum_type_STRING, &is_pmc);