mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-12 14:29:31 -06:00
Header and source file cleanup
This commit is contained in:
@@ -7,10 +7,11 @@
|
||||
#include "./expr.h"
|
||||
#include "./ffi.h"
|
||||
|
||||
/* static */
|
||||
// ----------------------------------------------------------------------------
|
||||
// errors
|
||||
|
||||
PyObject *PGFError;
|
||||
|
||||
/* static */
|
||||
PgfExnType handleError(PgfExn err)
|
||||
{
|
||||
if (err.type == PGF_EXN_SYSTEM_ERROR) {
|
||||
@@ -26,6 +27,7 @@ PgfExnType handleError(PgfExn err)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// string conversions
|
||||
|
||||
PgfText *
|
||||
PyUnicode_AsPgfText(PyObject *pystr)
|
||||
@@ -53,15 +55,10 @@ PyUnicode_FromPgfText(PgfText *text)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// unmarshaller
|
||||
|
||||
/* The PgfUnmarshaller structure tells the runtime how to create
|
||||
* abstract syntax expressions and types in the heap of the host language.
|
||||
* In Python the expressions are normal objects.
|
||||
* From the point of view of the runtime, each node is a value of type object.
|
||||
* For Python that would be a PyObject pointer.
|
||||
*/
|
||||
|
||||
PgfExpr eabs(PgfUnmarshaller *this, PgfBindType btype, PgfText *name, PgfExpr body)
|
||||
static PgfExpr
|
||||
eabs(PgfUnmarshaller *this, PgfBindType btype, PgfText *name, PgfExpr body)
|
||||
{
|
||||
ExprAbsObject *pyexpr = (ExprAbsObject *)pgf_ExprAbsType.tp_alloc(&pgf_ExprAbsType, 0);
|
||||
pyexpr->bindType = PyLong_FromLong(btype);
|
||||
@@ -71,7 +68,8 @@ PgfExpr eabs(PgfUnmarshaller *this, PgfBindType btype, PgfText *name, PgfExpr bo
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr eapp(PgfUnmarshaller *this, PgfExpr fun, PgfExpr arg)
|
||||
static PgfExpr
|
||||
eapp(PgfUnmarshaller *this, PgfExpr fun, PgfExpr arg)
|
||||
{
|
||||
ExprAppObject *pyexpr = (ExprAppObject *)pgf_ExprAppType.tp_alloc(&pgf_ExprAppType, 0);
|
||||
pyexpr->e1 = (ExprObject *)fun;
|
||||
@@ -81,7 +79,8 @@ PgfExpr eapp(PgfUnmarshaller *this, PgfExpr fun, PgfExpr arg)
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr elit(PgfUnmarshaller *this, PgfLiteral lit)
|
||||
static PgfExpr
|
||||
elit(PgfUnmarshaller *this, PgfLiteral lit)
|
||||
{
|
||||
ExprLitObject *pyexpr = (ExprLitObject *)pgf_ExprLitType.tp_alloc(&pgf_ExprLitType, 0);
|
||||
PyObject *pyobj = (PyObject *)lit;
|
||||
@@ -90,14 +89,16 @@ PgfExpr elit(PgfUnmarshaller *this, PgfLiteral lit)
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr emeta(PgfUnmarshaller *this, PgfMetaId meta)
|
||||
static PgfExpr
|
||||
emeta(PgfUnmarshaller *this, PgfMetaId meta)
|
||||
{
|
||||
ExprMetaObject *pyexpr = (ExprMetaObject *)pgf_ExprMetaType.tp_alloc(&pgf_ExprMetaType, 0);
|
||||
pyexpr->id = PyLong_FromLong(meta);
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr efun(PgfUnmarshaller *this, PgfText *name)
|
||||
static PgfExpr
|
||||
efun(PgfUnmarshaller *this, PgfText *name)
|
||||
{
|
||||
ExprFunObject *pyexpr = (ExprFunObject *)pgf_ExprFunType.tp_alloc(&pgf_ExprFunType, 0);
|
||||
PyObject *pyobj = PyUnicode_FromPgfText(name);
|
||||
@@ -106,14 +107,16 @@ PgfExpr efun(PgfUnmarshaller *this, PgfText *name)
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr evar(PgfUnmarshaller *this, int index)
|
||||
static PgfExpr
|
||||
evar(PgfUnmarshaller *this, int index)
|
||||
{
|
||||
ExprVarObject *pyexpr = (ExprVarObject *)pgf_ExprVarType.tp_alloc(&pgf_ExprVarType, 0);
|
||||
pyexpr->index = PyLong_FromLong(index);
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr etyped(PgfUnmarshaller *this, PgfExpr expr, PgfType typ)
|
||||
static PgfExpr
|
||||
etyped(PgfUnmarshaller *this, PgfExpr expr, PgfType typ)
|
||||
{
|
||||
ExprTypedObject *pyexpr = (ExprTypedObject *)pgf_ExprTypedType.tp_alloc(&pgf_ExprTypedType, 0);
|
||||
pyexpr->expr = (ExprObject *)expr;
|
||||
@@ -123,7 +126,8 @@ PgfExpr etyped(PgfUnmarshaller *this, PgfExpr expr, PgfType typ)
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfExpr eimplarg(PgfUnmarshaller *this, PgfExpr expr)
|
||||
static PgfExpr
|
||||
eimplarg(PgfUnmarshaller *this, PgfExpr expr)
|
||||
{
|
||||
ExprImplArgObject *pyexpr = (ExprImplArgObject *)pgf_ExprImplArgType.tp_alloc(&pgf_ExprImplArgType, 0);
|
||||
pyexpr->expr = (ExprObject *)expr;
|
||||
@@ -131,7 +135,8 @@ PgfExpr eimplarg(PgfUnmarshaller *this, PgfExpr expr)
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
|
||||
PgfLiteral lint(PgfUnmarshaller *this, size_t size, uintmax_t *v)
|
||||
static PgfLiteral
|
||||
lint(PgfUnmarshaller *this, size_t size, uintmax_t *v)
|
||||
{
|
||||
intmax_t *v0 = (intmax_t *)v;
|
||||
PyObject *i = PyLong_FromLong(*v0);
|
||||
@@ -155,19 +160,22 @@ PgfLiteral lint(PgfUnmarshaller *this, size_t size, uintmax_t *v)
|
||||
}
|
||||
}
|
||||
|
||||
PgfLiteral lflt(PgfUnmarshaller *this, double v)
|
||||
static PgfLiteral
|
||||
lflt(PgfUnmarshaller *this, double v)
|
||||
{
|
||||
PyObject *d = PyFloat_FromDouble(v);
|
||||
return (PgfLiteral) d;
|
||||
}
|
||||
|
||||
PgfLiteral lstr(PgfUnmarshaller *this, PgfText *v)
|
||||
static PgfLiteral
|
||||
lstr(PgfUnmarshaller *this, PgfText *v)
|
||||
{
|
||||
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)
|
||||
static PgfType
|
||||
dtyp(PgfUnmarshaller *this, int n_hypos, PgfTypeHypo *hypos, PgfText *cat, int n_exprs, PgfExpr *exprs)
|
||||
{
|
||||
TypeObject *pytype = (TypeObject *)pgf_TypeType.tp_alloc(&pgf_TypeType, 0);
|
||||
|
||||
@@ -191,7 +199,8 @@ PgfType dtyp(PgfUnmarshaller *this, int n_hypos, PgfTypeHypo *hypos, PgfText *ca
|
||||
return (PgfType) pytype;
|
||||
}
|
||||
|
||||
void free_ref(PgfUnmarshaller *this, object x)
|
||||
static void
|
||||
free_ref(PgfUnmarshaller *this, object x)
|
||||
{
|
||||
// Py_XDECREF(x);
|
||||
}
|
||||
@@ -213,12 +222,13 @@ static PgfUnmarshallerVtbl unmarshallerVtbl =
|
||||
free_ref
|
||||
};
|
||||
|
||||
/* static */
|
||||
PgfUnmarshaller unmarshaller = { &unmarshallerVtbl };
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// marshaller
|
||||
|
||||
object match_lit(PgfMarshaller *this, PgfUnmarshaller *u, PgfLiteral lit)
|
||||
static object
|
||||
match_lit(PgfMarshaller *this, PgfUnmarshaller *u, PgfLiteral lit)
|
||||
{
|
||||
PyObject *pyobj = (PyObject *)lit;
|
||||
|
||||
@@ -265,7 +275,8 @@ object match_lit(PgfMarshaller *this, PgfUnmarshaller *u, PgfLiteral lit)
|
||||
}
|
||||
}
|
||||
|
||||
object match_expr(PgfMarshaller *this, PgfUnmarshaller *u, PgfExpr expr)
|
||||
static object
|
||||
match_expr(PgfMarshaller *this, PgfUnmarshaller *u, PgfExpr expr)
|
||||
{
|
||||
PyObject *pyobj = (PyObject *)expr;
|
||||
|
||||
@@ -306,7 +317,8 @@ object match_expr(PgfMarshaller *this, PgfUnmarshaller *u, PgfExpr expr)
|
||||
}
|
||||
}
|
||||
|
||||
object match_type(PgfMarshaller *this, PgfUnmarshaller *u, PgfType ty)
|
||||
static object
|
||||
match_type(PgfMarshaller *this, PgfUnmarshaller *u, PgfType ty)
|
||||
{
|
||||
TypeObject *type = (TypeObject *)ty;
|
||||
|
||||
@@ -353,5 +365,4 @@ static PgfMarshallerVtbl marshallerVtbl =
|
||||
match_type
|
||||
};
|
||||
|
||||
/* static */
|
||||
PgfMarshaller marshaller = { &marshallerVtbl };
|
||||
|
||||
Reference in New Issue
Block a user