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