Add feature:constasvar to guile module

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9255 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2006-08-19 23:32:56 +00:00
commit ebeee6b93b
4 changed files with 50 additions and 4 deletions

View file

@ -1,6 +1,10 @@
Version 1.3.30 (in progress) Version 1.3.30 (in progress)
============================ ============================
08/19/2006: wuzzeb (John Lenz)
[Guile] Add feature:constasvar to export constants as variables instead of functions
that return the constant value.
08/11/2006: wsfulton 08/11/2006: wsfulton
[Java] DetachCurrentThread calls have been added so that natively created threads [Java] DetachCurrentThread calls have been added so that natively created threads
no longer prevent the JVM from exiting. Bug reported by Thomas Dudziak and no longer prevent the JVM from exiting. Bug reported by Thomas Dudziak and

View file

@ -405,6 +405,13 @@ In <code><var>body</var></code>, the first result of
See also the "multivalue" example. See also the "multivalue" example.
</p> </p>
<p>Constants are exported as a function that returns the value. The
%feature("constasvar") can be applied to any constant, immutable variable, or enum.
Instead of exporting the constant as a function that must be called, the
constant will appear as a scheme variable. See
<a href="Customization.html#features">Features and the %feature directive</a>
for info on how to apply the %feature.</p>
<H2><a name="Guile_nn12"></a>19.6 Representation of pointers as smobs</H2> <H2><a name="Guile_nn12"></a>19.6 Representation of pointers as smobs</H2>

View file

@ -89,6 +89,10 @@ Information about SWIG is also available in Japanese translation at
What's New? What's New?
=========== ===========
SWIG-1.3.30 summary:
- Add feature:constasvar to guile and chicken modules, to export constants
as variables instead of functions that return the constant value.
SWIG-1.3.29 summary: SWIG-1.3.29 summary:
- Numerous important bug fixes - Numerous important bug fixes
- Few minor new features - Few minor new features

View file

@ -1279,8 +1279,25 @@ public:
value; read-write variables become a simple procedure with value; read-write variables become a simple procedure with
an optional argument. */ an optional argument. */
if (use_scm_interface) { if (use_scm_interface) {
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
proc_name, !GetFlag(n, "feature:immutable"), var_name); proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
/* Export the function as normal */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
proc_name, !GetFlag(n, "feature:immutable"), var_name);
}
} else { } else {
Printf (f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", Printf (f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n",
proc_name, var_name, !GetFlag(n,"feature:immutable")); proc_name, var_name, !GetFlag(n,"feature:immutable"));
@ -1312,7 +1329,12 @@ public:
Printv(primitive_name, "primitive:", NIL); Printv(primitive_name, "primitive:", NIL);
Printv(primitive_name, proc_name, NIL); Printv(primitive_name, proc_name, NIL);
/* Simply re-export the procedure */ /* Simply re-export the procedure */
if ( (!emit_setters || GetFlag(n, "feature:immutable"))
&& GetFlag(n, "feature:constasvar")) {
Printv(goopscode, "(define ", goops_name, " (", primitive_name, "))\n", NIL);
} else {
Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL); Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL);
}
Printf(goopsexport, "%s ", goops_name); Printf(goopsexport, "%s ", goops_name);
Delete(primitive_name); Delete(primitive_name);
Delete(class_name); Delete(class_name);
@ -1327,7 +1349,11 @@ public:
if (GetFlag(n,"feature:immutable")) { if (GetFlag(n,"feature:immutable")) {
Printv(signature, proc_name, NIL); Printv(signature, proc_name, NIL);
if (GetFlag(n, "feature:constasvar")) {
Printv(doc, "Is constant ", NIL);
} else {
Printv(doc, "Returns constant ", NIL); Printv(doc, "Returns constant ", NIL);
}
if ((tm = Getattr(n,"tmap:varout:doc"))) { if ((tm = Getattr(n,"tmap:varout:doc"))) {
Printv(doc,tm,NIL); Printv(doc,tm,NIL);
} else { } else {
@ -1399,6 +1425,8 @@ public:
char *iname = GetChar(n,"sym:name"); char *iname = GetChar(n,"sym:name");
SwigType *type = Getattr(n,"type"); SwigType *type = Getattr(n,"type");
String *value = Getattr(n,"value"); String *value = Getattr(n,"value");
int constasvar = GetFlag(n, "feature:constasvar");
String *proc_name; String *proc_name;
char var_name[256]; char var_name[256];
@ -1457,6 +1485,9 @@ public:
Setattr(n,"sym:name",iname); Setattr(n,"sym:name",iname);
Setattr(n,"type", nctype); Setattr(n,"type", nctype);
SetFlag(n,"feature:immutable"); SetFlag(n,"feature:immutable");
if (constasvar) {
SetFlag(n,"feature:constasvar");
}
variableWrapper(n); variableWrapper(n);
Delete(n); Delete(n);
} }