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 * chicken.swg
6 *
7 * CHICKEN configuration module.
8 * ----------------------------------------------------------------------------- */
9
10/* chicken.h has to appear first. */
11
12%insert(runtime) %{
13#include <assert.h>
14#include <chicken.h>
15%}
16
17%insert(runtime) "swigrun.swg";            // Common C API type-checking code
18%insert(runtime) "chickenrun.swg";      // CHICKEN run-time code
19
20/* -----------------------------------------------------------------------------
21 *                          standard typemaps
22 * ----------------------------------------------------------------------------- */
23
24/*
25  CHICKEN: C
26  ----------
27
28  fixnum: int, short, unsigned int, unsigned short, unsigned char,
29  signed char
30
31  char: char
32
33  bool: bool
34
35  flonum: float, double, long, long long, unsigned long, unsigned long
36  long
37 */
38
39/* --- Primitive types --- */
40
41%define SIMPLE_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_)
42
43%typemap(in) type_
44%{  if (!checker ($input)) {
45    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
46  }
47  $1 = ($1_ltype) from_scheme ($input); %}
48
49/* Const primitive references.  Passed by value */
50
51%typemap(in) const type_ & ($*1_ltype temp)
52%{  if (!checker ($input)) {
53    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
54  }
55  temp = ($*1_ltype) from_scheme ($input);
56  $1 = &temp; %}
57
58/* --- Variable input --- */
59%typemap(varin) type_
60%{  if (!checker ($input)) {
61    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use '$1_ltype' for variable '$name' of type 'type_'");
62  }
63  $1 = ($1_ltype) from_scheme ($input); %}
64
65#if "storage_" == "0"
66
67%typemap(out) type_
68%{
69  $result = to_scheme (convtype ($1));
70%}
71
72/* References to primitive types.  Return by value */
73
74%typemap(out) const type_ &
75%{
76  $result = to_scheme (convtype (*$1));
77%}
78
79/* --- Variable output --- */
80%typemap(varout) type_
81%{
82  $result = to_scheme (convtype ($varname));
83%}
84
85%typemap(throws) type_
86%{
87  SWIG_Chicken_ThrowException(to_scheme ( convtype ($1)));
88%}
89
90#else
91
92%typemap(out) type_
93%{
94  {
95  C_word *space = C_alloc(storage_);
96  $result = to_scheme (&space, convtype ($1));
97  }
98%}
99
100/* References to primitive types.  Return by value */
101
102%typemap(out) const type_ &
103%{
104  {
105  C_word *space = C_alloc(storage_);
106  $result = to_scheme (&space, convtype (*$1));
107  }
108%}
109
110/* --- Variable output --- */
111%typemap(varout) type_
112%{
113  {
114  C_word *space = C_alloc(storage_);
115  $result = to_scheme (&space, convtype ($varname));
116  }
117%}
118
119%typemap(throws) type_
120%{
121  {
122  C_word *space = C_alloc(storage_);
123  SWIG_Chicken_ThrowException(to_scheme (&space, convtype ($1)));
124  }
125%}
126
127#endif
128
129/* --- Constants --- */
130
131%typemap(constcode) type_
132"static const $1_type $result = $value;"
133
134%enddef
135
136SIMPLE_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
137//SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
138SIMPLE_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
139SIMPLE_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
140SIMPLE_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
141SIMPLE_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (unsigned int), C_SIZEOF_FLONUM);
142SIMPLE_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0);
143SIMPLE_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
144SIMPLE_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
145SIMPLE_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
146SIMPLE_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
147SIMPLE_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
148SIMPLE_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
149SIMPLE_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
150SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
151
152/* enum SWIGTYPE */
153%apply int { enum SWIGTYPE };
154%apply const int& { const enum SWIGTYPE& };
155
156%typemap(varin) enum SWIGTYPE
157{
158  if (!C_swig_is_fixnum($input) && sizeof(int) != sizeof($1)) {
159    swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "enum variable '$name' can not be set");
160  }
161  *((int *)(void *)&$1) = C_unfix($input);
162}
163
164
165/* --- Input arguments --- */
166
167/* Strings */
168
169%typemap(in) char *
170{ if ($input == C_SCHEME_FALSE) {
171  $1 = NULL;
172 }
173 else {
174   if (!C_swig_is_string ($input)) {
175     swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'char *'");
176   }
177   $1 = ($ltype) SWIG_MakeString ($input);
178 }
179}
180
181%typemap(freearg) char * "if ($1 != NULL) { free ($1); }"
182
183/* Pointers, references, and arrays */
184%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE &  {
185   $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, $disown);
186}
187
188%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *DISOWN {
189  $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_DISOWN);
190}
191
192/* Void pointer.  Accepts any kind of pointer */
193%typemap(in) void * {
194  $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0);
195}
196
197%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE * {
198  $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, SWIG_POINTER_DISOWN);
199}
200
201%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE & {
202  $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0));
203}
204
205%typemap(varin) SWIGTYPE [] {
206  SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "Type error");
207}
208
209%typemap(varin) SWIGTYPE [ANY] {
210  void *temp;
211  int ii;
212  $1_basetype *b = 0;
213  temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0);
214  b = ($1_basetype *) $1;
215  for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii);
216}
217
218%typemap(varin) void * {
219  $1 = SWIG_MustGetPtr($input, NULL, 1, 0);
220}
221
222%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
223  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
224  $result = SWIG_NewPointerObj($1, $descriptor, $owner);
225}
226
227%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
228  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
229  swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
230  $result = SWIG_NewPointerObj($1, ty, $owner);
231}
232
233%typemap(varout) SWIGTYPE *, SWIGTYPE [] {
234  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
235  $result = SWIG_NewPointerObj($varname, $descriptor, 0);
236}
237
238%typemap(varout) SWIGTYPE & {
239  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
240  $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0);
241}
242
243/* special typemaps for class pointers */
244%typemap(in) SWIGTYPE (CLASS::*) {
245  char err_msg[256];
246
247  if (C_swig_is_pair($input)) {
248    /* try and convert pointer object */
249    void *result;
250    if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
251      C_word ptr = C_block_item($input,0);
252      if (C_swig_is_string(ptr)) {
253        SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type));
254      } else {
255        snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
256        SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
257      }
258    } else {
259      snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
260      SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
261    }
262  } else {
263    snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
264    SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
265  }
266}
267
268%typemap(out) SWIGTYPE (CLASS::*) {
269  size_t ptr_size = sizeof($type);
270  C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER);
271  char *temp = (char *)malloc(2*ptr_size);
272  C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0);
273
274  SWIG_PackData(temp, (void *) &$1, ptr_size);
275  $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr);
276  free(temp);
277}
278
279%typemap(varin) SWIGTYPE (CLASS::*) {
280  char err_msg[256];
281
282  if (C_swig_is_pair($input)) {
283    /* try and convert pointer object */
284    void *result;
285    if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
286      C_word ptr = C_block_item($input,0);
287      if (C_swig_is_string(ptr)) {
288        SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type));
289      } else {
290        snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
291        SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
292      }
293    } else {
294      snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
295      SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
296    }
297  } else {
298    snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
299    SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
300  }
301}
302
303%typemap(varout) SWIGTYPE (CLASS::*) {
304  size_t ptr_size = sizeof($type);
305  C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER);
306  char *temp = (char *)malloc(2*ptr_size);
307  C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0);
308
309  SWIG_PackData(temp, (void *) &$varname, ptr_size);
310  $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr);
311  free(temp);
312}
313
314
315
316/* Pass-by-value */
317
318%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE($&1_ltype argp) {
319  argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
320  $1 = *argp;
321}
322
323%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE {
324  $&1_ltype argp;
325  argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, 1, 0);
326  $1 = *argp;
327}
328
329%typemap(out) SWIGTYPE
330#ifdef __cplusplus
331{
332  $&1_ltype resultptr;
333  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
334  resultptr = new $1_ltype((const $1_ltype &) $1);
335  $result =  SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
336}
337#else
338{
339  $&1_ltype resultptr;
340  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
341  resultptr = ($&1_ltype) malloc(sizeof($1_type));
342  memmove(resultptr, &$1, sizeof($1_type));
343  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
344}
345#endif
346
347%typemap(varout) SWIGTYPE
348#ifdef __cplusplus
349{
350  $&1_ltype resultptr;
351  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
352  resultptr = new $1_ltype((const $1_ltype&) $1);
353  $result =  SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
354}
355#else
356{
357  $&1_ltype resultptr;
358  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
359  resultptr = ($&1_ltype) malloc(sizeof($1_type));
360  memmove(resultptr, &$1, sizeof($1_type));
361  $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
362}
363#endif
364
365/* --- Output values --- */
366
367/* Strings */
368
369%typemap(out)
370  char *
371{ char *s = (char*) $1;
372  if ($1 == NULL) {
373    $result = C_SCHEME_FALSE;
374  }
375  else {
376    int string_len = strlen ((char *) ($1));
377    C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
378    $result = C_string (&string_space, string_len, s);
379  }
380}
381
382%typemap(varout)
383  char *
384{ char *s = (char*) $varname;
385  if ($varname == NULL) {
386    $result = C_SCHEME_FALSE;
387  }
388  else {
389    int string_len = strlen ($varname);
390    C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
391    $result = C_string (&string_space, string_len, s);
392  }
393}
394
395%typemap(throws) char *
396{
397  if ($1 == NULL) {
398    SWIG_Chicken_ThrowException(C_SCHEME_FALSE);
399  } else {
400    int string_len = strlen($1);
401    C_word *string_space = C_alloc(C_SIZEOF_STRING(string_len));
402    SWIG_Chicken_ThrowException(C_string(&string_space, string_len, (char *) $1));
403  }
404}
405
406/* Void */
407%typemap(out) void
408%{
409$result = C_SCHEME_UNDEFINED;
410%}
411
412/* Special typemap for character array return values */
413
414%typemap(out)
415  char [ANY], const char [ANY]
416%{ if ($1 == NULL) {
417  $result = C_SCHEME_FALSE;
418 }
419 else {
420   const int string_len = strlen ($1);
421   C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
422   $result = C_string (&string_space, string_len, $1);
423 } %}
424
425/* Primitive types--return by value */
426
427/* --- Variable input --- */
428
429/* A string */
430#ifdef __cplusplus
431%typemap(varin) char * {
432  if ($input == C_SCHEME_FALSE) {
433    $1 = NULL;
434  }
435  else if (!C_swig_is_string ($input)) {
436      swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
437  }
438  else {
439    char *temp = C_c_string ($input);
440    int  len   = C_header_size ($input);
441    if ($1) delete [] $1;
442    $1 = ($type) new char[len+1];
443    strncpy((char*)$1, temp, len);
444    ((char*)$1) [len] = 0;
445  }
446}
447%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
448  if ($input == C_SCHEME_FALSE) {
449    $1 = NULL;
450  }
451  else if (!C_swig_is_string ($input)) {
452    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
453  }
454  else {
455    char *temp = C_c_string ($input);
456    int  len   = C_header_size ($input);
457    $1 = ($type) new char[len+1];
458    strncpy((char*)$1,temp,len);
459    ((char*)$1) [len] = 0;
460  }
461}
462#else
463%typemap(varin) char * {
464  if ($input == C_SCHEME_FALSE) {
465    $1 = NULL;
466  }
467  else if (!C_swig_is_string ($input)) {
468    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
469  }
470  else {
471    char *temp = C_c_string ($input);
472    int  len   = C_header_size ($input);
473    if ($1) free((char*) $1);
474    $1 = ($type) malloc(len+1);
475    strncpy((char*)$1,temp,len);
476    ((char*)$1) [len] = 0;
477  }
478}
479%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
480  if ($input == C_SCHEME_FALSE) {
481    $1 = NULL;
482  }
483  else if (!C_swig_is_string ($input)) {
484    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
485  }
486  else {
487    char *temp = C_c_string ($input);
488    int  len   = C_header_size ($input);
489    $1 = ($type) malloc(len+1);
490    strncpy((char*)$1,temp,len);
491    ((char*)$1) [len] = 0;
492  }
493}
494#endif
495
496%typemap(varin) char [] {
497  swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "C/C++ variable '$name' is read-only");
498}
499
500/* Special case for string array variables */
501%typemap(varin) char [ANY] {
502  if ($input == C_SCHEME_FALSE) {
503    memset($1,0,$1_dim0*sizeof(char));
504  }
505  else if (!C_swig_is_string ($input)) {
506    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
507  }
508  else {
509    char *temp = C_c_string ($input);
510    strncpy($1,temp,$1_dim0*sizeof(char));
511  }
512}
513
514/* --- Variable output --- */
515
516/* Void */
517%typemap(varout) void "$result = C_SCHEME_UNDEFINED;";
518
519/* Special typemap for character array return values */
520%typemap(varout) char [ANY], const char [ANY]
521%{  if ($varname == NULL) {
522    $result = C_SCHEME_FALSE;
523  }
524  else {
525   const int string_len = strlen ($varname);
526   C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
527   $result = C_string (&string_space, string_len, (char *) $varname);
528  }
529%}
530
531
532/* --- Constants --- */
533
534%typemap(constcode) char *
535"static const char *$result = $value;"
536
537%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
538"static const void *$result = (void*) $value;"
539
540/* ------------------------------------------------------------
541 * String & length
542 * ------------------------------------------------------------ */
543
544%typemap(in) (char *STRING, int LENGTH) {
545  if ($input == C_SCHEME_FALSE) {
546    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use a null/#f string for a char*, int arguments");
547  }
548  else if (C_swig_is_string ($input)) {
549    $1 = ($1_ltype) C_c_string ($input);
550    $2 = ($2_ltype) C_header_size ($input);
551  }
552  else {
553    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'string'");
554  }
555}
556
557/* ------------------------------------------------------------
558 * CHICKEN types
559 * ------------------------------------------------------------ */
560
561%typemap(in)   C_word "$1 = $input;";
562%typemap(out)  C_word "$result = $1;";
563
564/* ------------------------------------------------------------
565 * Typechecking rules
566 * ------------------------------------------------------------ */
567
568%typecheck(SWIG_TYPECHECK_INTEGER)
569         bool, const bool &
570{
571  $1 = C_swig_is_bool ($input);
572}
573
574%typecheck(SWIG_TYPECHECK_INTEGER)
575	 int, short,
576 	 unsigned int, unsigned short,
577	 signed char, unsigned char,
578	 const int &, const short &,
579 	 const unsigned int &, const unsigned short &,
580	 enum SWIGTYPE
581{
582  $1 = C_swig_is_fixnum ($input);
583}
584
585%typecheck(SWIG_TYPECHECK_INTEGER)
586	 long,
587 	 unsigned long,
588	 long long, unsigned long long,
589	 const long &,
590 	 const unsigned long &,
591	 const long long &, const unsigned long long &
592{
593  $1 = (C_swig_is_bool ($input) ||
594    C_swig_is_fixnum ($input) ||
595    C_swig_is_flonum ($input)) ? 1 : 0;
596}
597
598%typecheck(SWIG_TYPECHECK_DOUBLE)
599	float, double,
600	const float &, const double &
601{
602  $1 = C_swig_is_flonum ($input);
603}
604
605%typecheck(SWIG_TYPECHECK_CHAR) char {
606  $1 = C_swig_is_string ($input);
607}
608
609%typecheck(SWIG_TYPECHECK_STRING) char * {
610  $1 = C_swig_is_string ($input);
611}
612
613%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
614  void *ptr;
615  $1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0);
616}
617
618%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
619  void *ptr;
620  $1 = !SWIG_ConvertPtr($input, &ptr, 0, 0);
621}
622
623%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
624{
625  void *ptr = 0;
626  if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
627    /* error */
628    $1 = 0;
629  } else {
630    $1 = (ptr != 0);
631  }
632}
633
634%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
635{
636  void *ptr = 0;
637  if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0)) {
638    /* error */
639    $1 = 0;
640  } else {
641    $1 = (ptr != 0);
642  }
643}
644
645
646/* ------------------------------------------------------------
647 * Exception handling
648 * ------------------------------------------------------------ */
649
650/* ------------------------------------------------------------
651 * --- Exception handling ---
652 * ------------------------------------------------------------ */
653
654%typemap(throws) SWIGTYPE {
655  $&ltype temp = new $ltype($1);
656  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
657  C_word ptr = SWIG_NewPointerObj(temp, $&descriptor,1);
658  SWIG_Chicken_ThrowException(ptr);
659}
660
661%typemap(throws) SWIGTYPE * {
662  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
663  C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
664  SWIG_Chicken_ThrowException(ptr);
665}
666
667%typemap(throws) SWIGTYPE [ANY] {
668  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
669  C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
670  SWIG_Chicken_ThrowException(ptr);
671}
672
673%typemap(throws) SWIGTYPE & {
674  C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
675  C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0);
676  SWIG_Chicken_ThrowException(ptr);
677}
678
679/* ------------------------------------------------------------
680 * ANSI C typemaps
681 * ------------------------------------------------------------ */
682
683%apply unsigned long { size_t };
684
685/* ------------------------------------------------------------
686 * Overloaded operator support
687 * ------------------------------------------------------------ */
688
689#ifdef __cplusplus
690%rename(__add__)      *::operator+;
691%rename(__pos__)      *::operator+();
692%rename(__pos__)      *::operator+() const;
693%rename(__sub__)      *::operator-;
694%rename(__neg__)      *::operator-();
695%rename(__neg__)      *::operator-() const;
696%rename(__mul__)      *::operator*;
697%rename(__div__)      *::operator/;
698%rename(__mod__)      *::operator%;
699%rename(__lshift__)   *::operator<<;
700%rename(__rshift__)   *::operator>>;
701%rename(__and__)      *::operator&;
702%rename(__or__)       *::operator|;
703%rename(__xor__)      *::operator^;
704%rename(__invert__)   *::operator~;
705%rename(__iadd__)     *::operator+=;
706%rename(__isub__)     *::operator-=;
707%rename(__imul__)     *::operator*=;
708%rename(__idiv__)     *::operator/=;
709%rename(__imod__)     *::operator%=;
710%rename(__ilshift__)  *::operator<<=;
711%rename(__irshift__)  *::operator>>=;
712%rename(__iand__)     *::operator&=;
713%rename(__ior__)      *::operator|=;
714%rename(__ixor__)     *::operator^=;
715%rename(__lt__)       *::operator<;
716%rename(__le__)       *::operator<=;
717%rename(__gt__)       *::operator>;
718%rename(__ge__)       *::operator>=;
719%rename(__eq__)       *::operator==;
720%rename(__ne__)       *::operator!=;
721
722/* Special cases */
723%rename(__call__)     *::operator();
724
725#endif
726/* Warnings for certain CHICKEN keywords */
727%include <chickenkw.swg>
728
729/* TinyCLOS <--> Low-level CHICKEN */
730
731%typemap("clos_in") SIMPLE_CLOS_OBJECT * "(slot-ref $input (quote this))"
732%typemap("clos_out") SIMPLE_CLOS_OBJECT * "(make $class (quote this) $1)"
733
734%insert(header) %{
735#ifdef __cplusplus
736extern "C" {
737#endif
738/* Chicken initialization function */
739SWIGEXPORT void SWIG_init(C_word, C_word, C_word) C_noret;
740#ifdef __cplusplus
741}
742#endif
743%}
744
745%insert(closprefix) "swigclosprefix.scm"
746
747%insert(init) "swiginit.swg"
748
749%insert(init) %{
750/* CHICKEN initialization function */
751#ifdef __cplusplus
752extern "C" {
753#endif
754SWIGEXPORT void SWIG_init(C_word argc, C_word closure, C_word continuation) {
755  int       i;
756  C_word sym;
757  C_word tmp;
758  C_word *a;
759  C_word ret;
760  C_word *return_vec;
761
762  SWIG_InitializeModule(0);
763  SWIG_PropagateClientData();
764  ret = C_SCHEME_TRUE;
765
766#if $veclength
767  return_vec = C_alloc(C_SIZEOF_VECTOR($veclength));
768  ret = (C_word) return_vec;
769  *(return_vec++) = C_VECTOR_TYPE | $veclength;
770#endif
771
772  a = C_alloc(2*$nummethods$symsize);
773
774%}
775