mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
First attempts at marshalling in Python bindings, not really sure what I'm doing
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
// #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
|
// #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
|
||||||
|
|
||||||
#define PyStringObject PyUnicodeObject
|
#define PyStringObject PyUnicodeObject
|
||||||
// #define PyString_Check PyUnicode_Check
|
#define PyString_Check PyUnicode_Check
|
||||||
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
|
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
|
||||||
// #define PyString_FromFormat PyUnicode_FromFormat
|
// #define PyString_FromFormat PyUnicode_FromFormat
|
||||||
// #define PyString_Concat(ps,s) {PyObject* tmp = *(ps); *(ps) = PyUnicode_Concat(tmp,s); Py_DECREF(tmp);}
|
// #define PyString_Concat(ps,s) {PyObject* tmp = *(ps); *(ps) = PyUnicode_Concat(tmp,s); Py_DECREF(tmp);}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "./compat.h"
|
||||||
#include "./expr.h"
|
#include "./expr.h"
|
||||||
|
#include "./marshaller.h"
|
||||||
|
|
||||||
// static ExprObject*
|
// static ExprObject*
|
||||||
// Expr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
// Expr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
@@ -810,24 +812,10 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
Type_repr(TypeObject *self)
|
Type_str(TypeObject *self)
|
||||||
{
|
{
|
||||||
// GuPool* tmp_pool = gu_local_pool();
|
PgfText *s = pgf_print_type((PgfType) &self, NULL, 0, &marshaller);
|
||||||
//
|
return PyString_FromStringAndSize(s->text, s->size);
|
||||||
// GuExn* err = gu_exn(tmp_pool);
|
|
||||||
// GuStringBuf* sbuf = gu_new_string_buf(tmp_pool);
|
|
||||||
// GuOut* out = gu_string_buf_out(sbuf);
|
|
||||||
//
|
|
||||||
// pgf_print_type(self->type, NULL, 0, out, err);
|
|
||||||
//
|
|
||||||
// PyObject* pystr = PyString_FromStringAndSize(gu_string_buf_data(sbuf),
|
|
||||||
// gu_string_buf_length(sbuf));
|
|
||||||
//
|
|
||||||
// gu_pool_free(tmp_pool);
|
|
||||||
// return pystr;
|
|
||||||
|
|
||||||
PyErr_SetString(PyExc_TypeError, "Type_repr: not implemented");
|
|
||||||
Py_RETURN_NOTIMPLEMENTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@@ -1061,7 +1049,7 @@ PyTypeObject pgf_TypeType = {
|
|||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
0, /*tp_hash */
|
0, /*tp_hash */
|
||||||
0, /*tp_call*/
|
0, /*tp_call*/
|
||||||
(reprfunc) Type_repr, /*tp_str*/
|
(reprfunc) Type_str, /*tp_str*/
|
||||||
0, /*tp_getattro*/
|
0, /*tp_getattro*/
|
||||||
0, /*tp_setattro*/
|
0, /*tp_setattro*/
|
||||||
0, /*tp_as_buffer*/
|
0, /*tp_as_buffer*/
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ PgfLiteral lflt(PgfUnmarshaller *this, double v)
|
|||||||
|
|
||||||
PgfLiteral lstr(PgfUnmarshaller *this, PgfText *v)
|
PgfLiteral lstr(PgfUnmarshaller *this, PgfText *v)
|
||||||
{
|
{
|
||||||
PyObject *s = PyUnicode_FromStringAndSize(v->text, v->size);
|
PyObject *s = PyString_FromStringAndSize(v->text, v->size);
|
||||||
return (PgfLiteral) s;
|
return (PgfLiteral) s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ void free_ref(PgfUnmarshaller *this, object x)
|
|||||||
Py_XDECREF(x);
|
Py_XDECREF(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PgfUnmarshallerVtbl unmarshallervtbl =
|
static PgfUnmarshallerVtbl unmarshallerVtbl =
|
||||||
{
|
{
|
||||||
eabs,
|
eabs,
|
||||||
eapp,
|
eapp,
|
||||||
@@ -115,4 +115,49 @@ static PgfUnmarshallerVtbl unmarshallervtbl =
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
PgfUnmarshaller unmarshaller = { &unmarshallervtbl };
|
PgfUnmarshaller unmarshaller = { &unmarshallerVtbl };
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
object match_lit(PgfUnmarshaller *u, PgfLiteral lit)
|
||||||
|
{
|
||||||
|
if (PyString_Check(lit)) {
|
||||||
|
// PgfText t = {
|
||||||
|
// PyUnicode_GetLength((PyObject*) lit),
|
||||||
|
// lit,
|
||||||
|
// };
|
||||||
|
// return lstr(u, &lit);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (PyLong_Check(lit)) {
|
||||||
|
|
||||||
|
return lint(u, 1, (uintmax_t *)lit);
|
||||||
|
}
|
||||||
|
else if (PyFloat_Check(lit)) {
|
||||||
|
return lflt(u, *(double *)lit);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Unable to match on literal");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object match_expr(PgfUnmarshaller *u, PgfExpr expr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
object match_type(PgfUnmarshaller *u, PgfType ty)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PgfMarshallerVtbl marshallerVtbl =
|
||||||
|
{
|
||||||
|
match_lit,
|
||||||
|
match_expr,
|
||||||
|
match_type
|
||||||
|
};
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
PgfMarshaller marshaller = { &marshallerVtbl };
|
||||||
|
|||||||
@@ -8,4 +8,6 @@
|
|||||||
|
|
||||||
extern PgfUnmarshaller unmarshaller;
|
extern PgfUnmarshaller unmarshaller;
|
||||||
|
|
||||||
|
extern PgfMarshaller marshaller;
|
||||||
|
|
||||||
#endif // PYPGF_MARSHALLER_H_
|
#endif // PYPGF_MARSHALLER_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user