[pypy-svn] r10252 - in pypy/dist/pypy/translator: . genc genc/test test

arigo at codespeak.net arigo at codespeak.net
Sat Apr 2 17:57:38 CEST 2005


Author: arigo
Date: Sat Apr  2 17:57:37 2005
New Revision: 10252

Added:
   pypy/dist/pypy/translator/genc/   (props changed)
   pypy/dist/pypy/translator/genc/__init__.py
   pypy/dist/pypy/translator/genc/autopath.py
      - copied unchanged from r10250, pypy/dist/pypy/translator/autopath.py
   pypy/dist/pypy/translator/genc/ctyper.py
   pypy/dist/pypy/translator/genc/funcdef.py
      - copied, changed from r10251, pypy/dist/pypy/translator/genc_funcdef.py
   pypy/dist/pypy/translator/genc/g_include.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc/g_int.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc_type.h
   pypy/dist/pypy/translator/genc/g_module.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc/g_operation.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc/g_support.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc/g_trace.h
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc/genc.py
      - copied, changed from r10250, pypy/dist/pypy/translator/genc.py
   pypy/dist/pypy/translator/genc/t_int.py
      - copied unchanged from r10250, pypy/dist/pypy/translator/genc_type.py
   pypy/dist/pypy/translator/genc/t_pyobj.py
      - copied unchanged from r10250, pypy/dist/pypy/translator/genc_pyobj.py
   pypy/dist/pypy/translator/genc/test/   (props changed)
   pypy/dist/pypy/translator/genc/test/__init__.py   (contents, props changed)
   pypy/dist/pypy/translator/genc/test/autopath.py
      - copied unchanged from r10250, pypy/dist/pypy/translator/test/autopath.py
   pypy/dist/pypy/translator/genc/test/test_ctrans.py
      - copied, changed from r10251, pypy/dist/pypy/translator/test/test_ctrans.py
Removed:
   pypy/dist/pypy/translator/genc.h
   pypy/dist/pypy/translator/genc.py
   pypy/dist/pypy/translator/genc_funcdef.py
   pypy/dist/pypy/translator/genc_pyobj.py
   pypy/dist/pypy/translator/genc_type.h
   pypy/dist/pypy/translator/genc_type.py
   pypy/dist/pypy/translator/test/test_ctrans.py
Modified:
   pypy/dist/pypy/translator/translator.py
   pypy/dist/pypy/translator/typer.py
Log:
Moved all the pieces specific to genc into a single subdirectory genc/.



Deleted: /pypy/dist/pypy/translator/genc.h
==============================================================================
--- /pypy/dist/pypy/translator/genc.h	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,873 +0,0 @@
-
-/************************************************************/
-/***  Generic C header section                            ***/
-
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include "structmember.h"
-#include "traceback.h"
-#include "marshal.h"
-#include "eval.h"
-
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif /* MIN */
-
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
-
-/* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
-
-#if 0
-#define OBNOXIOUS_PRINT_STATEMENTS
-#endif
-
-#define op_bool(r,err,what) { \
-		int _retval = what; \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyBool_FromLong(_retval); \
-	}
-
-#define op_richcmp(x,y,r,err,dir) \
-					if (!(r=PyObject_RichCompare(x,y,dir))) FAIL(err)
-#define OP_LT(x,y,r,err)  op_richcmp(x,y,r,err, Py_LT)
-#define OP_LE(x,y,r,err)  op_richcmp(x,y,r,err, Py_LE)
-#define OP_EQ(x,y,r,err)  op_richcmp(x,y,r,err, Py_EQ)
-#define OP_NE(x,y,r,err)  op_richcmp(x,y,r,err, Py_NE)
-#define OP_GT(x,y,r,err)  op_richcmp(x,y,r,err, Py_GT)
-#define OP_GE(x,y,r,err)  op_richcmp(x,y,r,err, Py_GE)
-
-#define OP_IS_(x,y,r,err) op_bool(r,err,(x == y))
-
-#define OP_IS_TRUE(x,r,err) op_bool(r,err,PyObject_IsTrue(x))
-
-#define OP_LEN(x,r,err) { \
-		int _retval = PyObject_Size(x); \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyInt_FromLong(_retval); \
-	}
-#define OP_NEG(x,r,err)           if (!(r=PyNumber_Negative(x)))     FAIL(err)
-#define OP_POS(x,r,err)           if (!(r=PyNumber_Positive(x)))     FAIL(err)
-#define OP_INVERT(x,r,err)        if (!(r=PyNumber_Invert(x)))       FAIL(err)
-
-#define OP_ADD(x,y,r,err)         if (!(r=PyNumber_Add(x,y)))        FAIL(err)
-#define OP_SUB(x,y,r,err)         if (!(r=PyNumber_Subtract(x,y)))   FAIL(err)
-#define OP_MUL(x,y,r,err)         if (!(r=PyNumber_Multiply(x,y)))   FAIL(err)
-#define OP_TRUEDIV(x,y,r,err)     if (!(r=PyNumber_TrueDivide(x,y))) FAIL(err)
-#define OP_FLOORDIV(x,y,r,err)    if (!(r=PyNumber_FloorDivide(x,y)))FAIL(err)
-#define OP_DIV(x,y,r,err)         if (!(r=PyNumber_Divide(x,y)))     FAIL(err)
-#define OP_MOD(x,y,r,err)         if (!(r=PyNumber_Remainder(x,y)))  FAIL(err)
-#define OP_POW(x,y,z,r,err)       if (!(r=PyNumber_Power(x,y,z)))    FAIL(err)
-#define OP_LSHIFT(x,y,r,err)      if (!(r=PyNumber_Lshift(x,y)))     FAIL(err)
-#define OP_RSHIFT(x,y,r,err)      if (!(r=PyNumber_Rshift(x,y)))     FAIL(err)
-#define OP_AND_(x,y,r,err)        if (!(r=PyNumber_And(x,y)))        FAIL(err)
-#define OP_OR_(x,y,r,err)         if (!(r=PyNumber_Or(x,y)))         FAIL(err)
-#define OP_XOR(x,y,r,err)         if (!(r=PyNumber_Xor(x,y)))        FAIL(err)
-
-#define OP_INPLACE_ADD(x,y,r,err) if (!(r=PyNumber_InPlaceAdd(x,y)))           \
-								     FAIL(err)
-#define OP_INPLACE_SUB(x,y,r,err) if (!(r=PyNumber_InPlaceSubtract(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_MUL(x,y,r,err) if (!(r=PyNumber_InPlaceMultiply(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_TRUEDIV(x,y,r,err) if (!(r=PyNumber_InPlaceTrueDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_FLOORDIV(x,y,r,err)if(!(r=PyNumber_InPlaceFloorDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_DIV(x,y,r,err) if (!(r=PyNumber_InPlaceDivide(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_MOD(x,y,r,err) if (!(r=PyNumber_InPlaceRemainder(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_POW(x,y,r,err) if (!(r=PyNumber_InPlacePower(x,y,Py_None))) \
-								     FAIL(err)
-#define OP_INPLACE_LSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceLshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_RSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceRshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_AND(x,y,r,err)    if (!(r=PyNumber_InPlaceAnd(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_OR(x,y,r,err)     if (!(r=PyNumber_InPlaceOr(x,y)))         \
-								     FAIL(err)
-#define OP_INPLACE_XOR(x,y,r,err)    if (!(r=PyNumber_InPlaceXor(x,y)))        \
-								     FAIL(err)
-
-#define OP_GETITEM(x,y,r,err)     if (!(r=PyObject_GetItem1(x,y)))   FAIL(err)
-#define OP_SETITEM(x,y,z,r,err)   if ((PyObject_SetItem1(x,y,z))<0)  FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELITEM(x,y,r,err)     if ((PyObject_DelItem(x,y))<0)     FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_CONTAINS(x,y,r,err)    op_bool(r,err,(PySequence_Contains(x,y)))
-
-#define OP_GETATTR(x,y,r,err)     if (!(r=PyObject_GetAttr(x,y)))    FAIL(err)
-#define OP_SETATTR(x,y,z,r,err)   if ((PyObject_SetAttr(x,y,z))<0)   FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELATTR(x,y,r,err)     if ((PyObject_SetAttr(x,y,NULL))<0)FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-
-#define OP_NEWSLICE(x,y,z,r,err)  if (!(r=PySlice_New(x,y,z)))       FAIL(err)
-
-#define OP_GETSLICE(x,y,z,r,err)  {					\
-		PyObject *__yo = y, *__zo = z;				\
-		int __y = 0, __z = INT_MAX;				\
-		if (__yo == Py_None) __yo = NULL;			\
-		if (__zo == Py_None) __zo = NULL;			\
-		if (!_PyEval_SliceIndex(__yo, &__y) ||			\
-		    !_PyEval_SliceIndex(__zo, &__z) ||			\
-		    !(r=PySequence_GetSlice(x, __y, __z))) FAIL(err)	\
-	}
-
-#define OP_ALLOC_AND_SET(x,y,r,err) { \
-		/* XXX check for long/int overflow */ \
-		int __i, __x = PyInt_AsLong(x); \
-		if (PyErr_Occurred()) FAIL(err) \
-		if (!(r = PyList_New(__x))) FAIL(err) \
-		for (__i=0; __i<__x; __i++) { \
-			Py_INCREF(y); \
-			PyList_SET_ITEM(r, __i, y); \
-		} \
-	}
-
-#define OP_ITER(x,r,err)          if (!(r=PyObject_GetIter(x)))      FAIL(err)
-#define OP_NEXT(x,r,err)          if (!(r=PyIter_Next(x))) {                   \
-		if (!PyErr_Occurred()) PyErr_SetNone(PyExc_StopIteration);     \
-		FAIL(err)                                                      \
-	}
-
-#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
-					FAIL(err)
-#define OP_CALL_ARGS(args,r,err)   if (!(r=CallWithShape args))    FAIL(err)
-
-/* Needs to act like getattr(x, '__class__', type(x)) */
-#define OP_TYPE(x,r,err) { \
-		PyObject *o = x; \
-		if (PyInstance_Check(o)) { \
-			r = (PyObject*)(((PyInstanceObject*)o)->in_class); \
-		} else { \
-			r = (PyObject*)o->ob_type; \
-		} \
-		Py_INCREF(r); \
-	}
-
-/* Needs to act like instance(x,y) */
-#define OP_ISSUBTYPE(x,y,r,err)  \
-		op_bool(r,err,PyClass_IsSubclass(x, y))
-
-
-/*** misc ***/
-
-#define MOVE(x, y)             y = x;
-
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
-
-
-#if defined(USE_CALL_TRACE)
-
-#define TRACE_CALL       __f, __tstate
-#define TRACE_ARGS       PyFrameObject *__f, PyThreadState *__tstate
-
-#define FAIL(err) { __f->f_lineno = __f->f_code->co_firstlineno = __LINE__; goto err; }
-
-#define FUNCTION_HEAD(signature, self, args, names, file, line) \
-	PyThreadState *__tstate = PyThreadState_GET(); \
-	PyObject *__localnames = PyList_CrazyStringPack names; \
-	PyFrameObject *__f = traced_function_head(self, args, signature, file, line, __tstate, __localnames);
-
-#define FUNCTION_CHECK() \
-	assert (__f != NULL);
-
-#define ERR_DECREF(arg) { if (__f->f_locals) { PyDict_SetItemString(__f->f_locals, #arg, arg); } Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return traced_function_tail(rval, __f, __tstate);
-
-#else /* !defined(USE_CALL_TRACE) */
-
-#define FAIL(err) { goto err; }
-
-#define ERR_DECREF(arg) { Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return rval;
-
-#endif /* defined(USE_CALL_TRACE) */
-
-
-
-
-
-/* we need a subclass of 'builtin_function_or_method' which can be used
-   as methods: builtin function objects that can be bound on instances */
-static PyObject *
-gencfunc_descr_get(PyObject *func, PyObject *obj, PyObject *type)
-{
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
-}
-static PyTypeObject PyGenCFunction_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,
-	"pypy_generated_function",
-	sizeof(PyCFunctionObject),
-	0,
-	0,					/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	0,					/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	/*&PyCFunction_Type set below*/ 0,	/* tp_base */
-	0,					/* tp_dict */
-	gencfunc_descr_get,			/* tp_descr_get */
-	0,					/* tp_descr_set */
-};
-
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
-	PyMODINIT_FUNC init##modname(void)
-
-#define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
-	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
-	this_module_globals = PyModule_GetDict(m); \
-	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\
-	PyType_Ready(&PyGenCFunction_Type);	\
-	if (setup_globalfunctions(globalfunctiondefs) < 0) \
-		return;	\
-	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
-		return;	\
-	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return;
-
-
-/*** table of global objects ***/
-
-typedef struct {
-	PyObject** p;
-	char* name;
-} globalobjectdef_t;
-
-typedef struct {
-	PyObject** p;
-	PyMethodDef ml;
-} globalfunctiondef_t;
-
-static int setup_globalobjects(globalobjectdef_t* def)
-{
-	PyObject* obj;
-	
-	for (; def->p != NULL; def++) {
-		obj = PyDict_GetItemString(this_module_globals, def->name);
-		if (obj == NULL) {
-			PyErr_Format(PyExc_AttributeError,
-				     "initialization code should have "
-				     "created '%s'", def->name);
-			return -1;
-		}
-		Py_INCREF(obj);
-		*def->p = obj;   /* store the object ref in the global var */
-	}
-	return 0;
-}
-
-static int setup_globalfunctions(globalfunctiondef_t* def)
-{
-	PyObject* fn;
-	PyObject* name;
-	int len;
-
-	for (; def->p != NULL; def++) {
-		fn = PyCFunction_New(&def->ml, NULL);
-		if (fn == NULL)
-			return -1;
-		fn->ob_type = &PyGenCFunction_Type;
-		*def->p = fn;   /* store the object ref in the global var */
-
-		len = 0;
-		while (def->ml.ml_name[len] != 0)
-			len++;
-		name = PyString_FromStringAndSize(NULL, 6+len);
-		if (name == NULL)
-			return -1;
-		memcpy(PyString_AS_STRING(name), "gfunc_", 6);
-		memcpy(PyString_AS_STRING(name)+6, def->ml.ml_name, len);
-		if (PyDict_SetItem(this_module_globals, name, fn) < 0)
-			return -1;
-		Py_DECREF(name);
-	}
-	return 0;
-}
-
-static int setup_initcode(char* frozendata[], int len)
-{
-	PyObject* co;
-	PyObject* globals;
-	PyObject* res;
-	char *buffer, *bufp;
-	int chunk, count = 0;
-	
-	buffer = PyMem_NEW(char, len);
-	if (buffer == NULL)
-		return -1;
-	bufp = buffer;
-	while (count < len) {
-		chunk = len-count < 1024 ? len-count : 1024;
-		memcpy(bufp, *frozendata, chunk);
-		bufp += chunk;
-		count += chunk;
-		++frozendata;
-	}
-	co = PyMarshal_ReadObjectFromString(buffer, len);
-	if (co == NULL)
-		return -1;
-	PyMem_DEL(buffer);
-	if (!PyCode_Check(co)) {
-		PyErr_SetString(PyExc_TypeError, "uh?");
-		return -1;
-	}
-	globals = this_module_globals;
-	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
-		PyDict_SetItemString(globals, "__builtins__",
-				     PyEval_GetBuiltins());
-	res = PyEval_EvalCode((PyCodeObject *) co, globals, globals);
-	if (res == NULL)
-		return -1;
-	Py_DECREF(res);
-	return 0;
-}
-
-
-/*** operations with a variable number of arguments ***/
-
-#define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
-#define OP_NEWLIST(args,r,err)     if (!(r=PyList_Pack args)) FAIL(err)
-#define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
-#define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
-#define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
-
-static PyObject* PyList_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyList_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyList_SET_ITEM(result, i, o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-static PyObject* PyDict_Pack(int n, ...)
-{
-	int i;
-	PyObject *key, *val;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyDict_New();
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		key = va_arg(vargs, PyObject *);
-		val = va_arg(vargs, PyObject *);
-		if (PyDict_SetItem(result, key, val) < 0) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	va_end(vargs);
-	return result;
-}
-
-#if PY_VERSION_HEX < 0x02040000   /* 2.4 */
-static PyObject* PyTuple_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	PyObject **items;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyTuple_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	items = ((PyTupleObject *)result)->ob_item;
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		items[i] = o;
-	}
-	va_end(vargs);
-	return result;
-}
-#endif
-
-#if PY_VERSION_HEX >= 0x02030000   /* 2.3 */
-# define PyObject_GetItem1  PyObject_GetItem
-# define PyObject_SetItem1  PyObject_SetItem
-#else
-/* for Python 2.2 only */
-static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_GetItem(obj, index);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_GetSlice(obj, start, stop);
-}
-static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_SetItem(obj, index, v);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_SetSlice(obj, start, stop, v);
-}
-#endif
-
-static PyObject* CallWithShape(PyObject* callable, PyObject* shape, ...)
-{
-	/* XXX the 'shape' argument is a tuple as specified by
-	   XXX pypy.interpreter.argument.fromshape().  This code should
-	   XXX we made independent on the format of the 'shape' later... */
-	PyObject* result = NULL;
-	PyObject* t = NULL;
-	PyObject* d = NULL;
-	PyObject* o;
-	PyObject* key;
-	PyObject* t2;
-	int i, nargs, nkwds, starflag, starstarflag;
-	va_list vargs;
-
-	if (!PyTuple_Check(shape) ||
-	    PyTuple_GET_SIZE(shape) != 4 ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 0)) ||
-	    !PyTuple_Check(PyTuple_GET_ITEM(shape, 1)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 2)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 3))) {
-		Py_FatalError("in genc.h: invalid 'shape' argument");
-	}
-	nargs = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 0));
-	nkwds = PyTuple_GET_SIZE(PyTuple_GET_ITEM(shape, 1));
-	starflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 2));
-	starstarflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 3));
-
-	va_start(vargs, shape);
-	t = PyTuple_New(nargs);
-	if (t == NULL)
-		goto finally;
-	for (i = 0; i < nargs; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyTuple_SET_ITEM(t, i, o);
-	}
-	if (nkwds) {
-		d = PyDict_New();
-		if (d == NULL)
-			goto finally;
-		for (i = 0; i < nkwds; i++) {
-			o = va_arg(vargs, PyObject *);
-			key = PyTuple_GET_ITEM(PyTuple_GET_ITEM(shape, 1), i);
-			if (PyDict_SetItem(d, key, o) < 0)
-				goto finally;
-		}
-	}
-	if (starflag) {
-		o = va_arg(vargs, PyObject *);
-		o = PySequence_Tuple(o);
-		if (o == NULL)
-			goto finally;
-		t2 = PySequence_Concat(t, o);
-		Py_DECREF(o);
-		Py_DECREF(t);
-		t = t2;
-		if (t == NULL)
-			goto finally;
-	}
-	if (starstarflag) {
-		int len1, len2, len3;
-		o = va_arg(vargs, PyObject *);
-		len1 = PyDict_Size(d);
-		len2 = PyDict_Size(o);
-		if (len1 < 0 || len2 < 0)
-			goto finally;
-		if (PyDict_Update(d, o) < 0)
-			goto finally;
-		len3 = PyDict_Size(d);
-		if (len1 + len2 != len3) {
-			PyErr_SetString(PyExc_TypeError,
-					"genc.h: duplicate keyword arguments");
-			goto finally;
-		}
-	}
-	va_end(vargs);
-
-	result = PyObject_Call(callable, t, d);
-
- finally:
-	Py_XDECREF(d);
-	Py_XDECREF(t);
-	return result;
-}
-
-
-#if defined(USE_CALL_TRACE)
-
-static int callstack_depth = -1;
-static PyCodeObject* getcode(char *func_name, char *func_filename, int lineno);
-static int trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val);
-static int trace_frame_exc(PyThreadState *tstate, PyFrameObject *f);
-
-static int
-trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
-{
-	int result = 0;
-	if (!tstate->use_tracing || tstate->tracing) {
-		/*printf("if (!tstate->use_tracing || tstate->tracing)\n");*/
-		return 0;
-	}
-	if (tstate->c_profilefunc != NULL) {
-		/*printf("if (tstate->c_profilefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_profilefunc(tstate->c_profileobj,
-						   f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-		if (result) {
-			/*printf("	if (result)\n");*/
-			return result;
-		}
-	}
-	if (tstate->c_tracefunc != NULL) {
-		/*printf("if (tstate->c_tracefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_tracefunc(tstate->c_traceobj,
-						 f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-	}   
-	/*printf("return result;\n");*/
-	return result;
-}
-
-static int
-trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
-{
-	PyObject *type, *value, *traceback, *arg;
-	int err;
-
-	if (tstate->c_tracefunc == NULL) {
-		return 0;
-	}
-
-	PyErr_Fetch(&type, &value, &traceback);
-	if (value == NULL) {
-		value = Py_None;
-		Py_INCREF(value);
-	}
-	arg = PyTuple_Pack(3, type, value, traceback);
-	if (arg == NULL) {
-		PyErr_Restore(type, value, traceback);
-		return 0;
-	}
-	err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
-	Py_DECREF(arg);
-	if (err == 0) {
-		PyErr_Restore(type, value, traceback);
-	} else {
-		Py_XDECREF(type);
-		Py_XDECREF(value);
-		Py_XDECREF(traceback);
-	}
-	return err;
-}
-
-static PyCodeObject*
-getcode(char *func_name, char *func_filename, int lineno)
-{
-	PyObject *code = NULL;
-	PyObject *name = NULL;
-	PyObject *nulltuple = NULL;
-	PyObject *filename = NULL;
-	PyCodeObject *tb_code = NULL;
-#if defined(OBNOXIOUS_PRINT_STATEMENTS)
-	int i;
-
-	printf("%5d: ", lineno);
-	assert(callstack_depth >= 0);
-	if (callstack_depth) {
-		for (i=0; i<callstack_depth; ++i) {
-			printf("  ");
-		}
-	}
-	printf("%s\n", func_name);
-#endif /* !defined(OBNOXIOUS_PRINT_STATEMENTS) */
-
-	code = PyString_FromString("");
-	if (code == NULL)
-		goto failed;
-	name = PyString_FromString(func_name);
-	if (name == NULL)
-		goto failed;
-	nulltuple = PyTuple_New(0);
-	if (nulltuple == NULL)
-		goto failed;
-	filename = PyString_FromString(func_filename);
-	tb_code = PyCode_New(0,       /* argcount */
-						 0,       /* nlocals */
-						 0,       /* stacksize */
-						 0,       /* flags */
-						 code,        /* code */
-						 nulltuple,   /* consts */
-						 nulltuple,   /* names */
-						 nulltuple,   /* varnames */
-						 nulltuple,   /* freevars */
-						 nulltuple,   /* cellvars */
-						 filename,    /* filename */
-						 name,        /* name */
-						 lineno,      /* firstlineno */
-						 code     /* lnotab */
-						 );
-	if (tb_code == NULL)
-		goto failed;
-	Py_DECREF(code);
-	Py_DECREF(nulltuple);
-	Py_DECREF(filename);
-	Py_DECREF(name);
-	return tb_code;
-failed:
-	Py_XDECREF(code);
-	Py_XDECREF(name);
-	return NULL;
-}
-
-static PyFrameObject *traced_function_head(PyObject *function, PyObject *args, char *c_signature, char *filename, int c_lineno, PyThreadState *tstate, PyObject *extra_local_names) {
-	/*
-		STEALS a reference to extra_local_names if not NULL
-	*/
-
-	PyCodeObject *c;
-	PyFrameObject *f;
-	PyObject *locals;
-	PyObject *locals_signature;
-	PyObject *locals_lineno;
-	PyObject *locals_filename;
-
-	assert(function && args && tstate);
-
-	locals = PyDict_New();
-	locals_signature = PyString_FromString(c_signature);
-	locals_lineno = PyInt_FromLong(c_lineno);
-	locals_filename = PyString_FromString(filename);
-	if (locals == NULL || function == NULL || args == NULL || 
-		locals_signature == NULL || locals_lineno == NULL ||
-		locals_filename == NULL) {
-		Py_XDECREF(locals);
-		Py_XDECREF(locals_signature);
-		Py_XDECREF(locals_lineno);
-		Py_XDECREF(locals_filename);
-		return NULL;
-	}
-	PyDict_SetItemString(locals, "function", function);
-	PyDict_SetItemString(locals, "args", args);
-	PyDict_SetItemString(locals, "signature", locals_signature);
-	PyDict_SetItemString(locals, "lineno", locals_lineno);
-	PyDict_SetItemString(locals, "filename", locals_filename);
-	Py_DECREF(locals_signature);
-	Py_DECREF(locals_lineno);
-	Py_DECREF(locals_filename);
-	if (extra_local_names != NULL) {
-		int max_locals = MIN(PyList_Size(extra_local_names), PyTuple_Size(args));
-        int i;
-		for (i = 0; i < max_locals; ++i) {
-			PyDict_SetItem(locals, PyList_GET_ITEM(extra_local_names, i), PyTuple_GET_ITEM(args, i));
-		}
-		Py_DECREF(extra_local_names);
-	}
-
-	callstack_depth++;
-	c = getcode(c_signature, filename, c_lineno);
-	if (c == NULL) {
-		Py_DECREF(locals);
-		callstack_depth--;
-		return NULL;
-	}
-	f = PyFrame_New(tstate, c, this_module_globals, locals);
-	if (f == NULL) {
-		callstack_depth--;
-		return NULL;
-	}
-	Py_DECREF(c);
-	Py_DECREF(locals);
-	tstate->frame = f;
-	if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
-		Py_DECREF(args);
-		callstack_depth--;
-		return NULL;
-	}
-
-	return f;
-}
-
-static PyObject *traced_function_tail(PyObject *rval, PyFrameObject *f, PyThreadState *tstate) {
-	/*
-		STEALS a reference to f
-	*/
-	if (f == NULL) {
-		goto bad_args;
-	}
-	if (rval == NULL) {
-		if (tstate->curexc_traceback == NULL) {
-			PyTraceBack_Here(f);
-		}
-		if (trace_frame_exc(tstate, f) < 0) {
-			goto end;
-		}
-	} else {
-		if (trace_frame(tstate, f, PyTrace_RETURN, rval) < 0) {
-			Py_DECREF(rval);
-			rval = NULL;
-		}
-	}
-end:
-	tstate->frame = f->f_back;
-	Py_DECREF(f);
-bad_args:
-	callstack_depth--;
-	return rval;
-}
-
-static PyObject* PyList_CrazyStringPack(char *begin, ...)
-{
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	result = PyList_New(0);
-	if (result == NULL || begin == NULL) {
-		return result;
-	}
-	va_start(vargs, begin);
-	o = PyString_FromString(begin);
-	if (o == NULL) {
-		Py_XDECREF(result);
-		return NULL;
-	}
-	if (PyList_Append(result, o) == -1) {
-		Py_DECREF(o);
-		Py_XDECREF(result);
-		return result;
-	}
-	Py_DECREF(o);
-	while ((begin = va_arg(vargs, char *)) != NULL) {
-		o = PyString_FromString(begin);
-		if (o == NULL) {
-			Py_XDECREF(result);
-			return NULL;
-		}
-		if (PyList_Append(result, o) == -1) {
-			Py_DECREF(o);
-			Py_XDECREF(result);
-			return NULL;
-		}
-		Py_DECREF(o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-#endif /* defined(USE_CALL_TRACE) */

Deleted: /pypy/dist/pypy/translator/genc.py
==============================================================================
--- /pypy/dist/pypy/translator/genc.py	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,206 +0,0 @@
-"""
-Generate a C source file from the flowmodel.
-
-"""
-import autopath, os
-from pypy.objspace.flow.model import Variable, Constant
-
-from pypy.translator.gensupp import uniquemodulename
-from pypy.translator.gensupp import NameManager
-
-from pypy.translator.genc_funcdef import FunctionDef, USE_CALL_TRACE
-from pypy.translator.genc_pyobj import CType_PyObject, ctypeof
-
-# ____________________________________________________________
-
-#def go_figure_out_this_name(source):
-#    # ahem
-#    return 'PyRun_String("%s", Py_eval_input, PyEval_GetGlobals(), NULL)' % (
-#        source, )
-
-class GenC:
-    MODNAMES = {}
-
-    def __init__(self, f, translator, modname=None, f2=None):
-        self.f = f
-        self.f2 = f2
-        self.translator = translator
-        self.modname = (modname or
-                        uniquemodulename(translator.functions[0].__name__))
-        self.namespace= NameManager()
-        # keywords cannot be reused.  This is the C99 draft's list.
-        self.namespace.make_reserved_names('''
-           auto      enum      restrict  unsigned
-           break     extern    return    void
-           case      float     short     volatile
-           char      for       signed    while
-           const     goto      sizeof    _Bool
-           continue  if        static    _Complex
-           default   inline    struct    _Imaginary
-           do        int       switch
-           double    long      typedef
-           else      register  union
-           ''')
-        self.globaldecl = []
-        self.pendingfunctions = []
-        self.funcdefs = {}
-        self.allfuncdefs = []
-        self.ctyperepresenters = {}
-        self.pyobjrepr = self.getrepresenter(CType_PyObject)
-        self.gen_source()
-
-    def getrepresenter(self, type_cls):
-        try:
-            return self.ctyperepresenters[type_cls]
-        except KeyError:
-            crepr = self.ctyperepresenters[type_cls] = type_cls(self)
-            return crepr
-
-    def nameofconst(self, c, debug=None):
-        crepr = self.getrepresenter(ctypeof(c))
-        return crepr.nameof(c.value, debug=debug)
-
-    def nameofvalue(self, value, type_cls):
-        crepr = self.getrepresenter(type_cls)
-        return crepr.nameof(value)
-
-    def getfuncdef(self, func):
-        if func not in self.funcdefs:
-            if self.translator.frozen:
-                if func not in self.translator.flowgraphs:
-                    return None
-            else:
-                if (func.func_doc and
-                    func.func_doc.lstrip().startswith('NOT_RPYTHON')):
-                    return None
-            funcdef = FunctionDef(func, self)
-            self.funcdefs[func] = funcdef
-            self.allfuncdefs.append(funcdef)
-            self.pendingfunctions.append(funcdef)
-        return self.funcdefs[func]
-
-    # ____________________________________________________________
-
-    def gen_source(self):
-        f = self.f
-        info = {
-            'modname': self.modname,
-            'entrypointname': self.translator.functions[0].__name__,
-            'entrypoint': self.pyobjrepr.nameof(self.translator.functions[0]),
-            }
-        # header
-        if USE_CALL_TRACE:
-            print >> f, '#define USE_CALL_TRACE'
-        print >> f, self.C_HEADER
-
-        # function implementations
-        while self.pendingfunctions:
-            funcdef = self.pendingfunctions.pop()
-            self.gen_cfunction(funcdef)
-            # collect more of the latercode after each function
-            for crepr in self.ctyperepresenters.values():
-                if hasattr(crepr, 'collect_globals'):
-                    crepr.collect_globals()
-            self.gen_global_declarations()
-
-        # after all the ff_xxx() functions we generate the pyff_xxx() wrappers
-        for funcdef in self.allfuncdefs:
-            if funcdef.wrapper_name is not None:
-                funcdef.gen_wrapper(f)
-
-        # global object table
-        print >> f, self.C_OBJECT_TABLE
-        for name in self.pyobjrepr.globalobjects:
-            if not name.startswith('gfunc_'):
-                print >> f, '\t{&%s, "%s"},' % (name, name)
-        print >> f, self.C_TABLE_END
-
-        # global function table
-        print >> f, self.C_FUNCTION_TABLE
-        for funcdef in self.allfuncdefs:
-            if funcdef.globalobject_name is not None:
-                print >> f, ('\t{&%s, {"%s", (PyCFunction)%s, '
-                             'METH_VARARGS|METH_KEYWORDS}},' % (
-                    funcdef.globalobject_name,
-                    funcdef.base_name,
-                    funcdef.wrapper_name))
-        print >> f, self.C_TABLE_END
-
-        # frozen init bytecode
-        print >> f, self.C_FROZEN_BEGIN
-        bytecode = self.pyobjrepr.getfrozenbytecode()
-        def char_repr(c):
-            if c in '\\"': return '\\' + c
-            if ' ' <= c < '\x7F': return c
-            return '\\%03o' % ord(c)
-        for i in range(0, len(bytecode), 32):
-            print >> f, ''.join([char_repr(c) for c in bytecode[i:i+32]])+'\\'
-            if (i+32) % 1024 == 0:
-                print >> f, self.C_FROZEN_BETWEEN
-        print >> f, self.C_FROZEN_END
-        print >> f, "#define FROZEN_INITCODE_SIZE %d" % len(bytecode)
-
-        # the footer proper: the module init function */
-        print >> f, self.C_FOOTER % info
-
-    def gen_global_declarations(self):
-        g = self.globaldecl
-        if g:
-            f = self.f
-            print >> f, '/* global declaration%s */' % ('s'*(len(g)>1))
-            for line in g:
-                print >> f, line
-            print >> f
-            del g[:]
-    
-    def gen_cfunction(self, funcdef):
-##         print 'gen_cfunction (%s:%d) %s' % (
-##             func.func_globals.get('__name__', '?'),
-##             func.func_code.co_firstlineno,
-##             func.__name__)
-
-        # compute the whole body
-        body = list(funcdef.cfunction_body())
-
-        # generate the source now
-        self.gen_global_declarations() #.. before the body where they are needed
-        funcdef.gen_cfunction(self.f, body)
-
-        # this is only to keep the RAM consumption under control
-        funcdef.clear()
-        if not self.translator.frozen:
-            del self.translator.flowgraphs[funcdef.func]
-            Variable.instances.clear()
-
-# ____________________________________________________________
-
-    C_HEADER = '#include "genc.h"\n'
-
-    C_SEP = "/************************************************************/"
-
-    C_OBJECT_TABLE = C_SEP + '''
-
-/* Table of global objects */
-static globalobjectdef_t globalobjectdefs[] = {'''
-
-    C_FUNCTION_TABLE = '''
-/* Table of functions */
-static globalfunctiondef_t globalfunctiondefs[] = {'''
-
-    C_TABLE_END = '\t{ NULL }\t/* Sentinel */\n};'
-
-    C_FROZEN_BEGIN = '''
-/* Frozen Python bytecode: the initialization code */
-static char *frozen_initcode[] = {"\\'''
-
-    C_FROZEN_BETWEEN = '''", "\\'''
-
-    C_FROZEN_END = '''"};\n'''
-
-    C_FOOTER = C_SEP + '''
-
-MODULE_INITFUNC(%(modname)s)
-{
-\tSETUP_MODULE(%(modname)s)
-\tPyModule_AddObject(m, "%(entrypointname)s", %(entrypoint)s);
-}'''

Added: pypy/dist/pypy/translator/genc/__init__.py
==============================================================================

Added: pypy/dist/pypy/translator/genc/ctyper.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/genc/ctyper.py	Sat Apr  2 17:57:37 2005
@@ -0,0 +1,21 @@
+"""
+GenC-specific type specializer
+"""
+
+from pypy.translator.typer import Specializer, TypeMatch
+from pypy.annotation.model import SomeInteger
+from pypy.translator.genc.t_pyobj import CType_PyObject
+from pypy.translator.genc.t_int import CType_Int
+
+class GenCSpecializer(Specializer):
+
+    TInt = TypeMatch(SomeInteger(), CType_Int)
+    typematches = [TInt]   # in more-specific-first, more-general-last order
+    defaulttypecls = CType_PyObject
+
+    specializationtable = [
+        ## op      specialized op   arg types   concrete return type
+        ('add',     'int_add',     TInt, TInt,   CType_Int),
+        ('sub',     'int_sub',     TInt, TInt,   CType_Int),
+        ('is_true', 'int_is_true', TInt,         CType_Int),
+        ]

Copied: pypy/dist/pypy/translator/genc/funcdef.py (from r10251, pypy/dist/pypy/translator/genc_funcdef.py)
==============================================================================
--- pypy/dist/pypy/translator/genc_funcdef.py	(original)
+++ pypy/dist/pypy/translator/genc/funcdef.py	Sat Apr  2 17:57:37 2005
@@ -8,7 +8,7 @@
 from types import FunctionType
 
 from pypy.translator.gensupp import c_string
-from pypy.translator.genc_pyobj import ctypeof
+from pypy.translator.genc.t_pyobj import ctypeof
 
 # Set this if you want call trace frames to be built
 USE_CALL_TRACE = False

Copied: pypy/dist/pypy/translator/genc/g_include.h (from r10250, pypy/dist/pypy/translator/genc.h)
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc/g_include.h	Sat Apr  2 17:57:37 2005
@@ -1,6 +1,6 @@
 
 /************************************************************/
-/***  Generic C header section                            ***/
+/***  C header file for code produced by genc.py          ***/
 
 #include "Python.h"
 #include "compile.h"
@@ -10,864 +10,8 @@
 #include "marshal.h"
 #include "eval.h"
 
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif /* MIN */
-
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
-
-/* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
-
-#if 0
-#define OBNOXIOUS_PRINT_STATEMENTS
-#endif
-
-#define op_bool(r,err,what) { \
-		int _retval = what; \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyBool_FromLong(_retval); \
-	}
-
-#define op_richcmp(x,y,r,err,dir) \
-					if (!(r=PyObject_RichCompare(x,y,dir))) FAIL(err)
-#define OP_LT(x,y,r,err)  op_richcmp(x,y,r,err, Py_LT)
-#define OP_LE(x,y,r,err)  op_richcmp(x,y,r,err, Py_LE)
-#define OP_EQ(x,y,r,err)  op_richcmp(x,y,r,err, Py_EQ)
-#define OP_NE(x,y,r,err)  op_richcmp(x,y,r,err, Py_NE)
-#define OP_GT(x,y,r,err)  op_richcmp(x,y,r,err, Py_GT)
-#define OP_GE(x,y,r,err)  op_richcmp(x,y,r,err, Py_GE)
-
-#define OP_IS_(x,y,r,err) op_bool(r,err,(x == y))
-
-#define OP_IS_TRUE(x,r,err) op_bool(r,err,PyObject_IsTrue(x))
-
-#define OP_LEN(x,r,err) { \
-		int _retval = PyObject_Size(x); \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyInt_FromLong(_retval); \
-	}
-#define OP_NEG(x,r,err)           if (!(r=PyNumber_Negative(x)))     FAIL(err)
-#define OP_POS(x,r,err)           if (!(r=PyNumber_Positive(x)))     FAIL(err)
-#define OP_INVERT(x,r,err)        if (!(r=PyNumber_Invert(x)))       FAIL(err)
-
-#define OP_ADD(x,y,r,err)         if (!(r=PyNumber_Add(x,y)))        FAIL(err)
-#define OP_SUB(x,y,r,err)         if (!(r=PyNumber_Subtract(x,y)))   FAIL(err)
-#define OP_MUL(x,y,r,err)         if (!(r=PyNumber_Multiply(x,y)))   FAIL(err)
-#define OP_TRUEDIV(x,y,r,err)     if (!(r=PyNumber_TrueDivide(x,y))) FAIL(err)
-#define OP_FLOORDIV(x,y,r,err)    if (!(r=PyNumber_FloorDivide(x,y)))FAIL(err)
-#define OP_DIV(x,y,r,err)         if (!(r=PyNumber_Divide(x,y)))     FAIL(err)
-#define OP_MOD(x,y,r,err)         if (!(r=PyNumber_Remainder(x,y)))  FAIL(err)
-#define OP_POW(x,y,z,r,err)       if (!(r=PyNumber_Power(x,y,z)))    FAIL(err)
-#define OP_LSHIFT(x,y,r,err)      if (!(r=PyNumber_Lshift(x,y)))     FAIL(err)
-#define OP_RSHIFT(x,y,r,err)      if (!(r=PyNumber_Rshift(x,y)))     FAIL(err)
-#define OP_AND_(x,y,r,err)        if (!(r=PyNumber_And(x,y)))        FAIL(err)
-#define OP_OR_(x,y,r,err)         if (!(r=PyNumber_Or(x,y)))         FAIL(err)
-#define OP_XOR(x,y,r,err)         if (!(r=PyNumber_Xor(x,y)))        FAIL(err)
-
-#define OP_INPLACE_ADD(x,y,r,err) if (!(r=PyNumber_InPlaceAdd(x,y)))           \
-								     FAIL(err)
-#define OP_INPLACE_SUB(x,y,r,err) if (!(r=PyNumber_InPlaceSubtract(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_MUL(x,y,r,err) if (!(r=PyNumber_InPlaceMultiply(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_TRUEDIV(x,y,r,err) if (!(r=PyNumber_InPlaceTrueDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_FLOORDIV(x,y,r,err)if(!(r=PyNumber_InPlaceFloorDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_DIV(x,y,r,err) if (!(r=PyNumber_InPlaceDivide(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_MOD(x,y,r,err) if (!(r=PyNumber_InPlaceRemainder(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_POW(x,y,r,err) if (!(r=PyNumber_InPlacePower(x,y,Py_None))) \
-								     FAIL(err)
-#define OP_INPLACE_LSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceLshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_RSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceRshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_AND(x,y,r,err)    if (!(r=PyNumber_InPlaceAnd(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_OR(x,y,r,err)     if (!(r=PyNumber_InPlaceOr(x,y)))         \
-								     FAIL(err)
-#define OP_INPLACE_XOR(x,y,r,err)    if (!(r=PyNumber_InPlaceXor(x,y)))        \
-								     FAIL(err)
-
-#define OP_GETITEM(x,y,r,err)     if (!(r=PyObject_GetItem1(x,y)))   FAIL(err)
-#define OP_SETITEM(x,y,z,r,err)   if ((PyObject_SetItem1(x,y,z))<0)  FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELITEM(x,y,r,err)     if ((PyObject_DelItem(x,y))<0)     FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_CONTAINS(x,y,r,err)    op_bool(r,err,(PySequence_Contains(x,y)))
-
-#define OP_GETATTR(x,y,r,err)     if (!(r=PyObject_GetAttr(x,y)))    FAIL(err)
-#define OP_SETATTR(x,y,z,r,err)   if ((PyObject_SetAttr(x,y,z))<0)   FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELATTR(x,y,r,err)     if ((PyObject_SetAttr(x,y,NULL))<0)FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-
-#define OP_NEWSLICE(x,y,z,r,err)  if (!(r=PySlice_New(x,y,z)))       FAIL(err)
-
-#define OP_GETSLICE(x,y,z,r,err)  {					\
-		PyObject *__yo = y, *__zo = z;				\
-		int __y = 0, __z = INT_MAX;				\
-		if (__yo == Py_None) __yo = NULL;			\
-		if (__zo == Py_None) __zo = NULL;			\
-		if (!_PyEval_SliceIndex(__yo, &__y) ||			\
-		    !_PyEval_SliceIndex(__zo, &__z) ||			\
-		    !(r=PySequence_GetSlice(x, __y, __z))) FAIL(err)	\
-	}
-
-#define OP_ALLOC_AND_SET(x,y,r,err) { \
-		/* XXX check for long/int overflow */ \
-		int __i, __x = PyInt_AsLong(x); \
-		if (PyErr_Occurred()) FAIL(err) \
-		if (!(r = PyList_New(__x))) FAIL(err) \
-		for (__i=0; __i<__x; __i++) { \
-			Py_INCREF(y); \
-			PyList_SET_ITEM(r, __i, y); \
-		} \
-	}
-
-#define OP_ITER(x,r,err)          if (!(r=PyObject_GetIter(x)))      FAIL(err)
-#define OP_NEXT(x,r,err)          if (!(r=PyIter_Next(x))) {                   \
-		if (!PyErr_Occurred()) PyErr_SetNone(PyExc_StopIteration);     \
-		FAIL(err)                                                      \
-	}
-
-#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
-					FAIL(err)
-#define OP_CALL_ARGS(args,r,err)   if (!(r=CallWithShape args))    FAIL(err)
-
-/* Needs to act like getattr(x, '__class__', type(x)) */
-#define OP_TYPE(x,r,err) { \
-		PyObject *o = x; \
-		if (PyInstance_Check(o)) { \
-			r = (PyObject*)(((PyInstanceObject*)o)->in_class); \
-		} else { \
-			r = (PyObject*)o->ob_type; \
-		} \
-		Py_INCREF(r); \
-	}
-
-/* Needs to act like instance(x,y) */
-#define OP_ISSUBTYPE(x,y,r,err)  \
-		op_bool(r,err,PyClass_IsSubclass(x, y))
-
-
-/*** misc ***/
-
-#define MOVE(x, y)             y = x;
-
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
-
-
-#if defined(USE_CALL_TRACE)
-
-#define TRACE_CALL       __f, __tstate
-#define TRACE_ARGS       PyFrameObject *__f, PyThreadState *__tstate
-
-#define FAIL(err) { __f->f_lineno = __f->f_code->co_firstlineno = __LINE__; goto err; }
-
-#define FUNCTION_HEAD(signature, self, args, names, file, line) \
-	PyThreadState *__tstate = PyThreadState_GET(); \
-	PyObject *__localnames = PyList_CrazyStringPack names; \
-	PyFrameObject *__f = traced_function_head(self, args, signature, file, line, __tstate, __localnames);
-
-#define FUNCTION_CHECK() \
-	assert (__f != NULL);
-
-#define ERR_DECREF(arg) { if (__f->f_locals) { PyDict_SetItemString(__f->f_locals, #arg, arg); } Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return traced_function_tail(rval, __f, __tstate);
-
-#else /* !defined(USE_CALL_TRACE) */
-
-#define FAIL(err) { goto err; }
-
-#define ERR_DECREF(arg) { Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return rval;
-
-#endif /* defined(USE_CALL_TRACE) */
-
-
-
-
-
-/* we need a subclass of 'builtin_function_or_method' which can be used
-   as methods: builtin function objects that can be bound on instances */
-static PyObject *
-gencfunc_descr_get(PyObject *func, PyObject *obj, PyObject *type)
-{
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
-}
-static PyTypeObject PyGenCFunction_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,
-	"pypy_generated_function",
-	sizeof(PyCFunctionObject),
-	0,
-	0,					/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	0,					/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	/*&PyCFunction_Type set below*/ 0,	/* tp_base */
-	0,					/* tp_dict */
-	gencfunc_descr_get,			/* tp_descr_get */
-	0,					/* tp_descr_set */
-};
-
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
-	PyMODINIT_FUNC init##modname(void)
-
-#define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
-	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
-	this_module_globals = PyModule_GetDict(m); \
-	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\
-	PyType_Ready(&PyGenCFunction_Type);	\
-	if (setup_globalfunctions(globalfunctiondefs) < 0) \
-		return;	\
-	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
-		return;	\
-	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return;
-
-
-/*** table of global objects ***/
-
-typedef struct {
-	PyObject** p;
-	char* name;
-} globalobjectdef_t;
-
-typedef struct {
-	PyObject** p;
-	PyMethodDef ml;
-} globalfunctiondef_t;
-
-static int setup_globalobjects(globalobjectdef_t* def)
-{
-	PyObject* obj;
-	
-	for (; def->p != NULL; def++) {
-		obj = PyDict_GetItemString(this_module_globals, def->name);
-		if (obj == NULL) {
-			PyErr_Format(PyExc_AttributeError,
-				     "initialization code should have "
-				     "created '%s'", def->name);
-			return -1;
-		}
-		Py_INCREF(obj);
-		*def->p = obj;   /* store the object ref in the global var */
-	}
-	return 0;
-}
-
-static int setup_globalfunctions(globalfunctiondef_t* def)
-{
-	PyObject* fn;
-	PyObject* name;
-	int len;
-
-	for (; def->p != NULL; def++) {
-		fn = PyCFunction_New(&def->ml, NULL);
-		if (fn == NULL)
-			return -1;
-		fn->ob_type = &PyGenCFunction_Type;
-		*def->p = fn;   /* store the object ref in the global var */
-
-		len = 0;
-		while (def->ml.ml_name[len] != 0)
-			len++;
-		name = PyString_FromStringAndSize(NULL, 6+len);
-		if (name == NULL)
-			return -1;
-		memcpy(PyString_AS_STRING(name), "gfunc_", 6);
-		memcpy(PyString_AS_STRING(name)+6, def->ml.ml_name, len);
-		if (PyDict_SetItem(this_module_globals, name, fn) < 0)
-			return -1;
-		Py_DECREF(name);
-	}
-	return 0;
-}
-
-static int setup_initcode(char* frozendata[], int len)
-{
-	PyObject* co;
-	PyObject* globals;
-	PyObject* res;
-	char *buffer, *bufp;
-	int chunk, count = 0;
-	
-	buffer = PyMem_NEW(char, len);
-	if (buffer == NULL)
-		return -1;
-	bufp = buffer;
-	while (count < len) {
-		chunk = len-count < 1024 ? len-count : 1024;
-		memcpy(bufp, *frozendata, chunk);
-		bufp += chunk;
-		count += chunk;
-		++frozendata;
-	}
-	co = PyMarshal_ReadObjectFromString(buffer, len);
-	if (co == NULL)
-		return -1;
-	PyMem_DEL(buffer);
-	if (!PyCode_Check(co)) {
-		PyErr_SetString(PyExc_TypeError, "uh?");
-		return -1;
-	}
-	globals = this_module_globals;
-	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
-		PyDict_SetItemString(globals, "__builtins__",
-				     PyEval_GetBuiltins());
-	res = PyEval_EvalCode((PyCodeObject *) co, globals, globals);
-	if (res == NULL)
-		return -1;
-	Py_DECREF(res);
-	return 0;
-}
-
-
-/*** operations with a variable number of arguments ***/
-
-#define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
-#define OP_NEWLIST(args,r,err)     if (!(r=PyList_Pack args)) FAIL(err)
-#define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
-#define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
-#define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
-
-static PyObject* PyList_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyList_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyList_SET_ITEM(result, i, o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-static PyObject* PyDict_Pack(int n, ...)
-{
-	int i;
-	PyObject *key, *val;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyDict_New();
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		key = va_arg(vargs, PyObject *);
-		val = va_arg(vargs, PyObject *);
-		if (PyDict_SetItem(result, key, val) < 0) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	va_end(vargs);
-	return result;
-}
-
-#if PY_VERSION_HEX < 0x02040000   /* 2.4 */
-static PyObject* PyTuple_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	PyObject **items;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyTuple_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	items = ((PyTupleObject *)result)->ob_item;
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		items[i] = o;
-	}
-	va_end(vargs);
-	return result;
-}
-#endif
-
-#if PY_VERSION_HEX >= 0x02030000   /* 2.3 */
-# define PyObject_GetItem1  PyObject_GetItem
-# define PyObject_SetItem1  PyObject_SetItem
-#else
-/* for Python 2.2 only */
-static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_GetItem(obj, index);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_GetSlice(obj, start, stop);
-}
-static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_SetItem(obj, index, v);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_SetSlice(obj, start, stop, v);
-}
-#endif
-
-static PyObject* CallWithShape(PyObject* callable, PyObject* shape, ...)
-{
-	/* XXX the 'shape' argument is a tuple as specified by
-	   XXX pypy.interpreter.argument.fromshape().  This code should
-	   XXX we made independent on the format of the 'shape' later... */
-	PyObject* result = NULL;
-	PyObject* t = NULL;
-	PyObject* d = NULL;
-	PyObject* o;
-	PyObject* key;
-	PyObject* t2;
-	int i, nargs, nkwds, starflag, starstarflag;
-	va_list vargs;
-
-	if (!PyTuple_Check(shape) ||
-	    PyTuple_GET_SIZE(shape) != 4 ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 0)) ||
-	    !PyTuple_Check(PyTuple_GET_ITEM(shape, 1)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 2)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 3))) {
-		Py_FatalError("in genc.h: invalid 'shape' argument");
-	}
-	nargs = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 0));
-	nkwds = PyTuple_GET_SIZE(PyTuple_GET_ITEM(shape, 1));
-	starflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 2));
-	starstarflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 3));
-
-	va_start(vargs, shape);
-	t = PyTuple_New(nargs);
-	if (t == NULL)
-		goto finally;
-	for (i = 0; i < nargs; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyTuple_SET_ITEM(t, i, o);
-	}
-	if (nkwds) {
-		d = PyDict_New();
-		if (d == NULL)
-			goto finally;
-		for (i = 0; i < nkwds; i++) {
-			o = va_arg(vargs, PyObject *);
-			key = PyTuple_GET_ITEM(PyTuple_GET_ITEM(shape, 1), i);
-			if (PyDict_SetItem(d, key, o) < 0)
-				goto finally;
-		}
-	}
-	if (starflag) {
-		o = va_arg(vargs, PyObject *);
-		o = PySequence_Tuple(o);
-		if (o == NULL)
-			goto finally;
-		t2 = PySequence_Concat(t, o);
-		Py_DECREF(o);
-		Py_DECREF(t);
-		t = t2;
-		if (t == NULL)
-			goto finally;
-	}
-	if (starstarflag) {
-		int len1, len2, len3;
-		o = va_arg(vargs, PyObject *);
-		len1 = PyDict_Size(d);
-		len2 = PyDict_Size(o);
-		if (len1 < 0 || len2 < 0)
-			goto finally;
-		if (PyDict_Update(d, o) < 0)
-			goto finally;
-		len3 = PyDict_Size(d);
-		if (len1 + len2 != len3) {
-			PyErr_SetString(PyExc_TypeError,
-					"genc.h: duplicate keyword arguments");
-			goto finally;
-		}
-	}
-	va_end(vargs);
-
-	result = PyObject_Call(callable, t, d);
-
- finally:
-	Py_XDECREF(d);
-	Py_XDECREF(t);
-	return result;
-}
-
-
-#if defined(USE_CALL_TRACE)
-
-static int callstack_depth = -1;
-static PyCodeObject* getcode(char *func_name, char *func_filename, int lineno);
-static int trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val);
-static int trace_frame_exc(PyThreadState *tstate, PyFrameObject *f);
-
-static int
-trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
-{
-	int result = 0;
-	if (!tstate->use_tracing || tstate->tracing) {
-		/*printf("if (!tstate->use_tracing || tstate->tracing)\n");*/
-		return 0;
-	}
-	if (tstate->c_profilefunc != NULL) {
-		/*printf("if (tstate->c_profilefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_profilefunc(tstate->c_profileobj,
-						   f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-		if (result) {
-			/*printf("	if (result)\n");*/
-			return result;
-		}
-	}
-	if (tstate->c_tracefunc != NULL) {
-		/*printf("if (tstate->c_tracefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_tracefunc(tstate->c_traceobj,
-						 f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-	}   
-	/*printf("return result;\n");*/
-	return result;
-}
-
-static int
-trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
-{
-	PyObject *type, *value, *traceback, *arg;
-	int err;
-
-	if (tstate->c_tracefunc == NULL) {
-		return 0;
-	}
-
-	PyErr_Fetch(&type, &value, &traceback);
-	if (value == NULL) {
-		value = Py_None;
-		Py_INCREF(value);
-	}
-	arg = PyTuple_Pack(3, type, value, traceback);
-	if (arg == NULL) {
-		PyErr_Restore(type, value, traceback);
-		return 0;
-	}
-	err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
-	Py_DECREF(arg);
-	if (err == 0) {
-		PyErr_Restore(type, value, traceback);
-	} else {
-		Py_XDECREF(type);
-		Py_XDECREF(value);
-		Py_XDECREF(traceback);
-	}
-	return err;
-}
-
-static PyCodeObject*
-getcode(char *func_name, char *func_filename, int lineno)
-{
-	PyObject *code = NULL;
-	PyObject *name = NULL;
-	PyObject *nulltuple = NULL;
-	PyObject *filename = NULL;
-	PyCodeObject *tb_code = NULL;
-#if defined(OBNOXIOUS_PRINT_STATEMENTS)
-	int i;
-
-	printf("%5d: ", lineno);
-	assert(callstack_depth >= 0);
-	if (callstack_depth) {
-		for (i=0; i<callstack_depth; ++i) {
-			printf("  ");
-		}
-	}
-	printf("%s\n", func_name);
-#endif /* !defined(OBNOXIOUS_PRINT_STATEMENTS) */
-
-	code = PyString_FromString("");
-	if (code == NULL)
-		goto failed;
-	name = PyString_FromString(func_name);
-	if (name == NULL)
-		goto failed;
-	nulltuple = PyTuple_New(0);
-	if (nulltuple == NULL)
-		goto failed;
-	filename = PyString_FromString(func_filename);
-	tb_code = PyCode_New(0,       /* argcount */
-						 0,       /* nlocals */
-						 0,       /* stacksize */
-						 0,       /* flags */
-						 code,        /* code */
-						 nulltuple,   /* consts */
-						 nulltuple,   /* names */
-						 nulltuple,   /* varnames */
-						 nulltuple,   /* freevars */
-						 nulltuple,   /* cellvars */
-						 filename,    /* filename */
-						 name,        /* name */
-						 lineno,      /* firstlineno */
-						 code     /* lnotab */
-						 );
-	if (tb_code == NULL)
-		goto failed;
-	Py_DECREF(code);
-	Py_DECREF(nulltuple);
-	Py_DECREF(filename);
-	Py_DECREF(name);
-	return tb_code;
-failed:
-	Py_XDECREF(code);
-	Py_XDECREF(name);
-	return NULL;
-}
-
-static PyFrameObject *traced_function_head(PyObject *function, PyObject *args, char *c_signature, char *filename, int c_lineno, PyThreadState *tstate, PyObject *extra_local_names) {
-	/*
-		STEALS a reference to extra_local_names if not NULL
-	*/
-
-	PyCodeObject *c;
-	PyFrameObject *f;
-	PyObject *locals;
-	PyObject *locals_signature;
-	PyObject *locals_lineno;
-	PyObject *locals_filename;
-
-	assert(function && args && tstate);
-
-	locals = PyDict_New();
-	locals_signature = PyString_FromString(c_signature);
-	locals_lineno = PyInt_FromLong(c_lineno);
-	locals_filename = PyString_FromString(filename);
-	if (locals == NULL || function == NULL || args == NULL || 
-		locals_signature == NULL || locals_lineno == NULL ||
-		locals_filename == NULL) {
-		Py_XDECREF(locals);
-		Py_XDECREF(locals_signature);
-		Py_XDECREF(locals_lineno);
-		Py_XDECREF(locals_filename);
-		return NULL;
-	}
-	PyDict_SetItemString(locals, "function", function);
-	PyDict_SetItemString(locals, "args", args);
-	PyDict_SetItemString(locals, "signature", locals_signature);
-	PyDict_SetItemString(locals, "lineno", locals_lineno);
-	PyDict_SetItemString(locals, "filename", locals_filename);
-	Py_DECREF(locals_signature);
-	Py_DECREF(locals_lineno);
-	Py_DECREF(locals_filename);
-	if (extra_local_names != NULL) {
-		int max_locals = MIN(PyList_Size(extra_local_names), PyTuple_Size(args));
-        int i;
-		for (i = 0; i < max_locals; ++i) {
-			PyDict_SetItem(locals, PyList_GET_ITEM(extra_local_names, i), PyTuple_GET_ITEM(args, i));
-		}
-		Py_DECREF(extra_local_names);
-	}
-
-	callstack_depth++;
-	c = getcode(c_signature, filename, c_lineno);
-	if (c == NULL) {
-		Py_DECREF(locals);
-		callstack_depth--;
-		return NULL;
-	}
-	f = PyFrame_New(tstate, c, this_module_globals, locals);
-	if (f == NULL) {
-		callstack_depth--;
-		return NULL;
-	}
-	Py_DECREF(c);
-	Py_DECREF(locals);
-	tstate->frame = f;
-	if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
-		Py_DECREF(args);
-		callstack_depth--;
-		return NULL;
-	}
-
-	return f;
-}
-
-static PyObject *traced_function_tail(PyObject *rval, PyFrameObject *f, PyThreadState *tstate) {
-	/*
-		STEALS a reference to f
-	*/
-	if (f == NULL) {
-		goto bad_args;
-	}
-	if (rval == NULL) {
-		if (tstate->curexc_traceback == NULL) {
-			PyTraceBack_Here(f);
-		}
-		if (trace_frame_exc(tstate, f) < 0) {
-			goto end;
-		}
-	} else {
-		if (trace_frame(tstate, f, PyTrace_RETURN, rval) < 0) {
-			Py_DECREF(rval);
-			rval = NULL;
-		}
-	}
-end:
-	tstate->frame = f->f_back;
-	Py_DECREF(f);
-bad_args:
-	callstack_depth--;
-	return rval;
-}
-
-static PyObject* PyList_CrazyStringPack(char *begin, ...)
-{
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	result = PyList_New(0);
-	if (result == NULL || begin == NULL) {
-		return result;
-	}
-	va_start(vargs, begin);
-	o = PyString_FromString(begin);
-	if (o == NULL) {
-		Py_XDECREF(result);
-		return NULL;
-	}
-	if (PyList_Append(result, o) == -1) {
-		Py_DECREF(o);
-		Py_XDECREF(result);
-		return result;
-	}
-	Py_DECREF(o);
-	while ((begin = va_arg(vargs, char *)) != NULL) {
-		o = PyString_FromString(begin);
-		if (o == NULL) {
-			Py_XDECREF(result);
-			return NULL;
-		}
-		if (PyList_Append(result, o) == -1) {
-			Py_DECREF(o);
-			Py_XDECREF(result);
-			return NULL;
-		}
-		Py_DECREF(o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-#endif /* defined(USE_CALL_TRACE) */
+#include "g_operation.h"
+#include "g_int.h"
+#include "g_trace.h"
+#include "g_support.h"
+#include "g_module.h"

Copied: pypy/dist/pypy/translator/genc/g_int.h (from r10250, pypy/dist/pypy/translator/genc_type.h)
==============================================================================
--- pypy/dist/pypy/translator/genc_type.h	(original)
+++ pypy/dist/pypy/translator/genc/g_int.h	Sat Apr  2 17:57:37 2005
@@ -1,8 +1,6 @@
 
 /************************************************************/
- /***  C header subsection: typed operations               ***/
-
-/* This file is included from genc.h. */
+ /***  C header subsection: operations between ints        ***/
 
 
 #define OP_INT2OBJ(i,r,err)   if (!(r=PyInt_FromLong(i))) FAIL(err)

Copied: pypy/dist/pypy/translator/genc/g_module.h (from r10250, pypy/dist/pypy/translator/genc.h)
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc/g_module.h	Sat Apr  2 17:57:37 2005
@@ -1,251 +1,7 @@
 
 /************************************************************/
-/***  Generic C header section                            ***/
+ /***  C header subsection: CPython-extension-module-ness  ***/
 
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include "structmember.h"
-#include "traceback.h"
-#include "marshal.h"
-#include "eval.h"
-
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif /* MIN */
-
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
-
-/* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
-
-#if 0
-#define OBNOXIOUS_PRINT_STATEMENTS
-#endif
-
-#define op_bool(r,err,what) { \
-		int _retval = what; \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyBool_FromLong(_retval); \
-	}
-
-#define op_richcmp(x,y,r,err,dir) \
-					if (!(r=PyObject_RichCompare(x,y,dir))) FAIL(err)
-#define OP_LT(x,y,r,err)  op_richcmp(x,y,r,err, Py_LT)
-#define OP_LE(x,y,r,err)  op_richcmp(x,y,r,err, Py_LE)
-#define OP_EQ(x,y,r,err)  op_richcmp(x,y,r,err, Py_EQ)
-#define OP_NE(x,y,r,err)  op_richcmp(x,y,r,err, Py_NE)
-#define OP_GT(x,y,r,err)  op_richcmp(x,y,r,err, Py_GT)
-#define OP_GE(x,y,r,err)  op_richcmp(x,y,r,err, Py_GE)
-
-#define OP_IS_(x,y,r,err) op_bool(r,err,(x == y))
-
-#define OP_IS_TRUE(x,r,err) op_bool(r,err,PyObject_IsTrue(x))
-
-#define OP_LEN(x,r,err) { \
-		int _retval = PyObject_Size(x); \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyInt_FromLong(_retval); \
-	}
-#define OP_NEG(x,r,err)           if (!(r=PyNumber_Negative(x)))     FAIL(err)
-#define OP_POS(x,r,err)           if (!(r=PyNumber_Positive(x)))     FAIL(err)
-#define OP_INVERT(x,r,err)        if (!(r=PyNumber_Invert(x)))       FAIL(err)
-
-#define OP_ADD(x,y,r,err)         if (!(r=PyNumber_Add(x,y)))        FAIL(err)
-#define OP_SUB(x,y,r,err)         if (!(r=PyNumber_Subtract(x,y)))   FAIL(err)
-#define OP_MUL(x,y,r,err)         if (!(r=PyNumber_Multiply(x,y)))   FAIL(err)
-#define OP_TRUEDIV(x,y,r,err)     if (!(r=PyNumber_TrueDivide(x,y))) FAIL(err)
-#define OP_FLOORDIV(x,y,r,err)    if (!(r=PyNumber_FloorDivide(x,y)))FAIL(err)
-#define OP_DIV(x,y,r,err)         if (!(r=PyNumber_Divide(x,y)))     FAIL(err)
-#define OP_MOD(x,y,r,err)         if (!(r=PyNumber_Remainder(x,y)))  FAIL(err)
-#define OP_POW(x,y,z,r,err)       if (!(r=PyNumber_Power(x,y,z)))    FAIL(err)
-#define OP_LSHIFT(x,y,r,err)      if (!(r=PyNumber_Lshift(x,y)))     FAIL(err)
-#define OP_RSHIFT(x,y,r,err)      if (!(r=PyNumber_Rshift(x,y)))     FAIL(err)
-#define OP_AND_(x,y,r,err)        if (!(r=PyNumber_And(x,y)))        FAIL(err)
-#define OP_OR_(x,y,r,err)         if (!(r=PyNumber_Or(x,y)))         FAIL(err)
-#define OP_XOR(x,y,r,err)         if (!(r=PyNumber_Xor(x,y)))        FAIL(err)
-
-#define OP_INPLACE_ADD(x,y,r,err) if (!(r=PyNumber_InPlaceAdd(x,y)))           \
-								     FAIL(err)
-#define OP_INPLACE_SUB(x,y,r,err) if (!(r=PyNumber_InPlaceSubtract(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_MUL(x,y,r,err) if (!(r=PyNumber_InPlaceMultiply(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_TRUEDIV(x,y,r,err) if (!(r=PyNumber_InPlaceTrueDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_FLOORDIV(x,y,r,err)if(!(r=PyNumber_InPlaceFloorDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_DIV(x,y,r,err) if (!(r=PyNumber_InPlaceDivide(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_MOD(x,y,r,err) if (!(r=PyNumber_InPlaceRemainder(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_POW(x,y,r,err) if (!(r=PyNumber_InPlacePower(x,y,Py_None))) \
-								     FAIL(err)
-#define OP_INPLACE_LSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceLshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_RSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceRshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_AND(x,y,r,err)    if (!(r=PyNumber_InPlaceAnd(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_OR(x,y,r,err)     if (!(r=PyNumber_InPlaceOr(x,y)))         \
-								     FAIL(err)
-#define OP_INPLACE_XOR(x,y,r,err)    if (!(r=PyNumber_InPlaceXor(x,y)))        \
-								     FAIL(err)
-
-#define OP_GETITEM(x,y,r,err)     if (!(r=PyObject_GetItem1(x,y)))   FAIL(err)
-#define OP_SETITEM(x,y,z,r,err)   if ((PyObject_SetItem1(x,y,z))<0)  FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELITEM(x,y,r,err)     if ((PyObject_DelItem(x,y))<0)     FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_CONTAINS(x,y,r,err)    op_bool(r,err,(PySequence_Contains(x,y)))
-
-#define OP_GETATTR(x,y,r,err)     if (!(r=PyObject_GetAttr(x,y)))    FAIL(err)
-#define OP_SETATTR(x,y,z,r,err)   if ((PyObject_SetAttr(x,y,z))<0)   FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELATTR(x,y,r,err)     if ((PyObject_SetAttr(x,y,NULL))<0)FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-
-#define OP_NEWSLICE(x,y,z,r,err)  if (!(r=PySlice_New(x,y,z)))       FAIL(err)
-
-#define OP_GETSLICE(x,y,z,r,err)  {					\
-		PyObject *__yo = y, *__zo = z;				\
-		int __y = 0, __z = INT_MAX;				\
-		if (__yo == Py_None) __yo = NULL;			\
-		if (__zo == Py_None) __zo = NULL;			\
-		if (!_PyEval_SliceIndex(__yo, &__y) ||			\
-		    !_PyEval_SliceIndex(__zo, &__z) ||			\
-		    !(r=PySequence_GetSlice(x, __y, __z))) FAIL(err)	\
-	}
-
-#define OP_ALLOC_AND_SET(x,y,r,err) { \
-		/* XXX check for long/int overflow */ \
-		int __i, __x = PyInt_AsLong(x); \
-		if (PyErr_Occurred()) FAIL(err) \
-		if (!(r = PyList_New(__x))) FAIL(err) \
-		for (__i=0; __i<__x; __i++) { \
-			Py_INCREF(y); \
-			PyList_SET_ITEM(r, __i, y); \
-		} \
-	}
-
-#define OP_ITER(x,r,err)          if (!(r=PyObject_GetIter(x)))      FAIL(err)
-#define OP_NEXT(x,r,err)          if (!(r=PyIter_Next(x))) {                   \
-		if (!PyErr_Occurred()) PyErr_SetNone(PyExc_StopIteration);     \
-		FAIL(err)                                                      \
-	}
-
-#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
-					FAIL(err)
-#define OP_CALL_ARGS(args,r,err)   if (!(r=CallWithShape args))    FAIL(err)
-
-/* Needs to act like getattr(x, '__class__', type(x)) */
-#define OP_TYPE(x,r,err) { \
-		PyObject *o = x; \
-		if (PyInstance_Check(o)) { \
-			r = (PyObject*)(((PyInstanceObject*)o)->in_class); \
-		} else { \
-			r = (PyObject*)o->ob_type; \
-		} \
-		Py_INCREF(r); \
-	}
-
-/* Needs to act like instance(x,y) */
-#define OP_ISSUBTYPE(x,y,r,err)  \
-		op_bool(r,err,PyClass_IsSubclass(x, y))
-
-
-/*** misc ***/
-
-#define MOVE(x, y)             y = x;
-
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
-
-
-#if defined(USE_CALL_TRACE)
-
-#define TRACE_CALL       __f, __tstate
-#define TRACE_ARGS       PyFrameObject *__f, PyThreadState *__tstate
-
-#define FAIL(err) { __f->f_lineno = __f->f_code->co_firstlineno = __LINE__; goto err; }
-
-#define FUNCTION_HEAD(signature, self, args, names, file, line) \
-	PyThreadState *__tstate = PyThreadState_GET(); \
-	PyObject *__localnames = PyList_CrazyStringPack names; \
-	PyFrameObject *__f = traced_function_head(self, args, signature, file, line, __tstate, __localnames);
-
-#define FUNCTION_CHECK() \
-	assert (__f != NULL);
-
-#define ERR_DECREF(arg) { if (__f->f_locals) { PyDict_SetItemString(__f->f_locals, #arg, arg); } Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return traced_function_tail(rval, __f, __tstate);
-
-#else /* !defined(USE_CALL_TRACE) */
-
-#define FAIL(err) { goto err; }
-
-#define ERR_DECREF(arg) { Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return rval;
-
-#endif /* defined(USE_CALL_TRACE) */
-
-
-
-
-
-/* we need a subclass of 'builtin_function_or_method' which can be used
-   as methods: builtin function objects that can be bound on instances */
-static PyObject *
-gencfunc_descr_get(PyObject *func, PyObject *obj, PyObject *type)
-{
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
-}
-static PyTypeObject PyGenCFunction_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,
-	"pypy_generated_function",
-	sizeof(PyCFunctionObject),
-	0,
-	0,					/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	0,					/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	/*&PyCFunction_Type set below*/ 0,	/* tp_base */
-	0,					/* tp_dict */
-	gencfunc_descr_get,			/* tp_descr_get */
-	0,					/* tp_descr_set */
-};
 
 #define MODULE_INITFUNC(modname) \
 	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
@@ -267,6 +23,8 @@
 
 /*** table of global objects ***/
 
+static PyObject *this_module_globals;
+
 typedef struct {
 	PyObject** p;
 	char* name;
@@ -360,514 +118,3 @@
 	Py_DECREF(res);
 	return 0;
 }
-
-
-/*** operations with a variable number of arguments ***/
-
-#define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
-#define OP_NEWLIST(args,r,err)     if (!(r=PyList_Pack args)) FAIL(err)
-#define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
-#define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
-#define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
-
-static PyObject* PyList_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyList_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyList_SET_ITEM(result, i, o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-static PyObject* PyDict_Pack(int n, ...)
-{
-	int i;
-	PyObject *key, *val;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyDict_New();
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		key = va_arg(vargs, PyObject *);
-		val = va_arg(vargs, PyObject *);
-		if (PyDict_SetItem(result, key, val) < 0) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	va_end(vargs);
-	return result;
-}
-
-#if PY_VERSION_HEX < 0x02040000   /* 2.4 */
-static PyObject* PyTuple_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	PyObject **items;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyTuple_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	items = ((PyTupleObject *)result)->ob_item;
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		items[i] = o;
-	}
-	va_end(vargs);
-	return result;
-}
-#endif
-
-#if PY_VERSION_HEX >= 0x02030000   /* 2.3 */
-# define PyObject_GetItem1  PyObject_GetItem
-# define PyObject_SetItem1  PyObject_SetItem
-#else
-/* for Python 2.2 only */
-static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_GetItem(obj, index);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_GetSlice(obj, start, stop);
-}
-static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_SetItem(obj, index, v);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_SetSlice(obj, start, stop, v);
-}
-#endif
-
-static PyObject* CallWithShape(PyObject* callable, PyObject* shape, ...)
-{
-	/* XXX the 'shape' argument is a tuple as specified by
-	   XXX pypy.interpreter.argument.fromshape().  This code should
-	   XXX we made independent on the format of the 'shape' later... */
-	PyObject* result = NULL;
-	PyObject* t = NULL;
-	PyObject* d = NULL;
-	PyObject* o;
-	PyObject* key;
-	PyObject* t2;
-	int i, nargs, nkwds, starflag, starstarflag;
-	va_list vargs;
-
-	if (!PyTuple_Check(shape) ||
-	    PyTuple_GET_SIZE(shape) != 4 ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 0)) ||
-	    !PyTuple_Check(PyTuple_GET_ITEM(shape, 1)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 2)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 3))) {
-		Py_FatalError("in genc.h: invalid 'shape' argument");
-	}
-	nargs = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 0));
-	nkwds = PyTuple_GET_SIZE(PyTuple_GET_ITEM(shape, 1));
-	starflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 2));
-	starstarflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 3));
-
-	va_start(vargs, shape);
-	t = PyTuple_New(nargs);
-	if (t == NULL)
-		goto finally;
-	for (i = 0; i < nargs; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyTuple_SET_ITEM(t, i, o);
-	}
-	if (nkwds) {
-		d = PyDict_New();
-		if (d == NULL)
-			goto finally;
-		for (i = 0; i < nkwds; i++) {
-			o = va_arg(vargs, PyObject *);
-			key = PyTuple_GET_ITEM(PyTuple_GET_ITEM(shape, 1), i);
-			if (PyDict_SetItem(d, key, o) < 0)
-				goto finally;
-		}
-	}
-	if (starflag) {
-		o = va_arg(vargs, PyObject *);
-		o = PySequence_Tuple(o);
-		if (o == NULL)
-			goto finally;
-		t2 = PySequence_Concat(t, o);
-		Py_DECREF(o);
-		Py_DECREF(t);
-		t = t2;
-		if (t == NULL)
-			goto finally;
-	}
-	if (starstarflag) {
-		int len1, len2, len3;
-		o = va_arg(vargs, PyObject *);
-		len1 = PyDict_Size(d);
-		len2 = PyDict_Size(o);
-		if (len1 < 0 || len2 < 0)
-			goto finally;
-		if (PyDict_Update(d, o) < 0)
-			goto finally;
-		len3 = PyDict_Size(d);
-		if (len1 + len2 != len3) {
-			PyErr_SetString(PyExc_TypeError,
-					"genc.h: duplicate keyword arguments");
-			goto finally;
-		}
-	}
-	va_end(vargs);
-
-	result = PyObject_Call(callable, t, d);
-
- finally:
-	Py_XDECREF(d);
-	Py_XDECREF(t);
-	return result;
-}
-
-
-#if defined(USE_CALL_TRACE)
-
-static int callstack_depth = -1;
-static PyCodeObject* getcode(char *func_name, char *func_filename, int lineno);
-static int trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val);
-static int trace_frame_exc(PyThreadState *tstate, PyFrameObject *f);
-
-static int
-trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
-{
-	int result = 0;
-	if (!tstate->use_tracing || tstate->tracing) {
-		/*printf("if (!tstate->use_tracing || tstate->tracing)\n");*/
-		return 0;
-	}
-	if (tstate->c_profilefunc != NULL) {
-		/*printf("if (tstate->c_profilefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_profilefunc(tstate->c_profileobj,
-						   f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-		if (result) {
-			/*printf("	if (result)\n");*/
-			return result;
-		}
-	}
-	if (tstate->c_tracefunc != NULL) {
-		/*printf("if (tstate->c_tracefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_tracefunc(tstate->c_traceobj,
-						 f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-	}   
-	/*printf("return result;\n");*/
-	return result;
-}
-
-static int
-trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
-{
-	PyObject *type, *value, *traceback, *arg;
-	int err;
-
-	if (tstate->c_tracefunc == NULL) {
-		return 0;
-	}
-
-	PyErr_Fetch(&type, &value, &traceback);
-	if (value == NULL) {
-		value = Py_None;
-		Py_INCREF(value);
-	}
-	arg = PyTuple_Pack(3, type, value, traceback);
-	if (arg == NULL) {
-		PyErr_Restore(type, value, traceback);
-		return 0;
-	}
-	err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
-	Py_DECREF(arg);
-	if (err == 0) {
-		PyErr_Restore(type, value, traceback);
-	} else {
-		Py_XDECREF(type);
-		Py_XDECREF(value);
-		Py_XDECREF(traceback);
-	}
-	return err;
-}
-
-static PyCodeObject*
-getcode(char *func_name, char *func_filename, int lineno)
-{
-	PyObject *code = NULL;
-	PyObject *name = NULL;
-	PyObject *nulltuple = NULL;
-	PyObject *filename = NULL;
-	PyCodeObject *tb_code = NULL;
-#if defined(OBNOXIOUS_PRINT_STATEMENTS)
-	int i;
-
-	printf("%5d: ", lineno);
-	assert(callstack_depth >= 0);
-	if (callstack_depth) {
-		for (i=0; i<callstack_depth; ++i) {
-			printf("  ");
-		}
-	}
-	printf("%s\n", func_name);
-#endif /* !defined(OBNOXIOUS_PRINT_STATEMENTS) */
-
-	code = PyString_FromString("");
-	if (code == NULL)
-		goto failed;
-	name = PyString_FromString(func_name);
-	if (name == NULL)
-		goto failed;
-	nulltuple = PyTuple_New(0);
-	if (nulltuple == NULL)
-		goto failed;
-	filename = PyString_FromString(func_filename);
-	tb_code = PyCode_New(0,       /* argcount */
-						 0,       /* nlocals */
-						 0,       /* stacksize */
-						 0,       /* flags */
-						 code,        /* code */
-						 nulltuple,   /* consts */
-						 nulltuple,   /* names */
-						 nulltuple,   /* varnames */
-						 nulltuple,   /* freevars */
-						 nulltuple,   /* cellvars */
-						 filename,    /* filename */
-						 name,        /* name */
-						 lineno,      /* firstlineno */
-						 code     /* lnotab */
-						 );
-	if (tb_code == NULL)
-		goto failed;
-	Py_DECREF(code);
-	Py_DECREF(nulltuple);
-	Py_DECREF(filename);
-	Py_DECREF(name);
-	return tb_code;
-failed:
-	Py_XDECREF(code);
-	Py_XDECREF(name);
-	return NULL;
-}
-
-static PyFrameObject *traced_function_head(PyObject *function, PyObject *args, char *c_signature, char *filename, int c_lineno, PyThreadState *tstate, PyObject *extra_local_names) {
-	/*
-		STEALS a reference to extra_local_names if not NULL
-	*/
-
-	PyCodeObject *c;
-	PyFrameObject *f;
-	PyObject *locals;
-	PyObject *locals_signature;
-	PyObject *locals_lineno;
-	PyObject *locals_filename;
-
-	assert(function && args && tstate);
-
-	locals = PyDict_New();
-	locals_signature = PyString_FromString(c_signature);
-	locals_lineno = PyInt_FromLong(c_lineno);
-	locals_filename = PyString_FromString(filename);
-	if (locals == NULL || function == NULL || args == NULL || 
-		locals_signature == NULL || locals_lineno == NULL ||
-		locals_filename == NULL) {
-		Py_XDECREF(locals);
-		Py_XDECREF(locals_signature);
-		Py_XDECREF(locals_lineno);
-		Py_XDECREF(locals_filename);
-		return NULL;
-	}
-	PyDict_SetItemString(locals, "function", function);
-	PyDict_SetItemString(locals, "args", args);
-	PyDict_SetItemString(locals, "signature", locals_signature);
-	PyDict_SetItemString(locals, "lineno", locals_lineno);
-	PyDict_SetItemString(locals, "filename", locals_filename);
-	Py_DECREF(locals_signature);
-	Py_DECREF(locals_lineno);
-	Py_DECREF(locals_filename);
-	if (extra_local_names != NULL) {
-		int max_locals = MIN(PyList_Size(extra_local_names), PyTuple_Size(args));
-        int i;
-		for (i = 0; i < max_locals; ++i) {
-			PyDict_SetItem(locals, PyList_GET_ITEM(extra_local_names, i), PyTuple_GET_ITEM(args, i));
-		}
-		Py_DECREF(extra_local_names);
-	}
-
-	callstack_depth++;
-	c = getcode(c_signature, filename, c_lineno);
-	if (c == NULL) {
-		Py_DECREF(locals);
-		callstack_depth--;
-		return NULL;
-	}
-	f = PyFrame_New(tstate, c, this_module_globals, locals);
-	if (f == NULL) {
-		callstack_depth--;
-		return NULL;
-	}
-	Py_DECREF(c);
-	Py_DECREF(locals);
-	tstate->frame = f;
-	if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
-		Py_DECREF(args);
-		callstack_depth--;
-		return NULL;
-	}
-
-	return f;
-}
-
-static PyObject *traced_function_tail(PyObject *rval, PyFrameObject *f, PyThreadState *tstate) {
-	/*
-		STEALS a reference to f
-	*/
-	if (f == NULL) {
-		goto bad_args;
-	}
-	if (rval == NULL) {
-		if (tstate->curexc_traceback == NULL) {
-			PyTraceBack_Here(f);
-		}
-		if (trace_frame_exc(tstate, f) < 0) {
-			goto end;
-		}
-	} else {
-		if (trace_frame(tstate, f, PyTrace_RETURN, rval) < 0) {
-			Py_DECREF(rval);
-			rval = NULL;
-		}
-	}
-end:
-	tstate->frame = f->f_back;
-	Py_DECREF(f);
-bad_args:
-	callstack_depth--;
-	return rval;
-}
-
-static PyObject* PyList_CrazyStringPack(char *begin, ...)
-{
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	result = PyList_New(0);
-	if (result == NULL || begin == NULL) {
-		return result;
-	}
-	va_start(vargs, begin);
-	o = PyString_FromString(begin);
-	if (o == NULL) {
-		Py_XDECREF(result);
-		return NULL;
-	}
-	if (PyList_Append(result, o) == -1) {
-		Py_DECREF(o);
-		Py_XDECREF(result);
-		return result;
-	}
-	Py_DECREF(o);
-	while ((begin = va_arg(vargs, char *)) != NULL) {
-		o = PyString_FromString(begin);
-		if (o == NULL) {
-			Py_XDECREF(result);
-			return NULL;
-		}
-		if (PyList_Append(result, o) == -1) {
-			Py_DECREF(o);
-			Py_XDECREF(result);
-			return NULL;
-		}
-		Py_DECREF(o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-#endif /* defined(USE_CALL_TRACE) */

Copied: pypy/dist/pypy/translator/genc/g_operation.h (from r10250, pypy/dist/pypy/translator/genc.h)
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc/g_operation.h	Sat Apr  2 17:57:37 2005
@@ -1,28 +1,8 @@
 
 /************************************************************/
-/***  Generic C header section                            ***/
+ /***  C header subsection: untyped operations             ***/
+  /***  as OP_XXX() macros calling the CPython API          ***/
 
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include "structmember.h"
-#include "traceback.h"
-#include "marshal.h"
-#include "eval.h"
-
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif /* MIN */
-
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
-
-/* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
-
-#if 0
-#define OBNOXIOUS_PRINT_STATEMENTS
-#endif
 
 #define op_bool(r,err,what) { \
 		int _retval = what; \
@@ -163,205 +143,6 @@
 
 #define MOVE(x, y)             y = x;
 
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
-
-
-#if defined(USE_CALL_TRACE)
-
-#define TRACE_CALL       __f, __tstate
-#define TRACE_ARGS       PyFrameObject *__f, PyThreadState *__tstate
-
-#define FAIL(err) { __f->f_lineno = __f->f_code->co_firstlineno = __LINE__; goto err; }
-
-#define FUNCTION_HEAD(signature, self, args, names, file, line) \
-	PyThreadState *__tstate = PyThreadState_GET(); \
-	PyObject *__localnames = PyList_CrazyStringPack names; \
-	PyFrameObject *__f = traced_function_head(self, args, signature, file, line, __tstate, __localnames);
-
-#define FUNCTION_CHECK() \
-	assert (__f != NULL);
-
-#define ERR_DECREF(arg) { if (__f->f_locals) { PyDict_SetItemString(__f->f_locals, #arg, arg); } Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return traced_function_tail(rval, __f, __tstate);
-
-#else /* !defined(USE_CALL_TRACE) */
-
-#define FAIL(err) { goto err; }
-
-#define ERR_DECREF(arg) { Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return rval;
-
-#endif /* defined(USE_CALL_TRACE) */
-
-
-
-
-
-/* we need a subclass of 'builtin_function_or_method' which can be used
-   as methods: builtin function objects that can be bound on instances */
-static PyObject *
-gencfunc_descr_get(PyObject *func, PyObject *obj, PyObject *type)
-{
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
-}
-static PyTypeObject PyGenCFunction_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,
-	"pypy_generated_function",
-	sizeof(PyCFunctionObject),
-	0,
-	0,					/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	0,					/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	/*&PyCFunction_Type set below*/ 0,	/* tp_base */
-	0,					/* tp_dict */
-	gencfunc_descr_get,			/* tp_descr_get */
-	0,					/* tp_descr_set */
-};
-
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
-	PyMODINIT_FUNC init##modname(void)
-
-#define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
-	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
-	this_module_globals = PyModule_GetDict(m); \
-	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\
-	PyType_Ready(&PyGenCFunction_Type);	\
-	if (setup_globalfunctions(globalfunctiondefs) < 0) \
-		return;	\
-	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
-		return;	\
-	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return;
-
-
-/*** table of global objects ***/
-
-typedef struct {
-	PyObject** p;
-	char* name;
-} globalobjectdef_t;
-
-typedef struct {
-	PyObject** p;
-	PyMethodDef ml;
-} globalfunctiondef_t;
-
-static int setup_globalobjects(globalobjectdef_t* def)
-{
-	PyObject* obj;
-	
-	for (; def->p != NULL; def++) {
-		obj = PyDict_GetItemString(this_module_globals, def->name);
-		if (obj == NULL) {
-			PyErr_Format(PyExc_AttributeError,
-				     "initialization code should have "
-				     "created '%s'", def->name);
-			return -1;
-		}
-		Py_INCREF(obj);
-		*def->p = obj;   /* store the object ref in the global var */
-	}
-	return 0;
-}
-
-static int setup_globalfunctions(globalfunctiondef_t* def)
-{
-	PyObject* fn;
-	PyObject* name;
-	int len;
-
-	for (; def->p != NULL; def++) {
-		fn = PyCFunction_New(&def->ml, NULL);
-		if (fn == NULL)
-			return -1;
-		fn->ob_type = &PyGenCFunction_Type;
-		*def->p = fn;   /* store the object ref in the global var */
-
-		len = 0;
-		while (def->ml.ml_name[len] != 0)
-			len++;
-		name = PyString_FromStringAndSize(NULL, 6+len);
-		if (name == NULL)
-			return -1;
-		memcpy(PyString_AS_STRING(name), "gfunc_", 6);
-		memcpy(PyString_AS_STRING(name)+6, def->ml.ml_name, len);
-		if (PyDict_SetItem(this_module_globals, name, fn) < 0)
-			return -1;
-		Py_DECREF(name);
-	}
-	return 0;
-}
-
-static int setup_initcode(char* frozendata[], int len)
-{
-	PyObject* co;
-	PyObject* globals;
-	PyObject* res;
-	char *buffer, *bufp;
-	int chunk, count = 0;
-	
-	buffer = PyMem_NEW(char, len);
-	if (buffer == NULL)
-		return -1;
-	bufp = buffer;
-	while (count < len) {
-		chunk = len-count < 1024 ? len-count : 1024;
-		memcpy(bufp, *frozendata, chunk);
-		bufp += chunk;
-		count += chunk;
-		++frozendata;
-	}
-	co = PyMarshal_ReadObjectFromString(buffer, len);
-	if (co == NULL)
-		return -1;
-	PyMem_DEL(buffer);
-	if (!PyCode_Check(co)) {
-		PyErr_SetString(PyExc_TypeError, "uh?");
-		return -1;
-	}
-	globals = this_module_globals;
-	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
-		PyDict_SetItemString(globals, "__builtins__",
-				     PyEval_GetBuiltins());
-	res = PyEval_EvalCode((PyCodeObject *) co, globals, globals);
-	if (res == NULL)
-		return -1;
-	Py_DECREF(res);
-	return 0;
-}
-
-
 /*** operations with a variable number of arguments ***/
 
 #define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
@@ -369,505 +150,3 @@
 #define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
 #define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
 #define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
-
-static PyObject* PyList_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyList_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyList_SET_ITEM(result, i, o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-static PyObject* PyDict_Pack(int n, ...)
-{
-	int i;
-	PyObject *key, *val;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyDict_New();
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		key = va_arg(vargs, PyObject *);
-		val = va_arg(vargs, PyObject *);
-		if (PyDict_SetItem(result, key, val) < 0) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	va_end(vargs);
-	return result;
-}
-
-#if PY_VERSION_HEX < 0x02040000   /* 2.4 */
-static PyObject* PyTuple_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	PyObject **items;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyTuple_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	items = ((PyTupleObject *)result)->ob_item;
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		items[i] = o;
-	}
-	va_end(vargs);
-	return result;
-}
-#endif
-
-#if PY_VERSION_HEX >= 0x02030000   /* 2.3 */
-# define PyObject_GetItem1  PyObject_GetItem
-# define PyObject_SetItem1  PyObject_SetItem
-#else
-/* for Python 2.2 only */
-static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_GetItem(obj, index);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_GetSlice(obj, start, stop);
-}
-static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_SetItem(obj, index, v);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_SetSlice(obj, start, stop, v);
-}
-#endif
-
-static PyObject* CallWithShape(PyObject* callable, PyObject* shape, ...)
-{
-	/* XXX the 'shape' argument is a tuple as specified by
-	   XXX pypy.interpreter.argument.fromshape().  This code should
-	   XXX we made independent on the format of the 'shape' later... */
-	PyObject* result = NULL;
-	PyObject* t = NULL;
-	PyObject* d = NULL;
-	PyObject* o;
-	PyObject* key;
-	PyObject* t2;
-	int i, nargs, nkwds, starflag, starstarflag;
-	va_list vargs;
-
-	if (!PyTuple_Check(shape) ||
-	    PyTuple_GET_SIZE(shape) != 4 ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 0)) ||
-	    !PyTuple_Check(PyTuple_GET_ITEM(shape, 1)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 2)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 3))) {
-		Py_FatalError("in genc.h: invalid 'shape' argument");
-	}
-	nargs = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 0));
-	nkwds = PyTuple_GET_SIZE(PyTuple_GET_ITEM(shape, 1));
-	starflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 2));
-	starstarflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 3));
-
-	va_start(vargs, shape);
-	t = PyTuple_New(nargs);
-	if (t == NULL)
-		goto finally;
-	for (i = 0; i < nargs; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyTuple_SET_ITEM(t, i, o);
-	}
-	if (nkwds) {
-		d = PyDict_New();
-		if (d == NULL)
-			goto finally;
-		for (i = 0; i < nkwds; i++) {
-			o = va_arg(vargs, PyObject *);
-			key = PyTuple_GET_ITEM(PyTuple_GET_ITEM(shape, 1), i);
-			if (PyDict_SetItem(d, key, o) < 0)
-				goto finally;
-		}
-	}
-	if (starflag) {
-		o = va_arg(vargs, PyObject *);
-		o = PySequence_Tuple(o);
-		if (o == NULL)
-			goto finally;
-		t2 = PySequence_Concat(t, o);
-		Py_DECREF(o);
-		Py_DECREF(t);
-		t = t2;
-		if (t == NULL)
-			goto finally;
-	}
-	if (starstarflag) {
-		int len1, len2, len3;
-		o = va_arg(vargs, PyObject *);
-		len1 = PyDict_Size(d);
-		len2 = PyDict_Size(o);
-		if (len1 < 0 || len2 < 0)
-			goto finally;
-		if (PyDict_Update(d, o) < 0)
-			goto finally;
-		len3 = PyDict_Size(d);
-		if (len1 + len2 != len3) {
-			PyErr_SetString(PyExc_TypeError,
-					"genc.h: duplicate keyword arguments");
-			goto finally;
-		}
-	}
-	va_end(vargs);
-
-	result = PyObject_Call(callable, t, d);
-
- finally:
-	Py_XDECREF(d);
-	Py_XDECREF(t);
-	return result;
-}
-
-
-#if defined(USE_CALL_TRACE)
-
-static int callstack_depth = -1;
-static PyCodeObject* getcode(char *func_name, char *func_filename, int lineno);
-static int trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val);
-static int trace_frame_exc(PyThreadState *tstate, PyFrameObject *f);
-
-static int
-trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
-{
-	int result = 0;
-	if (!tstate->use_tracing || tstate->tracing) {
-		/*printf("if (!tstate->use_tracing || tstate->tracing)\n");*/
-		return 0;
-	}
-	if (tstate->c_profilefunc != NULL) {
-		/*printf("if (tstate->c_profilefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_profilefunc(tstate->c_profileobj,
-						   f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-		if (result) {
-			/*printf("	if (result)\n");*/
-			return result;
-		}
-	}
-	if (tstate->c_tracefunc != NULL) {
-		/*printf("if (tstate->c_tracefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_tracefunc(tstate->c_traceobj,
-						 f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-	}   
-	/*printf("return result;\n");*/
-	return result;
-}
-
-static int
-trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
-{
-	PyObject *type, *value, *traceback, *arg;
-	int err;
-
-	if (tstate->c_tracefunc == NULL) {
-		return 0;
-	}
-
-	PyErr_Fetch(&type, &value, &traceback);
-	if (value == NULL) {
-		value = Py_None;
-		Py_INCREF(value);
-	}
-	arg = PyTuple_Pack(3, type, value, traceback);
-	if (arg == NULL) {
-		PyErr_Restore(type, value, traceback);
-		return 0;
-	}
-	err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
-	Py_DECREF(arg);
-	if (err == 0) {
-		PyErr_Restore(type, value, traceback);
-	} else {
-		Py_XDECREF(type);
-		Py_XDECREF(value);
-		Py_XDECREF(traceback);
-	}
-	return err;
-}
-
-static PyCodeObject*
-getcode(char *func_name, char *func_filename, int lineno)
-{
-	PyObject *code = NULL;
-	PyObject *name = NULL;
-	PyObject *nulltuple = NULL;
-	PyObject *filename = NULL;
-	PyCodeObject *tb_code = NULL;
-#if defined(OBNOXIOUS_PRINT_STATEMENTS)
-	int i;
-
-	printf("%5d: ", lineno);
-	assert(callstack_depth >= 0);
-	if (callstack_depth) {
-		for (i=0; i<callstack_depth; ++i) {
-			printf("  ");
-		}
-	}
-	printf("%s\n", func_name);
-#endif /* !defined(OBNOXIOUS_PRINT_STATEMENTS) */
-
-	code = PyString_FromString("");
-	if (code == NULL)
-		goto failed;
-	name = PyString_FromString(func_name);
-	if (name == NULL)
-		goto failed;
-	nulltuple = PyTuple_New(0);
-	if (nulltuple == NULL)
-		goto failed;
-	filename = PyString_FromString(func_filename);
-	tb_code = PyCode_New(0,       /* argcount */
-						 0,       /* nlocals */
-						 0,       /* stacksize */
-						 0,       /* flags */
-						 code,        /* code */
-						 nulltuple,   /* consts */
-						 nulltuple,   /* names */
-						 nulltuple,   /* varnames */
-						 nulltuple,   /* freevars */
-						 nulltuple,   /* cellvars */
-						 filename,    /* filename */
-						 name,        /* name */
-						 lineno,      /* firstlineno */
-						 code     /* lnotab */
-						 );
-	if (tb_code == NULL)
-		goto failed;
-	Py_DECREF(code);
-	Py_DECREF(nulltuple);
-	Py_DECREF(filename);
-	Py_DECREF(name);
-	return tb_code;
-failed:
-	Py_XDECREF(code);
-	Py_XDECREF(name);
-	return NULL;
-}
-
-static PyFrameObject *traced_function_head(PyObject *function, PyObject *args, char *c_signature, char *filename, int c_lineno, PyThreadState *tstate, PyObject *extra_local_names) {
-	/*
-		STEALS a reference to extra_local_names if not NULL
-	*/
-
-	PyCodeObject *c;
-	PyFrameObject *f;
-	PyObject *locals;
-	PyObject *locals_signature;
-	PyObject *locals_lineno;
-	PyObject *locals_filename;
-
-	assert(function && args && tstate);
-
-	locals = PyDict_New();
-	locals_signature = PyString_FromString(c_signature);
-	locals_lineno = PyInt_FromLong(c_lineno);
-	locals_filename = PyString_FromString(filename);
-	if (locals == NULL || function == NULL || args == NULL || 
-		locals_signature == NULL || locals_lineno == NULL ||
-		locals_filename == NULL) {
-		Py_XDECREF(locals);
-		Py_XDECREF(locals_signature);
-		Py_XDECREF(locals_lineno);
-		Py_XDECREF(locals_filename);
-		return NULL;
-	}
-	PyDict_SetItemString(locals, "function", function);
-	PyDict_SetItemString(locals, "args", args);
-	PyDict_SetItemString(locals, "signature", locals_signature);
-	PyDict_SetItemString(locals, "lineno", locals_lineno);
-	PyDict_SetItemString(locals, "filename", locals_filename);
-	Py_DECREF(locals_signature);
-	Py_DECREF(locals_lineno);
-	Py_DECREF(locals_filename);
-	if (extra_local_names != NULL) {
-		int max_locals = MIN(PyList_Size(extra_local_names), PyTuple_Size(args));
-        int i;
-		for (i = 0; i < max_locals; ++i) {
-			PyDict_SetItem(locals, PyList_GET_ITEM(extra_local_names, i), PyTuple_GET_ITEM(args, i));
-		}
-		Py_DECREF(extra_local_names);
-	}
-
-	callstack_depth++;
-	c = getcode(c_signature, filename, c_lineno);
-	if (c == NULL) {
-		Py_DECREF(locals);
-		callstack_depth--;
-		return NULL;
-	}
-	f = PyFrame_New(tstate, c, this_module_globals, locals);
-	if (f == NULL) {
-		callstack_depth--;
-		return NULL;
-	}
-	Py_DECREF(c);
-	Py_DECREF(locals);
-	tstate->frame = f;
-	if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
-		Py_DECREF(args);
-		callstack_depth--;
-		return NULL;
-	}
-
-	return f;
-}
-
-static PyObject *traced_function_tail(PyObject *rval, PyFrameObject *f, PyThreadState *tstate) {
-	/*
-		STEALS a reference to f
-	*/
-	if (f == NULL) {
-		goto bad_args;
-	}
-	if (rval == NULL) {
-		if (tstate->curexc_traceback == NULL) {
-			PyTraceBack_Here(f);
-		}
-		if (trace_frame_exc(tstate, f) < 0) {
-			goto end;
-		}
-	} else {
-		if (trace_frame(tstate, f, PyTrace_RETURN, rval) < 0) {
-			Py_DECREF(rval);
-			rval = NULL;
-		}
-	}
-end:
-	tstate->frame = f->f_back;
-	Py_DECREF(f);
-bad_args:
-	callstack_depth--;
-	return rval;
-}
-
-static PyObject* PyList_CrazyStringPack(char *begin, ...)
-{
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	result = PyList_New(0);
-	if (result == NULL || begin == NULL) {
-		return result;
-	}
-	va_start(vargs, begin);
-	o = PyString_FromString(begin);
-	if (o == NULL) {
-		Py_XDECREF(result);
-		return NULL;
-	}
-	if (PyList_Append(result, o) == -1) {
-		Py_DECREF(o);
-		Py_XDECREF(result);
-		return result;
-	}
-	Py_DECREF(o);
-	while ((begin = va_arg(vargs, char *)) != NULL) {
-		o = PyString_FromString(begin);
-		if (o == NULL) {
-			Py_XDECREF(result);
-			return NULL;
-		}
-		if (PyList_Append(result, o) == -1) {
-			Py_DECREF(o);
-			Py_XDECREF(result);
-			return NULL;
-		}
-		Py_DECREF(o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-#endif /* defined(USE_CALL_TRACE) */

Copied: pypy/dist/pypy/translator/genc/g_support.h (from r10250, pypy/dist/pypy/translator/genc.h)
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc/g_support.h	Sat Apr  2 17:57:37 2005
@@ -1,204 +1,12 @@
 
 /************************************************************/
-/***  Generic C header section                            ***/
+ /***  C header subsection: support functions              ***/
 
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include "structmember.h"
-#include "traceback.h"
-#include "marshal.h"
-#include "eval.h"
 
 #if !defined(MIN)
 #define MIN(a,b) (((a)<(b))?(a):(b))
 #endif /* MIN */
 
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
-
-/* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
-
-#if 0
-#define OBNOXIOUS_PRINT_STATEMENTS
-#endif
-
-#define op_bool(r,err,what) { \
-		int _retval = what; \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyBool_FromLong(_retval); \
-	}
-
-#define op_richcmp(x,y,r,err,dir) \
-					if (!(r=PyObject_RichCompare(x,y,dir))) FAIL(err)
-#define OP_LT(x,y,r,err)  op_richcmp(x,y,r,err, Py_LT)
-#define OP_LE(x,y,r,err)  op_richcmp(x,y,r,err, Py_LE)
-#define OP_EQ(x,y,r,err)  op_richcmp(x,y,r,err, Py_EQ)
-#define OP_NE(x,y,r,err)  op_richcmp(x,y,r,err, Py_NE)
-#define OP_GT(x,y,r,err)  op_richcmp(x,y,r,err, Py_GT)
-#define OP_GE(x,y,r,err)  op_richcmp(x,y,r,err, Py_GE)
-
-#define OP_IS_(x,y,r,err) op_bool(r,err,(x == y))
-
-#define OP_IS_TRUE(x,r,err) op_bool(r,err,PyObject_IsTrue(x))
-
-#define OP_LEN(x,r,err) { \
-		int _retval = PyObject_Size(x); \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyInt_FromLong(_retval); \
-	}
-#define OP_NEG(x,r,err)           if (!(r=PyNumber_Negative(x)))     FAIL(err)
-#define OP_POS(x,r,err)           if (!(r=PyNumber_Positive(x)))     FAIL(err)
-#define OP_INVERT(x,r,err)        if (!(r=PyNumber_Invert(x)))       FAIL(err)
-
-#define OP_ADD(x,y,r,err)         if (!(r=PyNumber_Add(x,y)))        FAIL(err)
-#define OP_SUB(x,y,r,err)         if (!(r=PyNumber_Subtract(x,y)))   FAIL(err)
-#define OP_MUL(x,y,r,err)         if (!(r=PyNumber_Multiply(x,y)))   FAIL(err)
-#define OP_TRUEDIV(x,y,r,err)     if (!(r=PyNumber_TrueDivide(x,y))) FAIL(err)
-#define OP_FLOORDIV(x,y,r,err)    if (!(r=PyNumber_FloorDivide(x,y)))FAIL(err)
-#define OP_DIV(x,y,r,err)         if (!(r=PyNumber_Divide(x,y)))     FAIL(err)
-#define OP_MOD(x,y,r,err)         if (!(r=PyNumber_Remainder(x,y)))  FAIL(err)
-#define OP_POW(x,y,z,r,err)       if (!(r=PyNumber_Power(x,y,z)))    FAIL(err)
-#define OP_LSHIFT(x,y,r,err)      if (!(r=PyNumber_Lshift(x,y)))     FAIL(err)
-#define OP_RSHIFT(x,y,r,err)      if (!(r=PyNumber_Rshift(x,y)))     FAIL(err)
-#define OP_AND_(x,y,r,err)        if (!(r=PyNumber_And(x,y)))        FAIL(err)
-#define OP_OR_(x,y,r,err)         if (!(r=PyNumber_Or(x,y)))         FAIL(err)
-#define OP_XOR(x,y,r,err)         if (!(r=PyNumber_Xor(x,y)))        FAIL(err)
-
-#define OP_INPLACE_ADD(x,y,r,err) if (!(r=PyNumber_InPlaceAdd(x,y)))           \
-								     FAIL(err)
-#define OP_INPLACE_SUB(x,y,r,err) if (!(r=PyNumber_InPlaceSubtract(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_MUL(x,y,r,err) if (!(r=PyNumber_InPlaceMultiply(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_TRUEDIV(x,y,r,err) if (!(r=PyNumber_InPlaceTrueDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_FLOORDIV(x,y,r,err)if(!(r=PyNumber_InPlaceFloorDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_DIV(x,y,r,err) if (!(r=PyNumber_InPlaceDivide(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_MOD(x,y,r,err) if (!(r=PyNumber_InPlaceRemainder(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_POW(x,y,r,err) if (!(r=PyNumber_InPlacePower(x,y,Py_None))) \
-								     FAIL(err)
-#define OP_INPLACE_LSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceLshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_RSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceRshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_AND(x,y,r,err)    if (!(r=PyNumber_InPlaceAnd(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_OR(x,y,r,err)     if (!(r=PyNumber_InPlaceOr(x,y)))         \
-								     FAIL(err)
-#define OP_INPLACE_XOR(x,y,r,err)    if (!(r=PyNumber_InPlaceXor(x,y)))        \
-								     FAIL(err)
-
-#define OP_GETITEM(x,y,r,err)     if (!(r=PyObject_GetItem1(x,y)))   FAIL(err)
-#define OP_SETITEM(x,y,z,r,err)   if ((PyObject_SetItem1(x,y,z))<0)  FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELITEM(x,y,r,err)     if ((PyObject_DelItem(x,y))<0)     FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_CONTAINS(x,y,r,err)    op_bool(r,err,(PySequence_Contains(x,y)))
-
-#define OP_GETATTR(x,y,r,err)     if (!(r=PyObject_GetAttr(x,y)))    FAIL(err)
-#define OP_SETATTR(x,y,z,r,err)   if ((PyObject_SetAttr(x,y,z))<0)   FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELATTR(x,y,r,err)     if ((PyObject_SetAttr(x,y,NULL))<0)FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-
-#define OP_NEWSLICE(x,y,z,r,err)  if (!(r=PySlice_New(x,y,z)))       FAIL(err)
-
-#define OP_GETSLICE(x,y,z,r,err)  {					\
-		PyObject *__yo = y, *__zo = z;				\
-		int __y = 0, __z = INT_MAX;				\
-		if (__yo == Py_None) __yo = NULL;			\
-		if (__zo == Py_None) __zo = NULL;			\
-		if (!_PyEval_SliceIndex(__yo, &__y) ||			\
-		    !_PyEval_SliceIndex(__zo, &__z) ||			\
-		    !(r=PySequence_GetSlice(x, __y, __z))) FAIL(err)	\
-	}
-
-#define OP_ALLOC_AND_SET(x,y,r,err) { \
-		/* XXX check for long/int overflow */ \
-		int __i, __x = PyInt_AsLong(x); \
-		if (PyErr_Occurred()) FAIL(err) \
-		if (!(r = PyList_New(__x))) FAIL(err) \
-		for (__i=0; __i<__x; __i++) { \
-			Py_INCREF(y); \
-			PyList_SET_ITEM(r, __i, y); \
-		} \
-	}
-
-#define OP_ITER(x,r,err)          if (!(r=PyObject_GetIter(x)))      FAIL(err)
-#define OP_NEXT(x,r,err)          if (!(r=PyIter_Next(x))) {                   \
-		if (!PyErr_Occurred()) PyErr_SetNone(PyExc_StopIteration);     \
-		FAIL(err)                                                      \
-	}
-
-#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
-					FAIL(err)
-#define OP_CALL_ARGS(args,r,err)   if (!(r=CallWithShape args))    FAIL(err)
-
-/* Needs to act like getattr(x, '__class__', type(x)) */
-#define OP_TYPE(x,r,err) { \
-		PyObject *o = x; \
-		if (PyInstance_Check(o)) { \
-			r = (PyObject*)(((PyInstanceObject*)o)->in_class); \
-		} else { \
-			r = (PyObject*)o->ob_type; \
-		} \
-		Py_INCREF(r); \
-	}
-
-/* Needs to act like instance(x,y) */
-#define OP_ISSUBTYPE(x,y,r,err)  \
-		op_bool(r,err,PyClass_IsSubclass(x, y))
-
-
-/*** misc ***/
-
-#define MOVE(x, y)             y = x;
-
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
-
-
-#if defined(USE_CALL_TRACE)
-
-#define TRACE_CALL       __f, __tstate
-#define TRACE_ARGS       PyFrameObject *__f, PyThreadState *__tstate
-
-#define FAIL(err) { __f->f_lineno = __f->f_code->co_firstlineno = __LINE__; goto err; }
-
-#define FUNCTION_HEAD(signature, self, args, names, file, line) \
-	PyThreadState *__tstate = PyThreadState_GET(); \
-	PyObject *__localnames = PyList_CrazyStringPack names; \
-	PyFrameObject *__f = traced_function_head(self, args, signature, file, line, __tstate, __localnames);
-
-#define FUNCTION_CHECK() \
-	assert (__f != NULL);
-
-#define ERR_DECREF(arg) { if (__f->f_locals) { PyDict_SetItemString(__f->f_locals, #arg, arg); } Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return traced_function_tail(rval, __f, __tstate);
-
-#else /* !defined(USE_CALL_TRACE) */
-
-#define FAIL(err) { goto err; }
-
-#define ERR_DECREF(arg) { Py_DECREF(arg); }
-
-#define FUNCTION_RETURN(rval) return rval;
-
-#endif /* defined(USE_CALL_TRACE) */
-
-
-
-
 
 /* we need a subclass of 'builtin_function_or_method' which can be used
    as methods: builtin function objects that can be bound on instances */
@@ -247,128 +55,8 @@
 	0,					/* tp_descr_set */
 };
 
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
-	PyMODINIT_FUNC init##modname(void)
-
-#define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
-	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
-	this_module_globals = PyModule_GetDict(m); \
-	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\
-	PyType_Ready(&PyGenCFunction_Type);	\
-	if (setup_globalfunctions(globalfunctiondefs) < 0) \
-		return;	\
-	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
-		return;	\
-	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return;
-
-
-/*** table of global objects ***/
-
-typedef struct {
-	PyObject** p;
-	char* name;
-} globalobjectdef_t;
-
-typedef struct {
-	PyObject** p;
-	PyMethodDef ml;
-} globalfunctiondef_t;
 
-static int setup_globalobjects(globalobjectdef_t* def)
-{
-	PyObject* obj;
-	
-	for (; def->p != NULL; def++) {
-		obj = PyDict_GetItemString(this_module_globals, def->name);
-		if (obj == NULL) {
-			PyErr_Format(PyExc_AttributeError,
-				     "initialization code should have "
-				     "created '%s'", def->name);
-			return -1;
-		}
-		Py_INCREF(obj);
-		*def->p = obj;   /* store the object ref in the global var */
-	}
-	return 0;
-}
-
-static int setup_globalfunctions(globalfunctiondef_t* def)
-{
-	PyObject* fn;
-	PyObject* name;
-	int len;
-
-	for (; def->p != NULL; def++) {
-		fn = PyCFunction_New(&def->ml, NULL);
-		if (fn == NULL)
-			return -1;
-		fn->ob_type = &PyGenCFunction_Type;
-		*def->p = fn;   /* store the object ref in the global var */
-
-		len = 0;
-		while (def->ml.ml_name[len] != 0)
-			len++;
-		name = PyString_FromStringAndSize(NULL, 6+len);
-		if (name == NULL)
-			return -1;
-		memcpy(PyString_AS_STRING(name), "gfunc_", 6);
-		memcpy(PyString_AS_STRING(name)+6, def->ml.ml_name, len);
-		if (PyDict_SetItem(this_module_globals, name, fn) < 0)
-			return -1;
-		Py_DECREF(name);
-	}
-	return 0;
-}
-
-static int setup_initcode(char* frozendata[], int len)
-{
-	PyObject* co;
-	PyObject* globals;
-	PyObject* res;
-	char *buffer, *bufp;
-	int chunk, count = 0;
-	
-	buffer = PyMem_NEW(char, len);
-	if (buffer == NULL)
-		return -1;
-	bufp = buffer;
-	while (count < len) {
-		chunk = len-count < 1024 ? len-count : 1024;
-		memcpy(bufp, *frozendata, chunk);
-		bufp += chunk;
-		count += chunk;
-		++frozendata;
-	}
-	co = PyMarshal_ReadObjectFromString(buffer, len);
-	if (co == NULL)
-		return -1;
-	PyMem_DEL(buffer);
-	if (!PyCode_Check(co)) {
-		PyErr_SetString(PyExc_TypeError, "uh?");
-		return -1;
-	}
-	globals = this_module_globals;
-	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
-		PyDict_SetItemString(globals, "__builtins__",
-				     PyEval_GetBuiltins());
-	res = PyEval_EvalCode((PyCodeObject *) co, globals, globals);
-	if (res == NULL)
-		return -1;
-	Py_DECREF(res);
-	return 0;
-}
-
-
-/*** operations with a variable number of arguments ***/
-
-#define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
-#define OP_NEWLIST(args,r,err)     if (!(r=PyList_Pack args)) FAIL(err)
-#define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
-#define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
-#define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
+/*** misc support functions ***/
 
 static PyObject* PyList_Pack(int n, ...)
 {
@@ -601,273 +289,3 @@
 	Py_XDECREF(t);
 	return result;
 }
-
-
-#if defined(USE_CALL_TRACE)
-
-static int callstack_depth = -1;
-static PyCodeObject* getcode(char *func_name, char *func_filename, int lineno);
-static int trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val);
-static int trace_frame_exc(PyThreadState *tstate, PyFrameObject *f);
-
-static int
-trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
-{
-	int result = 0;
-	if (!tstate->use_tracing || tstate->tracing) {
-		/*printf("if (!tstate->use_tracing || tstate->tracing)\n");*/
-		return 0;
-	}
-	if (tstate->c_profilefunc != NULL) {
-		/*printf("if (tstate->c_profilefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_profilefunc(tstate->c_profileobj,
-						   f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-		if (result) {
-			/*printf("	if (result)\n");*/
-			return result;
-		}
-	}
-	if (tstate->c_tracefunc != NULL) {
-		/*printf("if (tstate->c_tracefunc != NULL)\n");*/
-		tstate->tracing++;
-		result = tstate->c_tracefunc(tstate->c_traceobj,
-						 f, code , val);
-		tstate->use_tracing = ((tstate->c_tracefunc != NULL)
-					   || (tstate->c_profilefunc != NULL));
-		tstate->tracing--;
-	}   
-	/*printf("return result;\n");*/
-	return result;
-}
-
-static int
-trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
-{
-	PyObject *type, *value, *traceback, *arg;
-	int err;
-
-	if (tstate->c_tracefunc == NULL) {
-		return 0;
-	}
-
-	PyErr_Fetch(&type, &value, &traceback);
-	if (value == NULL) {
-		value = Py_None;
-		Py_INCREF(value);
-	}
-	arg = PyTuple_Pack(3, type, value, traceback);
-	if (arg == NULL) {
-		PyErr_Restore(type, value, traceback);
-		return 0;
-	}
-	err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
-	Py_DECREF(arg);
-	if (err == 0) {
-		PyErr_Restore(type, value, traceback);
-	} else {
-		Py_XDECREF(type);
-		Py_XDECREF(value);
-		Py_XDECREF(traceback);
-	}
-	return err;
-}
-
-static PyCodeObject*
-getcode(char *func_name, char *func_filename, int lineno)
-{
-	PyObject *code = NULL;
-	PyObject *name = NULL;
-	PyObject *nulltuple = NULL;
-	PyObject *filename = NULL;
-	PyCodeObject *tb_code = NULL;
-#if defined(OBNOXIOUS_PRINT_STATEMENTS)
-	int i;
-
-	printf("%5d: ", lineno);
-	assert(callstack_depth >= 0);
-	if (callstack_depth) {
-		for (i=0; i<callstack_depth; ++i) {
-			printf("  ");
-		}
-	}
-	printf("%s\n", func_name);
-#endif /* !defined(OBNOXIOUS_PRINT_STATEMENTS) */
-
-	code = PyString_FromString("");
-	if (code == NULL)
-		goto failed;
-	name = PyString_FromString(func_name);
-	if (name == NULL)
-		goto failed;
-	nulltuple = PyTuple_New(0);
-	if (nulltuple == NULL)
-		goto failed;
-	filename = PyString_FromString(func_filename);
-	tb_code = PyCode_New(0,       /* argcount */
-						 0,       /* nlocals */
-						 0,       /* stacksize */
-						 0,       /* flags */
-						 code,        /* code */
-						 nulltuple,   /* consts */
-						 nulltuple,   /* names */
-						 nulltuple,   /* varnames */
-						 nulltuple,   /* freevars */
-						 nulltuple,   /* cellvars */
-						 filename,    /* filename */
-						 name,        /* name */
-						 lineno,      /* firstlineno */
-						 code     /* lnotab */
-						 );
-	if (tb_code == NULL)
-		goto failed;
-	Py_DECREF(code);
-	Py_DECREF(nulltuple);
-	Py_DECREF(filename);
-	Py_DECREF(name);
-	return tb_code;
-failed:
-	Py_XDECREF(code);
-	Py_XDECREF(name);
-	return NULL;
-}
-
-static PyFrameObject *traced_function_head(PyObject *function, PyObject *args, char *c_signature, char *filename, int c_lineno, PyThreadState *tstate, PyObject *extra_local_names) {
-	/*
-		STEALS a reference to extra_local_names if not NULL
-	*/
-
-	PyCodeObject *c;
-	PyFrameObject *f;
-	PyObject *locals;
-	PyObject *locals_signature;
-	PyObject *locals_lineno;
-	PyObject *locals_filename;
-
-	assert(function && args && tstate);
-
-	locals = PyDict_New();
-	locals_signature = PyString_FromString(c_signature);
-	locals_lineno = PyInt_FromLong(c_lineno);
-	locals_filename = PyString_FromString(filename);
-	if (locals == NULL || function == NULL || args == NULL || 
-		locals_signature == NULL || locals_lineno == NULL ||
-		locals_filename == NULL) {
-		Py_XDECREF(locals);
-		Py_XDECREF(locals_signature);
-		Py_XDECREF(locals_lineno);
-		Py_XDECREF(locals_filename);
-		return NULL;
-	}
-	PyDict_SetItemString(locals, "function", function);
-	PyDict_SetItemString(locals, "args", args);
-	PyDict_SetItemString(locals, "signature", locals_signature);
-	PyDict_SetItemString(locals, "lineno", locals_lineno);
-	PyDict_SetItemString(locals, "filename", locals_filename);
-	Py_DECREF(locals_signature);
-	Py_DECREF(locals_lineno);
-	Py_DECREF(locals_filename);
-	if (extra_local_names != NULL) {
-		int max_locals = MIN(PyList_Size(extra_local_names), PyTuple_Size(args));
-        int i;
-		for (i = 0; i < max_locals; ++i) {
-			PyDict_SetItem(locals, PyList_GET_ITEM(extra_local_names, i), PyTuple_GET_ITEM(args, i));
-		}
-		Py_DECREF(extra_local_names);
-	}
-
-	callstack_depth++;
-	c = getcode(c_signature, filename, c_lineno);
-	if (c == NULL) {
-		Py_DECREF(locals);
-		callstack_depth--;
-		return NULL;
-	}
-	f = PyFrame_New(tstate, c, this_module_globals, locals);
-	if (f == NULL) {
-		callstack_depth--;
-		return NULL;
-	}
-	Py_DECREF(c);
-	Py_DECREF(locals);
-	tstate->frame = f;
-	if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
-		Py_DECREF(args);
-		callstack_depth--;
-		return NULL;
-	}
-
-	return f;
-}
-
-static PyObject *traced_function_tail(PyObject *rval, PyFrameObject *f, PyThreadState *tstate) {
-	/*
-		STEALS a reference to f
-	*/
-	if (f == NULL) {
-		goto bad_args;
-	}
-	if (rval == NULL) {
-		if (tstate->curexc_traceback == NULL) {
-			PyTraceBack_Here(f);
-		}
-		if (trace_frame_exc(tstate, f) < 0) {
-			goto end;
-		}
-	} else {
-		if (trace_frame(tstate, f, PyTrace_RETURN, rval) < 0) {
-			Py_DECREF(rval);
-			rval = NULL;
-		}
-	}
-end:
-	tstate->frame = f->f_back;
-	Py_DECREF(f);
-bad_args:
-	callstack_depth--;
-	return rval;
-}
-
-static PyObject* PyList_CrazyStringPack(char *begin, ...)
-{
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	result = PyList_New(0);
-	if (result == NULL || begin == NULL) {
-		return result;
-	}
-	va_start(vargs, begin);
-	o = PyString_FromString(begin);
-	if (o == NULL) {
-		Py_XDECREF(result);
-		return NULL;
-	}
-	if (PyList_Append(result, o) == -1) {
-		Py_DECREF(o);
-		Py_XDECREF(result);
-		return result;
-	}
-	Py_DECREF(o);
-	while ((begin = va_arg(vargs, char *)) != NULL) {
-		o = PyString_FromString(begin);
-		if (o == NULL) {
-			Py_XDECREF(result);
-			return NULL;
-		}
-		if (PyList_Append(result, o) == -1) {
-			Py_DECREF(o);
-			Py_XDECREF(result);
-			return NULL;
-		}
-		Py_DECREF(o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-#endif /* defined(USE_CALL_TRACE) */

Copied: pypy/dist/pypy/translator/genc/g_trace.h (from r10250, pypy/dist/pypy/translator/genc.h)
==============================================================================
--- pypy/dist/pypy/translator/genc.h	(original)
+++ pypy/dist/pypy/translator/genc/g_trace.h	Sat Apr  2 17:57:37 2005
@@ -1,22 +1,6 @@
 
 /************************************************************/
-/***  Generic C header section                            ***/
-
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include "structmember.h"
-#include "traceback.h"
-#include "marshal.h"
-#include "eval.h"
-
-#if !defined(MIN)
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif /* MIN */
-
-#include "genc_type.h"
-
-static PyObject *this_module_globals;
+ /***  C header subsection: pdb tracing of calls           ***/
 
 /* Set genc_funcdef.USE_CALL_TRACE if you want call trace frames to be built */
 
@@ -24,148 +8,8 @@
 #define OBNOXIOUS_PRINT_STATEMENTS
 #endif
 
-#define op_bool(r,err,what) { \
-		int _retval = what; \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyBool_FromLong(_retval); \
-	}
-
-#define op_richcmp(x,y,r,err,dir) \
-					if (!(r=PyObject_RichCompare(x,y,dir))) FAIL(err)
-#define OP_LT(x,y,r,err)  op_richcmp(x,y,r,err, Py_LT)
-#define OP_LE(x,y,r,err)  op_richcmp(x,y,r,err, Py_LE)
-#define OP_EQ(x,y,r,err)  op_richcmp(x,y,r,err, Py_EQ)
-#define OP_NE(x,y,r,err)  op_richcmp(x,y,r,err, Py_NE)
-#define OP_GT(x,y,r,err)  op_richcmp(x,y,r,err, Py_GT)
-#define OP_GE(x,y,r,err)  op_richcmp(x,y,r,err, Py_GE)
-
-#define OP_IS_(x,y,r,err) op_bool(r,err,(x == y))
-
-#define OP_IS_TRUE(x,r,err) op_bool(r,err,PyObject_IsTrue(x))
-
-#define OP_LEN(x,r,err) { \
-		int _retval = PyObject_Size(x); \
-		if (_retval < 0) { \
-			FAIL(err) \
-		} \
-		r = PyInt_FromLong(_retval); \
-	}
-#define OP_NEG(x,r,err)           if (!(r=PyNumber_Negative(x)))     FAIL(err)
-#define OP_POS(x,r,err)           if (!(r=PyNumber_Positive(x)))     FAIL(err)
-#define OP_INVERT(x,r,err)        if (!(r=PyNumber_Invert(x)))       FAIL(err)
-
-#define OP_ADD(x,y,r,err)         if (!(r=PyNumber_Add(x,y)))        FAIL(err)
-#define OP_SUB(x,y,r,err)         if (!(r=PyNumber_Subtract(x,y)))   FAIL(err)
-#define OP_MUL(x,y,r,err)         if (!(r=PyNumber_Multiply(x,y)))   FAIL(err)
-#define OP_TRUEDIV(x,y,r,err)     if (!(r=PyNumber_TrueDivide(x,y))) FAIL(err)
-#define OP_FLOORDIV(x,y,r,err)    if (!(r=PyNumber_FloorDivide(x,y)))FAIL(err)
-#define OP_DIV(x,y,r,err)         if (!(r=PyNumber_Divide(x,y)))     FAIL(err)
-#define OP_MOD(x,y,r,err)         if (!(r=PyNumber_Remainder(x,y)))  FAIL(err)
-#define OP_POW(x,y,z,r,err)       if (!(r=PyNumber_Power(x,y,z)))    FAIL(err)
-#define OP_LSHIFT(x,y,r,err)      if (!(r=PyNumber_Lshift(x,y)))     FAIL(err)
-#define OP_RSHIFT(x,y,r,err)      if (!(r=PyNumber_Rshift(x,y)))     FAIL(err)
-#define OP_AND_(x,y,r,err)        if (!(r=PyNumber_And(x,y)))        FAIL(err)
-#define OP_OR_(x,y,r,err)         if (!(r=PyNumber_Or(x,y)))         FAIL(err)
-#define OP_XOR(x,y,r,err)         if (!(r=PyNumber_Xor(x,y)))        FAIL(err)
-
-#define OP_INPLACE_ADD(x,y,r,err) if (!(r=PyNumber_InPlaceAdd(x,y)))           \
-								     FAIL(err)
-#define OP_INPLACE_SUB(x,y,r,err) if (!(r=PyNumber_InPlaceSubtract(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_MUL(x,y,r,err) if (!(r=PyNumber_InPlaceMultiply(x,y)))      \
-								     FAIL(err)
-#define OP_INPLACE_TRUEDIV(x,y,r,err) if (!(r=PyNumber_InPlaceTrueDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_FLOORDIV(x,y,r,err)if(!(r=PyNumber_InPlaceFloorDivide(x,y)))\
-								     FAIL(err)
-#define OP_INPLACE_DIV(x,y,r,err) if (!(r=PyNumber_InPlaceDivide(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_MOD(x,y,r,err) if (!(r=PyNumber_InPlaceRemainder(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_POW(x,y,r,err) if (!(r=PyNumber_InPlacePower(x,y,Py_None))) \
-								     FAIL(err)
-#define OP_INPLACE_LSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceLshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_RSHIFT(x,y,r,err) if (!(r=PyNumber_InPlaceRshift(x,y)))     \
-								     FAIL(err)
-#define OP_INPLACE_AND(x,y,r,err)    if (!(r=PyNumber_InPlaceAnd(x,y)))        \
-								     FAIL(err)
-#define OP_INPLACE_OR(x,y,r,err)     if (!(r=PyNumber_InPlaceOr(x,y)))         \
-								     FAIL(err)
-#define OP_INPLACE_XOR(x,y,r,err)    if (!(r=PyNumber_InPlaceXor(x,y)))        \
-								     FAIL(err)
-
-#define OP_GETITEM(x,y,r,err)     if (!(r=PyObject_GetItem1(x,y)))   FAIL(err)
-#define OP_SETITEM(x,y,z,r,err)   if ((PyObject_SetItem1(x,y,z))<0)  FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELITEM(x,y,r,err)     if ((PyObject_DelItem(x,y))<0)     FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_CONTAINS(x,y,r,err)    op_bool(r,err,(PySequence_Contains(x,y)))
-
-#define OP_GETATTR(x,y,r,err)     if (!(r=PyObject_GetAttr(x,y)))    FAIL(err)
-#define OP_SETATTR(x,y,z,r,err)   if ((PyObject_SetAttr(x,y,z))<0)   FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-#define OP_DELATTR(x,y,r,err)     if ((PyObject_SetAttr(x,y,NULL))<0)FAIL(err) \
-				  r=Py_None; Py_INCREF(r);
-
-#define OP_NEWSLICE(x,y,z,r,err)  if (!(r=PySlice_New(x,y,z)))       FAIL(err)
-
-#define OP_GETSLICE(x,y,z,r,err)  {					\
-		PyObject *__yo = y, *__zo = z;				\
-		int __y = 0, __z = INT_MAX;				\
-		if (__yo == Py_None) __yo = NULL;			\
-		if (__zo == Py_None) __zo = NULL;			\
-		if (!_PyEval_SliceIndex(__yo, &__y) ||			\
-		    !_PyEval_SliceIndex(__zo, &__z) ||			\
-		    !(r=PySequence_GetSlice(x, __y, __z))) FAIL(err)	\
-	}
-
-#define OP_ALLOC_AND_SET(x,y,r,err) { \
-		/* XXX check for long/int overflow */ \
-		int __i, __x = PyInt_AsLong(x); \
-		if (PyErr_Occurred()) FAIL(err) \
-		if (!(r = PyList_New(__x))) FAIL(err) \
-		for (__i=0; __i<__x; __i++) { \
-			Py_INCREF(y); \
-			PyList_SET_ITEM(r, __i, y); \
-		} \
-	}
-
-#define OP_ITER(x,r,err)          if (!(r=PyObject_GetIter(x)))      FAIL(err)
-#define OP_NEXT(x,r,err)          if (!(r=PyIter_Next(x))) {                   \
-		if (!PyErr_Occurred()) PyErr_SetNone(PyExc_StopIteration);     \
-		FAIL(err)                                                      \
-	}
-
-#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
-					FAIL(err)
-#define OP_CALL_ARGS(args,r,err)   if (!(r=CallWithShape args))    FAIL(err)
-
-/* Needs to act like getattr(x, '__class__', type(x)) */
-#define OP_TYPE(x,r,err) { \
-		PyObject *o = x; \
-		if (PyInstance_Check(o)) { \
-			r = (PyObject*)(((PyInstanceObject*)o)->in_class); \
-		} else { \
-			r = (PyObject*)o->ob_type; \
-		} \
-		Py_INCREF(r); \
-	}
-
-/* Needs to act like instance(x,y) */
-#define OP_ISSUBTYPE(x,y,r,err)  \
-		op_bool(r,err,PyClass_IsSubclass(x, y))
-
-
-/*** misc ***/
-
-#define MOVE(x, y)             y = x;
-
-#define INITCHK(expr)          if (!(expr)) return;
-#define REGISTER_GLOBAL(name)  Py_INCREF(name); PyModule_AddObject(m, #name, name);
 
+/***  Interface  ***/
 
 #if defined(USE_CALL_TRACE)
 
@@ -197,411 +41,7 @@
 #endif /* defined(USE_CALL_TRACE) */
 
 
-
-
-
-/* we need a subclass of 'builtin_function_or_method' which can be used
-   as methods: builtin function objects that can be bound on instances */
-static PyObject *
-gencfunc_descr_get(PyObject *func, PyObject *obj, PyObject *type)
-{
-	if (obj == Py_None)
-		obj = NULL;
-	return PyMethod_New(func, obj, type);
-}
-static PyTypeObject PyGenCFunction_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,
-	"pypy_generated_function",
-	sizeof(PyCFunctionObject),
-	0,
-	0,					/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	0,					/* tp_repr */
-	0,					/* tp_as_number */
-	0,					/* tp_as_sequence */
-	0,					/* tp_as_mapping */
-	0,					/* tp_hash */
-	0,					/* tp_call */
-	0,					/* tp_str */
-	0,					/* tp_getattro */
-	0,					/* tp_setattro */
-	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	0,					/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	0,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	/*&PyCFunction_Type set below*/ 0,	/* tp_base */
-	0,					/* tp_dict */
-	gencfunc_descr_get,			/* tp_descr_get */
-	0,					/* tp_descr_set */
-};
-
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
-	PyMODINIT_FUNC init##modname(void)
-
-#define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
-	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
-	this_module_globals = PyModule_GetDict(m); \
-	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\
-	PyType_Ready(&PyGenCFunction_Type);	\
-	if (setup_globalfunctions(globalfunctiondefs) < 0) \
-		return;	\
-	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
-		return;	\
-	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return;
-
-
-/*** table of global objects ***/
-
-typedef struct {
-	PyObject** p;
-	char* name;
-} globalobjectdef_t;
-
-typedef struct {
-	PyObject** p;
-	PyMethodDef ml;
-} globalfunctiondef_t;
-
-static int setup_globalobjects(globalobjectdef_t* def)
-{
-	PyObject* obj;
-	
-	for (; def->p != NULL; def++) {
-		obj = PyDict_GetItemString(this_module_globals, def->name);
-		if (obj == NULL) {
-			PyErr_Format(PyExc_AttributeError,
-				     "initialization code should have "
-				     "created '%s'", def->name);
-			return -1;
-		}
-		Py_INCREF(obj);
-		*def->p = obj;   /* store the object ref in the global var */
-	}
-	return 0;
-}
-
-static int setup_globalfunctions(globalfunctiondef_t* def)
-{
-	PyObject* fn;
-	PyObject* name;
-	int len;
-
-	for (; def->p != NULL; def++) {
-		fn = PyCFunction_New(&def->ml, NULL);
-		if (fn == NULL)
-			return -1;
-		fn->ob_type = &PyGenCFunction_Type;
-		*def->p = fn;   /* store the object ref in the global var */
-
-		len = 0;
-		while (def->ml.ml_name[len] != 0)
-			len++;
-		name = PyString_FromStringAndSize(NULL, 6+len);
-		if (name == NULL)
-			return -1;
-		memcpy(PyString_AS_STRING(name), "gfunc_", 6);
-		memcpy(PyString_AS_STRING(name)+6, def->ml.ml_name, len);
-		if (PyDict_SetItem(this_module_globals, name, fn) < 0)
-			return -1;
-		Py_DECREF(name);
-	}
-	return 0;
-}
-
-static int setup_initcode(char* frozendata[], int len)
-{
-	PyObject* co;
-	PyObject* globals;
-	PyObject* res;
-	char *buffer, *bufp;
-	int chunk, count = 0;
-	
-	buffer = PyMem_NEW(char, len);
-	if (buffer == NULL)
-		return -1;
-	bufp = buffer;
-	while (count < len) {
-		chunk = len-count < 1024 ? len-count : 1024;
-		memcpy(bufp, *frozendata, chunk);
-		bufp += chunk;
-		count += chunk;
-		++frozendata;
-	}
-	co = PyMarshal_ReadObjectFromString(buffer, len);
-	if (co == NULL)
-		return -1;
-	PyMem_DEL(buffer);
-	if (!PyCode_Check(co)) {
-		PyErr_SetString(PyExc_TypeError, "uh?");
-		return -1;
-	}
-	globals = this_module_globals;
-	if (PyDict_GetItemString(globals, "__builtins__") == NULL)
-		PyDict_SetItemString(globals, "__builtins__",
-				     PyEval_GetBuiltins());
-	res = PyEval_EvalCode((PyCodeObject *) co, globals, globals);
-	if (res == NULL)
-		return -1;
-	Py_DECREF(res);
-	return 0;
-}
-
-
-/*** operations with a variable number of arguments ***/
-
-#define OP_NEWLIST0(r,err)         if (!(r=PyList_New(0))) FAIL(err)
-#define OP_NEWLIST(args,r,err)     if (!(r=PyList_Pack args)) FAIL(err)
-#define OP_NEWDICT0(r,err)         if (!(r=PyDict_New())) FAIL(err)
-#define OP_NEWDICT(args,r,err)     if (!(r=PyDict_Pack args)) FAIL(err)
-#define OP_NEWTUPLE(args,r,err)    if (!(r=PyTuple_Pack args)) FAIL(err)
-
-static PyObject* PyList_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyList_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyList_SET_ITEM(result, i, o);
-	}
-	va_end(vargs);
-	return result;
-}
-
-static PyObject* PyDict_Pack(int n, ...)
-{
-	int i;
-	PyObject *key, *val;
-	PyObject *result;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyDict_New();
-	if (result == NULL) {
-		return NULL;
-	}
-	for (i = 0; i < n; i++) {
-		key = va_arg(vargs, PyObject *);
-		val = va_arg(vargs, PyObject *);
-		if (PyDict_SetItem(result, key, val) < 0) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
-	va_end(vargs);
-	return result;
-}
-
-#if PY_VERSION_HEX < 0x02040000   /* 2.4 */
-static PyObject* PyTuple_Pack(int n, ...)
-{
-	int i;
-	PyObject *o;
-	PyObject *result;
-	PyObject **items;
-	va_list vargs;
-
-	va_start(vargs, n);
-	result = PyTuple_New(n);
-	if (result == NULL) {
-		return NULL;
-	}
-	items = ((PyTupleObject *)result)->ob_item;
-	for (i = 0; i < n; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		items[i] = o;
-	}
-	va_end(vargs);
-	return result;
-}
-#endif
-
-#if PY_VERSION_HEX >= 0x02030000   /* 2.3 */
-# define PyObject_GetItem1  PyObject_GetItem
-# define PyObject_SetItem1  PyObject_SetItem
-#else
-/* for Python 2.2 only */
-static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_GetItem(obj, index);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_GetSlice(obj, start, stop);
-}
-static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
-{
-	int start, stop, step;
-	if (!PySlice_Check(index)) {
-		return PyObject_SetItem(obj, index, v);
-	}
-	if (((PySliceObject*) index)->start == Py_None) {
-		start = -INT_MAX-1;
-	} else {
-		start = PyInt_AsLong(((PySliceObject*) index)->start);
-		if (start == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->stop == Py_None) {
-		stop = INT_MAX;
-	} else {
-		stop = PyInt_AsLong(((PySliceObject*) index)->stop);
-		if (stop == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-	}
-	if (((PySliceObject*) index)->step != Py_None) {
-		step = PyInt_AsLong(((PySliceObject*) index)->step);
-		if (step == -1 && PyErr_Occurred()) {
-			return NULL;
-		}
-		if (step != 1) {
-			PyErr_SetString(PyExc_ValueError,
-					"obj[slice]: no step allowed");
-			return NULL;
-		}
-	}
-	return PySequence_SetSlice(obj, start, stop, v);
-}
-#endif
-
-static PyObject* CallWithShape(PyObject* callable, PyObject* shape, ...)
-{
-	/* XXX the 'shape' argument is a tuple as specified by
-	   XXX pypy.interpreter.argument.fromshape().  This code should
-	   XXX we made independent on the format of the 'shape' later... */
-	PyObject* result = NULL;
-	PyObject* t = NULL;
-	PyObject* d = NULL;
-	PyObject* o;
-	PyObject* key;
-	PyObject* t2;
-	int i, nargs, nkwds, starflag, starstarflag;
-	va_list vargs;
-
-	if (!PyTuple_Check(shape) ||
-	    PyTuple_GET_SIZE(shape) != 4 ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 0)) ||
-	    !PyTuple_Check(PyTuple_GET_ITEM(shape, 1)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 2)) ||
-	    !PyInt_Check(PyTuple_GET_ITEM(shape, 3))) {
-		Py_FatalError("in genc.h: invalid 'shape' argument");
-	}
-	nargs = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 0));
-	nkwds = PyTuple_GET_SIZE(PyTuple_GET_ITEM(shape, 1));
-	starflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 2));
-	starstarflag = PyInt_AS_LONG(PyTuple_GET_ITEM(shape, 3));
-
-	va_start(vargs, shape);
-	t = PyTuple_New(nargs);
-	if (t == NULL)
-		goto finally;
-	for (i = 0; i < nargs; i++) {
-		o = va_arg(vargs, PyObject *);
-		Py_INCREF(o);
-		PyTuple_SET_ITEM(t, i, o);
-	}
-	if (nkwds) {
-		d = PyDict_New();
-		if (d == NULL)
-			goto finally;
-		for (i = 0; i < nkwds; i++) {
-			o = va_arg(vargs, PyObject *);
-			key = PyTuple_GET_ITEM(PyTuple_GET_ITEM(shape, 1), i);
-			if (PyDict_SetItem(d, key, o) < 0)
-				goto finally;
-		}
-	}
-	if (starflag) {
-		o = va_arg(vargs, PyObject *);
-		o = PySequence_Tuple(o);
-		if (o == NULL)
-			goto finally;
-		t2 = PySequence_Concat(t, o);
-		Py_DECREF(o);
-		Py_DECREF(t);
-		t = t2;
-		if (t == NULL)
-			goto finally;
-	}
-	if (starstarflag) {
-		int len1, len2, len3;
-		o = va_arg(vargs, PyObject *);
-		len1 = PyDict_Size(d);
-		len2 = PyDict_Size(o);
-		if (len1 < 0 || len2 < 0)
-			goto finally;
-		if (PyDict_Update(d, o) < 0)
-			goto finally;
-		len3 = PyDict_Size(d);
-		if (len1 + len2 != len3) {
-			PyErr_SetString(PyExc_TypeError,
-					"genc.h: duplicate keyword arguments");
-			goto finally;
-		}
-	}
-	va_end(vargs);
-
-	result = PyObject_Call(callable, t, d);
-
- finally:
-	Py_XDECREF(d);
-	Py_XDECREF(t);
-	return result;
-}
-
+/***  Implementation  ***/
 
 #if defined(USE_CALL_TRACE)
 

Copied: pypy/dist/pypy/translator/genc/genc.py (from r10250, pypy/dist/pypy/translator/genc.py)
==============================================================================
--- pypy/dist/pypy/translator/genc.py	(original)
+++ pypy/dist/pypy/translator/genc/genc.py	Sat Apr  2 17:57:37 2005
@@ -8,8 +8,8 @@
 from pypy.translator.gensupp import uniquemodulename
 from pypy.translator.gensupp import NameManager
 
-from pypy.translator.genc_funcdef import FunctionDef, USE_CALL_TRACE
-from pypy.translator.genc_pyobj import CType_PyObject, ctypeof
+from pypy.translator.genc.funcdef import FunctionDef, USE_CALL_TRACE
+from pypy.translator.genc.t_pyobj import CType_PyObject, ctypeof
 
 # ____________________________________________________________
 
@@ -174,7 +174,7 @@
 
 # ____________________________________________________________
 
-    C_HEADER = '#include "genc.h"\n'
+    C_HEADER = '#include "g_include.h"\n'
 
     C_SEP = "/************************************************************/"
 

Added: pypy/dist/pypy/translator/genc/test/__init__.py
==============================================================================

Copied: pypy/dist/pypy/translator/genc/test/test_ctrans.py (from r10251, pypy/dist/pypy/translator/test/test_ctrans.py)
==============================================================================
--- pypy/dist/pypy/translator/test/test_ctrans.py	(original)
+++ pypy/dist/pypy/translator/genc/test/test_ctrans.py	Sat Apr  2 17:57:37 2005
@@ -1,8 +1,8 @@
 import autopath
 import py, sys
 from pypy.tool.udir import udir
-from pypy.translator.genc import GenC
-from pypy.translator.typer import GenCSpecializer
+from pypy.translator.genc.genc import GenC
+from pypy.translator.genc.ctyper import GenCSpecializer
 from pypy.objspace.flow.model import *
 from pypy.translator.tool.buildpyxmodule import make_module_from_c
 from pypy.translator.tool.buildpyxmodule import skip_missing_compiler

Deleted: /pypy/dist/pypy/translator/genc_funcdef.py
==============================================================================
--- /pypy/dist/pypy/translator/genc_funcdef.py	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,486 +0,0 @@
-from __future__ import generators
-from pypy.objspace.flow.model import Variable, Constant
-from pypy.objspace.flow.model import traverse, uniqueitems, checkgraph
-from pypy.objspace.flow.model import Block, Link
-from pypy.objspace.flow.model import last_exception, last_exc_value
-from pypy.translator.unsimplify import remove_direct_loops
-from pypy.interpreter.pycode import CO_VARARGS
-from types import FunctionType
-
-from pypy.translator.gensupp import c_string
-from pypy.translator.genc_pyobj import ctypeof
-
-# Set this if you want call trace frames to be built
-USE_CALL_TRACE = False
-
-
-class FunctionDef:
-    """
-    Collects information about a function which we have to generate.
-    The operations of each function are collected in a C function
-    with signature:
-
-        static T fn_xxx(T1 arg1, T2 arg2, etc);
-
-    where the T, T1, T2.. are C types like 'int' or 'PyObject *'.
-
-    If needed, another wrapper function is created with a signature
-    suitable for the built-in function type of CPython:
-
-        static PyObject *pyfn_xxx(PyObject *self, PyObject *args, PyObject* kw);
-
-    The built-in function object, if needed, is put in the global
-    variable named gfn_xxx.
-    """
-
-    def __init__(self, func, genc):
-        self.func = func
-        self.genc = genc
-
-        # get the function name
-        namespace = genc.namespace
-        self.fast_name = namespace.uniquename('fn_' + func.__name__) # fn_xxx
-        self.base_name = self.fast_name[3:]                          # xxx
-        self.wrapper_name = None                                     # pyfn_xxx
-        self.globalobject_name = None                                # gfunc_xxx
-        self.localscope = namespace.localScope()
-
-        # get the flow graph, and ensure that there is no direct loop in it
-        # as we cannot generate valid code for this case.
-        self.graph = graph = genc.translator.getflowgraph(func)
-        remove_direct_loops(genc.translator, graph)
-        checkgraph(graph)
-        graph_args = graph.getargs()
-
-        # collect all the local variables
-        localslst = []
-        def visit(node):
-            if isinstance(node, Block):
-                localslst.extend(node.getvariables())
-        traverse(visit, graph)
-        fast_set = dict(zip(graph_args, graph_args))
-        self.localnames = [self.decl(a) for a in localslst if a not in fast_set]
-
-        # collect all the arguments
-        fast_args         = [self.expr(a) for a in graph_args]
-        declare_fast_args = [self.decl(a) for a in graph_args]
-        if USE_CALL_TRACE:
-            declare_fast_args.insert(0, 'TRACE_ARGS')
-        declare_fast_args = ', '.join(declare_fast_args) or 'void'
-        name_and_arguments = '%s(%s)' % (self.fast_name, declare_fast_args)
-        ctret = ctypeof(graph.getreturnvar())
-        fast_function_header = 'static ' + (
-            ctret.ctypetemplate % (name_and_arguments,))
-
-        name_of_defaults = [self.genc.pyobjrepr.nameof(x, debug=('Default argument of',
-                                                       self))
-                            for x in (func.func_defaults or ())]
-
-        # store misc. information
-        self.fast_function_header = fast_function_header
-        self.graphargs = graph_args
-        self.ctret = ctret
-        self.vararg = bool(func.func_code.co_flags & CO_VARARGS)
-        self.fast_args = fast_args
-        self.name_of_defaults = name_of_defaults
-        
-        error_return = getattr(ctret, 'error_return', 'NULL')
-        self.return_error = 'FUNCTION_RETURN(%s)' % error_return
-
-        # generate the forward header
-        self.genc.globaldecl.append(fast_function_header + ';  /* forward */')
-
-
-    def get_globalobject(self):
-        if self.globalobject_name is None:
-            self.wrapper_name = 'py' + self.fast_name
-            self.globalobject_name = self.genc.pyobjrepr.uniquename('gfunc_' +
-                                                          self.base_name)
-        return self.globalobject_name
-
-    def clear(self):
-        del self.localscope
-        del self.localnames
-        del self.graph
-
-    def decl(self, v):
-        assert isinstance(v, Variable)
-        return ctypeof(v).ctypetemplate % (self.localscope.localname(v.name),)
-
-    def expr(self, v):
-        if isinstance(v, Variable):
-            return self.localscope.localname(v.name)
-        elif isinstance(v, Constant):
-            return self.genc.nameofconst(v,
-                                    debug=('Constant in the graph of', self))
-        else:
-            raise TypeError, "expr(%r)" % (v,)
-
-    # ____________________________________________________________
-
-    def gen_wrapper(self, f):
-        func             = self.func
-        f_name           = self.wrapper_name
-        name_of_defaults = self.name_of_defaults
-        graphargs        = self.graphargs
-        vararg           = self.vararg
-        nb_positional_args = len(graphargs) - vararg
-
-        min_number_of_args = nb_positional_args - len(name_of_defaults)
-        print >> f, 'static PyObject *'
-        print >> f, '%s(PyObject* self, PyObject* args, PyObject* kwds)' % (
-            f_name,)
-        print >> f, '{'
-        if USE_CALL_TRACE:
-            print >> f, '\tFUNCTION_HEAD(%s, %s, args, %s, __FILE__, __LINE__ - 2)' % (
-                c_string('%s(%s)' % (self.base_name, ', '.join(name_of_defaults))),
-                self.globalobject_name,
-                '(%s)' % (', '.join(map(c_string, name_of_defaults) + ['NULL']),),
-            )
-
-        kwlist = ['"%s"' % name for name in
-                      func.func_code.co_varnames[:func.func_code.co_argcount]]
-        kwlist.append('0')
-        print >> f, '\tstatic char* kwlist[] = {%s};' % (', '.join(kwlist),)
-
-        numberednames = ['o%d' % (i+1) for i in range(len(graphargs))]
-        if vararg:
-            numberednames[-1] = 'ovararg'
-        numberednames.append('oret')
-        print >> f, '\tPyObject *%s;' % (', *'.join(numberednames))
-        conversions = []
-        call_fast_args = []
-        for a, numberedname in zip(graphargs, numberednames):
-            try:
-                convert_from_obj = a.type_cls.convert_from_obj
-            except AttributeError:
-                call_fast_args.append(numberedname)
-            else:
-                convertedname = numberedname.replace('o', 'a')
-                ct = ctypeof(a)
-                print >> f, '\t%s;' % (ct.ctypetemplate % (convertedname,))
-                conversions.append('\tOP_%s(%s, %s, type_error)' % (
-                    convert_from_obj.upper(), numberedname, convertedname))
-                # XXX successfully converted objects may need to be decrefed
-                # XXX even though they are not PyObjects
-                call_fast_args.append(convertedname)
-        # return value conversion
-        try:
-            convert_to_obj = self.ctret.convert_to_obj
-        except AttributeError:
-            putresultin = 'oret'
-            footer = None
-        else:
-            print >> f, '\t%s;' % (self.ctret.ctypetemplate % ('aret',))
-            putresultin = 'aret'
-            footer = 'OP_%s(aret, oret, type_error)' % convert_to_obj.upper()
-        print >> f
-
-        if USE_CALL_TRACE:
-            print >> f, '\tFUNCTION_CHECK()'
-
-        # argument unpacking
-        if vararg:
-            print >> f, '\tovararg = PyTuple_GetSlice(args, %d, INT_MAX);' % (
-                nb_positional_args,)
-            print >> f, '\tif (ovararg == NULL)'
-            print >> f, '\t\tFUNCTION_RETURN(NULL)'
-            print >> f, '\targs = PyTuple_GetSlice(args, 0, %d);' % (
-                nb_positional_args,)
-            print >> f, '\tif (args == NULL) {'
-            print >> f, '\t\tERR_DECREF(ovararg)'
-            print >> f, '\t\tFUNCTION_RETURN(NULL)'
-            print >> f, '\t}'
-            tail = """{
-\t\tERR_DECREF(args)
-\t\tERR_DECREF(ovararg)
-\t\tFUNCTION_RETURN(NULL);
-\t}
-\tPy_DECREF(args);"""
-        else:
-            tail = '\n\t\tFUNCTION_RETURN(NULL)'
-        for i in range(len(name_of_defaults)):
-            print >> f, '\t%s = %s;' % (
-                numberednames[min_number_of_args+i],
-                name_of_defaults[i])
-        fmt = 'O'*min_number_of_args
-        if min_number_of_args < nb_positional_args:
-            fmt += '|' + 'O'*(nb_positional_args-min_number_of_args)
-        lst = ['args', 'kwds',
-               '"%s:%s"' % (fmt, func.__name__),
-               'kwlist',
-               ]
-        lst += ['&' + a for a in numberednames]
-        print >> f, '\tif (!PyArg_ParseTupleAndKeywords(%s))' % ', '.join(lst),
-        print >> f, tail
-
-        for line in conversions:
-            print >> f, line
-
-        if USE_CALL_TRACE:
-            call_fast_args.insert(0, 'TRACE_CALL')
-        call_fast_args = ', '.join(call_fast_args)
-        print >> f, '\t%s = %s(%s);' % (putresultin, self.fast_name,
-                                        call_fast_args)
-        if footer:
-            print >> f, '\t' + footer
-        print >> f, '\treturn oret;'
-
-        if conversions or footer:
-            print >> f, '    type_error:'
-            print >> f, '        return NULL;'
-        
-        print >> f, '}'
-        print >> f
-
-    # ____________________________________________________________
-
-    def gen_cfunction(self, f, body):
-        print >> f, self.fast_function_header
-        print >> f, '{'
-
-        localnames = self.localnames
-        lengths = [len(a) for a in localnames]
-        lengths.append(9999)
-        start = 0
-        while start < len(localnames):
-            total = lengths[start] + 9
-            end = start+1
-            while total + lengths[end] < 76:
-                total += lengths[end] + 2
-                end += 1
-            print >> f, '\t' + '; '.join(localnames[start:end]) + ';'
-            start = end
-        
-        # generate an incref for each input argument
-        for a in self.graphargs:
-            cincref = getattr(ctypeof(a), 'cincref', None)
-            if cincref:
-                print >> f, '\t' + cincref % (self.expr(a),)
-
-        # print the body
-        for line in body:
-            if line.endswith(':'):
-                if line.startswith('err'):
-                    fmt = '\t%s'
-                else:
-                    fmt = '    %s\n'
-            elif line:
-                fmt = '\t%s\n'
-            else:
-                fmt = '%s\n'
-            f.write(fmt % line)
-        print >> f, '}'
-        print >> f
-
-    # ____________________________________________________________
-
-    def cfunction_body(self):
-        graph = self.graph
-
-        blocknum = {}
-        allblocks = []
-
-        def gen_link(link, linklocalvars=None):
-            "Generate the code to jump across the given Link."
-            has_ref = {}
-            linklocalvars = linklocalvars or {}
-            for v in to_release:
-                linklocalvars[v] = self.expr(v)
-            has_ref = linklocalvars.copy()
-            for a1, a2 in zip(link.args, link.target.inputargs):
-                if a1 in linklocalvars:
-                    src = linklocalvars[a1]
-                else:
-                    src = self.expr(a1)
-                line = 'MOVE(%s, %s)' % (src, self.expr(a2))
-                if a1 in has_ref:
-                    del has_ref[a1]
-                else:
-                    ct1 = ctypeof(a1)
-                    ct2 = ctypeof(a2)
-                    assert ct1 == ct2
-                    cincref = getattr(ct1, 'cincref', None)
-                    if cincref:
-                        line += '\t' + cincref % (self.expr(a2),)
-                yield line
-            for v in has_ref:
-                cdecref = getattr(ctypeof(v), 'cdecref', None)
-                if cdecref:
-                    yield cdecref % (linklocalvars[v],)
-            yield 'goto block%d;' % blocknum[link.target]
-
-        # collect all blocks
-        def visit(block):
-            if isinstance(block, Block):
-                allblocks.append(block)
-                blocknum[block] = len(blocknum)
-        traverse(visit, graph)
-
-        # generate the body of each block
-        for block in allblocks:
-            yield ''
-            yield 'block%d:' % blocknum[block]
-            to_release = list(block.inputargs)
-            for op in block.operations:
-                args  = [lazy(self.expr, v) for v in op.args]
-                res   = self.expr(op.result)
-                err   = 'err%d_%d' % (blocknum[block], len(to_release))
-                macro = 'OP_%s' % op.opname.upper()
-                meth  = getattr(self, macro, None)
-                if meth:
-                    yield meth(args, res, err)
-                else:
-                    lst = [arg.compute() for arg in args] + [res, err]
-                    yield '%s(%s)' % (macro, ', '.join(lst))
-                to_release.append(op.result)
-
-            err_reachable = False
-            if len(block.exits) == 0:
-                if len(block.inputargs) == 2:   # exc_cls, exc_value
-                    # exceptional return block
-                    exc_cls   = self.expr(block.inputargs[0])
-                    exc_value = self.expr(block.inputargs[1])
-                    yield 'PyErr_Restore(%s, %s, NULL);' % (exc_cls, exc_value)
-                    yield self.return_error
-                else:
-                    # regular return block
-                    retval = self.expr(block.inputargs[0])
-                    yield 'FUNCTION_RETURN(%s)' % retval
-                continue
-            elif block.exitswitch is None:
-                # single-exit block
-                assert len(block.exits) == 1
-                for op in gen_link(block.exits[0]):
-                    yield op
-                yield ''
-            elif block.exitswitch == Constant(last_exception):
-                # block catching the exceptions raised by its last operation
-                # we handle the non-exceptional case first
-                link = block.exits[0]
-                assert link.exitcase is None
-                for op in gen_link(link):
-                    yield op
-                # we must catch the exception raised by the last operation,
-                # which goes to the last err%d_%d label written above.
-                yield ''
-                to_release.pop()  # skip default error handling for this label
-                yield 'err%d_%d:' % (blocknum[block], len(to_release))
-                yield ''
-                for link in block.exits[1:]:
-                    assert issubclass(link.exitcase, Exception)
-                    yield 'if (PyErr_ExceptionMatches(%s)) {' % (
-                        self.genc.pyobjrepr.nameof(link.exitcase),)
-                    yield '\tPyObject *exc_cls, *exc_value, *exc_tb;'
-                    yield '\tPyErr_Fetch(&exc_cls, &exc_value, &exc_tb);'
-                    yield '\tif (exc_value == NULL) {'
-                    yield '\t\texc_value = Py_None;'
-                    yield '\t\tPy_INCREF(Py_None);'
-                    yield '\t}'
-                    yield '\tPy_XDECREF(exc_tb);'
-                    for op in gen_link(link, {
-                                Constant(last_exception): 'exc_cls',
-                                Constant(last_exc_value): 'exc_value'}):
-                        yield '\t' + op
-                    yield '}'
-                err_reachable = True
-            else:
-                # block ending in a switch on a value
-                ct = ctypeof(block.exitswitch)
-                for link in block.exits[:-1]:
-                    assert link.exitcase in (False, True)
-                    yield 'if (%s == %s) {' % (self.expr(block.exitswitch),
-                                       self.genc.nameofvalue(link.exitcase, ct))
-                    for op in gen_link(link):
-                        yield '\t' + op
-                    yield '}'
-                link = block.exits[-1]
-                assert link.exitcase in (False, True)
-                yield 'assert(%s == %s);' % (self.expr(block.exitswitch),
-                                       self.genc.nameofvalue(link.exitcase, ct))
-                for op in gen_link(block.exits[-1]):
-                    yield op
-                yield ''
-
-            while to_release:
-                v = to_release.pop()
-                if err_reachable:
-                    if not hasattr(v, 'type_cls'):
-                        yield 'ERR_DECREF(%s)' % self.expr(v)
-                    else:
-                        cdecref = getattr(ctypeof(v), 'cdecref', None)
-                        if cdecref:
-                            yield cdecref % (self.expr(v),)
-                yield 'err%d_%d:' % (blocknum[block], len(to_release))
-                err_reachable = True
-            if err_reachable:
-                yield self.return_error
-
-    # ____________________________________________________________
-
-    # the C preprocessor cannot handle operations taking a variable number
-    # of arguments, so here are Python methods that do it
-    
-    def OP_NEWLIST(self, args, r, err):
-        args = [arg.compute() for arg in args]
-        if len(args) == 0:
-            return 'OP_NEWLIST0(%s, %s)' % (r, err)
-        else:
-            args.insert(0, '%d' % len(args))
-            return 'OP_NEWLIST((%s), %s, %s)' % (', '.join(args), r, err)
-
-    def OP_NEWDICT(self, args, r, err):
-        args = [arg.compute() for arg in args]
-        if len(args) == 0:
-            return 'OP_NEWDICT0(%s, %s)' % (r, err)
-        else:
-            assert len(args) % 2 == 0
-            args.insert(0, '%d' % (len(args)//2))
-            return 'OP_NEWDICT((%s), %s, %s)' % (', '.join(args), r, err)
-
-    def OP_NEWTUPLE(self, args, r, err):
-        args = [arg.compute() for arg in args]
-        args.insert(0, '%d' % len(args))
-        return 'OP_NEWTUPLE((%s), %s, %s)' % (', '.join(args), r, err)
-
-##    def fast_simple_call(self, args, r, err):
-##        # try to generate a SIMPLE_CALL using a shortcut:
-##        # a direct call to the ff_xxx() function, using its C signature.
-##        if USE_CALL_TRACE:
-##            return None
-##        target = args[0].args[0]
-##        args = [arg.compute() for arg in args[1:]]
-##        if not isinstance(target, Constant):
-##            return None
-##        if not isinstance(target.value, FunctionType):
-##            return None
-##        funcdef = self.genc.getfuncdef(target.value)
-##        if funcdef is None:
-##            return None
-##        if len(funcdef.graphargs) != len(args) or funcdef.vararg:
-##            return None
-##        return 'if (!(%s=%s(%s))) FAIL(%s);' % (
-##            r, funcdef.fast_name, ', '.join(args), err)
-
-    def OP_SIMPLE_CALL(self, args, r, err):
-##        result = self.fast_simple_call(args, r, err)
-##        if result is not None:
-##            return result
-##        # fall-back
-        args = [arg.compute() for arg in args]
-        args.append('NULL')
-        return 'OP_SIMPLE_CALL((%s), %s, %s)' % (', '.join(args), r, err)
-
-    def OP_CALL_ARGS(self, args, r, err):
-        args = [arg.compute() for arg in args]
-        return 'OP_CALL_ARGS((%s), %s, %s)' % (', '.join(args), r, err)
-
-# ____________________________________________________________
-
-class lazy:
-    def __init__(self, fn, *args, **kwds):
-        self.fn = fn
-        self.args = args
-        self.kwds = kwds
-    def compute(self):
-        return self.fn(*self.args, **self.kwds)

Deleted: /pypy/dist/pypy/translator/genc_pyobj.py
==============================================================================
--- /pypy/dist/pypy/translator/genc_pyobj.py	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,442 +0,0 @@
-from __future__ import generators
-import autopath, os, sys, __builtin__, marshal, zlib
-from pypy.objspace.flow.model import Variable, Constant
-from pypy.translator.gensupp import builtin_base
-from types import FunctionType, CodeType, InstanceType, ClassType
-
-from pypy.objspace.std.restricted_int import r_int, r_uint
-
-
-class CType_PyObject:
-    """The PyObject* C type.
-    This class contains all the nameof_xxx() methods that allow a wild variety
-    of Python objects to be 'pickled' as Python source code that will
-    reconstruct them.
-    """
-    ctypetemplate = 'PyObject *%s'
-    cincref       = 'Py_INCREF(%s);'
-    cdecref       = 'Py_DECREF(%s);'
-
-    def __init__(self, genc):
-        self.genc = genc
-        self.cnames = {Constant(None).key:  'Py_None',
-                       Constant(False).key: 'Py_False',
-                       Constant(True).key:  'Py_True',
-                       }
-        self.initcode = [      # list of lines for the module's initxxx()
-            'import new, types, sys',
-            'Py_None  = None',
-            'Py_False = False',
-            'Py_True  = True',
-            ]
-
-        self.latercode = []    # list of generators generating extra lines
-                               #   for later in initxxx() -- for recursive
-                               #   objects
-        self.globalobjects = []
-        self.debugstack = ()  # linked list of nested nameof()
-
-    def nameof(self, obj, debug=None):
-        key = Constant(obj).key
-        try:
-            return self.cnames[key]
-        except KeyError:
-            if debug:
-                stackentry = debug, obj
-            else:
-                stackentry = obj
-            self.debugstack = (self.debugstack, stackentry)
-            obj_builtin_base = builtin_base(obj)
-            if obj_builtin_base in (object, int, long) and type(obj) is not obj_builtin_base:
-                # assume it's a user defined thingy
-                name = self.nameof_instance(obj)
-            else:
-                for cls in type(obj).__mro__:
-                    meth = getattr(self,
-                                   'nameof_' + cls.__name__.replace(' ', ''),
-                                   None)
-                    if meth:
-                        break
-                else:
-                    raise Exception, "nameof(%r)" % (obj,)
-                name = meth(obj)
-            self.debugstack, x = self.debugstack
-            assert x is stackentry
-            self.cnames[key] = name
-            return name
-
-    def uniquename(self, basename):
-        name = self.genc.namespace.uniquename(basename)
-        self.globalobjects.append(name)
-        self.genc.globaldecl.append('static PyObject *%s;' % (name,))
-        return name
-
-    def initcode_python(self, name, pyexpr):
-        # generate init code that will evaluate the given Python expression
-        #self.initcode.append("print 'setting up', %r" % name)
-        self.initcode.append("%s = %s" % (name, pyexpr))
-
-    def nameof_object(self, value):
-        if type(value) is not object:
-            raise Exception, "nameof(%r)" % (value,)
-        name = self.uniquename('g_object')
-        self.initcode_python(name, "object()")
-        return name
-
-    def nameof_module(self, value):
-        assert value is os or not hasattr(value, "__file__") or \
-               not (value.__file__.endswith('.pyc') or
-                    value.__file__.endswith('.py') or
-                    value.__file__.endswith('.pyo')), \
-               "%r is not a builtin module (probably :)"%value
-        name = self.uniquename('mod%s'%value.__name__)
-        self.initcode_python(name, "__import__(%r)" % (value.__name__,))
-        return name
-        
-
-    def nameof_int(self, value):
-        if value >= 0:
-            name = 'gint_%d' % value
-        else:
-            name = 'gint_minus%d' % abs(value)
-        name = self.uniquename(name)
-        self.initcode_python(name, repr(value))
-        return name
-
-    def nameof_long(self, value):
-        if value >= 0:
-            name = 'glong%d' % value
-        else:
-            name = 'glong_minus%d' % abs(value)
-        name = self.uniquename(name)
-        self.initcode_python(name, repr(value))
-        return name
-
-    def nameof_float(self, value):
-        name = 'gfloat_%s' % value
-        name = (name.replace('-', 'minus')
-                    .replace('.', 'dot'))
-        name = self.uniquename(name)
-        self.initcode_python(name, repr(value))
-        return name
-
-    def nameof_str(self, value):
-        name = self.uniquename('gstr_' + value[:32])
-##        if [c for c in value if c<' ' or c>'~' or c=='"' or c=='\\']:
-##            # non-printable string
-##            s = 'chr_%s' % name
-##            self.globaldecl.append('static char %s[] = { %s };' % (
-##                s, ', '.join(['%d' % ord(c) for c in value])))
-##        else:
-##            # printable string
-##            s = '"%s"' % value
-        self.initcode_python(name, repr(value))
-        return name
-
-    def skipped_function(self, func):
-        # debugging only!  Generates a placeholder for missing functions
-        # that raises an exception when called.
-        if self.genc.translator.frozen:
-            warning = 'NOT GENERATING'
-        else:
-            warning = 'skipped'
-        printable_name = '(%s:%d) %s' % (
-            func.func_globals.get('__name__', '?'),
-            func.func_code.co_firstlineno,
-            func.__name__)
-        print warning, printable_name
-        name = self.uniquename('gskippedfunc_' + func.__name__)
-        self.initcode.append('def %s(*a,**k):' % name)
-        self.initcode.append('  raise NotImplementedError')
-        return name
-
-    def nameof_function(self, func, progress=['-\x08', '\\\x08',
-                                              '|\x08', '/\x08']):
-        funcdef = self.genc.getfuncdef(func)
-        if funcdef is None:
-            return self.skipped_function(func)
-        if not self.genc.translator.frozen:
-            p = progress.pop(0)
-            sys.stderr.write(p)
-            progress.append(p)
-        return funcdef.get_globalobject()
-
-    def nameof_staticmethod(self, sm):
-        # XXX XXX XXXX
-        func = sm.__get__(42.5)
-        name = self.uniquename('gsm_' + func.__name__)
-        functionname = self.nameof(func)
-        self.initcode_python(name, 'staticmethod(%s)' % functionname)
-        return name
-
-    def nameof_instancemethod(self, meth):
-        if meth.im_self is None:
-            # no error checking here
-            return self.nameof(meth.im_func)
-        else:
-            ob = self.nameof(meth.im_self)
-            func = self.nameof(meth.im_func)
-            typ = self.nameof(meth.im_class)
-            name = self.uniquename('gmeth_'+meth.im_func.__name__)
-            self.initcode_python(name, 'new.instancemethod(%s, %s, %s)' % (
-                func, ob, typ))
-            return name
-
-    def should_translate_attr(self, pbc, attr):
-        ann = self.genc.translator.annotator
-        if ann is None:
-            ignore = getattr(pbc.__class__, 'NOT_RPYTHON_ATTRIBUTES', [])
-            if attr in ignore:
-                return False
-            else:
-                return "probably"   # True
-        classdef = ann.getuserclasses().get(pbc.__class__)
-        if classdef and classdef.about_attribute(attr) is not None:
-            return True
-        return False
-
-    def nameof_instance(self, instance):
-        klass = instance.__class__
-        name = self.uniquename('ginst_' + klass.__name__)
-        cls = self.nameof(klass)
-        if hasattr(klass, '__base__'):
-            base_class = builtin_base(instance)
-            base = self.nameof(base_class)
-        else:
-            base_class = None
-            base = cls
-        def initinstance():
-            content = instance.__dict__.items()
-            content.sort()
-            for key, value in content:
-                if self.should_translate_attr(instance, key):
-                    line = '%s.%s = %s' % (name, key, self.nameof(value))
-                    yield line
-        if hasattr(instance,'__reduce_ex__'):
-            import copy_reg
-            reduced = instance.__reduce_ex__()
-            assert reduced[0] is copy_reg._reconstructor,"not clever enough"
-            assert reduced[1][1] is base_class, "not clever enough for %r vs. %r" % (base_class, reduced)
-            state = reduced[1][2]
-        else:
-            state = None
-        self.initcode.append('if isinstance(%s, type):' % cls)
-        if state is not None:
-            self.initcode.append('    %s = %s.__new__(%s, %r)' % (name, base, cls, state))
-        else:
-            self.initcode.append('    %s = %s.__new__(%s)' % (name, base, cls))
-        self.initcode.append('else:')
-        self.initcode.append('    %s = new.instance(%s)' % (name, cls))
-        self.later(initinstance())
-        return name
-
-    def nameof_builtin_function_or_method(self, func):
-        if func.__self__ is None:
-            # builtin function
-            # where does it come from? Python2.2 doesn't have func.__module__
-            for modname, module in sys.modules.items():
-                if hasattr(module, '__file__'):
-                    if (module.__file__.endswith('.py') or
-                        module.__file__.endswith('.pyc') or
-                        module.__file__.endswith('.pyo')):
-                        continue    # skip non-builtin modules
-                if func is getattr(module, func.__name__, None):
-                    break
-            else:
-                raise Exception, '%r not found in any built-in module' % (func,)
-            name = self.uniquename('gbltin_' + func.__name__)
-            if modname == '__builtin__':
-                self.initcode_python(name, func.__name__)
-            else:
-                modname = self.nameof(module)
-                self.initcode_python(name, '%s.%s' % (modname, func.__name__))
-        else:
-            # builtin (bound) method
-            name = self.uniquename('gbltinmethod_' + func.__name__)
-            selfname = self.nameof(func.__self__)
-            self.initcode_python(name, '%s.%s' % (selfname, func.__name__))
-        return name
-
-    def nameof_classobj(self, cls):
-        if cls.__doc__ and cls.__doc__.lstrip().startswith('NOT_RPYTHON'):
-            raise Exception, "%r should never be reached" % (cls,)
-
-        metaclass = "type"
-        if issubclass(cls, Exception):
-            if cls.__module__ == 'exceptions':
-                name = self.uniquename('gexc_' + cls.__name__)
-                self.initcode_python(name, cls.__name__)
-                return name
-            #else:
-            #    # exceptions must be old-style classes (grr!)
-            #    metaclass = "&PyClass_Type"
-        # For the moment, use old-style classes exactly when the
-        # pypy source uses old-style classes, to avoid strange problems.
-        if not isinstance(cls, type):
-            assert type(cls) is ClassType
-            metaclass = "types.ClassType"
-
-        name = self.uniquename('gcls_' + cls.__name__)
-        basenames = [self.nameof(base) for base in cls.__bases__]
-        def initclassobj():
-            content = cls.__dict__.items()
-            content.sort()
-            for key, value in content:
-                if key.startswith('__'):
-                    if key in ['__module__', '__doc__', '__dict__',
-                               '__weakref__', '__repr__', '__metaclass__']:
-                        continue
-                    # XXX some __NAMES__ are important... nicer solution sought
-                    #raise Exception, "unexpected name %r in class %s"%(key, cls)
-                if isinstance(value, staticmethod) and value.__get__(1) not in self.genc.translator.flowgraphs and self.genc.translator.frozen:
-                    print value
-                    continue
-                if isinstance(value, classmethod) and value.__get__(cls).__doc__.lstrip().startswith("NOT_RPYTHON"):
-                    continue
-                if isinstance(value, FunctionType) and value not in self.genc.translator.flowgraphs and self.genc.translator.frozen:
-                    print value
-                    continue
-                    
-                yield '%s.%s = %s' % (name, key, self.nameof(value))
-
-        baseargs = ", ".join(basenames)
-        if baseargs:
-            baseargs = '(%s)' % baseargs
-        self.initcode.append('class %s%s:' % (name, baseargs))
-        self.initcode.append('  __metaclass__ = %s' % metaclass)
-        self.later(initclassobj())
-        return name
-
-    nameof_class = nameof_classobj   # for Python 2.2
-
-    typename_mapping = {
-        InstanceType: 'types.InstanceType',
-        type(None):   'type(None)',
-        CodeType:     'types.CodeType',
-        type(sys):    'type(new)',
-
-        r_int:        'int',   # XXX
-        r_uint:       'int',   # XXX
-
-        # XXX more hacks
-        # type 'builtin_function_or_method':
-        type(len): 'type(len)',
-        # type 'method_descriptor':
-        type(list.append): 'type(list.append)',
-        # type 'wrapper_descriptor':
-        type(type(None).__repr__): 'type(type(None).__repr__)',
-        # type 'getset_descriptor':
-        type(type.__dict__['__dict__']): "type(type.__dict__['__dict__'])",
-        # type 'member_descriptor':
-        type(type.__dict__['__basicsize__']): "type(type.__dict__['__basicsize__'])",
-        }
-
-    def nameof_type(self, cls):
-        if cls.__module__ != '__builtin__':
-            return self.nameof_classobj(cls)   # user-defined type
-        name = self.uniquename('gtype_%s' % cls.__name__)
-        if getattr(__builtin__, cls.__name__, None) is cls:
-            expr = cls.__name__    # type available from __builtin__
-        else:
-            expr = self.typename_mapping[cls]
-        self.initcode_python(name, expr)
-        return name
-
-    def nameof_tuple(self, tup):
-        name = self.uniquename('g%dtuple' % len(tup))
-        args = [self.nameof(x) for x in tup]
-        args = ', '.join(args)
-        if args:
-            args += ','
-        self.initcode_python(name, '(%s)' % args)
-        return name
-
-    def nameof_list(self, lis):
-        name = self.uniquename('g%dlist' % len(lis))
-        def initlist():
-            for i in range(len(lis)):
-                item = self.nameof(lis[i])
-                yield '%s.append(%s)' % (name, item)
-        self.initcode_python(name, '[]')
-        self.later(initlist())
-        return name
-
-    def nameof_dict(self, dic):
-        assert dic is not __builtins__
-        assert '__builtins__' not in dic, 'Seems to be the globals of %s' % (
-            dic.get('__name__', '?'),)
-        name = self.uniquename('g%ddict' % len(dic))
-        def initdict():
-            for k in dic:
-                if type(k) is str:
-                    yield '%s[%r] = %s' % (name, k, self.nameof(dic[k]))
-                else:
-                    yield '%s[%s] = %s' % (name, self.nameof(k),
-                                           self.nameof(dic[k]))
-        self.initcode_python(name, '{}')
-        self.later(initdict())
-        return name
-
-    # strange prebuilt instances below, don't look too closely
-    # XXX oh well.
-    def nameof_member_descriptor(self, md):
-        name = self.uniquename('gdescriptor_%s_%s' % (
-            md.__objclass__.__name__, md.__name__))
-        cls = self.nameof(md.__objclass__)
-        self.initcode_python(name, '%s.__dict__[%r]' % (cls, md.__name__))
-        return name
-    nameof_getset_descriptor  = nameof_member_descriptor
-    nameof_method_descriptor  = nameof_member_descriptor
-    nameof_wrapper_descriptor = nameof_member_descriptor
-
-    def nameof_file(self, fil):
-        if fil is sys.stdin:
-            name = self.uniquename("gsys_stdin")
-            self.initcode_python(name, "sys.stdin")
-            return name
-        if fil is sys.stdout:
-            name = self.uniquename("gsys_stdout")
-            self.initcode_python(name, "sys.stdout")
-            return name
-        if fil is sys.stderr:
-            name = self.uniquename("gsys_stderr")
-            self.initcode_python(name, "sys.stderr")
-            return name
-        raise Exception, 'Cannot translate an already-open file: %r' % (fil,)
-
-
-    def later(self, gen):
-        self.latercode.append((gen, self.debugstack))
-
-    def collect_globals(self):
-        while self.latercode:
-            gen, self.debugstack = self.latercode.pop()
-            #self.initcode.extend(gen) -- eats TypeError! bad CPython!
-            for line in gen:
-                self.initcode.append(line)
-            self.debugstack = ()
-        if self.genc.f2 is not None:
-            for line in self.initcode:
-                print >> self.genc.f2, line
-            del self.initcode[:]
-
-    def getfrozenbytecode(self):
-        if self.genc.f2 is not None:
-            self.genc.f2.seek(0)
-            self.initcode.insert(0, self.genc.f2.read())
-        self.initcode.append('')
-        source = '\n'.join(self.initcode)
-        del self.initcode[:]
-        co = compile(source, self.genc.modname, 'exec')
-        del source
-        small = zlib.compress(marshal.dumps(co))
-        source = """if 1:
-            import zlib, marshal
-            exec marshal.loads(zlib.decompress(%r))""" % small
-        co = compile(source, self.genc.modname, 'exec')
-        del source
-        return marshal.dumps(co)
-
-
-def ctypeof(v):
-    return getattr(v, 'type_cls', CType_PyObject)

Deleted: /pypy/dist/pypy/translator/genc_type.h
==============================================================================
--- /pypy/dist/pypy/translator/genc_type.h	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,15 +0,0 @@
-
-/************************************************************/
- /***  C header subsection: typed operations               ***/
-
-/* This file is included from genc.h. */
-
-
-#define OP_INT2OBJ(i,r,err)   if (!(r=PyInt_FromLong(i))) FAIL(err)
-#define OP_OBJ2INT(o,r,err)   if ((r=PyInt_AsLong(o))==-1 && PyErr_Occurred()) \
-							  FAIL(err)
-
-#define OP_INT_IS_TRUE(x,r,err)   r = (x != 0);
-
-#define OP_INT_ADD(x,y,r,err)     r = x + y;
-#define OP_INT_SUB(x,y,r,err)     r = x - y;

Deleted: /pypy/dist/pypy/translator/genc_type.py
==============================================================================
--- /pypy/dist/pypy/translator/genc_type.py	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,13 +0,0 @@
-
-
-class CType_Int:
-    ctypetemplate    = 'int %s'
-    convert_to_obj   = 'int2obj'
-    convert_from_obj = 'obj2int'
-    error_return     = '-1'
-
-    def __init__(self, genc):
-        pass
-
-    def nameof(self, v, debug=None):
-        return '%d' % v

Deleted: /pypy/dist/pypy/translator/test/test_ctrans.py
==============================================================================
--- /pypy/dist/pypy/translator/test/test_ctrans.py	Sat Apr  2 17:57:37 2005
+++ (empty file)
@@ -1,338 +0,0 @@
-import autopath
-import py, sys
-from pypy.tool.udir import udir
-from pypy.translator.genc import GenC
-from pypy.translator.typer import GenCSpecializer
-from pypy.objspace.flow.model import *
-from pypy.translator.tool.buildpyxmodule import make_module_from_c
-from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
-from pypy.translator.translator import Translator
-
-from pypy.translator.test import snippet 
-
-# XXX this tries to make compiling faster for full-scale testing
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
-
-class TestNoTypeCGenTestCase:
-    objspacename = 'flow'
-
-    def build_cfunc(self, func, *morefuncs):
-        try: func = func.im_func
-        except AttributeError: pass
-        t = Translator(func)
-        for fn in morefuncs:
-            t.getflowgraph(fn)
-        t.simplify()
-        return skip_missing_compiler(t.ccompile)
-
-    def test_simple_func(self):
-        cfunc = self.build_cfunc(snippet.simple_func)
-        assert cfunc(1) == 2
-
-    def test_while_func(self):
-        while_func = self.build_cfunc(snippet.while_func)
-        assert while_func(10) == 55
-
-    def test_nested_whiles(self):
-        nested_whiles = self.build_cfunc(snippet.nested_whiles)
-        assert nested_whiles(111, 114) == (
-                          '...!...!...!...!...!')
-
-    def test_poor_man_range(self):
-        poor_man_range = self.build_cfunc(snippet.poor_man_range)
-        assert poor_man_range(10) == range(10)
-
-    def poor_man_rev_range(self):
-        poor_man_rev_range = self.build_cfunc(snippet.poor_man_rev_range)
-        assert poor_man_rev_range(10) == range(9,-1,-1)
-
-    def test_simple_id(self):
-        #we just want to see, if renaming of parameter works correctly
-        #if the first branch is the end branch
-        simple_id = self.build_cfunc(snippet.simple_id)
-        assert simple_id(9) == 9
-
-    def test_branch_id(self):
-        branch_id = self.build_cfunc(snippet.branch_id)
-        assert branch_id(1, 2, 3) == 2
-        assert branch_id(0, 2, 3) == 3
-
-    def test_int_id(self):
-        int_id = self.build_cfunc(snippet.int_id)
-        assert int_id(3) == 3
-
-    def dont_test_attrs(self):
-        attrs = self.build_cfunc(snippet.attrs)
-        assert attrs() == 9
-
-    def test_builtinusage(self):
-        fun = self.build_cfunc(snippet.builtinusage)
-        assert fun() == 4
-
-    def test_sieve(self):
-        sieve = self.build_cfunc(snippet.sieve_of_eratosthenes)
-        assert sieve() == 1028
-
-    def test_slice(self):
-        half = self.build_cfunc(snippet.half_of_n)
-        assert half(10) == 5
-
-    def test_poly_branch(self):
-        poly_branch = self.build_cfunc(snippet.poly_branch)
-        assert poly_branch(10) == [1,2,3]*2
-        assert poly_branch(0) == ['a','b','c']*2
-
-    def test_and(self):
-        sand = self.build_cfunc(snippet.s_and)
-        assert sand(5, 6) == "yes"
-        assert sand(5, 0) == "no"
-        assert sand(0, 6) == "no"
-        assert sand(0, 0) == "no"
-
-    def test_yast(self):
-        yast = self.build_cfunc(snippet.yast)
-        assert yast([1000,100,10,1]) == 1111
-        assert yast(range(100)) == (99*100)/2
-
-    def test_with_init(self):
-        with_init = self.build_cfunc(snippet.with_init)
-        assert with_init(0) == 0
-        assert with_init(-100) == -100
-
-    def test_with_more_init(self):
-        with_more_init = self.build_cfunc(snippet.with_more_init)
-        assert with_more_init(10, False) == -10
-        assert with_more_init(20, True) == 20
-
-    def test_global_instance(self):
-        global_instance = self.build_cfunc(snippet.global_instance)
-        assert global_instance() == 42
-
-    def test_global_newstyle_instance(self):
-        global_newstyle_instance = self.build_cfunc(snippet.global_newstyle_instance)
-        assert global_newstyle_instance().a == 1
-
-    def test_global_recursive_list(self):
-        global_recursive_list = self.build_cfunc(snippet.global_recursive_list)
-        lst = global_recursive_list()
-        assert len(lst) == 1
-        assert lst[0] is lst
-
-##     def test_global_badinit(self):
-##         global_badinit = self.build_cfunc(snippet.global_badinit)
-##         self.assertEquals(global_badinit(), 1)
-
-    def test_multiple_inheritance(self):
-        multiple_inheritance = self.build_cfunc(snippet.multiple_inheritance)
-        assert multiple_inheritance() == 1+2+3+4
-
-    def test_call_star_args(self):
-        call_star_args = self.build_cfunc(snippet.call_star_args)
-        assert call_star_args(42) == 52
-
-    def test_call_default_args(self):
-        call_default_args = self.build_cfunc(snippet.call_default_args)
-        assert call_default_args(42) == 111+42+3
-
-    def test_call_default_and_star_args(self):
-        call_default_and_star_args = self.build_cfunc(
-            snippet.call_default_and_star_args)
-        assert call_default_and_star_args(42) == (
-                          (111+42+3+0, -1000-2000-3000+2))
-
-    def test_call_with_star(self):
-        call_with_star = self.build_cfunc(snippet.call_with_star)
-        assert call_with_star(()) == -15L
-        assert call_with_star((4,)) == -13L
-        assert call_with_star((4,7)) == -9L
-        assert call_with_star([]) == -15L
-        assert call_with_star([4]) == -13L
-        assert call_with_star([4,7]) == -9L
-        raises(TypeError, call_with_star, (4,7,12))
-        raises(TypeError, call_with_star, [4,7,12,63])
-        raises(TypeError, call_with_star, 521)
-
-    def test_call_with_keyword(self):
-        call_with_keyword = self.build_cfunc(snippet.call_with_keyword)
-        assert call_with_keyword(100) == 82
-
-    def test_call_very_complex(self):
-        call_very_complex = self.build_cfunc(snippet.call_very_complex,
-                                             snippet.default_args)
-        assert call_very_complex(5, (3,), {}) == -12
-        assert call_very_complex(5, (), {'y': 3}) == -12
-        raises(TypeError, call_very_complex, 5, (3,), {'y': 4})
-
-    def test_finallys(self):
-        finallys = self.build_cfunc(snippet.finallys)
-        assert finallys(['hello']) == 8
-        assert finallys('X') == 8
-        assert finallys([]) == 6
-        assert finallys('XY') == 6
-
-    def test_finally2(self):
-        finally2 = self.build_cfunc(snippet.finally2)
-        lst = range(10)
-        finally2(lst, 5)
-        assert lst == [0,1,2,3,4, 6, 6,7,8, 'done']
-        dic = {}
-        raises(KeyError, finally2, dic, "won't find this key")
-        assert dic == {-1: 'done'}
-
-    def test_bare_raise(self):
-        bare_raise = self.build_cfunc(snippet.bare_raise)
-        assert bare_raise(range(0, 100, 10), False) == 50
-        assert bare_raise(range(0, 100, 10), True) == 50
-        raises(IndexError, bare_raise, range(0, 30, 10), False)
-        assert bare_raise(range(0, 30, 10), True) == None
-
-    def test_get_set_del_slice(self):
-        fn = self.build_cfunc(snippet.get_set_del_slice)
-        l = list('abcdefghij')
-        result = fn(l)
-        assert l == [3, 'c', 8, 11, 'h', 9]
-        assert result == ([3, 'c'], [9], [11, 'h'])
-
-    def test_global_const_w_init(self):
-        fn = self.build_cfunc(snippet.one_thing1)
-        assert fn().thingness == 1
-
-    def test_global_const_w_new(self):
-        fn = self.build_cfunc(snippet.one_thing2)
-        assert fn() == 4
-
-    def test_direct_loop(self):
-        # check that remove_direct_loops() does its job correctly
-        def direct_loop(n, m):
-            while 1:
-                o = n; n = m; m = o
-                n -= 10
-                if n < 0:
-                    return n
-        fn = self.build_cfunc(direct_loop)
-        assert fn(117, 114) == -6
-        assert fn(117, 124) == -3
-
-
-class TestAnnotatedTestCase:
-
-    def getcompiled(self, func):
-        t = Translator(func, simplifying=True)
-        # builds starting-types from func_defs 
-        argstypelist = []
-        if func.func_defaults:
-            for spec in func.func_defaults:
-                if isinstance(spec, tuple):
-                    spec = spec[0] # use the first type only for the tests
-                argstypelist.append(spec)
-        a = t.annotate(argstypelist)
-        a.simplify()
-        return skip_missing_compiler(t.ccompile)
-
-    def test_set_attr(self):
-        set_attr = self.getcompiled(snippet.set_attr)
-        assert set_attr() == 2
-
-    def test_inheritance2(self):
-        inheritance2 = self.getcompiled(snippet.inheritance2)
-        assert inheritance2() == ((-12, -12), (3, "world"))
-
-    def test_factorial2(self):
-        factorial2 = self.getcompiled(snippet.factorial2)
-        assert factorial2(5) == 120
-
-    def test_factorial(self):
-        factorial = self.getcompiled(snippet.factorial)
-        assert factorial(5) == 120
-
-    def test_simple_method(self):
-        simple_method = self.getcompiled(snippet.simple_method)
-        assert simple_method(55) == 55
-
-    def test_sieve_of_eratosthenes(self):
-        sieve_of_eratosthenes = self.getcompiled(snippet.sieve_of_eratosthenes)
-        assert sieve_of_eratosthenes() == 1028
-
-    def test_nested_whiles(self):
-        nested_whiles = self.getcompiled(snippet.nested_whiles)
-        assert nested_whiles(5,3) == '!!!!!'
-
-    def test_call_five(self):
-        call_five = self.getcompiled(snippet.call_five)
-        result = call_five()
-        assert result == [5]
-        # --  currently result isn't a real list, but a pseudo-array
-        #     that can't be inspected from Python.
-        #self.assertEquals(result.__class__.__name__[:8], "list of ")
-
-    def test_call_unpack_56(self):
-        call_unpack_56 = self.getcompiled(snippet.call_unpack_56)
-        result = call_unpack_56()
-        assert result == (2, 5, 6)
-
-    def test_class_defaultattr(self):
-        class K:
-            n = "hello"
-        def class_defaultattr():
-            k = K()
-            k.n += " world"
-            return k.n
-        fn = self.getcompiled(class_defaultattr)
-        assert fn() == "hello world"
-
-    def test_tuple_repr(self):
-        def tuple_repr(x=int, y=object):
-            z = x, y
-            while x:
-                x = x-1
-            return z
-        fn = self.getcompiled(tuple_repr)
-        assert fn(6,'a') == (6,'a')
-
-    def test_classattribute(self):
-        fn = self.getcompiled(snippet.classattribute)
-        assert fn(1) == 123
-        assert fn(2) == 456
-        assert fn(3) == 789
-        assert fn(4) == 789
-        assert fn(5) == 101112
-
-    def test_get_set_del_slice(self):
-        fn = self.getcompiled(snippet.get_set_del_slice)
-        l = list('abcdefghij')
-        result = fn(l)
-        assert l == [3, 'c', 8, 11, 'h', 9]
-        assert result == ([3, 'c'], [9], [11, 'h'])
-
-    def test_slice_long(self):
-        def slice_long(l=list, n=long):
-            return l[:n]
-        fn = self.getcompiled(slice_long)
-        l = list('abc')
-        result = fn(l, 2**32)
-        assert result == list('abc')
-        result = fn(l, 2**64)
-        assert result == list('abc')
-
-
-class TestTypedTestCase(TestAnnotatedTestCase):
-
-    def getcompiled(self, func):
-        t = Translator(func, simplifying=True)
-        # builds starting-types from func_defs 
-        argstypelist = []
-        if func.func_defaults:
-            for spec in func.func_defaults:
-                if isinstance(spec, tuple):
-                    spec = spec[0] # use the first type only for the tests
-                argstypelist.append(spec)
-        a = t.annotate(argstypelist)
-        a.simplify()
-        GenCSpecializer(a).specialize()
-        t.checkgraphs()
-        return skip_missing_compiler(t.ccompile)
-
-    def test_int_overflow(self):
-        fn = self.getcompiled(snippet.simple_func)
-        raises(OverflowError, fn, sys.maxint+1)

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Sat Apr  2 17:57:37 2005
@@ -29,7 +29,7 @@
 Try dir(test) for list of current snippets.
 """
 
-import autopath
+import autopath, os
 
 from pypy.objspace.flow.model import *
 from pypy.annotation.model import *
@@ -37,7 +37,7 @@
 from pypy.translator.simplify import simplify_graph
 from pypy.translator.genpyrex import GenPyrex
 from pypy.translator.gencl import GenCL
-from pypy.translator.genc import GenC
+from pypy.translator.genc.genc import GenC
 from pypy.translator.gensupp import uniquemodulename
 from pypy.translator.tool.buildpyxmodule import make_module_from_pyxstring
 from pypy.translator.tool.buildpyxmodule import make_module_from_c
@@ -242,7 +242,7 @@
         if not really_compile:
             return cfile
         mod = make_module_from_c(cfile,
-            include_dirs=[autopath.this_dir])
+            include_dirs=[os.path.join(autopath.this_dir, 'genc')])
         return getattr(mod, self.entrypoint.func_name)
 
     def call(self, *args):

Modified: pypy/dist/pypy/translator/typer.py
==============================================================================
--- pypy/dist/pypy/translator/typer.py	(original)
+++ pypy/dist/pypy/translator/typer.py	Sat Apr  2 17:57:37 2005
@@ -179,26 +179,6 @@
         else:
             # specialization not found
             opname2 = op.opname
-            argtypes = [CType_PyObject] * len(op.args)
+            argtypes = [self.defaulttypecls] * len(op.args)
             restypecls = self.defaulttypecls
         return opname2, argtypes, restypecls
-
-# ____________________________________________________________
-# GenC-specific specializer
-
-from pypy.annotation.model import SomeInteger
-from pypy.translator.genc_pyobj import CType_PyObject
-from pypy.translator.genc_type import CType_Int
-
-class GenCSpecializer(Specializer):
-
-    TInt = TypeMatch(SomeInteger(), CType_Int)
-    typematches = [TInt]   # in more-specific-first, more-general-last order
-    defaulttypecls = CType_PyObject
-
-    specializationtable = [
-        ## op      specialized op   arg types   concrete return type
-        ('add',     'int_add',     TInt, TInt,   CType_Int),
-        ('sub',     'int_sub',     TInt, TInt,   CType_Int),
-        ('is_true', 'int_is_true', TInt,         CType_Int),
-        ]



More information about the Pypy-commit mailing list