swig/Lib/mzscheme/typemaps.i
2003-02-18 17:13:54 +00:00

343 lines
9 KiB
C

/* typemaps.i --- mzscheme typemaps -*- c -*-
Copyright 2000, 2001 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
Based on code written by Oleg Tolmatcev.
$Id$
*/
/* The MzScheme module handles all types uniformly via typemaps. Here
are the definitions. */
/* Pointers */
%typemap(in) SWIGTYPE * {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum);
}
%typemap(in) void * {
$1 = SWIG_MustGetPtr($input, NULL, $argnum);
}
%typemap(varin) SWIGTYPE * {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, 1);
}
%typemap(varin) void * {
$1 = SWIG_MustGetPtr($input, NULL, 1);
}
%typemap(out) SWIGTYPE * {
$result = SWIG_MakePtr ($1, $descriptor);
}
%typemap(out) SWIGTYPE *DYNAMIC {
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
$result = SWIG_MakePtr ($1, ty);
}
%typemap(varout) SWIGTYPE * {
$result = SWIG_MakePtr ($1, $descriptor);
}
/* C++ References */
#ifdef __cplusplus
%typemap(in) SWIGTYPE &, const SWIGTYPE & {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum);
if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)");
}
%typemap(out) SWIGTYPE &, const SWIGTYPE & {
$result = SWIG_MakePtr ($1, $descriptor);
}
%typemap(out) SWIGTYPE &DYNAMIC {
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
$result = SWIG_MakePtr ($1, ty);
}
#endif
%typemap(out) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1);
$result = SWIG_MakePtr (resultptr, $&1_descriptor);
}
#else
{
$&1_ltype resultptr;
resultptr = ($&1_ltype) malloc(sizeof($1_type));
memmove(resultptr, &$1, sizeof($1_type));
$result = SWIG_MakePtr(resultptr, $&1_descriptor);
}
#endif
/* Arrays */
%typemap(in) SWIGTYPE[] {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum);
}
%typemap(out) SWIGTYPE[] {
$result = SWIG_MakePtr ($1, $descriptor);
}
/* Enums */
%typemap(in) enum SWIGTYPE {
if (!SCHEME_INTP($input))
scheme_wrong_type("$name", "integer", $argnum, argc, argv);
$1 = SCHEME_INT_VAL($input);
}
%typemap(varin) enum SWIGTYPE {
if (!SCHEME_INTP($input))
scheme_wrong_type("$name", "integer", 1, argc, argv);
$1 = ($1_type) SCHEME_INT_VAL($input);
}
%typemap(out) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
%typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
/* Pass-by-value */
%typemap(in) SWIGTYPE($&1_ltype argp) {
argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, $argnum);
$1 = *argp;
}
%typemap(varin) SWIGTYPE {
$&1_ltype argp;
argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, 1);
$1 = *argp;
}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1);
$result = SWIG_MakePtr (resultptr, $&1_descriptor);
}
#else
{
$&1_ltype resultptr;
resultptr = ($&1_ltype) malloc(sizeof($1_type));
memmove(resultptr, &$1, sizeof($1_type));
$result = SWIG_MakePtr(resultptr, $&1_descriptor);
}
#endif
%typemap(varout) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1);
$result = SWIG_MakePtr (resultptr, $&1_descriptor);
}
#else
{
$&1_ltype resultptr;
resultptr = ($&1_ltype) malloc(sizeof($1_type));
memmove(resultptr, &$1, sizeof($1_type));
$result = SWIG_MakePtr(resultptr, $&1_descriptor);
}
#endif
/* The SIMPLE_MAP macro below defines the whole set of typemaps needed
for simple types. */
%define SIMPLE_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME)
%typemap(in) C_NAME {
if (!MZ_PREDICATE($input))
scheme_wrong_type("$name", #MZ_NAME, $argnum, argc, argv);
$1 = MZ_TO_C($input);
}
%typemap(varin) C_NAME {
if (!MZ_PREDICATE($input))
scheme_wrong_type("$name", #MZ_NAME, 1, argc, argv);
$1 = MZ_TO_C($input);
}
%typemap(out) C_NAME {
$result = C_TO_MZ($1);
}
%typemap(varout) C_NAME {
$result = C_TO_MZ($1);
}
%typemap(in) C_NAME *INPUT (C_NAME temp) {
temp = (C_NAME) MZ_TO_C($input);
$1 = &temp;
}
%typemap(in,numinputs=0) C_NAME *OUTPUT (C_NAME temp) {
$1 = &temp;
}
%typemap(argout) C_NAME *OUTPUT {
Scheme_Object *s;
s = C_TO_MZ(*$1);
SWIG_APPEND_VALUE(s);
}
%typemap(in) C_NAME *BOTH = C_NAME *INPUT;
%typemap(argout) C_NAME *BOTH = C_NAME *OUTPUT;
%typemap(in) C_NAME *INOUT = C_NAME *INPUT;
%typemap(argout) C_NAME *INOUT = C_NAME *OUTPUT;
%enddef
SIMPLE_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP,
swig_make_boolean, boolean);
SIMPLE_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL,
scheme_make_character, character);
SIMPLE_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL,
scheme_make_character, character);
SIMPLE_MAP(int, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
SIMPLE_MAP(short, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
SIMPLE_MAP(long, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
SIMPLE_MAP(ptrdiff_t, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
SIMPLE_MAP(unsigned int, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
SIMPLE_MAP(unsigned short, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
SIMPLE_MAP(unsigned long, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
SIMPLE_MAP(size_t, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
SIMPLE_MAP(float, SCHEME_REALP, scheme_real_to_double,
scheme_make_double, real);
SIMPLE_MAP(double, SCHEME_REALP, scheme_real_to_double,
scheme_make_double, real);
SIMPLE_MAP(char *, SCHEME_STRINGP, SCHEME_STR_VAL,
scheme_make_string_without_copying, string);
SIMPLE_MAP(const char *, SCHEME_STRINGP, SCHEME_STR_VAL,
scheme_make_string_without_copying, string);
/* Const primitive references. Passed by value */
%define REF_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME)
%typemap(in) const C_NAME & (C_NAME temp) {
if (!MZ_PREDICATE($input))
scheme_wrong_type("$name", #MZ_NAME, $argnum, argc, argv);
temp = MZ_TO_C($input);
$1 = &temp;
}
%typemap(out) const C_NAME & {
$result = C_TO_MZ(*$1);
}
%enddef
REF_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP,
swig_make_boolean, boolean);
REF_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL,
scheme_make_character, character);
REF_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL,
scheme_make_character, character);
REF_MAP(int, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
REF_MAP(short, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
REF_MAP(long, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value, integer);
REF_MAP(unsigned int, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
REF_MAP(unsigned short, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
REF_MAP(unsigned long, SCHEME_INTP, SCHEME_INT_VAL,
scheme_make_integer_value_from_unsigned, integer);
REF_MAP(float, SCHEME_REALP, scheme_real_to_double,
scheme_make_double, real);
REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
scheme_make_double, real);
/* Void */
%typemap(out) void "$result = scheme_void;";
/* Pass through Scheme_Object * */
%typemap (in) Scheme_Object * "$1=$input;";
%typemap (out) Scheme_Object * "$result=$1;";
/* ------------------------------------------------------------
* String & length
* ------------------------------------------------------------ */
//%typemap(in) (char *STRING, int LENGTH) {
// int temp;
// $1 = ($1_ltype) gh_scm2newstr($input, &temp);
// $2 = ($2_ltype) temp;
//}
/* ------------------------------------------------------------
* Typechecking rules
* ------------------------------------------------------------ */
%typecheck(SWIG_TYPECHECK_INTEGER)
int, short, long,
unsigned int, unsigned short, unsigned long,
signed char, unsigned char,
long long, unsigned long long,
const int &, const short &, const long &,
const unsigned int &, const unsigned short &, const unsigned long &,
const long long &, const unsigned long long &,
enum SWIGTYPE
{
$1 = (SCHEME_INTP($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_BOOL) bool, bool &, const bool &
{
$1 = (SCHEME_BOOLP($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE)
float, double,
const float &, const double &
{
$1 = (SCHEME_REALP($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING) char {
$1 = (SCHEME_STRINGP($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING) char * {
$1 = (SCHEME_STRINGP($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
void *ptr;
if (SWIG_GetPtr($input, (void **) &ptr, $1_descriptor)) {
$1 = 0;
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
if (SWIG_GetPtr($input, (void **) &ptr, $&1_descriptor)) {
$1 = 0;
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
void *ptr;
if (SWIG_GetPtr($input, (void **) &ptr, 0)) {
$1 = 0;
} else {
$1 = 1;
}
}