From d53b7587f5c485e654830baa28e3cb49e2708f28 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Fri, 3 Sep 2021 15:26:10 +0200 Subject: [PATCH] Fill in literal cases in Python unmarshaller (untested) --- src/runtime/python/expr.c | 2 +- src/runtime/python/marshaller.c | 15 +++++++++------ src/runtime/python/test_suite.py | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/runtime/python/expr.c b/src/runtime/python/expr.c index 09cfd2b4c..03fb6d1e2 100644 --- a/src/runtime/python/expr.c +++ b/src/runtime/python/expr.c @@ -856,7 +856,7 @@ Type_richcompare(TypeObject *t1, TypeObject *t2, int op) } else if (op == Py_NE) { if (cmp) Py_RETURN_FALSE; else Py_RETURN_TRUE; } else { - PyErr_SetString(PyExc_TypeError, "the operation is not supported"); + PyErr_SetString(PyExc_TypeError, "comparison operation not supported"); return NULL; } } diff --git a/src/runtime/python/marshaller.c b/src/runtime/python/marshaller.c index 75aebb3a7..5ab3ebe08 100644 --- a/src/runtime/python/marshaller.c +++ b/src/runtime/python/marshaller.c @@ -53,33 +53,36 @@ PgfExpr eimplarg(PgfUnmarshaller *this, PgfExpr expr) PgfLiteral lint(PgfUnmarshaller *this, size_t size, uintmax_t *v) { - return 0; + PyObject *i = PyLong_FromUnsignedLong(*v); + return (PgfLiteral) i; } PgfLiteral lflt(PgfUnmarshaller *this, double v) { - return 0; + PyObject *d = PyFloat_FromDouble(v); + return (PgfLiteral) d; } PgfLiteral lstr(PgfUnmarshaller *this, PgfText *v) { - return 0; + PyObject *s = PyUnicode_FromStringAndSize(v->text, v->size); + return (PgfLiteral) s; } PgfType dtyp(PgfUnmarshaller *this, int n_hypos, PgfTypeHypo *hypos, PgfText *cat, int n_exprs, PgfExpr *exprs) { - PgfText* catname = (PgfText*) malloc(sizeof(PgfText)+cat->size+1); + PgfText *catname = (PgfText*) malloc(sizeof(PgfText)+cat->size+1); memcpy(catname->text, cat->text, cat->size+1); catname->size = cat->size; - TypeObject* pytype = (TypeObject*) pgf_TypeType.tp_alloc(&pgf_TypeType, 0); + TypeObject *pytype = (TypeObject*) pgf_TypeType.tp_alloc(&pgf_TypeType, 0); pytype->cat = catname; return (PgfType) pytype; } void free_ref(PgfUnmarshaller *this, object x) { - return; + Py_XDECREF(x); } static PgfUnmarshallerVtbl unmarshallervtbl = diff --git a/src/runtime/python/test_suite.py b/src/runtime/python/test_suite.py index b695a4dc7..ec8793f80 100644 --- a/src/runtime/python/test_suite.py +++ b/src/runtime/python/test_suite.py @@ -15,7 +15,7 @@ def test_readPGF_GF(): with pytest.raises(pgf.PGFError): pgf.readPGF("../haskell/tests/basic.gf") -@pytest.mark.skip(reason="Bug in runtime") +@pytest.mark.skip(reason="Unhandled case in runtime") def test_readPGF_NGF(NGF): with pytest.raises(pgf.PGFError): pgf.readPGF("./basic.ngf") @@ -34,7 +34,7 @@ def test_bootNGF_GF(): with pytest.raises(pgf.PGFError): pgf.bootNGF("../haskell/tests/basic.gf", "./abc.ngf") -@pytest.mark.skip(reason="Bug in runtime") +@pytest.mark.skip(reason="Unhandled case in runtime") def test_bootNGF_NGF(NGF): with pytest.raises(pgf.PGFError): pgf.bootNGF("./basic.ngf", "./abc.ngf") @@ -45,17 +45,17 @@ def test_bootNGF_existing(NGF): # readNGF -@pytest.mark.skip(reason="Bug in runtime") +@pytest.mark.skip(reason="Unhandled case in runtime") def test_readNGF_non_existant(): with pytest.raises(FileNotFoundError): pgf.readNGF("./abc.ngf") -@pytest.mark.skip(reason="Bug in runtime") +@pytest.mark.skip(reason="Unhandled case in runtime") def test_readNGF_GF(): with pytest.raises(pgf.PGFError): pgf.readNGF("../haskell/tests/basic.gf") -@pytest.mark.skip(reason="Bug in runtime") +@pytest.mark.skip(reason="Unhandled case in runtime") def test_readNGF_PGF(): with pytest.raises(pgf.PGFError): pgf.readNGF("../haskell/tests/basic.pgf")