From b9de5c36c0a62048abee457d89b994ebbeb7acf7 Mon Sep 17 00:00:00 2001 From: "jordi.saludes" Date: Tue, 27 Jul 2010 07:50:48 +0000 Subject: Added inferExpr to py-bindings. --- contrib/py-bindings/gfmodule.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'contrib/py-bindings/gfmodule.c') diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index 06896b9ba..8491f2eb5 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -245,13 +245,33 @@ unapp(Expr *self) { return obj; } +static PyObject* +infer_expr(Expr *self, PyObject* args) { + PGF* pgf; + if (!PyArg_ParseTuple(args, "O", &pgf)) + return NULL; + if (!checkType(pgf, &PGFType)) { + PyErr_Format(PyExc_ValueError, "Must be a pgf module."); + return NULL; + } + gfType* gftp = (gfType*)gfTypeType.tp_new(&gfTypeType,NULL,NULL); + gf_inferexpr(pgf, self, gftp); + return gftp; +} + + + +/* todo: Is Tree == Expr ? + static PyMethodDef tree_methods[] = { - {"unapply", (PyCFunction)unapp, METH_NOARGS,"Unapply a tree."}, - {NULL, NULL, 0, NULL} /* Sentinel */ + {"unapply", (PyCFunction)unapp, METH_NOARGS, "Unapply a tree."}, + {NULL, NULL, 0, NULL} // * Sentinel * // }; +*/ static PyMethodDef expr_methods[] = { - {"unapply", (PyCFunction)unapp, METH_NOARGS,"Unapply an expression."}, + {"unapply", (PyCFunction)unapp, METH_NOARGS, "Unapply an expression."}, + {"infer", (PyCFunction)infer_expr, METH_VARARGS, "Infer the type of an expression."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -297,7 +317,7 @@ initgf(void) READYTYPE(gfTypeType, gfType_repr, gfType_dealloc) ExprType.tp_methods = expr_methods; READYTYPE(ExprType, expr_repr, expr_dealloc) - TreeType.tp_methods = tree_methods; + TreeType.tp_methods = expr_methods; // Tree == Expr ? READYTYPE(TreeType, tree_repr, Tree_dealloc) m = Py_InitModule3("gf", gf_methods, -- cgit v1.2.3