summaryrefslogtreecommitdiff
path: root/Lib/guile/guile_gh_run.swg
blob: 0eba1f97efdc752d844f4a2f1db49e8e665a0260 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* -----------------------------------------------------------------------------
 * guile_gh_run.swg
 *
 * Guile GH runtime file
 * ----------------------------------------------------------------------------- */

#define SWIGGUILE
#include "guile/gh.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef SCM (*swig_guile_proc)();

#define SWIG_malloc(size) \
  SCM_MUST_MALLOC(size)
#define SWIG_free(mem) \
  scm_must_free(mem)
#define SWIG_ConvertPtr(s, result, type, flags) \
  SWIG_Guile_ConvertPtr(&swig_module, s, result, type, flags)
#define SWIG_MustGetPtr(s, type, argnum, flags) \
  SWIG_Guile_MustGetPtr(&swig_module, s, type, argnum, flags, FUNC_NAME)
#define SWIG_NewPointerObj(ptr, type, owner) \
  SWIG_Guile_NewPointerObj(&swig_module, (void*)ptr, type, owner)
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)

/* Ignore object-ownership changes in gh mode */
#define SWIG_Guile_MarkPointerNoncollectable(s) (s)
#define SWIG_Guile_MarkPointerDestroyed(s) (s)
  
#define SWIG_contract_assert(expr, msg)				\
  if (!(expr))							\
    scm_error(gh_symbol2scm("swig-contract-assertion-failed"),	\
	      (char *) FUNC_NAME, (char *) msg,			\
	      SCM_EOL, SCM_BOOL_F); else

/* SCM_CHAR and SCM_CHARP were introduced in Guile 1.4; the following is for
   1.3.4 compatibility. */
#ifndef SCM_CHAR
#  define SCM_CHAR SCM_ICHR
#endif
#ifndef SCM_CHARP
#  define SCM_CHARP SCM_ICHRP
#endif

/* This function replaces gh_scm2char, which is broken in Guile 1.4 */
SWIGINTERN char
GSWIG_scm2char (SCM s)
{
  if (SCM_CHARP(s)) return SCM_CHAR(s);
  scm_wrong_type_arg(NULL, 0, s);
}
#define gh_scm2char GSWIG_scm2char

/* Interface function */
#define SWIG_scm2str(x) gh_scm2newstr(x, NULL)

/* More 1.3.4 compatibility */
#ifndef SCM_INPUT_PORT_P
#  define SCM_INPUT_PORT_P SCM_INPORTP
#  define SCM_OUTPUT_PORT_P SCM_OUTPORTP
#endif

SWIGINTERN long
SWIG_convert_integer(SCM o,
		     long lower_bound, long upper_bound, 
		     const char *func_name, int argnum)
{
  long value = gh_scm2long(o);
  if (value < lower_bound || value > upper_bound)
    scm_wrong_type_arg((char *) func_name, argnum, o);
  return value;
}
  
SWIGINTERN unsigned long
SWIG_convert_unsigned_integer(SCM o,
			      unsigned long lower_bound,
			      unsigned long upper_bound, 
			      const char *func_name, int argnum)
{
  unsigned long value = gh_scm2ulong(o);
  if (value < lower_bound || value > upper_bound)
    scm_wrong_type_arg((char *) func_name, argnum, o);
  return value;
}

SWIGINTERN swig_type_info *
SWIG_Guile_LookupType(swig_module_info *module, SCM s, int normal) 
{
  swig_module_info *iter;
  if (!module) return 0;
  iter = module;
  do {
    if ((normal && (unsigned long) SCM_TYP16(s) == *((int *)iter->clientdata))) {
        
      return iter->types[(long) SCM_CAR(s) >> 16];
    }
    iter = iter->next;
  } while (iter != module);
  return 0;
}

#ifdef SWIG_GLOBAL
#define SWIG_GUILE_MODULE_STATIC
#elif !defined(SWIG_NOINCLUDE)
#define SWIG_GUILE_MODULE_STATIC static
#endif

#ifdef SWIG_GUILE_MODULE_STATIC
static swig_module_info *swig_guile_module = 0;
SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule(void) {
  return swig_guile_module;
}
SWIG_GUILE_MODULE_STATIC void SWIG_Guile_SetModule(swig_module_info *pointer) {
  swig_guile_module = pointer;
}
#else
SWIGEXPORT swig_module_info * SWIG_Guile_GetModule(void);
SWIGEXPORT void SWIG_Guile_SetModule(swig_module_info *pointer);
#endif

SWIGINTERN SCM
SWIG_Guile_NewPointerObj(swig_module_info *module, void *ptr, 
			 swig_type_info *type, int owner)
{
  unsigned long tag;
  if (ptr==NULL) return SCM_EOL;
  if (!module) return SCM_EOL;
  for (tag = 0; tag < module->size; ++tag) {
    if (module->types[tag] == type)
      break;
  }
  if (tag >= module->size)
    return SCM_EOL;
    

  SCM_RETURN_NEWSMOB( ((tag << 16) | *((int *)module->clientdata)), ptr);
}

/* Return 0 if successful. */
SWIGINTERN int
SWIG_Guile_ConvertPtr(swig_module_info *module, SCM s, void **result, 
		      swig_type_info *type, int flags)
{
  swig_cast_info *cast;
  swig_type_info *from;
  if (SCM_NULLP(s)) {
    *result = NULL;
    return SWIG_OK;
  } else if (SCM_NIMP(s)) {
    from = SWIG_Guile_LookupType(module, s, 1);
    if (!from) return SWIG_ERROR;
    if (type) {
      cast = SWIG_TypeCheckStruct(from, type);
      if (cast) {
        int newmemory = 0;
        *result = SWIG_TypeCast(cast, (void *) SCM_CDR(s), &newmemory);
        assert(!newmemory); /* newmemory handling not yet implemented */
        return SWIG_OK;
      } else {
        return SWIG_ERROR;
      }
    } else {
      *result = (void *) SCM_CDR(s);
      return SWIG_OK;
    }
  }
  return SWIG_ERROR;
}

SWIGINTERN void *
SWIG_Guile_MustGetPtr (swig_module_info *module, SCM s, swig_type_info *type,
                       int argnum, int flags, const char *func_name)
{
  void *result;
  int res = SWIG_Guile_ConvertPtr(module, s, &result, type, flags);
  if (!SWIG_IsOK(res)) {
    /* type mismatch */
    scm_wrong_type_arg((char *) func_name, argnum, s);
  }
  return result;
}

/* Init */

SWIGINTERN int
print_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
{
  swig_type_info *type = SWIG_Guile_LookupType(0, swig_smob, 1);
  if (type) {
    scm_puts((char *) "#<swig ", port);
    if (type->str != NULL)
      scm_puts((char *) type->str, port);
    else 
      scm_puts((char *) type->name, port);
    scm_puts((char *) " ", port);
    scm_intprint((long) SCM_CDR(swig_smob), 16, port);
    scm_puts((char *) ">", port);
    /* non-zero means success */
    return 1;
  } else {
    return 0;
  }
}

SWIGINTERN SCM
equalp_swig (SCM A, SCM B)
{
  if (SCM_CAR(A) == SCM_CAR(B)
      && SCM_CDR(A) == SCM_CDR(B))
    return SCM_BOOL_T;
  else return SCM_BOOL_F;
}

SWIGINTERN void
SWIG_Guile_Init (swig_module_info *module)
{
    *((int *)module->clientdata) = 
         scm_make_smob_type_mfpe((char *) "swig", 0, NULL, NULL, print_swig, equalp_swig);
}

SWIGINTERN int
SWIG_Guile_GetArgs (SCM *dest, SCM rest,
		    int reqargs, int optargs,
		    const char *procname)
{
  int i;
  int num_args_passed = 0;
  for (i = 0; i<reqargs; i++) {
    if (!SCM_CONSP(rest))
      scm_wrong_num_args(gh_str02scm((char *) procname));
    *dest++ = SCM_CAR(rest);
    rest = SCM_CDR(rest);
    num_args_passed++;
  }
  for (i = 0; i<optargs && SCM_CONSP(rest); i++) {
    *dest++ = SCM_CAR(rest);
    rest = SCM_CDR(rest);
    num_args_passed++;
  }
  for (; i<optargs; i++)
    *dest++ = SCM_UNDEFINED;
  if (!SCM_NULLP(rest))
    scm_wrong_num_args(gh_str02scm((char *) procname));
  return num_args_passed;
}

#ifdef __cplusplus
}
#endif

/* guile.swg ends here */