gh.h 9.3 KB

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