Some chicken bug fixes for overloaded -proxy methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7145 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
64d9c13420
commit
c70b62fee2
2 changed files with 35 additions and 62 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
(declare (hide swig-initialize swig-init-return))
|
(declare (hide swig-initialize))
|
||||||
|
|
||||||
(define (swig-initialize obj initargs create)
|
(define (swig-initialize obj initargs create)
|
||||||
(slot-set! obj 'swig-this
|
(slot-set! obj 'swig-this
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ CHICKEN Options (available with -chicken)\n\
|
||||||
-useclassprefix - Prepend the class name to all clos identifiers\n\
|
-useclassprefix - Prepend the class name to all clos identifiers\n\
|
||||||
-unhideprimitive - Unhide the primitive: symbols\n\
|
-unhideprimitive - Unhide the primitive: symbols\n\
|
||||||
-nounit - Do not (declare (unit ...)) in scheme file\n\
|
-nounit - Do not (declare (unit ...)) in scheme file\n\
|
||||||
|
-noclosuses - Do not (declare (uses ...)) in scheme file\n\
|
||||||
-nocollection - Do not register pointers with chicken garbage\n\
|
-nocollection - Do not register pointers with chicken garbage\n\
|
||||||
collector and export destructors\n\
|
collector and export destructors\n\
|
||||||
\n"
|
\n"
|
||||||
|
|
@ -59,6 +60,7 @@ static String *closcode = 0;
|
||||||
/* some options */
|
/* some options */
|
||||||
static int declare_unit = 1;
|
static int declare_unit = 1;
|
||||||
static int no_collection = 0;
|
static int no_collection = 0;
|
||||||
|
static int clos_uses = 1;
|
||||||
|
|
||||||
/* C++ Support + Clos Classes */
|
/* C++ Support + Clos Classes */
|
||||||
static int clos = 0;
|
static int clos = 0;
|
||||||
|
|
@ -116,7 +118,7 @@ protected:
|
||||||
|
|
||||||
String *runtimeCode();
|
String *runtimeCode();
|
||||||
String *defaultExternalRuntimeFilename();
|
String *defaultExternalRuntimeFilename();
|
||||||
String *buildClosFunctionCall(List *types, char *format, String_or_char *funcName, int method_specialize);
|
String *buildClosFunctionCall(List *types, String_or_char *closname, String_or_char *funcname);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
|
|
@ -180,6 +182,9 @@ CHICKEN::main(int argc, char *argv[])
|
||||||
} else if (strcmp(argv[i],"-nounit") == 0) {
|
} else if (strcmp(argv[i],"-nounit") == 0) {
|
||||||
declare_unit = 0;
|
declare_unit = 0;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i],"-noclosuses") == 0) {
|
||||||
|
clos_uses = 0;
|
||||||
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-nocollection") == 0) {
|
} else if (strcmp(argv[i],"-nocollection") == 0) {
|
||||||
no_collection = 1;
|
no_collection = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
|
@ -287,7 +292,7 @@ CHICKEN::top(Node *n)
|
||||||
if (declare_unit)
|
if (declare_unit)
|
||||||
Printv(f_scm,"(declare (unit ", scmmodule, "))\n\n", NIL);
|
Printv(f_scm,"(declare (unit ", scmmodule, "))\n\n", NIL);
|
||||||
Printv(f_scm,"(declare \n",
|
Printv(f_scm,"(declare \n",
|
||||||
tab4, "(hide swig-init)\n",
|
tab4, "(hide swig-init swig-init-return)\n",
|
||||||
tab4, "(foreign-declare \"C_extern void swig_", module, "_init(C_word,C_word,C_word) C_noret;\"))\n", NIL);
|
tab4, "(foreign-declare \"C_extern void swig_", module, "_init(C_word,C_word,C_word) C_noret;\"))\n", NIL);
|
||||||
Printv(f_scm,"(define swig-init (##core#primitive \"swig_", module,
|
Printv(f_scm,"(define swig-init (##core#primitive \"swig_", module,
|
||||||
"_init\"))\n", NIL);
|
"_init\"))\n", NIL);
|
||||||
|
|
@ -469,7 +474,7 @@ CHICKEN::functionWrapper(Node *n)
|
||||||
any_specialized_arg = true;
|
any_specialized_arg = true;
|
||||||
Delete(class_name);
|
Delete(class_name);
|
||||||
} else {
|
} else {
|
||||||
Append(function_arg_types, "^^##primitive$$");
|
Append(function_arg_types, "<top>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -631,16 +636,11 @@ CHICKEN::functionWrapper(Node *n)
|
||||||
|
|
||||||
if (!any_specialized_arg) {
|
if (!any_specialized_arg) {
|
||||||
method_def = NewString("");
|
method_def = NewString("");
|
||||||
Printv(method_def, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL);
|
Printv(method_def, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")", NIL);
|
||||||
} else {
|
} else {
|
||||||
String *fmt = NewStringf("(define-method (%s %%s) %%s)\n", clos_name);
|
method_def = buildClosFunctionCall(function_arg_types, clos_name, chickenPrimitiveName(scmname));
|
||||||
method_def = buildClosFunctionCall(function_arg_types,
|
|
||||||
Char(fmt),
|
|
||||||
chickenPrimitiveName(scmname),
|
|
||||||
1);
|
|
||||||
Delete(fmt);
|
|
||||||
}
|
}
|
||||||
Printv(clos_methods, method_def, NIL);
|
Printv(clos_methods, method_def, "\n", NIL);
|
||||||
Delete(clos_name);
|
Delete(clos_name);
|
||||||
Delete(method_def);
|
Delete(method_def);
|
||||||
}
|
}
|
||||||
|
|
@ -1060,22 +1060,22 @@ CHICKEN::classHandler(Node *n)
|
||||||
" (call-next-method)\n",
|
" (call-next-method)\n",
|
||||||
" (swig-initialize obj initargs ", NIL);
|
" (swig-initialize obj initargs ", NIL);
|
||||||
if (constructor_arg_types) {
|
if (constructor_arg_types) {
|
||||||
String *func_call = buildClosFunctionCall(constructor_arg_types,
|
String *initfunc_name = NewStringf("%s@@SWIG@initmethod", class_name);
|
||||||
"(lambda (%s) %s)",
|
String *func_call = buildClosFunctionCall(constructor_arg_types, initfunc_name, chickenPrimitiveName(constructor_name));
|
||||||
chickenPrimitiveName(constructor_name),
|
Printf(clos_methods, "%s)\n)\n", initfunc_name);
|
||||||
0);
|
Printf(clos_methods, "(declare (hide %s))\n", initfunc_name);
|
||||||
Printf(clos_methods, "%s", func_call);
|
Printf(clos_methods, "%s\n", func_call);
|
||||||
Delete(func_call);
|
Delete(func_call);
|
||||||
|
Delete(initfunc_name);
|
||||||
Delete(constructor_arg_types);
|
Delete(constructor_arg_types);
|
||||||
constructor_arg_types = 0;
|
constructor_arg_types = 0;
|
||||||
} else if (constructor_dispatch) {
|
} else if (constructor_dispatch) {
|
||||||
Printf(clos_methods, "%s", constructor_dispatch);
|
Printf(clos_methods, "%s)\n)\n", constructor_dispatch);
|
||||||
Delete(constructor_dispatch);
|
Delete(constructor_dispatch);
|
||||||
constructor_dispatch = 0;
|
constructor_dispatch = 0;
|
||||||
} else {
|
} else {
|
||||||
Printf(clos_methods, "%s", chickenPrimitiveName(constructor_name));
|
Printf(clos_methods, "%s)\n)\n", chickenPrimitiveName(constructor_name));
|
||||||
}
|
}
|
||||||
Printf(clos_methods, ")\n)\n");
|
|
||||||
Delete(constructor_name);
|
Delete(constructor_name);
|
||||||
constructor_name = 0;
|
constructor_name = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1240,7 +1240,7 @@ int CHICKEN::destructorHandler(Node *n) {
|
||||||
|
|
||||||
int CHICKEN::importDirective(Node *n) {
|
int CHICKEN::importDirective(Node *n) {
|
||||||
String *modname = Getattr(n, "module");
|
String *modname = Getattr(n, "module");
|
||||||
if (modname) {
|
if (modname && clos_uses) {
|
||||||
|
|
||||||
// Find the module node for this imported module. It should be the
|
// Find the module node for this imported module. It should be the
|
||||||
// first child but search just in case.
|
// first child but search just in case.
|
||||||
|
|
@ -1259,7 +1259,7 @@ int CHICKEN::importDirective(Node *n) {
|
||||||
return Language::importDirective(n);
|
return Language::importDirective(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
String *CHICKEN::buildClosFunctionCall(List *types, char *format, String_or_char *funcName, int method_specialize) {
|
String *CHICKEN::buildClosFunctionCall(List *types, String_or_char *closname, String_or_char *funcname) {
|
||||||
String *method_signature = NewString("");
|
String *method_signature = NewString("");
|
||||||
String *func_args = NewString("");
|
String *func_args = NewString("");
|
||||||
String *func_call = NewString("");
|
String *func_call = NewString("");
|
||||||
|
|
@ -1267,45 +1267,33 @@ String *CHICKEN::buildClosFunctionCall(List *types, char *format, String_or_char
|
||||||
Iterator arg_type;
|
Iterator arg_type;
|
||||||
int arg_count = 0;
|
int arg_count = 0;
|
||||||
int optional_arguments = 0;
|
int optional_arguments = 0;
|
||||||
int first_argument = 1;
|
|
||||||
|
|
||||||
for (arg_type = First(types); arg_type.item; arg_type = Next(arg_type)) {
|
for (arg_type = First(types); arg_type.item; arg_type = Next(arg_type)) {
|
||||||
if (Strcmp(arg_type.item, "^^##optional$$") == 0) {
|
if (Strcmp(arg_type.item, "^^##optional$$") == 0) {
|
||||||
optional_arguments = 1;
|
optional_arguments = 1;
|
||||||
} else if (Strcmp(arg_type.item, "^^##primitive$$") == 0) {
|
|
||||||
if (first_argument)
|
|
||||||
Printf(method_signature, " (arg%i <top>)", arg_count);
|
|
||||||
else
|
|
||||||
Printf(method_signature, " arg%i", arg_count);
|
|
||||||
|
|
||||||
Printf(func_args, " arg%i", arg_count);
|
|
||||||
first_argument = 0;
|
|
||||||
} else {
|
} else {
|
||||||
first_argument = 0;
|
|
||||||
if (method_specialize) {
|
|
||||||
Printf(method_signature, " (arg%i %s)", arg_count, arg_type.item);
|
Printf(method_signature, " (arg%i %s)", arg_count, arg_type.item);
|
||||||
|
if (Strcmp(arg_type.item, "<top>") == 0) {
|
||||||
|
Printf(func_args, " arg%i", arg_count);
|
||||||
} else {
|
} else {
|
||||||
Printf(method_signature, " arg%i", arg_count);
|
|
||||||
}
|
|
||||||
Printf(func_args, " (slot-ref arg%i 'swig-this)", arg_count);
|
Printf(func_args, " (slot-ref arg%i 'swig-this)", arg_count);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
arg_count++;
|
arg_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optional_arguments) {
|
if (optional_arguments) {
|
||||||
Printf(func_call, "(apply %s %s args)", funcName, func_args);
|
Printf(func_call, "(define-method (%s %s . args) (apply %s %s args))",
|
||||||
Printf(method_signature, " . args");
|
closname, method_signature, funcname, func_args);
|
||||||
} else {
|
} else {
|
||||||
Printf(func_call, "(%s %s)", funcName, func_args);
|
Printf(func_call, "(define-method (%s %s) (%s %s))",
|
||||||
|
closname, method_signature, funcname, func_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
String *ret = NewStringf(format, method_signature, func_call);
|
|
||||||
|
|
||||||
Delete(method_signature);
|
Delete(method_signature);
|
||||||
Delete(func_args);
|
Delete(func_args);
|
||||||
Delete(func_call);
|
|
||||||
|
|
||||||
return ret;
|
return func_call;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -1431,27 +1419,20 @@ CHICKEN::dispatchFunction(Node *n)
|
||||||
|
|
||||||
Iterator f;
|
Iterator f;
|
||||||
List *prev = 0;
|
List *prev = 0;
|
||||||
int has_empty_call = 0;
|
|
||||||
int all_primitive = 1;
|
int all_primitive = 1;
|
||||||
|
|
||||||
/* first check for duplicates and an empty call */
|
/* first check for duplicates and an empty call */
|
||||||
String *method_name = NewString(clos_name);
|
|
||||||
String *newlist = NewList();
|
String *newlist = NewList();
|
||||||
for (f = First(flist); f.item; f = Next(f)) {
|
for (f = First(flist); f.item; f = Next(f)) {
|
||||||
/* check if cur is a duplicate of prev */
|
/* check if cur is a duplicate of prev */
|
||||||
if (prev && compareTypeLists(f.item, prev) == 0) {
|
if (prev && compareTypeLists(f.item, prev) == 0) {
|
||||||
Delete(f.item);
|
Delete(f.item);
|
||||||
} else if (Len(f.item) == 0) {
|
|
||||||
has_empty_call = 1;
|
|
||||||
Delete(method_name);
|
|
||||||
method_name = NewStringf("%s@SWIG@multireal", clos_name);
|
|
||||||
Delete(f.item);
|
|
||||||
} else {
|
} else {
|
||||||
Append(newlist, f.item);
|
Append(newlist, f.item);
|
||||||
prev = f.item;
|
prev = f.item;
|
||||||
Iterator j;
|
Iterator j;
|
||||||
for (j = First(f.item); j.item; j = Next(j)) {
|
for (j = First(f.item); j.item; j = Next(j)) {
|
||||||
if (Strcmp(j.item, "^^##optional$$") != 0 && Strcmp(j.item, "^^##primitive$$") != 0)
|
if (Strcmp(j.item, "^^##optional$$") != 0 && Strcmp(j.item, "<top>") != 0)
|
||||||
all_primitive = 0;
|
all_primitive = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1460,25 +1441,17 @@ CHICKEN::dispatchFunction(Node *n)
|
||||||
flist = newlist;
|
flist = newlist;
|
||||||
|
|
||||||
if (all_primitive) {
|
if (all_primitive) {
|
||||||
Printf(clos_methods, "(define %s %s)\n", method_name, chickenPrimitiveName(scmname));
|
Printf(clos_methods, "(define %s %s)\n", clos_name, chickenPrimitiveName(scmname));
|
||||||
} else {
|
} else {
|
||||||
for (f = First(flist); f.item; f = Next(f)) {
|
for (f = First(flist); f.item; f = Next(f)) {
|
||||||
/* now export clos code for argument */
|
/* now export clos code for argument */
|
||||||
String *fmt = NewStringf("(define-method (%s %%s) %%s)\n", method_name);
|
String *func_call = buildClosFunctionCall(f.item, clos_name, chickenPrimitiveName(scmname));
|
||||||
String *func_call = buildClosFunctionCall(f.item, Char(fmt), chickenPrimitiveName(scmname), 1);
|
Printf(clos_methods, "%s\n", func_call);
|
||||||
Printf(clos_methods, "%s", func_call);
|
|
||||||
Delete(f.item);
|
Delete(f.item);
|
||||||
Delete(func_call);
|
Delete(func_call);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_empty_call) {
|
|
||||||
Printf(clos_methods, "(declare (hide %s))\n", method_name);
|
|
||||||
Printf(clos_methods, "(define (%s . args) (if (null? args) (%s) (apply %s@SWIG@multireal args)))\n",
|
|
||||||
clos_name, chickenPrimitiveName(scmname), clos_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Delete(method_name);
|
|
||||||
Delete(clos_name);
|
Delete(clos_name);
|
||||||
Delete(flist);
|
Delete(flist);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue