gh.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Copyright (C) 1995,1996,1997,1998,2000,2001, 2005, 2006 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifndef __GH_H
  18. #define __GH_H
  19. /* This needs to be included outside of the extern "C" block.
  20. */
  21. #include <libguile.h>
  22. #if SCM_ENABLE_DEPRECATED
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* gcc has extern inline functions that are basically as fast as macros */
  27. #ifdef __GNUC__
  28. # define INL inline
  29. # define EXTINL extern inline
  30. #else
  31. # define INL
  32. #define EXTINL
  33. #endif /* __GNUC__ */
  34. SCM_API void gh_enter(int argc, char *argv[],
  35. void (*c_main_prog)(int, char **));
  36. #define gh_init () scm_init_guile ()
  37. SCM_API void gh_repl(int argc, char *argv[]);
  38. SCM_API SCM gh_catch(SCM tag, scm_t_catch_body body, void *body_data,
  39. scm_t_catch_handler handler, void *handler_data);
  40. SCM_API SCM gh_standard_handler(void *data, SCM tag, SCM throw_args);
  41. SCM_API SCM gh_eval_str(const char *scheme_code);
  42. SCM_API SCM gh_eval_str_with_catch(const char *scheme_code, scm_t_catch_handler handler);
  43. SCM_API SCM gh_eval_str_with_standard_handler(const char *scheme_code);
  44. SCM_API SCM gh_eval_str_with_stack_saving_handler(const char *scheme_code);
  45. SCM_API SCM gh_eval_file(const char *fname);
  46. #define gh_load(fname) gh_eval_file(fname)
  47. SCM_API SCM gh_eval_file_with_catch(const char *scheme_code, scm_t_catch_handler handler);
  48. SCM_API SCM gh_eval_file_with_standard_handler(const char *scheme_code);
  49. #define gh_defer_ints() SCM_CRITICAL_SECTION_START
  50. #define gh_allow_ints() SCM_CRITICAL_SECTION_END
  51. SCM_API SCM gh_new_procedure(const char *proc_name, SCM (*fn)(),
  52. int n_required_args, int n_optional_args,
  53. int varp);
  54. SCM_API SCM gh_new_procedure0_0(const char *proc_name, SCM (*fn)(void));
  55. SCM_API SCM gh_new_procedure0_1(const char *proc_name, SCM (*fn)(SCM));
  56. SCM_API SCM gh_new_procedure0_2(const char *proc_name, SCM (*fn)(SCM, SCM));
  57. SCM_API SCM gh_new_procedure1_0(const char *proc_name, SCM (*fn)(SCM));
  58. SCM_API SCM gh_new_procedure1_1(const char *proc_name, SCM (*fn)(SCM, SCM));
  59. SCM_API SCM gh_new_procedure1_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
  60. SCM_API SCM gh_new_procedure2_0(const char *proc_name, SCM (*fn)(SCM, SCM));
  61. SCM_API SCM gh_new_procedure2_1(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
  62. SCM_API SCM gh_new_procedure2_2(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
  63. SCM_API SCM gh_new_procedure3_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM));
  64. SCM_API SCM gh_new_procedure4_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM));
  65. SCM_API SCM gh_new_procedure5_0(const char *proc_name, SCM (*fn)(SCM, SCM, SCM, SCM, SCM));
  66. /* C to Scheme conversion */
  67. SCM_API SCM gh_bool2scm(int x);
  68. SCM_API SCM gh_int2scm(int x);
  69. SCM_API SCM gh_ulong2scm(unsigned long x);
  70. SCM_API SCM gh_long2scm(long x);
  71. SCM_API SCM gh_double2scm(double x);
  72. SCM_API SCM gh_char2scm(char c);
  73. SCM_API SCM gh_str2scm(const char *s, size_t len);
  74. SCM_API SCM gh_str02scm(const char *s);
  75. SCM_API void gh_set_substr(const char *src, SCM dst, long start, size_t len);
  76. SCM_API SCM gh_symbol2scm(const char *symbol_str);
  77. SCM_API SCM gh_ints2scm(const int *d, long n);
  78. SCM_API SCM gh_chars2byvect(const char *d, long n);
  79. SCM_API SCM gh_shorts2svect(const short *d, long n);
  80. SCM_API SCM gh_longs2ivect(const long *d, long n);
  81. SCM_API SCM gh_ulongs2uvect(const unsigned long *d, long n);
  82. SCM_API SCM gh_floats2fvect(const float *d, long n);
  83. SCM_API SCM gh_doubles2dvect(const double *d, long n);
  84. SCM_API SCM gh_doubles2scm(const double *d, long n);
  85. /* Scheme to C conversion */
  86. SCM_API int gh_scm2bool(SCM obj);
  87. SCM_API int gh_scm2int(SCM obj);
  88. SCM_API unsigned long gh_scm2ulong(SCM obj);
  89. SCM_API long gh_scm2long(SCM obj);
  90. SCM_API char gh_scm2char(SCM obj);
  91. SCM_API double gh_scm2double(SCM obj);
  92. SCM_API char *gh_scm2newstr(SCM str, size_t *lenp);
  93. SCM_API void gh_get_substr(SCM src, char *dst, long start, size_t len);
  94. SCM_API char *gh_symbol2newstr(SCM sym, size_t *lenp);
  95. SCM_API char *gh_scm2chars(SCM vector, char *result);
  96. SCM_API short *gh_scm2shorts(SCM vector, short *result);
  97. SCM_API long *gh_scm2longs(SCM vector, long *result);
  98. SCM_API float *gh_scm2floats(SCM vector, float *result);
  99. SCM_API double *gh_scm2doubles(SCM vector, double *result);
  100. /* type predicates: tell you if an SCM object has a given type */
  101. SCM_API int gh_boolean_p(SCM val);
  102. SCM_API int gh_symbol_p(SCM val);
  103. SCM_API int gh_char_p(SCM val);
  104. SCM_API int gh_vector_p(SCM val);
  105. SCM_API int gh_pair_p(SCM val);
  106. SCM_API int gh_number_p(SCM val);
  107. SCM_API int gh_string_p(SCM val);
  108. SCM_API int gh_procedure_p(SCM val);
  109. SCM_API int gh_list_p(SCM val);
  110. SCM_API int gh_inexact_p(SCM val);
  111. SCM_API int gh_exact_p(SCM val);
  112. /* more predicates */
  113. SCM_API int gh_eq_p(SCM x, SCM y);
  114. SCM_API int gh_eqv_p(SCM x, SCM y);
  115. SCM_API int gh_equal_p(SCM x, SCM y);
  116. SCM_API int gh_string_equal_p(SCM s1, SCM s2);
  117. SCM_API int gh_null_p(SCM l);
  118. /* standard Scheme procedures available from C */
  119. #define gh_not(x) scm_not(x)
  120. SCM_API SCM gh_define(const char *name, SCM val);
  121. /* string manipulation routines */
  122. #define gh_make_string(k, chr) scm_make_string(k, chr)
  123. #define gh_string_length(str) scm_string_length(str)
  124. #define gh_string_ref(str, k) scm_string_ref(str, k)
  125. #define gh_string_set_x(str, k, chr) scm_string_set_x(str, k, chr)
  126. #define gh_substring(str, start, end) scm_substring(str, start, end)
  127. #define gh_string_append(args) scm_string_append(args)
  128. /* vector manipulation routines */
  129. /* note that gh_vector() does not behave quite like the Scheme (vector
  130. obj1 obj2 ...), because the interpreter engine does not pass the
  131. data element by element, but rather as a list. thus, gh_vector()
  132. ends up being identical to gh_list_to_vector() */
  133. #define gh_vector(ls) scm_vector(ls)
  134. SCM_API SCM gh_make_vector(SCM length, SCM val);
  135. SCM_API SCM gh_vector_set_x(SCM vec, SCM pos, SCM val);
  136. SCM_API SCM gh_vector_ref(SCM vec, SCM pos);
  137. SCM_API unsigned long gh_vector_length (SCM v);
  138. SCM_API unsigned long gh_uniform_vector_length (SCM v);
  139. SCM_API SCM gh_uniform_vector_ref (SCM v, SCM ilist);
  140. #define gh_list_to_vector(ls) scm_vector(ls)
  141. #define gh_vector_to_list(v) scm_vector_to_list(v)
  142. SCM_API SCM gh_lookup (const char *sname);
  143. SCM_API SCM gh_module_lookup (SCM module, const char *sname);
  144. SCM_API SCM gh_cons(SCM x, SCM y);
  145. #define gh_list scm_list_n
  146. SCM_API unsigned long gh_length(SCM l);
  147. SCM_API SCM gh_append(SCM args);
  148. SCM_API SCM gh_append2(SCM l1, SCM l2);
  149. SCM_API SCM gh_append3(SCM l1, SCM l2, SCM l3);
  150. SCM_API SCM gh_append4(SCM l1, SCM l2, SCM l3, SCM l4);
  151. #define gh_reverse(ls) scm_reverse(ls)
  152. #define gh_list_tail(ls, k) scm_list_tail(ls, k)
  153. #define gh_list_ref(ls, k) scm_list_ref(ls, k)
  154. #define gh_memq(x, ls) scm_memq(x, ls)
  155. #define gh_memv(x, ls) scm_memv(x, ls)
  156. #define gh_member(x, ls) scm_member(x, ls)
  157. #define gh_assq(x, alist) scm_assq(x, alist)
  158. #define gh_assv(x, alist) scm_assv(x, alist)
  159. #define gh_assoc(x, alist) scm_assoc(x, alist)
  160. SCM_API SCM gh_car(SCM x);
  161. SCM_API SCM gh_cdr(SCM x);
  162. SCM_API SCM gh_caar(SCM x);
  163. SCM_API SCM gh_cadr(SCM x);
  164. SCM_API SCM gh_cdar(SCM x);
  165. SCM_API SCM gh_cddr(SCM x);
  166. SCM_API SCM gh_caaar(SCM x);
  167. SCM_API SCM gh_caadr(SCM x);
  168. SCM_API SCM gh_cadar(SCM x);
  169. SCM_API SCM gh_caddr(SCM x);
  170. SCM_API SCM gh_cdaar(SCM x);
  171. SCM_API SCM gh_cdadr(SCM x);
  172. SCM_API SCM gh_cddar(SCM x);
  173. SCM_API SCM gh_cdddr(SCM x);
  174. SCM_API SCM gh_set_car_x(SCM pair, SCM value);
  175. SCM_API SCM gh_set_cdr_x(SCM pair, SCM value);
  176. /* Calling Scheme functions from C. */
  177. SCM_API SCM gh_apply (SCM proc, SCM ls);
  178. SCM_API SCM gh_call0 (SCM proc);
  179. SCM_API SCM gh_call1 (SCM proc, SCM arg);
  180. SCM_API SCM gh_call2 (SCM proc, SCM arg1, SCM arg2);
  181. SCM_API SCM gh_call3 (SCM proc, SCM arg1, SCM arg2, SCM arg3);
  182. /* reading and writing Scheme objects. */
  183. SCM_API void gh_display (SCM x);
  184. SCM_API void gh_write (SCM x);
  185. SCM_API void gh_newline (void);
  186. /* void gh_gc_mark(SCM) : mark an SCM as in use. */
  187. /* void gh_defer_ints() : don't interrupt code section. */
  188. /* void gh_allow_ints() : see gh_defer_ints(). */
  189. /* void gh_new_cell(SCM, int tag) : initialize SCM to be of type 'tag' */
  190. /* int gh_type_p(SCM, tag) : test if SCM is of type 'tag' */
  191. /* SCM gh_intern(char*) : get symbol corresponding to c-string.*/
  192. /* void gh_set_ext_data(SCM, void*) : set extension data on SCM */
  193. /* void *gh_get_ext_data(SCM) : return extension data from SCM. */
  194. /* void gh_assert(int cond, char *msg, SCM obj); */
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #endif
  199. #endif /* __GH_H */
  200. /*
  201. Local Variables:
  202. c-file-style: "gnu"
  203. End:
  204. */