mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
Refactoring py object constructors.
This commit is contained in:
@@ -97,8 +97,7 @@ languageCode(PGF *self, PyObject *args)
|
||||
Lang *lang;
|
||||
if (!PyArg_ParseTuple(args, "O", &lang))
|
||||
return NULL;
|
||||
if (!checkType(lang, &LangType))
|
||||
return NULL;
|
||||
if (!checkType(lang, &LangType)) return NULL;
|
||||
char* scode = gf_languageCode(self, lang);
|
||||
if (scode) {
|
||||
PyObject* result = PyString_FromString(scode);
|
||||
@@ -296,9 +295,9 @@ PyModule_AddObject(m, "gf", (PyObject *)&t);
|
||||
}
|
||||
|
||||
|
||||
inline Lang* newLang() {
|
||||
/* inline Lang* newLang() {
|
||||
return (Lang*)LangType.tp_new(&LangType,NULL,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
inline Tree* newTree() {
|
||||
return (Tree*)TreeType.tp_new(&TreeType,NULL,NULL);
|
||||
@@ -307,9 +306,7 @@ inline Tree* newTree() {
|
||||
inline CId* newCId() {
|
||||
return (CId*)CIdType.tp_new(&CIdType,NULL,NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
inline PyObject* newList() { return PyList_New(0); }
|
||||
|
||||
void append(PyObject* l, PyObject* ob) {
|
||||
PyList_Append(l, ob);
|
||||
}
|
||||
inline void append(PyObject* l, PyObject* ob) { PyList_Append(l, ob); }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <Python.h>
|
||||
//#include "pgf.h"
|
||||
#include "HsFFI.h"
|
||||
|
||||
#ifdef __GLASGOW_HASKELL__
|
||||
@@ -38,6 +37,10 @@ typedef struct {
|
||||
GFTYPE obj; \
|
||||
} OBJ;
|
||||
|
||||
#define PYTYPE(OBJ) OBJ ## Type
|
||||
#define NEWCONSTRUCTOR(OBJ) inline OBJ* new ## OBJ () {\
|
||||
return (OBJ*)PYTYPE(OBJ).tp_new(&PYTYPE(OBJ),NULL,NULL); }
|
||||
|
||||
#define NEWTYPE(TYPE,NAME,OBJECT,DOC) static PyTypeObject TYPE = {\
|
||||
PyObject_HEAD_INIT(NULL)\
|
||||
0, /*ob_size*/\
|
||||
@@ -63,7 +66,8 @@ typedef struct {
|
||||
DOC, /* tp_doc */\
|
||||
};
|
||||
#define NEWGF(OBJ,GFTYPE,TYPE,NAME,DOC) NEWOBJECT(OBJ,GFTYPE) \
|
||||
NEWTYPE(TYPE,NAME,OBJ,DOC)
|
||||
NEWTYPE(TYPE,NAME,OBJ,DOC)\
|
||||
NEWCONSTRUCTOR(OBJ)
|
||||
|
||||
|
||||
// NEWOBJECT(CID, GF_CId)
|
||||
|
||||
Reference in New Issue
Block a user