1
0
forked from GitHub/gf-core

Header and source file cleanup

This commit is contained in:
John J. Camilleri
2021-09-21 22:28:44 +02:00
parent 71dac482c8
commit b4b8572af3
8 changed files with 81 additions and 2204 deletions

View File

@@ -7,6 +7,7 @@
#include "./ffi.h"
// ----------------------------------------------------------------------------
// types
static TypeObject *
Type_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
@@ -135,7 +136,6 @@ static PyGetSetDef Type_getseters[] = {
{NULL} /* Sentinel */
};
/* static */
PyTypeObject pgf_TypeType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -179,6 +179,7 @@ PyTypeObject pgf_TypeType = {
};
// ----------------------------------------------------------------------------
// expressions
static PyObject *
Expr_str(ExprObject *self)
@@ -234,7 +235,6 @@ static PyGetSetDef Expr_getseters[] = {
{NULL} /* Sentinel */
};
/* static */
PyTypeObject pgf_ExprType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -327,7 +327,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprAbsType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -416,7 +415,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprAppType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -522,7 +520,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprLitType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -615,7 +612,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprMetaType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -700,7 +696,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprFunType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -793,7 +788,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprVarType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -882,7 +876,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprTypedType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/
@@ -967,7 +960,6 @@ done:
}
}
/* static */
PyTypeObject pgf_ExprImplArgType = {
PyVarObject_HEAD_INIT(NULL, 0)
//0, /*ob_size*/

View File

@@ -13,7 +13,7 @@ typedef struct {
PyObject *exprs; // PyListObject of ExprObject
} TypeObject;
extern PyTypeObject pgf_TypeType;
PyTypeObject pgf_TypeType;
typedef struct {
PyObject_HEAD
@@ -63,14 +63,14 @@ typedef struct {
ExprObject *expr;
} ExprImplArgObject;
extern PyTypeObject pgf_ExprType;
extern PyTypeObject pgf_ExprAbsType;
extern PyTypeObject pgf_ExprAppType;
extern PyTypeObject pgf_ExprLitType;
extern PyTypeObject pgf_ExprMetaType;
extern PyTypeObject pgf_ExprFunType;
extern PyTypeObject pgf_ExprVarType;
extern PyTypeObject pgf_ExprTypedType;
extern PyTypeObject pgf_ExprImplArgType;
PyTypeObject pgf_ExprType;
PyTypeObject pgf_ExprAbsType;
PyTypeObject pgf_ExprAppType;
PyTypeObject pgf_ExprLitType;
PyTypeObject pgf_ExprMetaType;
PyTypeObject pgf_ExprFunType;
PyTypeObject pgf_ExprVarType;
PyTypeObject pgf_ExprTypedType;
PyTypeObject pgf_ExprImplArgType;
#endif // PYPGF_EXPR_H_

View File

@@ -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 };

View File

@@ -12,13 +12,13 @@ typedef struct {
PgfRevision revision;
} PGFObject;
extern PyObject *PGFError;
PyObject *PGFError;
PgfExnType handleError(PgfExn err);
PgfText *PyUnicode_AsPgfText(PyObject *pystr);
PyObject *PyUnicode_FromPgfText(PgfText *text);
extern PgfUnmarshaller unmarshaller;
extern PgfMarshaller marshaller;
PgfUnmarshaller unmarshaller;
PgfMarshaller marshaller;
#endif // PYPGF_FFI_H_

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ def gr2(gr1):
@pytest.fixture(scope="module")
def gr3(gr1):
with gr1.newTransaction() as t:
with gr1.newTransaction("bar_branch") as t:
t.createFunction("bar", ty, 0, prob),
# t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob)
return gr1

View File

@@ -11,10 +11,22 @@ TransactionObject *
PGF_newTransaction(PGFObject *self, PyObject *args)
{
PgfText *name = NULL;
// PgfText *name = PyUnicode_AsPgfText(PyUnicode_FromString("transient"));
const char *s = NULL;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "|s#", &s, &size))
return NULL;
if (s != NULL) {
name = (PgfText *)PyMem_Malloc(sizeof(PgfText)+size+1);
memcpy(name->text, s, size+1);
name->size = size;
}
PgfExn err;
PgfRevision rev = pgf_clone_revision(self->db, self->revision, name, &err);
if (name != NULL) {
PyMem_Free(name);
}
if (handleError(err) != PGF_EXN_NONE) {
return NULL;
}
@@ -26,7 +38,7 @@ PGF_newTransaction(PGFObject *self, PyObject *args)
return trans;
}
PyObject *
static PyObject *
Transaction_commit(TransactionObject *self, PyObject *args)
{
PgfExn err;
@@ -40,7 +52,7 @@ Transaction_commit(TransactionObject *self, PyObject *args)
Py_RETURN_TRUE;
}
PyObject *
static PyObject *
Transaction_createFunction(TransactionObject *self, PyObject *args)
{
const char *s;
@@ -65,7 +77,7 @@ Transaction_createFunction(TransactionObject *self, PyObject *args)
Py_RETURN_NONE;
}
PyObject *
static PyObject *
Transaction_dropFunction(TransactionObject *self, PyObject *args)
{
const char *s;
@@ -87,7 +99,7 @@ Transaction_dropFunction(TransactionObject *self, PyObject *args)
Py_RETURN_NONE;
}
PyObject *
static PyObject *
Transaction_createCategory(TransactionObject *self, PyObject *args)
{
const char *s;
@@ -113,7 +125,7 @@ Transaction_createCategory(TransactionObject *self, PyObject *args)
Py_RETURN_NONE;
}
PyObject *
static PyObject *
Transaction_dropCategory(TransactionObject *self, PyObject *args)
{
const char *s;
@@ -135,8 +147,6 @@ Transaction_dropCategory(TransactionObject *self, PyObject *args)
Py_RETURN_NONE;
}
// ----------------------------------------------------------------------------
static PyObject *
Transaction_enter(TransactionObject *self, PyObject *Py_UNUSED(ignored))
{

View File

@@ -12,24 +12,9 @@ typedef struct {
PgfRevision revision; // transient branch
} TransactionObject;
extern PyTypeObject pgf_TransactionType;
PyTypeObject pgf_TransactionType;
TransactionObject *
PGF_newTransaction(PGFObject *self, PyObject *args);
PyObject *
Transaction_commit(TransactionObject *self, PyObject *args);
PyObject *
Transaction_createFunction(TransactionObject *self, PyObject *args);
PyObject *
Transaction_dropFunction(TransactionObject *self, PyObject *args);
PyObject *
Transaction_createCategory(TransactionObject *self, PyObject *args);
PyObject *
Transaction_dropCategory(TransactionObject *self, PyObject *args);
#endif // PYPGF_TRANSACTIONS_H_