PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/chicken/chicken.swg

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