1/* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4 *
5 * typemaps.i
6 * ----------------------------------------------------------------------------- */
7
8/* The MzScheme module handles all types uniformly via typemaps. Here
9   are the definitions.  */
10
11/* Pointers */
12
13%typemap(in) SWIGTYPE * {
14  $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
15}
16
17%typemap(in) void * {
18  $1 = SWIG_MustGetPtr($input, NULL, $argnum, 0);
19}
20
21%typemap(varin) SWIGTYPE * {
22  $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, 1, 0);
23}
24
25%typemap(varin) SWIGTYPE & {
26  $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0));
27}
28
29%typemap(varin) SWIGTYPE [ANY] {
30  void *temp;
31  int ii;
32  $1_basetype *b = 0;
33  temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0);
34  b = ($1_basetype *) $1;
35  for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii);
36}
37
38
39%typemap(varin) void * {
40  $1 = SWIG_MustGetPtr($input, NULL, 1, 0);
41}
42
43%typemap(out) SWIGTYPE * {
44  $result = SWIG_NewPointerObj ($1, $descriptor, $owner);
45}
46
47%typemap(out) SWIGTYPE *DYNAMIC {
48  swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
49  $result = SWIG_NewPointerObj ($1, ty, $owner);
50}
51
52%typemap(varout) SWIGTYPE *, SWIGTYPE [] {
53  $result = SWIG_NewPointerObj ($1, $descriptor, 0);
54}
55
56%typemap(varout) SWIGTYPE & {
57  $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0);
58}
59
60/* C++ References */
61
62#ifdef __cplusplus
63
64%typemap(in) SWIGTYPE &, const SWIGTYPE & {
65  $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
66  if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)");
67}
68
69%typemap(out) SWIGTYPE &, const SWIGTYPE & {
70  $result = SWIG_NewPointerObj ($1, $descriptor, $owner);
71}
72
73%typemap(out) SWIGTYPE &DYNAMIC {
74  swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
75  $result = SWIG_NewPointerObj ($1, ty, $owner);
76}
77
78#endif
79
80/* Arrays */
81
82%typemap(in) SWIGTYPE[] {
83  $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
84}
85
86%typemap(out) SWIGTYPE[] {
87  $result = SWIG_NewPointerObj ($1, $descriptor, $owner);
88}
89
90/* Enums */
91%typemap(in) enum SWIGTYPE {
92  if (!SWIG_is_integer($input))
93      scheme_wrong_type(FUNC_NAME, "integer", $argnum - 1, argc, argv);
94  $1 = ($1_type) SWIG_convert_int($input);
95}
96
97%typemap(varin) enum SWIGTYPE {
98  if (!SWIG_is_integer($input))
99      scheme_wrong_type(FUNC_NAME, "integer", 0, argc, argv);
100  $1 = ($1_type) SWIG_convert_int($input);
101}
102
103%typemap(out) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
104%typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
105
106
107/* Pass-by-value */
108
109%typemap(in) SWIGTYPE($&1_ltype argp) {
110  argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
111  $1 = *argp;
112}
113
114%typemap(varin) SWIGTYPE {
115  $&1_ltype argp;
116  argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, 1, 0);
117  $1 = *argp;
118}
119
120
121%typemap(out) SWIGTYPE
122#ifdef __cplusplus
123{
124  $&1_ltype resultptr;
125  resultptr = new $1_ltype(($1_ltype &) $1);
126  $result =  SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
127}
128#else
129{
130  $&1_ltype resultptr;
131  resultptr = ($&1_ltype) malloc(sizeof($1_type));
132  memmove(resultptr, &$1, sizeof($1_type));
133  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
134}
135#endif
136
137%typemap(varout) SWIGTYPE
138#ifdef __cplusplus
139{
140  $&1_ltype resultptr;
141  resultptr = new $1_ltype(($1_ltype &) $1);
142  $result =  SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
143}
144#else
145{
146  $&1_ltype resultptr;
147  resultptr = ($&1_ltype) malloc(sizeof($1_type));
148  memmove(resultptr, &$1, sizeof($1_type));
149  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
150}
151#endif
152
153/* The SIMPLE_MAP macro below defines the whole set of typemaps needed
154   for simple types. */
155
156%define SIMPLE_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME)
157%typemap(in) C_NAME {
158    if (!MZ_PREDICATE($input))
159	scheme_wrong_type(FUNC_NAME, #MZ_NAME, $argnum - 1, argc, argv);
160    $1 = MZ_TO_C($input);
161}
162%typemap(varin) C_NAME {
163    if (!MZ_PREDICATE($input))
164	scheme_wrong_type(FUNC_NAME, #MZ_NAME, 0, argc, argv);
165    $1 = MZ_TO_C($input);
166}
167%typemap(out) C_NAME {
168    $result = C_TO_MZ($1);
169}
170%typemap(varout) C_NAME {
171    $result = C_TO_MZ($1);
172}
173%typemap(in) C_NAME *INPUT (C_NAME temp) {
174    temp = (C_NAME) MZ_TO_C($input);
175    $1 = &temp;
176}
177%typemap(in,numinputs=0) C_NAME *OUTPUT (C_NAME temp) {
178    $1 = &temp;
179}
180%typemap(argout) C_NAME *OUTPUT {
181    Scheme_Object *s;
182    s = C_TO_MZ(*$1);
183    SWIG_APPEND_VALUE(s);
184}
185%typemap(in) C_NAME *BOTH = C_NAME *INPUT;
186%typemap(argout) C_NAME *BOTH = C_NAME *OUTPUT;
187%typemap(in) C_NAME *INOUT = C_NAME *INPUT;
188%typemap(argout) C_NAME *INOUT = C_NAME *OUTPUT;
189%enddef
190
191SIMPLE_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP,
192	   swig_make_boolean, boolean);
193SIMPLE_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL,
194	   scheme_make_character, character);
195SIMPLE_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL,
196	   scheme_make_character, character);
197SIMPLE_MAP(int, SWIG_is_integer, SWIG_convert_int,
198	   scheme_make_integer_value, integer);
199SIMPLE_MAP(short, SWIG_is_integer, SWIG_convert_short,
200	   scheme_make_integer_value, integer);
201SIMPLE_MAP(long, SWIG_is_integer, SWIG_convert_long,
202	   scheme_make_integer_value, integer);
203SIMPLE_MAP(ptrdiff_t, SWIG_is_integer, SWIG_convert_long,
204	   scheme_make_integer_value, integer);
205SIMPLE_MAP(unsigned int, SWIG_is_unsigned_integer, SWIG_convert_unsigned_int,
206	   scheme_make_integer_value_from_unsigned, integer);
207SIMPLE_MAP(unsigned short, SWIG_is_unsigned_integer, SWIG_convert_unsigned_short,
208	   scheme_make_integer_value_from_unsigned, integer);
209SIMPLE_MAP(unsigned long, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long,
210	   scheme_make_integer_value_from_unsigned, integer);
211SIMPLE_MAP(size_t, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long,
212	   scheme_make_integer_value_from_unsigned, integer);
213SIMPLE_MAP(float, SCHEME_REALP, scheme_real_to_double,
214	   scheme_make_double, real);
215SIMPLE_MAP(double, SCHEME_REALP, scheme_real_to_double,
216	   scheme_make_double, real);
217
218SIMPLE_MAP(char *, SCHEME_STRINGP, SCHEME_STR_VAL,
219	   SCHEME_MAKE_STRING, string);
220SIMPLE_MAP(const char *, SCHEME_STRINGP, SCHEME_STR_VAL,
221	   SCHEME_MAKE_STRING, string);
222
223/* For MzScheme 30x:  Use these typemaps if you are not going to use
224   UTF8 encodings in your C code.
225 SIMPLE_MAP(char *,SCHEME_BYTE_STRINGP, SCHEME_BYTE_STR_VAL,
226 	   scheme_make_byte_string_without_copying,bytestring);
227 SIMPLE_MAP(const char *,SCHEME_BYTE_STRINGP, SCHEME_BYTE_STR_VAL,
228 	   scheme_make_byte_string_without_copying,bytestring);
229*/
230
231/* Const primitive references.  Passed by value */
232
233%define REF_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME)
234  %typemap(in) const C_NAME & (C_NAME temp) {
235     if (!MZ_PREDICATE($input))
236        scheme_wrong_type(FUNC_NAME, #MZ_NAME, $argnum - 1, argc, argv);
237     temp = MZ_TO_C($input);
238     $1 = &temp;
239  }
240  %typemap(out) const C_NAME & {
241    $result = C_TO_MZ(*$1);
242  }
243%enddef
244
245REF_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP,
246	   swig_make_boolean, boolean);
247REF_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL,
248	   scheme_make_character, character);
249REF_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL,
250	   scheme_make_character, character);
251REF_MAP(int, SWIG_is_integer, SWIG_convert_int,
252	   scheme_make_integer_value, integer);
253REF_MAP(short, SWIG_is_integer, SWIG_convert_short,
254	   scheme_make_integer_value, integer);
255REF_MAP(long, SWIG_is_integer, SWIG_convert_long,
256	   scheme_make_integer_value, integer);
257REF_MAP(unsigned int, SWIG_is_unsigned_integer, SWIG_convert_unsigned_int,
258	   scheme_make_integer_value_from_unsigned, integer);
259REF_MAP(unsigned short, SWIG_is_unsigned_integer, SWIG_convert_unsigned_short,
260	   scheme_make_integer_value_from_unsigned, integer);
261REF_MAP(unsigned long, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long,
262	   scheme_make_integer_value_from_unsigned, integer);
263REF_MAP(float, SCHEME_REALP, scheme_real_to_double,
264	   scheme_make_double, real);
265REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
266	   scheme_make_double, real);
267
268/* Void */
269
270%typemap(out) void "$result = scheme_void;";
271
272/* Pass through Scheme_Object * */
273
274%typemap (in) Scheme_Object * "$1=$input;";
275%typemap (out) Scheme_Object * "$result=$1;";
276%typecheck(SWIG_TYPECHECK_POINTER) Scheme_Object * "$1=1;";
277
278
279/* ------------------------------------------------------------
280 * String & length
281 * ------------------------------------------------------------ */
282
283//%typemap(in) (char *STRING, int LENGTH) {
284//    int temp;
285//    $1 = ($1_ltype) gh_scm2newstr($input, &temp);
286//    $2 = ($2_ltype) temp;
287//}
288
289
290/* ------------------------------------------------------------
291 * Typechecking rules
292 * ------------------------------------------------------------ */
293
294%typecheck(SWIG_TYPECHECK_INTEGER)
295	 int, short, long,
296 	 unsigned int, unsigned short, unsigned long,
297	 signed char, unsigned char,
298	 long long, unsigned long long,
299	 const int &, const short &, const long &,
300 	 const unsigned int &, const unsigned short &, const unsigned long &,
301	 const long long &, const unsigned long long &,
302	 enum SWIGTYPE
303{
304  $1 = (SWIG_is_integer($input)) ? 1 : 0;
305}
306
307%typecheck(SWIG_TYPECHECK_BOOL) bool, bool &, const bool &
308{
309  $1 = (SCHEME_BOOLP($input)) ? 1 : 0;
310}
311
312%typecheck(SWIG_TYPECHECK_DOUBLE)
313	float, double,
314	const float &, const double &
315{
316  $1 = (SCHEME_REALP($input)) ? 1 : 0;
317}
318
319%typecheck(SWIG_TYPECHECK_STRING) char {
320  $1 = (SCHEME_STRINGP($input)) ? 1 : 0;
321}
322
323%typecheck(SWIG_TYPECHECK_STRING) char * {
324  $1 = (SCHEME_STRINGP($input)) ? 1 : 0;
325}
326
327%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
328  void *ptr;
329  if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0)) {
330    $1 = 0;
331  } else {
332    $1 = 1;
333  }
334}
335
336%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
337  void *ptr;
338  if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0)) {
339    $1 = 0;
340  } else {
341    $1 = 1;
342  }
343}
344
345%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
346  void *ptr;
347  if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0)) {
348    $1 = 0;
349  } else {
350    $1 = 1;
351  }
352}
353
354
355