summaryrefslogtreecommitdiff
path: root/src/runtime/python/pypgf.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-07-08 19:45:49 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-07-08 19:45:49 +0000
commit0222d2440c6b6246da2a5d8d397bb1d766419c0e (patch)
tree1e9b6ac4f918c021e4c197b16fae8a63fce4a802 /src/runtime/python/pypgf.c
parente0fe6d01c4b3ec1456f5124793bd1721bb0198fb (diff)
implemented computing with abstract syntax trees. It passes all test cases except those that require def rules. The design is consistent with the STG virtual machine
Diffstat (limited to 'src/runtime/python/pypgf.c')
-rw-r--r--src/runtime/python/pypgf.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index ddc1abe12..d31c3e77e 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -2301,8 +2301,30 @@ PGF_compute(PGFObject* self, PyObject *args)
if (!PyArg_ParseTuple(args, "O!", &pgf_ExprType, &py_expr))
return NULL;
- Py_INCREF(py_expr);
- return py_expr;
+ ExprObject* py_expr_res = (ExprObject*) pgf_ExprType.tp_alloc(&pgf_ExprType, 0);
+ if (py_expr_res == NULL)
+ return NULL;
+
+ GuPool* tmp_pool = gu_new_pool();
+ GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool);
+
+ py_expr_res->pool = gu_new_pool();
+ py_expr_res->expr = pgf_compute(self->pgf, py_expr->expr, err,
+ tmp_pool, py_expr_res->pool);
+ py_expr_res->master = (PyObject*) self;
+ Py_INCREF(py_expr_res->master);
+
+ if (!gu_ok(err)) {
+ GuString msg = (GuString) gu_exn_caught_data(err);
+ PyErr_SetString(PGFError, msg);
+
+ Py_DECREF(py_expr_res);
+ gu_pool_free(tmp_pool);
+ return NULL;
+ }
+
+ gu_pool_free(tmp_pool);
+ return py_expr_res;
}
static ExprObject*