[Guile] New command-line option "-emit-setters".
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@858 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8b3c2f1c0a
commit
2963e7676c
5 changed files with 110 additions and 18 deletions
6
CHANGES
6
CHANGES
|
|
@ -3,6 +3,12 @@ SWIG (Simplified Wrapper and Interface Generator)
|
|||
Version 1.3 Alpha 5
|
||||
===================
|
||||
|
||||
9/19/00 : mkoeppe
|
||||
[Guile] Removed "-with-smobs" command-line option, as this is the
|
||||
default now. Added "-emit-setters" command-line option,
|
||||
which turns on generating procedures-with-setters; see
|
||||
internals.html.
|
||||
|
||||
9/18/00 : mkoeppe
|
||||
Incorporated patch #101430, fixing bugs in the Guile module:
|
||||
1. Some arguments were erroneously taken as *optional* arguments when
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ beazley@cs.uchicago.edu </br>
|
|||
<li><a name="i10.4" href="#10.4">10.4 Typemaps</a>
|
||||
<li><a name="i10.5" href="#10.5">10.5 Smobs</a>
|
||||
<li><a name="i10.6" href="#10.6">10.6 Exception Handling</a>
|
||||
<li><a name="i10.7" href="#10.7">10.7 Procedure documentation</a>
|
||||
<li><a name="i10.8" href="#10.8">10.8 Procedures with setters</a>
|
||||
</ul>
|
||||
<li><a name="i11" href="#11">11. Python Support</a>
|
||||
<li><a name="i12" href="#12">12. Perl Support</a>
|
||||
|
|
@ -1030,11 +1032,7 @@ information is read from <code>Lib/guile/typemaps.i</code>.
|
|||
</a>
|
||||
|
||||
<p>
|
||||
For pointer types, SWIG uses Guile smobs. This feature used to be
|
||||
available only SWIG was invoked with the command-line option
|
||||
"-with-smobs", but as of 2000/07/06 (swig-1.3a4) this is the default
|
||||
behavior; the command-line option "-with-smobs" is ignored silently.
|
||||
We plan to drop silent recognition of this option after 1.3a4.
|
||||
For pointer types, SWIG uses Guile smobs.
|
||||
|
||||
<p>
|
||||
Currently, one wrapper module must be generated without
|
||||
|
|
@ -1102,7 +1100,7 @@ The default when not specified here is to use "swig-error".
|
|||
See Lib/exception.i for details.
|
||||
|
||||
<a name="10.7" href="#i10.7">
|
||||
<h3>10.7 Guile procedure documentation</h3>
|
||||
<h3>10.7 Procedure documentation</h3>
|
||||
</a>
|
||||
|
||||
<p>If invoked with the command-line option <code>-procdoc
|
||||
|
|
@ -1125,7 +1123,27 @@ typemaps <code>indoc</code>, <code>outdoc</code>,
|
|||
<code>varoutdoc</code>. See <code>Lib/guile/typemaps.i</code> for
|
||||
details.
|
||||
|
||||
<a name="10.8" href="#i10.8">
|
||||
<h3>10.8 Procedures with setters</h3>
|
||||
</a>
|
||||
|
||||
<p>For global variables, SWIG creates a single wrapper procedure
|
||||
<code>(<var>variable</var> :optional value)</code>, which is used for
|
||||
both getting and setting the value. For struct members, SWIG creates
|
||||
two wrapper procedures <code>(<var>struct</var>-<var>member</var>-get
|
||||
pointer)</code> and <code>(<var>struct-member</var>-set pointer value)</code>.
|
||||
|
||||
<p>If invoked with the command-line option <code>-emit-setters</code>,
|
||||
SWIG will additionally create procedures with setters. For global
|
||||
variables, the procedure-with-setter <code><var>variable</var></code>
|
||||
is created, so you can use <code>(<var>variable</var>)</code> to get
|
||||
the value and <code>(set! (<var>variable</var>)
|
||||
<var>value</var>)</code> to set it. For struct members, the
|
||||
procedure-with-setter <code><var>struct</var>-<var>member</var></code>
|
||||
is created, so you can use <code>(<var>struct</var>-<var>member</var>
|
||||
<var>pointer</var>)</code> to get the value and <code>(set!
|
||||
(<var>struct</var>-<var>member</var> <var>pointer</var>)
|
||||
<var>value</var>)</code> to set it.
|
||||
|
||||
<a name="11" href="#i11">
|
||||
<h2>11. Python Support</h2>
|
||||
|
|
|
|||
7
NEW
7
NEW
|
|
@ -177,6 +177,13 @@ and it is simpler to implement than the old string based approach.
|
|||
|
||||
5.4 Perl shadow classes improved and optimized somewhat.
|
||||
|
||||
5.5 The Guile module represents pointers as smobs. (They used to be
|
||||
mangled into strings.) Memory leaks and type conversion bugs have been
|
||||
fixed. The Guile module system, including dynamic loading, and
|
||||
exceptions are supported. A typemap-driven procedure-documentation
|
||||
system has been added (requires Guile 1.4). Procedures-with-setters
|
||||
can be generated.
|
||||
|
||||
6. New Features
|
||||
---------------
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ GUILE::GUILE ()
|
|||
package = NULL;
|
||||
linkage = GUILE_LSTYLE_SIMPLE;
|
||||
procdoc = NULL;
|
||||
emit_setters = 0;
|
||||
struct_member = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
|
@ -81,12 +83,6 @@ GUILE::parse_args (int argc, char *argv[])
|
|||
fputs (guile_usage, stderr);
|
||||
SWIG_exit (EXIT_SUCCESS);
|
||||
}
|
||||
// Silent recognition (no side effects) of "-with-smobs" is here
|
||||
// as a convenience to users. This will be removed after 1.3a4
|
||||
// release. --ttn, 2000/07/20 13:01:07.
|
||||
else if (strcmp (argv[i], "-with-smobs") == 0) {
|
||||
Swig_mark_arg (i);
|
||||
}
|
||||
else if (strcmp (argv[i], "-prefix") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
prefix = new char[strlen (argv[i + 1]) + 2];
|
||||
|
|
@ -147,6 +143,10 @@ GUILE::parse_args (int argc, char *argv[])
|
|||
Swig_arg_error();
|
||||
}
|
||||
}
|
||||
else if (strcmp (argv[i], "-emit-setters") == 0) {
|
||||
emit_setters = 1;
|
||||
Swig_mark_arg (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -665,13 +665,44 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
|||
Printv(f_wrappers, ");\n", 0);
|
||||
Printv(f_wrappers, "}\n", 0);
|
||||
/* Register it */
|
||||
Printf (f_init, "\t gh_new_procedure(\"%s\", %s_rest, 0, 0, 1);\n",
|
||||
Printf (f_init, "gh_new_procedure(\"%s\", %s_rest, 0, 0, 1);\n",
|
||||
proc_name, wname, numargs-numopt, numopt);
|
||||
}
|
||||
else if (emit_setters && struct_member && strlen(Char(proc_name))>3) {
|
||||
int len = Len(proc_name);
|
||||
const char *pc = Char(proc_name);
|
||||
/* MEMBER-set and MEMBER-get functions. */
|
||||
int is_setter = (pc[len - 3] == 's');
|
||||
if (is_setter) {
|
||||
Printf(f_init, "SCM setter = ");
|
||||
struct_member = 2; /* have a setter */
|
||||
}
|
||||
else Printf(f_init, "SCM getter = ");
|
||||
Printf (f_init, "gh_new_procedure(\"%s\", %s, %d, %d, 0);\n",
|
||||
proc_name, wname, numargs-numopt, numopt);
|
||||
if (!is_setter) {
|
||||
/* Strip off "-get" */
|
||||
char *pws_name = (char*) malloc(sizeof(char) * (len - 3));
|
||||
strncpy(pws_name, pc, len - 3);
|
||||
pws_name[len - 4] = 0;
|
||||
if (struct_member==2) {
|
||||
/* There was a setter, so create a procedure with setter */
|
||||
Printf (f_init, "gh_define(\"%s\", "
|
||||
"scm_make_procedure_with_setter(getter, setter));\n",
|
||||
pws_name);
|
||||
}
|
||||
else {
|
||||
/* There was no setter, so make an alias to the getter */
|
||||
Printf (f_init, "gh_define(\"%s\", getter);\n",
|
||||
pws_name);
|
||||
}
|
||||
free(pws_name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Now register the function
|
||||
Printf (f_init, "\t gh_new_procedure(\"%s\", %s, %d, %d, 0);\n",
|
||||
proc_name, wname, numargs-numopt, numopt);
|
||||
/* Register the function */
|
||||
Printf (f_init, "gh_new_procedure(\"%s\", %s, %d, %d, 0);\n",
|
||||
proc_name, wname, numargs-numopt, numopt);
|
||||
}
|
||||
if (procdoc) {
|
||||
/* Write out procedure documentation */
|
||||
|
|
@ -797,8 +828,21 @@ GUILE::link_variable (char *name, char *iname, SwigType *t)
|
|||
|
||||
// Now add symbol to the Guile interpreter
|
||||
|
||||
Printf (f_init, "\t gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",
|
||||
proc_name, var_name);
|
||||
if (!emit_setters
|
||||
|| Status & STAT_READONLY) {
|
||||
/* Read-only variables become a simple procedure returning the
|
||||
value. */
|
||||
Printf (f_init, "\t gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",
|
||||
proc_name, var_name);
|
||||
}
|
||||
else {
|
||||
/* Read/write variables become a procedure with setter. */
|
||||
Printf (f_init, "\t{ SCM p = gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",
|
||||
proc_name, var_name);
|
||||
Printf (f_init, "\t gh_define(\"%s\", "
|
||||
"scm_make_procedure_with_setter(p, p)); }\n",
|
||||
proc_name);
|
||||
}
|
||||
|
||||
if (procdoc) {
|
||||
/* Compute documentation */
|
||||
|
|
@ -904,3 +948,17 @@ GUILE::declare_const (char *name, char *, SwigType *type, char *value)
|
|||
DelWrapper(f);
|
||||
}
|
||||
|
||||
void GUILE::cpp_variable(char *name, char *iname, SwigType *t)
|
||||
{
|
||||
if (emit_setters) {
|
||||
struct_member = 1;
|
||||
Printf(f_init, "{\n");
|
||||
Language::cpp_variable(name, iname, t);
|
||||
Printf(f_init, "}\n");
|
||||
struct_member = 0;
|
||||
}
|
||||
else {
|
||||
/* Only emit traditional VAR-get and VAR-set procedures */
|
||||
Language::cpp_variable(name, iname, t);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ private:
|
|||
GUILE_LSTYLE_HOBBIT // use (hobbit4d link)
|
||||
} linkage;
|
||||
File *procdoc;
|
||||
int emit_setters;
|
||||
int struct_member;
|
||||
void emit_linkage(char *module_name);
|
||||
|
||||
public :
|
||||
|
|
@ -51,6 +53,7 @@ public :
|
|||
void set_module(char *);
|
||||
void set_init (char *);
|
||||
void create_command (char *, char *) { };
|
||||
void cpp_variable(char *name, char *iname, SwigType *t);
|
||||
};
|
||||
|
||||
/* guile.h ends here */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue