Chicken: Add the %feature("constasvar"), which exports constants as variables instead of functions
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9197 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2f67b5a05c
commit
b001bf16a5
3 changed files with 34 additions and 4 deletions
|
|
@ -1,5 +1,10 @@
|
|||
Version 1.3.30 (in progress)
|
||||
============================
|
||||
07/04/2006: wuzzeb (John Lenz)
|
||||
[Chicken]
|
||||
Add %feature("constasvar"), which instead of exporting a constant as a
|
||||
scheme function, exports the constant as a scheme variable. Update the
|
||||
documentation as well.
|
||||
|
||||
07/04/2006: wsfulton
|
||||
New explicitcall feature which generates additional wrappers for virtual methods
|
||||
|
|
|
|||
|
|
@ -217,6 +217,16 @@
|
|||
use <tt>(my-variable)</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <tt>%feature("constasvar")</tt> can be applied to any constant
|
||||
or immutable variable. Instead of exporting the constant as
|
||||
as function that must be called, the constant will appear as a
|
||||
scheme variable. This causes the generated .scm file just contain the code
|
||||
<tt>(set! MYCONSTANT1 (MYCONSTANT1))</tt>. See
|
||||
<a href="Customization.html#features">Features and the %feature directive</a>
|
||||
for info on how to apply the %feature.
|
||||
</p>
|
||||
|
||||
<H3><a name="Chicken_nn9"></a>18.2.4 Functions</H3>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ static bool exporting_constructor = false;
|
|||
static String *constructor_name = 0;
|
||||
static String *member_name = 0;
|
||||
|
||||
/* sections of the clos code */
|
||||
/* sections of the .scm code */
|
||||
static String *scm_const_defs = 0;
|
||||
static String *clos_class_defines = 0;
|
||||
static String *clos_methods = 0;
|
||||
|
||||
|
|
@ -217,6 +218,7 @@ CHICKEN::top(Node *n)
|
|||
|
||||
clos_class_defines = NewString("");
|
||||
clos_methods = NewString("");
|
||||
scm_const_defs = NewString("");
|
||||
|
||||
Printf(f_runtime, "/* -*- buffer-read-only: t -*- vi: set ro: */\n");
|
||||
Swig_banner(f_runtime);
|
||||
|
|
@ -279,6 +281,8 @@ CHICKEN::top(Node *n)
|
|||
Printf (f_scm, "%s\n", closprefix);
|
||||
Printf (f_scm, "%s\n", clos_class_defines);
|
||||
Printf (f_scm, "%s\n", clos_methods);
|
||||
} else {
|
||||
Printf (f_scm, "%s\n", scm_const_defs);
|
||||
}
|
||||
|
||||
Printf(f_scm, "%s\n", chickentext);
|
||||
|
|
@ -304,6 +308,7 @@ CHICKEN::top(Node *n)
|
|||
|
||||
Delete(clos_class_defines);
|
||||
Delete(clos_methods);
|
||||
Delete(scm_const_defs);
|
||||
|
||||
/* Close all of the files */
|
||||
Delete(primitive_names);
|
||||
|
|
@ -824,13 +829,18 @@ CHICKEN::variableWrapper(Node *n) {
|
|||
|
||||
Node *class_node = classLookup(t);
|
||||
String *clos_code = Getattr(n, "tmap:varin:closcode");
|
||||
if (class_node && clos_code) {
|
||||
if (class_node && clos_code && !GetFlag(n, "feature:immutable")) {
|
||||
Replaceall(clos_code,"$input", "(car lst)");
|
||||
Printv(clos_methods, "(define (", clos_name, " . lst) (if (null? lst) (", chickenPrimitiveName(scmname), ") (",
|
||||
chickenPrimitiveName(scmname), " ", clos_code, ")))\n", NIL);
|
||||
} else {
|
||||
/* Simply re-export the procedure */
|
||||
Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL);
|
||||
if (GetFlag(n, "feature:immutable") && GetFlag(n, "feature:constasvar")) {
|
||||
Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL);
|
||||
Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL);
|
||||
} else {
|
||||
Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL);
|
||||
}
|
||||
}
|
||||
Delete(clos_name);
|
||||
}
|
||||
|
|
@ -1008,7 +1018,12 @@ CHICKEN::constantWrapper(Node *n)
|
|||
clos_name = NewString(member_name);
|
||||
else
|
||||
clos_name = chickenNameMapping(scmname, (char *)"");
|
||||
Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL);
|
||||
if (GetFlag(n,"feature:constasvar")) {
|
||||
Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL);
|
||||
Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL);
|
||||
} else {
|
||||
Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL);
|
||||
}
|
||||
Delete(clos_name);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue