chickenrun.swg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /* -----------------------------------------------------------------------------
  2. * chickenrun.swg
  3. * ----------------------------------------------------------------------------- */
  4. #include <chicken.h>
  5. #include <assert.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
  10. # ifndef snprintf
  11. # define snprintf _snprintf
  12. # endif
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #define SWIG_malloc(size) \
  18. malloc(size)
  19. #define SWIG_free(mem) \
  20. free(mem)
  21. #define SWIG_MakeString(c) \
  22. SWIG_Chicken_MakeString(c)
  23. #define SWIG_ConvertPtr(s, result, type, flags) \
  24. SWIG_Chicken_ConvertPtr(s, result, type, flags)
  25. #define SWIG_MustGetPtr(s, type, argnum, flags) \
  26. SWIG_Chicken_MustGetPtr(s, type, argnum, flags)
  27. #define SWIG_NewPointerObj(ptr, type, owner) \
  28. SWIG_Chicken_NewPointerObj((void*)ptr, type, owner, &known_space)
  29. #define swig_barf SWIG_Chicken_Barf
  30. #define SWIG_ThrowException(val) SWIG_Chicken_ThrowException(val)
  31. #define SWIG_contract_assert(expr, message) if (!(expr)) { \
  32. SWIG_Chicken_Barf(SWIG_BARF1_CONTRACT_ASSERT, C_text(message)); } else
  33. /* Runtime API */
  34. #define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule(clientdata)
  35. #define SWIG_SetModule(clientdata, pointer) SWIG_Chicken_SetModule(pointer)
  36. #define C_swig_is_bool(x) C_truep (C_booleanp (x))
  37. #define C_swig_is_char(x) C_truep (C_charp (x))
  38. #define C_swig_is_fixnum(x) C_truep (C_fixnump (x))
  39. #define C_swig_is_flonum(x) (C_truep (C_blockp (x)) && C_truep (C_flonump (x)))
  40. #define C_swig_is_string(x) (C_truep (C_blockp (x)) && C_truep (C_stringp (x)))
  41. #define C_swig_is_vector(x) (C_truep (C_blockp (x)) && C_truep (C_vectorp (x)))
  42. #define C_swig_is_list(x) (C_truep (C_i_listp (x)))
  43. #define C_swig_is_pair(x) (C_truep (C_blockp(x)) && C_truep (C_pairp(x)))
  44. #define C_swig_is_ptr(x) (C_truep (C_blockp (x)) && C_truep (C_pointerp (x)))
  45. #define C_swig_is_swigpointer(x) (C_truep (C_blockp(x)) && C_truep (C_swigpointerp(x)))
  46. #define C_swig_is_closurep(x) (C_truep (C_blockp(x)) && C_truep(C_closurep(x)))
  47. #define C_swig_is_number(x) (C_swig_is_fixnum(x) || C_swig_is_flonum(x))
  48. #define C_swig_is_long(x) C_swig_is_number(x)
  49. #define C_swig_sizeof_closure(num) (num+1)
  50. #define SWIG_Chicken_SetupArgout { \
  51. C_word *a = C_alloc(C_swig_sizeof_closure(2)); \
  52. C_word *closure = a; \
  53. *(a++)=C_CLOSURE_TYPE|2; \
  54. *(a++)=(C_word)SWIG_Chicken_ApplyResults; \
  55. *(a++)=continuation; \
  56. continuation=(C_word)closure; \
  57. }
  58. #define SWIG_APPEND_VALUE(obj) { \
  59. C_word val = (C_word)(obj); \
  60. if (val != C_SCHEME_UNDEFINED) { \
  61. C_word *a = C_alloc(C_swig_sizeof_closure(3)); \
  62. C_word *closure = a; \
  63. *(a++)=C_CLOSURE_TYPE|3; \
  64. *(a++)=(C_word)SWIG_Chicken_MultiResultBuild; \
  65. *(a++)=(C_word)continuation; \
  66. *(a++)=val; \
  67. continuation=(C_word)closure; \
  68. } }
  69. #define SWIG_Chicken_FindCreateProxy(func,obj) \
  70. if (C_swig_is_swigpointer(obj)) { \
  71. swig_type_info *t = (swig_type_info *) C_block_item(obj, 1); \
  72. if (t && t->clientdata && ((swig_chicken_clientdata *)t->clientdata)->gc_proxy_create) { \
  73. func = CHICKEN_gc_root_ref( ((swig_chicken_clientdata *)t->clientdata)->gc_proxy_create); \
  74. } else { \
  75. func = C_SCHEME_FALSE; \
  76. } \
  77. } else { \
  78. func = C_SCHEME_FALSE; \
  79. }
  80. enum {
  81. SWIG_BARF1_BAD_ARGUMENT_TYPE /* 1 arg */,
  82. SWIG_BARF1_ARGUMENT_NULL /* 1 arg */,
  83. SWIG_BARF1_CONTRACT_ASSERT /* 1 arg */,
  84. };
  85. typedef C_word (*swig_chicken_destructor)(C_word,C_word,C_word,C_word);
  86. typedef struct swig_chicken_clientdata {
  87. void *gc_proxy_create;
  88. swig_chicken_destructor destroy;
  89. } swig_chicken_clientdata;
  90. static char *
  91. SWIG_Chicken_MakeString(C_word str) {
  92. char *ret;
  93. size_t l;
  94. l = C_header_size(str);
  95. ret = (char *) SWIG_malloc( (l + 1) * sizeof(char));
  96. if (!ret) return NULL;
  97. memcpy(ret, C_c_string(str), l);
  98. ret[l] = '\0';
  99. return ret;
  100. }
  101. static C_word SWIG_Chicken_LookupSymbol(char *name, C_SYMBOL_TABLE *stable) {
  102. C_word *a = C_alloc(C_SIZEOF_STRING (strlen (name)));
  103. C_word n = C_string2(&a, name);
  104. C_word sym = C_find_symbol(n, stable);
  105. if (C_truep(sym)) {
  106. return C_symbol_value(sym);
  107. } else {
  108. return C_SCHEME_FALSE;
  109. }
  110. }
  111. /* Just a helper function. Do not export it */
  112. static void SWIG_Chicken_Panic (C_char *) C_noret;
  113. static void SWIG_Chicken_Panic (C_char *msg)
  114. {
  115. C_word *a = C_alloc (C_SIZEOF_STRING (strlen (msg)));
  116. C_word scmmsg = C_string2 (&a, msg);
  117. C_halt (scmmsg);
  118. exit (5); /* should never get here */
  119. }
  120. static void
  121. SWIG_Chicken_Barf(int code, C_char *msg, ...) C_noret;
  122. static void
  123. SWIG_Chicken_Barf(int code, C_char *msg, ...)
  124. {
  125. char *errorhook = C_text("\003syserror-hook");
  126. C_word *a = C_alloc (C_SIZEOF_STRING (strlen (errorhook)));
  127. C_word err = C_intern2 (&a, errorhook);
  128. int c = -1;
  129. int i, barfval;
  130. va_list v;
  131. C_temporary_stack = C_temporary_stack_bottom;
  132. err = C_block_item(err, 0);
  133. if(C_immediatep (err))
  134. SWIG_Chicken_Panic (C_text ("`##sys#error-hook' is not defined"));
  135. switch (code) {
  136. case SWIG_BARF1_BAD_ARGUMENT_TYPE:
  137. barfval = C_BAD_ARGUMENT_TYPE_ERROR;
  138. c = 1;
  139. break;
  140. case SWIG_BARF1_ARGUMENT_NULL:
  141. barfval = C_BAD_ARGUMENT_TYPE_ERROR;
  142. c = 1;
  143. break;
  144. case SWIG_BARF1_CONTRACT_ASSERT:
  145. barfval = C_BAD_ARGUMENT_TYPE_ERROR;
  146. c = 1;
  147. break;
  148. default:
  149. SWIG_Chicken_Panic (C_text (msg));
  150. };
  151. if(c > 0 && !C_immediatep (err)) {
  152. C_save (C_fix (barfval));
  153. i = c;
  154. if (i) {
  155. C_word *b = C_alloc (C_SIZEOF_STRING (strlen (msg)));
  156. C_word scmmsg = C_string2 (&b, msg);
  157. C_save (scmmsg);
  158. i--;
  159. }
  160. va_start (v, msg);
  161. while(i--)
  162. C_save (va_arg (v, C_word));
  163. va_end (v);
  164. C_do_apply (c + 1, err,
  165. C_SCHEME_UNDEFINED); /* <- no continuation is passed:
  166. '##sys#error-hook' may not
  167. return! */
  168. }
  169. else if (msg) {
  170. SWIG_Chicken_Panic (msg);
  171. }
  172. else {
  173. SWIG_Chicken_Panic (C_text ("unspecified panic"));
  174. }
  175. }
  176. static void SWIG_Chicken_ThrowException(C_word value) C_noret;
  177. static void SWIG_Chicken_ThrowException(C_word value)
  178. {
  179. char *aborthook = C_text("\003sysabort");
  180. C_word *a = C_alloc(C_SIZEOF_STRING(strlen(aborthook)));
  181. C_word abort = C_intern2(&a, aborthook);
  182. abort = C_block_item(abort, 0);
  183. if (C_immediatep(abort))
  184. SWIG_Chicken_Panic(C_text("`##sys#abort' is not defined"));
  185. C_save(value);
  186. C_do_apply(1, abort, C_SCHEME_UNDEFINED);
  187. }
  188. static void
  189. SWIG_Chicken_Finalizer(C_word argc, C_word closure, C_word continuation, C_word s)
  190. {
  191. swig_type_info *type;
  192. swig_chicken_clientdata *cdata;
  193. if (argc == 3 && s != C_SCHEME_FALSE && C_swig_is_swigpointer(s)) {
  194. type = (swig_type_info *) C_block_item(s, 1);
  195. if (type) {
  196. cdata = (swig_chicken_clientdata *) type->clientdata;
  197. if (cdata && cdata->destroy) {
  198. /* this will not return, but will continue correctly */
  199. cdata->destroy(3,closure,continuation,s);
  200. }
  201. }
  202. }
  203. C_kontinue(continuation, C_SCHEME_UNDEFINED);
  204. }
  205. static C_word finalizer_obj[2] = {(C_word) (C_CLOSURE_TYPE|1), (C_word) SWIG_Chicken_Finalizer};
  206. static C_word
  207. SWIG_Chicken_NewPointerObj(void *ptr, swig_type_info *type, int owner, C_word **data)
  208. {
  209. swig_chicken_clientdata *cdata = (swig_chicken_clientdata *) type->clientdata;
  210. if (ptr == NULL)
  211. return C_SCHEME_FALSE;
  212. else {
  213. C_word cptr = C_swigmpointer(data, ptr, type);
  214. /* add finalizer to object */
  215. #ifndef SWIG_CHICKEN_NO_COLLECTION
  216. if (owner)
  217. C_do_register_finalizer(cptr, (C_word) finalizer_obj);
  218. #endif
  219. return cptr;
  220. }
  221. }
  222. /* Return 0 if successful. */
  223. static int
  224. SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags)
  225. {
  226. swig_cast_info *cast;
  227. swig_type_info *from;
  228. if (s == C_SCHEME_FALSE) {
  229. *result = NULL;
  230. } else if (C_swig_is_swigpointer(s)) {
  231. /* try and convert type */
  232. from = (swig_type_info *) C_block_item(s, 1);
  233. if (!from) return 1;
  234. if (type) {
  235. cast = SWIG_TypeCheckStruct(from, type);
  236. if (cast) {
  237. int newmemory = 0;
  238. *result = SWIG_TypeCast(cast, (void *) C_block_item(s, 0), &newmemory);
  239. assert(!newmemory); /* newmemory handling not yet implemented */
  240. } else {
  241. return 1;
  242. }
  243. } else {
  244. *result = (void *) C_block_item(s, 0);
  245. }
  246. /* check if we are disowning this object */
  247. if (flags & SWIG_POINTER_DISOWN) {
  248. C_do_unregister_finalizer(s);
  249. }
  250. } else {
  251. return 1;
  252. }
  253. return 0;
  254. }
  255. static SWIGINLINE void *
  256. SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags)
  257. {
  258. void *result;
  259. char err_msg[256];
  260. if (SWIG_Chicken_ConvertPtr(s, &result, type, flags)) {
  261. /* type mismatch */
  262. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", argnum, (type->str ? type->str : type->name));
  263. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  264. }
  265. return result;
  266. }
  267. static char *chicken_runtimevar_name = "type_pointer" SWIG_TYPE_TABLE_NAME;
  268. static swig_module_info *
  269. SWIG_Chicken_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
  270. swig_module_info *ret = 0;
  271. C_word sym;
  272. /* lookup the type pointer... it is stored in its own symbol table */
  273. C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
  274. if (stable != NULL) {
  275. sym = SWIG_Chicken_LookupSymbol(chicken_runtimevar_name, stable);
  276. if (C_truep(sym) && C_swig_is_ptr(sym)) {
  277. ret = (swig_module_info *) C_block_item(sym, 0);
  278. }
  279. }
  280. return ret;
  281. }
  282. static void
  283. SWIG_Chicken_SetModule(swig_module_info *module) {
  284. C_word *a;
  285. C_SYMBOL_TABLE *stable;
  286. C_word sym;
  287. C_word pointer;
  288. static C_word *space = 0;
  289. /* type pointer is stored in its own symbol table */
  290. stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
  291. if (stable == NULL) {
  292. stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16);
  293. }
  294. if (!space) {
  295. space = (C_word *) C_malloc((C_SIZEOF_POINTER + C_SIZEOF_INTERNED_SYMBOL(C_strlen(chicken_runtimevar_name))) * sizeof(C_word));
  296. }
  297. a = space;
  298. pointer = C_mpointer(&a, (void *) module);
  299. sym = C_intern_in(&a, C_strlen(chicken_runtimevar_name), chicken_runtimevar_name, stable);
  300. C_set_block_item(sym, 0, pointer);
  301. }
  302. static C_word SWIG_Chicken_MultiResultBuild(C_word num, C_word closure, C_word lst) {
  303. C_word cont = C_block_item(closure,1);
  304. C_word obj = C_block_item(closure,2);
  305. C_word func;
  306. SWIG_Chicken_FindCreateProxy(func,obj);
  307. if (C_swig_is_closurep(func)) {
  308. ((C_proc4)(void *)C_block_item(func, 0))(4,func,cont,obj,lst);
  309. } else {
  310. C_word *a = C_alloc(C_SIZEOF_PAIR);
  311. C_kontinue(cont,C_pair(&a,obj,lst));
  312. }
  313. return C_SCHEME_UNDEFINED; /* never reached */
  314. }
  315. static C_word SWIG_Chicken_ApplyResults(C_word num, C_word closure, C_word result) {
  316. C_apply_values(3,C_SCHEME_UNDEFINED,C_block_item(closure,1),result);
  317. return C_SCHEME_UNDEFINED; /* never reached */
  318. }
  319. #ifdef __cplusplus
  320. }
  321. #endif