[pypy-svn] r7554 - in pypy/trunk/src/pypy/translator: . tool
arigo at codespeak.net
arigo at codespeak.net
Mon Nov 22 13:27:34 CET 2004
Author: arigo
Date: Mon Nov 22 13:27:33 2004
New Revision: 7554
Modified:
pypy/trunk/src/pypy/translator/genc.h
pypy/trunk/src/pypy/translator/genc.py
pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py
Log:
genc:
- OP_DELITEM()
- OP_CALL()
- OP_NEWDICT()
- fixed string escaping
And when build_module_form_c fails, it dumps the errors/warnings text to a
.error file in addition of printing it to the console.
Modified: pypy/trunk/src/pypy/translator/genc.h
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.h (original)
+++ pypy/trunk/src/pypy/translator/genc.h Mon Nov 22 13:27:33 2004
@@ -97,6 +97,8 @@
#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)
@@ -115,6 +117,7 @@
#define OP_SIMPLE_CALL(args,r,err) if (!(r=PyObject_CallFunctionObjArgs args)) \
FAIL(err)
+#define OP_CALL(x,y,z,r,err) if (!(r=PyObject_Call(x,y,z))) FAIL(err)
/* Needs to act like getattr(x, '__class__', type(x)) */
#define OP_TYPE(x,r,err) { \
@@ -262,6 +265,8 @@
#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)
#if defined(USE_CALL_TRACE)
@@ -555,6 +560,30 @@
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, ...)
{
Modified: pypy/trunk/src/pypy/translator/genc.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.py (original)
+++ pypy/trunk/src/pypy/translator/genc.py Mon Nov 22 13:27:33 2004
@@ -159,7 +159,7 @@
'0' <= c <='9' or
'_' == c )]
name = self.uniquename('gstr_' + ''.join(chrs))
- if [c for c in value if not (' '<=c<='~')]:
+ 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 };' % (
@@ -767,6 +767,14 @@
args.insert(0, '%d' % len(args))
return 'OP_NEWLIST((%s), %s, %s)' % (', '.join(args), r, err)
+ def OP_NEWDICT(self, args, r, err):
+ 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.insert(0, '%d' % len(args))
return 'OP_NEWTUPLE((%s), %s, %s)' % (', '.join(args), r, err)
Modified: pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py (original)
+++ pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py Mon Nov 22 13:27:33 2004
@@ -70,7 +70,11 @@
finally:
foutput, foutput = c.done()
except:
- print foutput.read()
+ data = foutput.read()
+ fdump = open("%s.errors" % modname, "w")
+ fdump.write(data)
+ fdump.close()
+ print data
raise
# XXX do we need to do some check on fout/ferr?
# XXX not a nice way to import a module
More information about the Pypy-commit
mailing list