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