Major clean up in the Guile module.
Started new typemap-based procedure documentation system. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@707 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
14fb2af077
commit
a227b419fe
2 changed files with 163 additions and 365 deletions
|
|
@ -1,175 +1,48 @@
|
||||||
/* typemaps.i --- guile-specific typemaps
|
/* typemaps.i --- guile-specific typemaps -*- c -*-
|
||||||
Copyright (C) 2000 Matthias Koeppe <mkoeppe@saturn.Math.Uni-Magdeburg.DE>
|
Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
|
||||||
|
|
||||||
$Header$ */
|
$Header$ */
|
||||||
|
|
||||||
#define MK_SIMPLE_MAP(f) $target = f ($source)
|
/* Basic types */
|
||||||
|
|
||||||
#define SIMPLE_IN_MAP_SET(op) \
|
#define SIMPLE_MAP(C_NAME, SCM_TO_C, C_TO_SCM, SCM_NAME) \
|
||||||
%typemap (guile, op) bool { MK_SIMPLE_MAP (gh_scm2bool); } \
|
%typemap (guile, in) C_NAME "$target = SCM_TO_C($source);"; \
|
||||||
%typemap (guile, op) char { MK_SIMPLE_MAP (gh_scm2char); } \
|
%typemap (guile, varin) C_NAME "$target = SCM_TO_C($source);"; \
|
||||||
%typemap (guile, op) int { MK_SIMPLE_MAP (gh_scm2int); } \
|
%typemap (guile, out) C_NAME "$target = C_TO_SCM($source);"; \
|
||||||
%typemap (guile, op) short { MK_SIMPLE_MAP (gh_scm2int); } \
|
%typemap (guile, varout) C_NAME "$target = C_TO_SCM($source);"; \
|
||||||
%typemap (guile, op) long { MK_SIMPLE_MAP (gh_scm2long); } \
|
%typemap (guile, indoc) C_NAME "($ARG <SCM_NAME>)"; \
|
||||||
%typemap (guile, op) ptrdiff_t { MK_SIMPLE_MAP (gh_scm2long); } \
|
%typemap (guile, outdoc) C_NAME "<SCM_NAME>"; \
|
||||||
%typemap (guile, op) unsigned int { MK_SIMPLE_MAP (gh_scm2ulong); } \
|
%typemap (guile, in) C_NAME *INPUT (C_NAME temp) \
|
||||||
%typemap (guile, op) unsigned short { MK_SIMPLE_MAP (gh_scm2ulong); } \
|
{ temp = (C_NAME) C_TO_SCM($source); $target = &temp; } \
|
||||||
%typemap (guile, op) unsigned long { MK_SIMPLE_MAP (gh_scm2ulong); } \
|
%typemap (guile, indoc) C_NAME *INPUT "($arg <SCM_NAME>)"; \
|
||||||
%typemap (guile, op) size_t { MK_SIMPLE_MAP (gh_scm2ulong); } \
|
%typemap (guile, ignore) C_NAME *OUTPUT (C_NAME temp) \
|
||||||
%typemap (guile, op) float { MK_SIMPLE_MAP (gh_scm2double); } \
|
{ $target = &temp; } \
|
||||||
%typemap (guile, op) double { MK_SIMPLE_MAP (gh_scm2double); } \
|
%typemap (guile, argout) C_NAME *OUTPUT \
|
||||||
%typemap (guile, op) char * { MK_SIMPLE_MAP (GSWIG_scm2str); }
|
"GUILE_APPEND_RESULT(C_TO_SCM(*$target));"; \
|
||||||
|
%typemap (guile, argoutdoc) C_NAME *OUTPUT "($ARG <SCM_NAME>)"; \
|
||||||
|
%typemap (guile, in) C_NAME *BOTH = C_NAME *INPUT; \
|
||||||
|
%typemap (guile, indoc) C_NAME *BOTH = C_NAME *INPUT; \
|
||||||
|
%typemap (guile, argout) C_NAME *BOTH = C_NAME *OUTPUT; \
|
||||||
|
%typemap (guile, argoutdoc) C_NAME *BOTH = C_NAME *OUTPUT
|
||||||
|
|
||||||
#define SIMPLE_OUT_MAP_SET(op) \
|
SIMPLE_MAP(bool, gh_scm2bool, gh_bool2scm, boolean);
|
||||||
%typemap (guile, op) bool { MK_SIMPLE_MAP (gh_bool2scm); } \
|
SIMPLE_MAP(char, gh_scm2char, gh_char2scm, char);
|
||||||
%typemap (guile, op) char { MK_SIMPLE_MAP (gh_char2scm); } \
|
SIMPLE_MAP(unsigned char, gh_scm2char, gh_char2scm, char);
|
||||||
%typemap (guile, op) int { MK_SIMPLE_MAP (gh_int2scm); } \
|
SIMPLE_MAP(int, gh_scm2int, gh_int2scm, integer);
|
||||||
%typemap (guile, op) short { MK_SIMPLE_MAP (gh_int2scm); } \
|
SIMPLE_MAP(short, gh_scm2int, gh_int2scm, integer);
|
||||||
%typemap (guile, op) long { MK_SIMPLE_MAP (gh_long2scm); } \
|
SIMPLE_MAP(long, gh_scm2long, gh_long2scm, integer);
|
||||||
%typemap (guile, op) ptrdiff_t { MK_SIMPLE_MAP (gh_long2scm); } \
|
SIMPLE_MAP(ptrdiff_t, gh_scm2long, gh_long2scm, integer);
|
||||||
%typemap (guile, op) unsigned int { MK_SIMPLE_MAP (gh_ulong2scm); } \
|
SIMPLE_MAP(unsigned int, gh_scm2ulong, gh_ulong2scm, integer);
|
||||||
%typemap (guile, op) unsigned short { MK_SIMPLE_MAP (gh_ulong2scm); } \
|
SIMPLE_MAP(unsigned short, gh_scm2ulong, gh_ulong2scm, integer);
|
||||||
%typemap (guile, op) unsigned long { MK_SIMPLE_MAP (gh_ulong2scm); } \
|
SIMPLE_MAP(unsigned long, gh_scm2ulong, gh_ulong2scm, integer);
|
||||||
%typemap (guile, op) size_t { MK_SIMPLE_MAP (gh_ulong2scm); } \
|
SIMPLE_MAP(size_t, gh_scm2ulong, gh_ulong2scm, integer);
|
||||||
%typemap (guile, op) float { MK_SIMPLE_MAP (gh_double2scm); } \
|
SIMPLE_MAP(float, gh_scm2double, gh_double2scm, real);
|
||||||
%typemap (guile, op) double { MK_SIMPLE_MAP (gh_double2scm); } \
|
SIMPLE_MAP(double, gh_scm2double, gh_double2scm, real);
|
||||||
%typemap (guile, op) char * { MK_SIMPLE_MAP (gh_str02scm); }
|
SIMPLE_MAP(char *, GSWIG_scm2str, gh_str02scm, string);
|
||||||
|
|
||||||
/*
|
/* Void */
|
||||||
* Declaration start here
|
|
||||||
*/
|
|
||||||
|
|
||||||
SIMPLE_IN_MAP_SET (in)
|
%typemap (guile, out) void "gswig_result = GH_UNSPECIFIED;";
|
||||||
SIMPLE_IN_MAP_SET (varin)
|
%typemap (guile, outdoc) void "";
|
||||||
|
|
||||||
SIMPLE_OUT_MAP_SET (out)
|
|
||||||
SIMPLE_OUT_MAP_SET (varout)
|
|
||||||
|
|
||||||
/* INPUT/OUTPUT/BOTH typemaps */
|
|
||||||
|
|
||||||
%typemap(guile,in) double *INPUT(double temp)
|
|
||||||
{
|
|
||||||
temp = gh_scm2double($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) float *INPUT(float temp)
|
|
||||||
{
|
|
||||||
temp = (float) gh_scm2double($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) int *INPUT(int temp)
|
|
||||||
{
|
|
||||||
temp = (int) gh_scm2int($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) short *INPUT(short temp)
|
|
||||||
{
|
|
||||||
temp = (short) gh_scm2int($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) long *INPUT(long temp),
|
|
||||||
ptrdiff_t *INPUT(long temp)
|
|
||||||
{
|
|
||||||
temp = (long) gh_scm2long($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) unsigned int *INPUT(unsigned int temp)
|
|
||||||
{
|
|
||||||
temp = (unsigned int) gh_scm2ulong($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) unsigned short *INPUT(unsigned short temp)
|
|
||||||
{
|
|
||||||
temp = (unsigned short) gh_scm2ulong($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) unsigned long *INPUT(unsigned long temp),
|
|
||||||
size_t *INPUT(unsigned long temp)
|
|
||||||
{
|
|
||||||
temp = (unsigned long) gh_scm2ulong($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
%typemap(guile,in) unsigned char *INPUT(unsigned char temp)
|
|
||||||
{
|
|
||||||
temp = (unsigned char) gh_scm2char($source);
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,ignore) int *OUTPUT(int temp),
|
|
||||||
short *OUTPUT(short temp),
|
|
||||||
long *OUTPUT(long temp),
|
|
||||||
ptrdiff_t *OUTPUT(ptrdiff_t temp),
|
|
||||||
unsigned int *OUTPUT(unsigned int temp),
|
|
||||||
unsigned short *OUTPUT(unsigned short temp),
|
|
||||||
unsigned long *OUTPUT(unsigned long temp),
|
|
||||||
size_t *OUTPUT(size_t temp),
|
|
||||||
unsigned char *OUTPUT(unsigned char temp),
|
|
||||||
float *OUTPUT(float temp),
|
|
||||||
double *OUTPUT(double temp)
|
|
||||||
{
|
|
||||||
$target = &temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,argout) int *OUTPUT,
|
|
||||||
short *OUTPUT
|
|
||||||
{
|
|
||||||
GUILE_APPEND_RESULT(gh_int2scm(*$target));
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,argout) long *OUTPUT,
|
|
||||||
ptrdiff_t *OUTPUT
|
|
||||||
{
|
|
||||||
GUILE_APPEND_RESULT(gh_long2scm(*$target));
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,argout) unsigned int *OUTPUT,
|
|
||||||
unsigned short *OUTPUT,
|
|
||||||
unsigned long *OUTPUT,
|
|
||||||
size_t *OUTPUT
|
|
||||||
{
|
|
||||||
GUILE_APPEND_RESULT(gh_ulong2scm(*$target));
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,argout) unsigned char *OUTPUT
|
|
||||||
{
|
|
||||||
GUILE_APPEND_RESULT(gh_char2scm(*$target));
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,argout) float *OUTPUT,
|
|
||||||
double *OUTPUT
|
|
||||||
{
|
|
||||||
GUILE_APPEND_RESULT(gh_double2scm(*$target));
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(guile,in) int *BOTH = int *INPUT;
|
|
||||||
%typemap(guile,in) short *BOTH = short *INPUT;
|
|
||||||
%typemap(guile,in) long *BOTH = long *INPUT;
|
|
||||||
%typemap(guile,in) ptrdiff_t *BOTH = ptrdiff_t *INPUT;
|
|
||||||
%typemap(guile,in) unsigned *BOTH = unsigned *INPUT;
|
|
||||||
%typemap(guile,in) unsigned short *BOTH = unsigned short *INPUT;
|
|
||||||
%typemap(guile,in) unsigned long *BOTH = unsigned long *INPUT;
|
|
||||||
%typemap(guile,in) size_t *BOTH = size_t *INPUT;
|
|
||||||
%typemap(guile,in) unsigned char *BOTH = unsigned char *INPUT;
|
|
||||||
%typemap(guile,in) float *BOTH = float *INPUT;
|
|
||||||
%typemap(guile,in) double *BOTH = double *INPUT;
|
|
||||||
|
|
||||||
%typemap(guile,argout) int *BOTH = int *OUTPUT;
|
|
||||||
%typemap(guile,argout) short *BOTH = short *OUTPUT;
|
|
||||||
%typemap(guile,argout) long *BOTH = long *OUTPUT;
|
|
||||||
%typemap(guile,argout) ptrdiff_t *BOTH = ptrdiff_t *OUTPUT;
|
|
||||||
%typemap(guile,argout) unsigned *BOTH = unsigned *OUTPUT;
|
|
||||||
%typemap(guile,argout) unsigned short *BOTH = unsigned short *OUTPUT;
|
|
||||||
%typemap(guile,argout) unsigned long *BOTH = unsigned long *OUTPUT;
|
|
||||||
%typemap(guile,argout) size_t *BOTH = size_t *OUTPUT;
|
|
||||||
%typemap(guile,argout) unsigned char *BOTH = unsigned char *OUTPUT;
|
|
||||||
%typemap(guile,argout) float *BOTH = float *OUTPUT;
|
|
||||||
%typemap(guile,argout) double *BOTH = double *OUTPUT;
|
|
||||||
|
|
||||||
/* typemaps.i ends here */
|
/* typemaps.i ends here */
|
||||||
|
|
|
||||||
|
|
@ -387,21 +387,36 @@ guile_typemap_lookup(const char *op, SwigType *type, String_or_char *pname, Stri
|
||||||
return tm;
|
return tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
/* Lookup a typemap, replace all relevant parameters and write it to
|
||||||
// GUILE::create_function(char *name, char *iname, SwigType *d,
|
the given generalized file. */
|
||||||
// ParmList *l)
|
|
||||||
//
|
|
||||||
// Create a function declaration and register it with the interpreter.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
static void
|
static int
|
||||||
mreplace (DOHString *s, DOHString_or_char *argnum, DOHString_or_char *arg, DOHString_or_char *proc_name)
|
guile_do_typemap(DOHFile *file, const char *op,
|
||||||
|
SwigType *type, String_or_char *arg,
|
||||||
|
String_or_char *source, String_or_char *target,
|
||||||
|
int argnum, DOHString *name, Wrapper *f,
|
||||||
|
int nonewline_p)
|
||||||
{
|
{
|
||||||
Replace(s,"$argnum",argnum, DOH_REPLACE_ANY);
|
char *tm;
|
||||||
Replace(s,"$arg", arg, DOH_REPLACE_ANY);
|
if ((tm = guile_typemap_lookup(op, type, arg,
|
||||||
Replace(s,"$name", proc_name, DOH_REPLACE_ANY);
|
source, target, f))) {
|
||||||
|
String *s = NewString(tm);
|
||||||
|
char argnum_s[10];
|
||||||
|
sprintf(argnum_s, "%d", argnum);
|
||||||
|
Replace(s,"$argnum", argnum_s, DOH_REPLACE_ANY);
|
||||||
|
Replace(s,"$arg", arg, DOH_REPLACE_ANY);
|
||||||
|
/* FIXME: Produce all-uppercase version of arg */
|
||||||
|
Replace(s,"$ARG", arg, DOH_REPLACE_ANY);
|
||||||
|
Replace(s,"$name", name, DOH_REPLACE_ANY);
|
||||||
|
if (nonewline_p)
|
||||||
|
Printv(file, s, 0);
|
||||||
|
else Printv(file, s, "\n", 0);
|
||||||
|
Delete(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
throw_unhandled_guile_type_error (SwigType *d)
|
throw_unhandled_guile_type_error (SwigType *d)
|
||||||
{
|
{
|
||||||
|
|
@ -409,20 +424,26 @@ throw_unhandled_guile_type_error (SwigType *d)
|
||||||
error_count++;
|
error_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// GUILE::create_function(char *name, char *iname, SwigType *d,
|
||||||
|
// ParmList *l)
|
||||||
|
//
|
||||||
|
// Create a function declaration and register it with the interpreter.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
{
|
{
|
||||||
Parm *p;
|
Parm *p;
|
||||||
DOHString *proc_name = 0;
|
DOHString *proc_name = 0;
|
||||||
char source[256], target[256], argnum[256], arg[256];
|
char source[256], target[256];
|
||||||
char *tm;
|
Wrapper *f = NewWrapper();;
|
||||||
Wrapper *f;
|
String *cleanup = NewString("");
|
||||||
DOHString *cleanup;
|
String *outarg = NewString("");
|
||||||
DOHString *outarg;
|
String *signature = NewString("");
|
||||||
|
String *returns = NewString("");
|
||||||
f = NewWrapper();
|
int returns_list = 0;
|
||||||
outarg = NewString("");
|
String *tmp = NewString("");
|
||||||
cleanup = NewString("");
|
|
||||||
|
|
||||||
// Make a wrapper name for this
|
// Make a wrapper name for this
|
||||||
char * wname = new char [strlen (prefix) + strlen (iname) + 2];
|
char * wname = new char [strlen (prefix) + strlen (iname) + 2];
|
||||||
|
|
@ -432,7 +453,7 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
proc_name = NewString(iname);
|
proc_name = NewString(iname);
|
||||||
Replace(proc_name,"_", "-", DOH_REPLACE_ANY);
|
Replace(proc_name,"_", "-", DOH_REPLACE_ANY);
|
||||||
|
|
||||||
// Now write the wrapper function itself....this is pretty ugly
|
/* Now write the wrapper function itself */
|
||||||
|
|
||||||
Printv(f->def, "static SCM\n", wname," (", 0);
|
Printv(f->def, "static SCM\n", wname," (", 0);
|
||||||
|
|
||||||
|
|
@ -453,30 +474,42 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
|
|
||||||
Printf(f->def, ")\n{\n");
|
Printf(f->def, ")\n{\n");
|
||||||
|
|
||||||
// Define the scheme name in C
|
/* Define the scheme name in C */
|
||||||
|
/* FIXME: This is only needed for the code in exception.i since
|
||||||
|
typemaps can always use $name. I propose to define a new macro
|
||||||
|
SWIG_exception_in(ERROR, MESSAGE, FUNCTION) and use it instead of
|
||||||
|
SWIG_exception(ERROR, MESSAGE). */
|
||||||
|
|
||||||
Printv(f->def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0);
|
Printv(f->def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0);
|
||||||
|
|
||||||
// Declare return variable and arguments
|
// Declare return variable and arguments
|
||||||
|
|
||||||
int pcount = emit_args (d, l, f);
|
emit_args (d, l, f);
|
||||||
int numargs = 0;
|
int numargs = 0;
|
||||||
int numopt = 0;
|
int numopt = 0;
|
||||||
|
|
||||||
Wrapper_add_local (f,"gswig_result", "SCM gswig_result");
|
Wrapper_add_local (f,"gswig_result", "SCM gswig_result");
|
||||||
|
|
||||||
|
if (!guile_do_typemap(returns, "outdoc", d, name,
|
||||||
|
(char*)"result", (char*)"gswig_result",
|
||||||
|
0, proc_name, f, 1)) {
|
||||||
|
String *s = NewString(SwigType_str(d, 0));
|
||||||
|
Chop(s);
|
||||||
|
Printf(returns, "<%s>", s);
|
||||||
|
Delete(s);
|
||||||
|
}
|
||||||
|
|
||||||
/* Now write code to extract the parameters */
|
/* Now write code to extract the parameters */
|
||||||
|
|
||||||
i = 0;
|
Printv(signature, "(", proc_name, 0);
|
||||||
int j = 0;
|
|
||||||
for (p = l; p; p=Getnext(p)) {
|
for (p = l, i = 0; p; p=Getnext(p), i++) {
|
||||||
SwigType *pt = Gettype(p);
|
SwigType *pt = Gettype(p);
|
||||||
String *pn = Getname(p);
|
String *pn = Getname(p);
|
||||||
|
|
||||||
// Produce names of source and target
|
// Produce names of source and target
|
||||||
sprintf(source,"s_%d",i);
|
sprintf(source,"s_%d",i);
|
||||||
sprintf(target,"%s", Char(Getlname(p)));
|
sprintf(target,"%s", Char(Getlname(p)));
|
||||||
sprintf(argnum,"%d",i);
|
|
||||||
|
|
||||||
// Handle parameter types.
|
// Handle parameter types.
|
||||||
|
|
||||||
|
|
@ -484,10 +517,9 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
Printv(f->code, "/* ", pn, " ignored... */\n", 0);
|
Printv(f->code, "/* ", pn, " ignored... */\n", 0);
|
||||||
else {
|
else {
|
||||||
++numargs;
|
++numargs;
|
||||||
if ((tm = guile_typemap_lookup ("in",
|
if (guile_do_typemap(f->code, "in", pt, pn,
|
||||||
pt, pn, source, target, f))) {
|
source, target, numargs, proc_name, f, 0)) {
|
||||||
Printv(f->code,tm,"\n",0);
|
/* nothing to do */
|
||||||
mreplace (f->code, argnum, pn, proc_name);
|
|
||||||
}
|
}
|
||||||
else if (is_a_pointer(pt)) {
|
else if (is_a_pointer(pt)) {
|
||||||
get_pointer (iname, i, pt, f, proc_name, numargs);
|
get_pointer (iname, i, pt, f, proc_name, numargs);
|
||||||
|
|
@ -495,35 +527,48 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
else {
|
else {
|
||||||
throw_unhandled_guile_type_error (pt);
|
throw_unhandled_guile_type_error (pt);
|
||||||
}
|
}
|
||||||
++j;
|
/* Add to signature */
|
||||||
|
Printf(signature, " ");
|
||||||
|
if (!guile_do_typemap(signature, "indoc", pt, pn,
|
||||||
|
source, target, numargs, proc_name, f, 1)) {
|
||||||
|
String *s = NewString(SwigType_str(pt, 0));
|
||||||
|
Chop(s);
|
||||||
|
Printf(signature, "(%s <%s>)", pn, s);
|
||||||
|
Delete(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are any constraints.
|
/* Check if there are any constraints. */
|
||||||
|
|
||||||
if ((tm = guile_typemap_lookup ("check",
|
guile_do_typemap(f->code, "check", pt, pn,
|
||||||
pt, pn, source, target, f))) {
|
source, target, numargs, proc_name, f, 0);
|
||||||
Printv(f->code,tm,"\n",0);
|
|
||||||
mreplace (f->code, argnum, arg, proc_name);
|
/* Pass output arguments back to the caller. */
|
||||||
|
|
||||||
|
guile_do_typemap(outarg, "argout", pt, pn,
|
||||||
|
source, target, numargs, proc_name, f, 0);
|
||||||
|
|
||||||
|
/* Document output arguments */
|
||||||
|
Clear(tmp);
|
||||||
|
if (guile_do_typemap(tmp, "argoutdoc", pt, pn,
|
||||||
|
source, target, numargs, proc_name, f, 1)) {
|
||||||
|
if (Len(returns) == 0) { /* unspecified -> singleton */
|
||||||
|
Printv(returns, tmp, 0);
|
||||||
|
}
|
||||||
|
else { /* append to list */
|
||||||
|
Printv(returns, " ", tmp, 0);
|
||||||
|
returns_list = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free up any memory allocated for the arguments.
|
||||||
|
|
||||||
// Pass output arguments back to the caller.
|
guile_do_typemap(cleanup, "freearg", pt, pn,
|
||||||
|
source, target, numargs, proc_name, f, 0);
|
||||||
if ((tm = guile_typemap_lookup ("argout",
|
|
||||||
pt, pn, source, target, f))) {
|
|
||||||
Printv(outarg,tm,"\n",0);
|
|
||||||
mreplace (outarg, argnum, arg, proc_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free up any memory allocated for the arguments.
|
|
||||||
|
|
||||||
if ((tm = guile_typemap_lookup ("freearg",
|
|
||||||
pt, pn, source, target, f))) {
|
|
||||||
Printv(cleanup, tm, "\n", 0);
|
|
||||||
mreplace (cleanup, argnum, arg, proc_name);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Printv(signature, ")\n", 0);
|
||||||
|
|
||||||
// Now write code to make the function call
|
// Now write code to make the function call
|
||||||
Printv(f->code, tab4, "gh_defer_ints();\n", 0);
|
Printv(f->code, tab4, "gh_defer_ints();\n", 0);
|
||||||
emit_func_call (name, d, l, f);
|
emit_func_call (name, d, l, f);
|
||||||
|
|
@ -531,12 +576,10 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
|
|
||||||
// Now have return value, figure out what to do with it.
|
// Now have return value, figure out what to do with it.
|
||||||
|
|
||||||
if (SwigType_type(d) == T_VOID)
|
if (guile_do_typemap(f->code, "out", d, name,
|
||||||
Printv(f->code, tab4, "gswig_result = GH_UNSPECIFIED;\n", 0);
|
(char*)"result", (char*)"gswig_result",
|
||||||
else if ((tm = guile_typemap_lookup ("out",
|
0, proc_name, f, 0)) {
|
||||||
d, name, (char*)"result", (char*)"gswig_result", f))) {
|
/* nothing */
|
||||||
Printv(f->code,tm,"\n",0);
|
|
||||||
mreplace (f->code, argnum, arg, proc_name);
|
|
||||||
}
|
}
|
||||||
else if (is_a_pointer(d)) {
|
else if (is_a_pointer(d)) {
|
||||||
SwigType_remember(d);
|
SwigType_remember(d);
|
||||||
|
|
@ -560,24 +603,18 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
// Look for any remaining cleanup
|
// Look for any remaining cleanup
|
||||||
|
|
||||||
if (NewObject) {
|
if (NewObject) {
|
||||||
if ((tm = guile_typemap_lookup ("newfree",
|
guile_do_typemap(f->code, "newfree", d, iname,
|
||||||
d, iname, (char*)"result", (char*)"", f))) {
|
(char*)"result", (char*)"", 0, proc_name, f, 0);
|
||||||
Printv(f->code,tm,"\n",0);
|
|
||||||
mreplace (f->code, argnum, arg, proc_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free any memory allocated by the function being wrapped..
|
// Free any memory allocated by the function being wrapped..
|
||||||
|
|
||||||
if ((tm = guile_typemap_lookup ("ret",
|
guile_do_typemap(f->code, "ret", d, name,
|
||||||
d, name, (char*)"result", (char*)"", f))) {
|
(char*)"result", (char*)"", 0, proc_name, f, 0);
|
||||||
Printv(f->code,tm,"\n",0);
|
|
||||||
mreplace (f->code, argnum, arg, proc_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap things up (in a manner of speaking)
|
// Wrap things up (in a manner of speaking)
|
||||||
|
|
||||||
Printv(f->code, tab4, "return gswig_result;\n", 0);
|
Printv(f->code, "return gswig_result;\n", 0);
|
||||||
|
|
||||||
// Undefine the scheme name
|
// Undefine the scheme name
|
||||||
|
|
||||||
|
|
@ -598,9 +635,20 @@ GUILE::create_function (char *name, char *iname, SwigType *d, ParmList *l)
|
||||||
Printf (f_init, "\t gh_new_procedure(\"%s\", %s, %d, %d, 0);\n",
|
Printf (f_init, "\t gh_new_procedure(\"%s\", %s, %d, %d, 0);\n",
|
||||||
proc_name, wname, numargs-numopt, numopt);
|
proc_name, wname, numargs-numopt, numopt);
|
||||||
}
|
}
|
||||||
|
/* Register procedure documentation */
|
||||||
|
Printv(signature, "Returns ", 0);
|
||||||
|
if (Len(returns)==0) Printv(signature, "unspecified", 0);
|
||||||
|
else if (returns_list) Printv(signature, "list (", returns, ")", 0);
|
||||||
|
else Printv(signature, returns, 0);
|
||||||
|
Printv(signature, "\n", 0);
|
||||||
|
printf("%s\n", Char(signature));
|
||||||
|
|
||||||
Delete(proc_name);
|
Delete(proc_name);
|
||||||
Delete(outarg);
|
Delete(outarg);
|
||||||
Delete(cleanup);
|
Delete(cleanup);
|
||||||
|
Delete(signature);
|
||||||
|
Delete(returns);
|
||||||
|
Delete(tmp);
|
||||||
DelWrapper(f);
|
DelWrapper(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -787,15 +835,14 @@ GUILE::declare_const (char *name, char *, SwigType *type, char *value)
|
||||||
DelWrapper(f);
|
DelWrapper(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// GUILE::usage_var(char *iname, SwigType *t, String &usage)
|
// GUILE::usage_var(char *iname, SwigType *t, String &usage)
|
||||||
//
|
//
|
||||||
// Produces a usage string for a Guile variable.
|
// Produces a usage string for a Guile variable.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
static void
|
||||||
GUILE::usage_var (char *iname, SwigType *t, DOHString *usage)
|
usage_var (char *iname, SwigType *t, DOHString *usage)
|
||||||
{
|
{
|
||||||
|
|
||||||
Printv(usage, "(", iname, " [value])", 0);
|
Printv(usage, "(", iname, " [value])", 0);
|
||||||
|
|
@ -804,136 +851,14 @@ GUILE::usage_var (char *iname, SwigType *t, DOHString *usage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// GUILE::usage_func(char *iname, SwigType *t, ParmList *l, String &usage)
|
|
||||||
//
|
|
||||||
// Produces a usage string for a function in Guile
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
|
||||||
GUILE::usage_func (char *iname, SwigType *d, ParmList *l, DOHString *usage)
|
|
||||||
{
|
|
||||||
|
|
||||||
Parm *p;
|
|
||||||
|
|
||||||
// Print the function name.
|
|
||||||
|
|
||||||
Printv(usage,"(",iname,0);
|
|
||||||
|
|
||||||
// Now go through and print parameters
|
|
||||||
|
|
||||||
for (p = l; p != 0; p = Getnext(p)) {
|
|
||||||
SwigType *pt = Gettype(p);
|
|
||||||
char *pn = Getname(p);
|
|
||||||
|
|
||||||
if (Getignore(p))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Print the type. If the parameter has been named, use that as well.
|
|
||||||
|
|
||||||
if (SwigType_type(pt) != T_VOID) {
|
|
||||||
|
|
||||||
// Print the type.
|
|
||||||
Printv(usage, " <", SwigType_Getname(pt), 0);
|
|
||||||
if (SwigType_is_pointer(pt)) {
|
|
||||||
/* for (int j = 0; j < (pt->is_pointer - pt->implicit_ptr); j++) {*/
|
|
||||||
for (int j = 0; j < SwigType_is_pointer(pt); j++) {
|
|
||||||
Putc('*', usage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Putc('>',usage);
|
|
||||||
|
|
||||||
// Print the name if it exists.
|
|
||||||
if (strlen (pn) > 0) {
|
|
||||||
Printv(usage," ", pn, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Putc(')', usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// GUILE::usage_returns(char *iname, SwigType *t, ParmList *l, String &usage)
|
|
||||||
//
|
|
||||||
// Produces a usage string for a function in Guile
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
|
||||||
GUILE::usage_returns (char *iname, SwigType *d, ParmList *l, DOHString *usage)
|
|
||||||
{
|
|
||||||
Parm *p;
|
|
||||||
DOHString *param;
|
|
||||||
int have_param = 0, j;
|
|
||||||
|
|
||||||
Clear(usage);
|
|
||||||
Printf(usage,"returns ");
|
|
||||||
param = NewString("");
|
|
||||||
|
|
||||||
// go through and see if any are output.
|
|
||||||
|
|
||||||
for (p = l; p != 0; p = Getnext(p)) {
|
|
||||||
SwigType *pt = Gettype(p);
|
|
||||||
char *pn = Getname(p);
|
|
||||||
|
|
||||||
if (strcmp (pn,"BOTH") && strcmp (pn,"OUTPUT"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Print the type. If the parameter has been named, use that as well.
|
|
||||||
|
|
||||||
if (SwigType_type(pt) != T_VOID) {
|
|
||||||
++have_param;
|
|
||||||
|
|
||||||
// Print the type.
|
|
||||||
Printv(param," $", SwigType_Getname(pt), 0);
|
|
||||||
if (SwigType_is_pointer(pt)) {
|
|
||||||
/* for (j = 0; j < (pt->is_pointer - pt->implicit_ptr - 1); j++) { */
|
|
||||||
for (j = 0; j < SwigType_is_pointer(pt) - 1; j++) {
|
|
||||||
Putc('*', param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Printf(param,"# ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if we stick on the function return type.
|
|
||||||
if ((SwigType_type(d) != T_VOID) || (have_param == 0)) {
|
|
||||||
++have_param;
|
|
||||||
if (SwigType_type(d) == T_VOID)
|
|
||||||
Insert(param,0," unspecified ");
|
|
||||||
else {
|
|
||||||
Insert(param,0,"# ");
|
|
||||||
Insert(param,0, SwigType_str(d,0));
|
|
||||||
Insert(param,0," $");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kill extra white space.
|
|
||||||
// param.strip(); - DB: Not supported right now
|
|
||||||
Replace(param,"$", "<", DOH_REPLACE_ANY);
|
|
||||||
Replace(param,"#", ">", DOH_REPLACE_ANY);
|
|
||||||
Replace(param,"><", "> <", DOH_REPLACE_ANY);
|
|
||||||
|
|
||||||
// If there are multiple return values put them in a list.
|
|
||||||
if (have_param > 1) {
|
|
||||||
Insert(param,0,"(");
|
|
||||||
Append(param,")");
|
|
||||||
}
|
|
||||||
Printv(usage,param,0);
|
|
||||||
Delete(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// GUILE::usage_const(char *iname, SwigType *type, char *value, String &usage)
|
// GUILE::usage_const(char *iname, SwigType *type, char *value, String &usage)
|
||||||
//
|
//
|
||||||
// Produces a usage string for a Guile constant
|
// Produces a usage string for a Guile constant
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
static void
|
||||||
GUILE::usage_const (char *iname, SwigType *, char *value, DOHString *usage)
|
usage_const (char *iname, SwigType *, char *value, DOHString *usage)
|
||||||
{
|
{
|
||||||
Printv(usage, "(", iname, " ", value, ")", 0);
|
Printv(usage, "(", iname, " ", value, ")", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue