forked from GitHub/gf-core
Refactoring py object constructors.
This commit is contained in:
@@ -97,8 +97,7 @@ languageCode(PGF *self, PyObject *args)
|
|||||||
Lang *lang;
|
Lang *lang;
|
||||||
if (!PyArg_ParseTuple(args, "O", &lang))
|
if (!PyArg_ParseTuple(args, "O", &lang))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!checkType(lang, &LangType))
|
if (!checkType(lang, &LangType)) return NULL;
|
||||||
return NULL;
|
|
||||||
char* scode = gf_languageCode(self, lang);
|
char* scode = gf_languageCode(self, lang);
|
||||||
if (scode) {
|
if (scode) {
|
||||||
PyObject* result = PyString_FromString(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);
|
return (Lang*)LangType.tp_new(&LangType,NULL,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Tree* newTree() {
|
inline Tree* newTree() {
|
||||||
return (Tree*)TreeType.tp_new(&TreeType,NULL,NULL);
|
return (Tree*)TreeType.tp_new(&TreeType,NULL,NULL);
|
||||||
@@ -307,9 +306,7 @@ inline Tree* newTree() {
|
|||||||
inline CId* newCId() {
|
inline CId* newCId() {
|
||||||
return (CId*)CIdType.tp_new(&CIdType,NULL,NULL);
|
return (CId*)CIdType.tp_new(&CIdType,NULL,NULL);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
inline PyObject* newList() { return PyList_New(0); }
|
inline PyObject* newList() { return PyList_New(0); }
|
||||||
|
inline void append(PyObject* l, PyObject* ob) { PyList_Append(l, ob); }
|
||||||
void append(PyObject* l, PyObject* ob) {
|
|
||||||
PyList_Append(l, ob);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
//#include "pgf.h"
|
|
||||||
#include "HsFFI.h"
|
#include "HsFFI.h"
|
||||||
|
|
||||||
#ifdef __GLASGOW_HASKELL__
|
#ifdef __GLASGOW_HASKELL__
|
||||||
@@ -38,6 +37,10 @@ typedef struct {
|
|||||||
GFTYPE obj; \
|
GFTYPE obj; \
|
||||||
} 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 = {\
|
#define NEWTYPE(TYPE,NAME,OBJECT,DOC) static PyTypeObject TYPE = {\
|
||||||
PyObject_HEAD_INIT(NULL)\
|
PyObject_HEAD_INIT(NULL)\
|
||||||
0, /*ob_size*/\
|
0, /*ob_size*/\
|
||||||
@@ -63,7 +66,8 @@ typedef struct {
|
|||||||
DOC, /* tp_doc */\
|
DOC, /* tp_doc */\
|
||||||
};
|
};
|
||||||
#define NEWGF(OBJ,GFTYPE,TYPE,NAME,DOC) NEWOBJECT(OBJ,GFTYPE) \
|
#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)
|
// NEWOBJECT(CID, GF_CId)
|
||||||
|
|||||||
Reference in New Issue
Block a user