summaryrefslogtreecommitdiff
path: root/Source/Modules/cffi.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Modules/cffi.cxx')
-rw-r--r--Source/Modules/cffi.cxx51
1 files changed, 32 insertions, 19 deletions
diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx
index 736564d1a..0aa933c56 100644
--- a/Source/Modules/cffi.cxx
+++ b/Source/Modules/cffi.cxx
@@ -22,7 +22,8 @@ public:
String *f_clhead;
String *f_clwrap;
bool CWrap; // generate wrapper file for C code?
- File *f_cxx;
+ File *f_begin;
+ File *f_runtime;
File *f_cxx_header;
File *f_cxx_wrapper;
File *f_clos;
@@ -67,6 +68,7 @@ private:
void CFFI::main(int argc, char *argv[]) {
int i;
+ Preprocessor_define("SWIGCFFI 1", 0);
SWIG_library_directory("cffi");
SWIG_config_file("cffi.swg");
generate_typedef_flag = 0;
@@ -119,16 +121,15 @@ int CFFI::top(Node *n) {
Printf(lisp_filename, "%s%s.lisp", SWIG_output_directory(), module);
- File *f_lisp = NewFile(lisp_filename, "w");
- NewFile(lisp_filename, "w");
+ File *f_lisp = NewFile(lisp_filename, "w", SWIG_output_files());
if (!f_lisp) {
FileErrorDisplay(lisp_filename);
SWIG_exit(EXIT_FAILURE);
}
if (CPlusPlus || CWrap) {
- f_cxx = NewFile(cxx_filename, "w");
- if (!f_cxx) {
+ f_begin = NewFile(cxx_filename, "w", SWIG_output_files());
+ if (!f_begin) {
Close(f_lisp);
Delete(f_lisp);
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
@@ -137,7 +138,7 @@ int CFFI::top(Node *n) {
String *clos_filename = NewString("");
Printf(clos_filename, "%s%s-clos.lisp", SWIG_output_directory(), module);
- f_clos = NewFile(clos_filename, "w");
+ f_clos = NewFile(clos_filename, "w", SWIG_output_files());
if (!f_clos) {
Close(f_lisp);
Delete(f_lisp);
@@ -145,22 +146,32 @@ int CFFI::top(Node *n) {
SWIG_exit(EXIT_FAILURE);
}
} else {
- f_cxx = NewString("");
+ f_begin = NewString("");
f_clos = NewString("");
}
- f_cxx_header = f_cxx;
+ f_runtime = NewString("");
+ f_cxx_header = f_runtime;
f_cxx_wrapper = NewString("");
Swig_register_filebyname("header", f_cxx_header);
Swig_register_filebyname("wrapper", f_cxx_wrapper);
- Swig_register_filebyname("runtime", f_cxx);
+ Swig_register_filebyname("begin", f_begin);
+ Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("lisphead", f_clhead);
if (!no_swig_lisp)
Swig_register_filebyname("swiglisp", f_cl);
else
Swig_register_filebyname("swiglisp", f_null);
+ Swig_banner(f_begin);
+
+ Printf(f_runtime, "\n");
+ Printf(f_runtime, "#define SWIGCFFI\n");
+ Printf(f_runtime, "\n");
+
+ Swig_banner_target_lang(f_lisp, ";;;");
+
Language::top(n);
Printf(f_lisp, "%s\n", f_clhead);
Printf(f_lisp, "%s\n", f_cl);
@@ -171,8 +182,10 @@ int CFFI::top(Node *n) {
Delete(f_cl);
Delete(f_clhead);
Delete(f_clwrap);
- Close(f_cxx);
- Delete(f_cxx);
+ Dump(f_runtime, f_begin);
+ Close(f_begin);
+ Delete(f_runtime);
+ Delete(f_begin);
Delete(f_cxx_wrapper);
Delete(f_null);
@@ -232,7 +245,7 @@ void CFFI::emit_defmethod(Node *n) {
ParmList *pl = Getattr(n, "parms");
int argnum = 0;
- Node *parent = parentNode(n);
+ Node *parent = getCurrentClass();
bool first = 0;
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
@@ -287,7 +300,7 @@ void CFFI::emit_initialize_instance(Node *n) {
ParmList *pl = Getattr(n, "parms");
int argnum = 0;
- Node *parent = parentNode(n);
+ Node *parent = getCurrentClass();
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
@@ -324,18 +337,18 @@ void CFFI::emit_initialize_instance(Node *n) {
}
void CFFI::emit_setter(Node *n) {
- Node *p = parentNode(n);
+ Node *parent = getCurrentClass();
Printf(f_clos, "(cl:defmethod (cl:setf %s) (arg0 (obj %s))\n (%s (ff-pointer obj) arg0))\n\n",
lispify_name(n, Getattr(n, "name"), "'method"),
- lispify_name(p, lispy_name(Char(Getattr(p, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function"));
+ lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function"));
}
void CFFI::emit_getter(Node *n) {
- Node *p = parentNode(n);
+ Node *parent = getCurrentClass();
Printf(f_clos, "(cl:defmethod %s ((obj %s))\n (%s (ff-pointer obj)))\n\n",
lispify_name(n, Getattr(n, "name"), "'method"),
- lispify_name(p, lispy_name(Char(Getattr(p, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function"));
+ lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function"));
}
int CFFI::memberfunctionHandler(Node *n) {
@@ -455,7 +468,7 @@ int CFFI::functionWrapper(Node *n) {
Printf(f->code, "}\n");
if (CPlusPlus)
- Wrapper_print(f, f_cxx);
+ Wrapper_print(f, f_runtime);
if (CPlusPlus) {
emit_defun(n, wname);
@@ -630,7 +643,7 @@ int CFFI::enumDeclaration(Node *n) {
else {
String *type = Getattr(c, "type");
String *converted_value = convert_literal(value, type);
- Printf(f_cl, "\n\t(%s %s)", slot_name, converted_value);
+ Printf(f_cl, "\n\t(%s #.%s)", slot_name, converted_value);
Delete(converted_value);
}
Delete(value);