PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/guile/guile_scm_run.swg

#
Unknown | 482 lines | 428 code | 54 blank | 0 comment | 0 complexity | a45a5cb49e23d263b985306ec1b36d56 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * guile_scm_run.swg
  3. * ----------------------------------------------------------------------------- */
  4. #include <libguile.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <assert.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef SCM (*swig_guile_proc)();
  13. typedef SCM (*guile_destructor)(SCM);
  14. typedef struct swig_guile_clientdata {
  15. guile_destructor destroy;
  16. SCM goops_class;
  17. } swig_guile_clientdata;
  18. #define SWIG_scm2str(s) \
  19. SWIG_Guile_scm2newstr(s, NULL)
  20. #define SWIG_malloc(size) \
  21. SCM_MUST_MALLOC(size)
  22. #define SWIG_free(mem) \
  23. scm_must_free(mem)
  24. #define SWIG_ConvertPtr(s, result, type, flags) \
  25. SWIG_Guile_ConvertPtr(s, result, type, flags)
  26. #define SWIG_MustGetPtr(s, type, argnum, flags) \
  27. SWIG_Guile_MustGetPtr(s, type, argnum, flags, FUNC_NAME)
  28. #define SWIG_NewPointerObj(ptr, type, owner) \
  29. SWIG_Guile_NewPointerObj((void*)ptr, type, owner)
  30. #define SWIG_PointerAddress(object) \
  31. SWIG_Guile_PointerAddress(object)
  32. #define SWIG_PointerType(object) \
  33. SWIG_Guile_PointerType(object)
  34. #define SWIG_IsPointerOfType(object, type) \
  35. SWIG_Guile_IsPointerOfType(object, type)
  36. #define SWIG_IsPointer(object) \
  37. SWIG_Guile_IsPointer(object)
  38. #define SWIG_contract_assert(expr, msg) \
  39. if (!(expr)) \
  40. scm_error(scm_str2symbol("swig-contract-assertion-failed"), \
  41. (char *) FUNC_NAME, (char *) msg, \
  42. SCM_EOL, SCM_BOOL_F); else
  43. /* for C++ member pointers, ie, member methods */
  44. #define SWIG_ConvertMember(obj, ptr, sz, ty) \
  45. SWIG_Guile_ConvertMember(obj, ptr, sz, ty, FUNC_NAME)
  46. #define SWIG_NewMemberObj(ptr, sz, type) \
  47. SWIG_Guile_NewMemberObj(ptr, sz, type, FUNC_NAME)
  48. /* Runtime API */
  49. static swig_module_info *SWIG_Guile_GetModule(void);
  50. #define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
  51. #define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)
  52. SWIGINTERN char *
  53. SWIG_Guile_scm2newstr(SCM str, size_t *len) {
  54. #define FUNC_NAME "SWIG_Guile_scm2newstr"
  55. char *ret;
  56. size_t l;
  57. SCM_ASSERT (SCM_STRINGP(str), str, 1, FUNC_NAME);
  58. l = SCM_STRING_LENGTH(str);
  59. ret = (char *) SWIG_malloc( (l + 1) * sizeof(char));
  60. if (!ret) return NULL;
  61. memcpy(ret, SCM_STRING_CHARS(str), l);
  62. ret[l] = '\0';
  63. if (len) *len = l;
  64. return ret;
  65. #undef FUNC_NAME
  66. }
  67. static int swig_initialized = 0;
  68. static scm_t_bits swig_tag = 0;
  69. static scm_t_bits swig_collectable_tag = 0;
  70. static scm_t_bits swig_destroyed_tag = 0;
  71. static scm_t_bits swig_member_function_tag = 0;
  72. static SCM swig_make_func = SCM_EOL;
  73. static SCM swig_keyword = SCM_EOL;
  74. static SCM swig_symbol = SCM_EOL;
  75. #define SWIG_Guile_GetSmob(x) \
  76. ( SCM_NNULLP(x) && SCM_INSTANCEP(x) && SCM_NFALSEP(scm_slot_exists_p(x, swig_symbol)) \
  77. ? scm_slot_ref(x, swig_symbol) : (x) )
  78. SWIGINTERN SCM
  79. SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner)
  80. {
  81. if (ptr == NULL)
  82. return SCM_EOL;
  83. else {
  84. SCM smob;
  85. swig_guile_clientdata *cdata = (swig_guile_clientdata *) type->clientdata;
  86. if (owner)
  87. SCM_NEWSMOB2(smob, swig_collectable_tag, ptr, (void *) type);
  88. else
  89. SCM_NEWSMOB2(smob, swig_tag, ptr, (void *) type);
  90. if (!cdata || SCM_NULLP(cdata->goops_class) || swig_make_func == SCM_EOL ) {
  91. return smob;
  92. } else {
  93. /* the scm_make() C function only handles the creation of gf,
  94. methods and classes (no instances) the (make ...) function is
  95. later redefined in goops.scm. So we need to call that
  96. Scheme function. */
  97. return scm_apply(swig_make_func,
  98. scm_list_3(cdata->goops_class,
  99. swig_keyword,
  100. smob),
  101. SCM_EOL);
  102. }
  103. }
  104. }
  105. SWIGINTERN unsigned long
  106. SWIG_Guile_PointerAddress(SCM object)
  107. {
  108. SCM smob = SWIG_Guile_GetSmob(object);
  109. if (SCM_NULLP(smob)) return 0;
  110. else if (SCM_SMOB_PREDICATE(swig_tag, smob)
  111. || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
  112. || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
  113. return (unsigned long) (void *) SCM_CELL_WORD_1(smob);
  114. }
  115. else scm_wrong_type_arg("SWIG-Guile-PointerAddress", 1, object);
  116. }
  117. SWIGINTERN swig_type_info *
  118. SWIG_Guile_PointerType(SCM object)
  119. {
  120. SCM smob = SWIG_Guile_GetSmob(object);
  121. if (SCM_NULLP(smob)) return NULL;
  122. else if (SCM_SMOB_PREDICATE(swig_tag, smob)
  123. || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
  124. || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
  125. return (swig_type_info *) SCM_CELL_WORD_2(smob);
  126. }
  127. else scm_wrong_type_arg("SWIG-Guile-PointerType", 1, object);
  128. }
  129. SWIGINTERN int
  130. SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
  131. {
  132. swig_cast_info *cast;
  133. swig_type_info *from;
  134. SCM smob = SWIG_Guile_GetSmob(s);
  135. if (SCM_NULLP(smob)) {
  136. *result = NULL;
  137. return SWIG_OK;
  138. } else if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
  139. /* we do not accept smobs representing destroyed pointers */
  140. from = (swig_type_info *) SCM_CELL_WORD_2(smob);
  141. if (!from) return SWIG_ERROR;
  142. if (type) {
  143. cast = SWIG_TypeCheckStruct(from, type);
  144. if (cast) {
  145. int newmemory = 0;
  146. *result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob), &newmemory);
  147. assert(!newmemory); /* newmemory handling not yet implemented */
  148. return SWIG_OK;
  149. } else {
  150. return SWIG_ERROR;
  151. }
  152. } else {
  153. *result = (void *) SCM_CELL_WORD_1(smob);
  154. return SWIG_OK;
  155. }
  156. }
  157. return SWIG_ERROR;
  158. }
  159. SWIGINTERNINLINE void *
  160. SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type,
  161. int argnum, int flags, const char *func_name)
  162. {
  163. void *result;
  164. int res = SWIG_Guile_ConvertPtr(s, &result, type, flags);
  165. if (!SWIG_IsOK(res)) {
  166. /* type mismatch */
  167. scm_wrong_type_arg((char *) func_name, argnum, s);
  168. }
  169. return result;
  170. }
  171. SWIGINTERNINLINE int
  172. SWIG_Guile_IsPointerOfType (SCM s, swig_type_info *type)
  173. {
  174. void *result;
  175. if (SWIG_Guile_ConvertPtr(s, &result, type, 0)) {
  176. /* type mismatch */
  177. return 0;
  178. }
  179. else return 1;
  180. }
  181. SWIGINTERNINLINE int
  182. SWIG_Guile_IsPointer (SCM s)
  183. {
  184. /* module might not be initialized yet, so initialize it */
  185. SWIG_Guile_GetModule();
  186. return SWIG_Guile_IsPointerOfType (s, NULL);
  187. }
  188. /* Mark a pointer object non-collectable */
  189. SWIGINTERN void
  190. SWIG_Guile_MarkPointerNoncollectable(SCM s)
  191. {
  192. SCM smob = SWIG_Guile_GetSmob(s);
  193. if (!SCM_NULLP(smob)) {
  194. if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
  195. SCM_SET_CELL_TYPE(smob, swig_tag);
  196. }
  197. else scm_wrong_type_arg(NULL, 0, s);
  198. }
  199. }
  200. /* Mark a pointer object destroyed */
  201. SWIGINTERN void
  202. SWIG_Guile_MarkPointerDestroyed(SCM s)
  203. {
  204. SCM smob = SWIG_Guile_GetSmob(s);
  205. if (!SCM_NULLP(smob)) {
  206. if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)) {
  207. SCM_SET_CELL_TYPE(smob, swig_destroyed_tag);
  208. }
  209. else scm_wrong_type_arg(NULL, 0, s);
  210. }
  211. }
  212. /* Member functions */
  213. SWIGINTERN SCM
  214. SWIG_Guile_NewMemberObj(void *ptr, size_t sz, swig_type_info *type,
  215. const char *func_name)
  216. {
  217. SCM smob;
  218. void *copy = malloc(sz);
  219. memcpy(copy, ptr, sz);
  220. SCM_NEWSMOB2(smob, swig_member_function_tag, copy, (void *) type);
  221. return smob;
  222. }
  223. SWIGINTERN int
  224. SWIG_Guile_ConvertMember(SCM smob, void *ptr, size_t sz, swig_type_info *type,
  225. const char *func_name)
  226. {
  227. swig_cast_info *cast;
  228. swig_type_info *from;
  229. if (SCM_SMOB_PREDICATE(swig_member_function_tag, smob)) {
  230. from = (swig_type_info *) SCM_CELL_WORD_2(smob);
  231. if (!from) return SWIG_ERROR;
  232. if (type) {
  233. cast = SWIG_TypeCheckStruct(from, type);
  234. if (!cast) return SWIG_ERROR;
  235. }
  236. memcpy(ptr, (void *) SCM_CELL_WORD_1(smob), sz);
  237. return SWIG_OK;
  238. }
  239. return SWIG_ERROR;
  240. }
  241. /* Init */
  242. SWIGINTERN int
  243. print_swig_aux (SCM swig_smob, SCM port, scm_print_state *pstate,
  244. const char *attribute)
  245. {
  246. swig_type_info *type;
  247. type = (swig_type_info *) SCM_CELL_WORD_2(swig_smob);
  248. if (type) {
  249. scm_puts((char *) "#<", port);
  250. scm_puts((char *) attribute, port);
  251. scm_puts((char *) "swig-pointer ", port);
  252. scm_puts((char *) SWIG_TypePrettyName(type), port);
  253. scm_puts((char *) " ", port);
  254. scm_intprint((long) SCM_CELL_WORD_1(swig_smob), 16, port);
  255. scm_puts((char *) ">", port);
  256. /* non-zero means success */
  257. return 1;
  258. } else {
  259. return 0;
  260. }
  261. }
  262. SWIGINTERN int
  263. print_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
  264. {
  265. return print_swig_aux(swig_smob, port, pstate, "");
  266. }
  267. SWIGINTERN int
  268. print_collectable_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
  269. {
  270. return print_swig_aux(swig_smob, port, pstate, "collectable-");
  271. }
  272. SWIGINTERN int
  273. print_destroyed_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
  274. {
  275. return print_swig_aux(swig_smob, port, pstate, "destroyed-");
  276. }
  277. SWIGINTERN int
  278. print_member_function_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
  279. {
  280. swig_type_info *type;
  281. type = (swig_type_info *) SCM_CELL_WORD_2(swig_smob);
  282. if (type) {
  283. scm_puts((char *) "#<", port);
  284. scm_puts((char *) "swig-member-function-pointer ", port);
  285. scm_puts((char *) SWIG_TypePrettyName(type), port);
  286. scm_puts((char *) " >", port);
  287. /* non-zero means success */
  288. return 1;
  289. } else {
  290. return 0;
  291. }
  292. }
  293. SWIGINTERN SCM
  294. equalp_swig (SCM A, SCM B)
  295. {
  296. if (SCM_CELL_WORD_0(A) == SCM_CELL_WORD_0(B) && SCM_CELL_WORD_1(A) == SCM_CELL_WORD_1(B)
  297. && SCM_CELL_WORD_2(A) == SCM_CELL_WORD_2(B))
  298. return SCM_BOOL_T;
  299. else return SCM_BOOL_F;
  300. }
  301. SWIGINTERN size_t
  302. free_swig(SCM A)
  303. {
  304. swig_type_info *type = (swig_type_info *) SCM_CELL_WORD_2(A);
  305. if (type) {
  306. if (type->clientdata && ((swig_guile_clientdata *)type->clientdata)->destroy)
  307. ((swig_guile_clientdata *)type->clientdata)->destroy(A);
  308. }
  309. return 0;
  310. }
  311. SWIGINTERN size_t
  312. free_swig_member_function(SCM A)
  313. {
  314. free((swig_type_info *) SCM_CELL_WORD_1(A));
  315. return 0;
  316. }
  317. SWIGINTERN int
  318. ensure_smob_tag(SCM swig_module,
  319. scm_t_bits *tag_variable,
  320. const char *smob_name,
  321. const char *scheme_variable_name)
  322. {
  323. SCM variable = scm_sym2var(scm_str2symbol(scheme_variable_name),
  324. scm_module_lookup_closure(swig_module),
  325. SCM_BOOL_T);
  326. if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) {
  327. *tag_variable = scm_make_smob_type((char*)scheme_variable_name, 0);
  328. SCM_VARIABLE_SET(variable,
  329. scm_ulong2num(*tag_variable));
  330. return 1;
  331. }
  332. else {
  333. *tag_variable = scm_num2ulong(SCM_VARIABLE_REF(variable), 0,
  334. "SWIG_Guile_Init");
  335. return 0;
  336. }
  337. }
  338. SWIGINTERN SCM
  339. SWIG_Guile_Init ()
  340. {
  341. static SCM swig_module;
  342. if (swig_initialized) return swig_module;
  343. swig_initialized = 1;
  344. swig_module = scm_c_resolve_module("Swig swigrun");
  345. if (ensure_smob_tag(swig_module, &swig_tag,
  346. "swig-pointer", "swig-pointer-tag")) {
  347. scm_set_smob_print(swig_tag, print_swig);
  348. scm_set_smob_equalp(swig_tag, equalp_swig);
  349. }
  350. if (ensure_smob_tag(swig_module, &swig_collectable_tag,
  351. "collectable-swig-pointer", "collectable-swig-pointer-tag")) {
  352. scm_set_smob_print(swig_collectable_tag, print_collectable_swig);
  353. scm_set_smob_equalp(swig_collectable_tag, equalp_swig);
  354. scm_set_smob_free(swig_collectable_tag, free_swig);
  355. }
  356. if (ensure_smob_tag(swig_module, &swig_destroyed_tag,
  357. "destroyed-swig-pointer", "destroyed-swig-pointer-tag")) {
  358. scm_set_smob_print(swig_destroyed_tag, print_destroyed_swig);
  359. scm_set_smob_equalp(swig_destroyed_tag, equalp_swig);
  360. }
  361. if (ensure_smob_tag(swig_module, &swig_member_function_tag,
  362. "swig-member-function-pointer", "swig-member-function-pointer-tag")) {
  363. scm_set_smob_print(swig_member_function_tag, print_member_function_swig);
  364. scm_set_smob_free(swig_member_function_tag, free_swig_member_function);
  365. }
  366. swig_make_func = scm_permanent_object(
  367. scm_variable_ref(scm_c_module_lookup(scm_c_resolve_module("oop goops"), "make")));
  368. swig_keyword = scm_permanent_object(scm_c_make_keyword((char*) "init-smob"));
  369. swig_symbol = scm_permanent_object(scm_str2symbol("swig-smob"));
  370. #ifdef SWIG_INIT_RUNTIME_MODULE
  371. SWIG_INIT_RUNTIME_MODULE
  372. #endif
  373. return swig_module;
  374. }
  375. SWIGINTERN swig_module_info *
  376. SWIG_Guile_GetModule(void)
  377. {
  378. SCM module;
  379. SCM variable;
  380. module = SWIG_Guile_Init();
  381. variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME),
  382. scm_module_lookup_closure(module),
  383. SCM_BOOL_T);
  384. if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) {
  385. return NULL;
  386. } else {
  387. return (swig_module_info *) scm_num2ulong(SCM_VARIABLE_REF(variable), 0, "SWIG_Guile_Init");
  388. }
  389. }
  390. SWIGINTERN void
  391. SWIG_Guile_SetModule(swig_module_info *swig_module)
  392. {
  393. SCM module;
  394. SCM variable;
  395. module = SWIG_Guile_Init();
  396. variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME),
  397. scm_module_lookup_closure(module),
  398. SCM_BOOL_T);
  399. SCM_VARIABLE_SET(variable, scm_ulong2num((unsigned long) swig_module));
  400. }
  401. SWIGINTERN int
  402. SWIG_Guile_GetArgs (SCM *dest, SCM rest,
  403. int reqargs, int optargs,
  404. const char *procname)
  405. {
  406. int i;
  407. int num_args_passed = 0;
  408. for (i = 0; i<reqargs; i++) {
  409. if (!SCM_CONSP(rest))
  410. scm_wrong_num_args(scm_makfrom0str((char *) procname));
  411. *dest++ = SCM_CAR(rest);
  412. rest = SCM_CDR(rest);
  413. num_args_passed++;
  414. }
  415. for (i = 0; i<optargs && SCM_CONSP(rest); i++) {
  416. *dest++ = SCM_CAR(rest);
  417. rest = SCM_CDR(rest);
  418. num_args_passed++;
  419. }
  420. for (; i<optargs; i++)
  421. *dest++ = SCM_UNDEFINED;
  422. if (!SCM_NULLP(rest))
  423. scm_wrong_num_args(scm_makfrom0str((char *) procname));
  424. return num_args_passed;
  425. }
  426. #ifdef __cplusplus
  427. }
  428. #endif