PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/chicken/chicken.swg

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