gh_funcs.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* Copyright (C) 1995,1996,1997,1998, 2000 Free Software Foundation, Inc.
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this software; see the file COPYING. If not, write to
  14. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  15. * Boston, MA 02111-1307 USA
  16. *
  17. * As a special exception, the Free Software Foundation gives permission
  18. * for additional uses of the text contained in its release of GUILE.
  19. *
  20. * The exception is that, if you link the GUILE library with other files
  21. * to produce an executable, this does not by itself cause the
  22. * resulting executable to be covered by the GNU General Public License.
  23. * Your use of that executable is in no way restricted on account of
  24. * linking the GUILE library code into it.
  25. *
  26. * This exception does not however invalidate any other reasons why
  27. * the executable file might be covered by the GNU General Public License.
  28. *
  29. * This exception applies only to the code released by the
  30. * Free Software Foundation under the name GUILE. If you copy
  31. * code from other Free Software Foundation releases into a copy of
  32. * GUILE, as the General Public License permits, the exception does
  33. * not apply to the code that you add in this way. To avoid misleading
  34. * anyone as to the status of such modified files, you must delete
  35. * this exception notice from them.
  36. *
  37. * If you write modifications of your own for GUILE, it is your choice
  38. * whether to permit this exception to apply to your modifications.
  39. * If you do not wish that, delete this exception notice. */
  40. /* Defining Scheme functions implemented by C functions --- subrs. */
  41. #include <stdio.h>
  42. #include "libguile/gh.h"
  43. /* allows you to define new scheme primitives written in C */
  44. SCM
  45. gh_new_procedure (const char *proc_name, SCM (*fn) (),
  46. int n_required_args, int n_optional_args, int varp)
  47. {
  48. return scm_make_gsubr (proc_name, n_required_args, n_optional_args,
  49. varp, fn);
  50. }
  51. SCM
  52. gh_new_procedure0_0 (const char *proc_name, SCM (*fn) ())
  53. {
  54. return gh_new_procedure (proc_name, fn, 0, 0, 0);
  55. }
  56. SCM
  57. gh_new_procedure0_1 (const char *proc_name, SCM (*fn) ())
  58. {
  59. return gh_new_procedure (proc_name, fn, 0, 1, 0);
  60. }
  61. SCM
  62. gh_new_procedure0_2 (const char *proc_name, SCM (*fn) ())
  63. {
  64. return gh_new_procedure (proc_name, fn, 0, 2, 0);
  65. }
  66. SCM
  67. gh_new_procedure1_0 (const char *proc_name, SCM (*fn) ())
  68. {
  69. return gh_new_procedure (proc_name, fn, 1, 0, 0);
  70. }
  71. SCM
  72. gh_new_procedure1_1 (const char *proc_name, SCM (*fn) ())
  73. {
  74. return gh_new_procedure (proc_name, fn, 1, 1, 0);
  75. }
  76. SCM
  77. gh_new_procedure1_2 (const char *proc_name, SCM (*fn) ())
  78. {
  79. return gh_new_procedure (proc_name, fn, 1, 2, 0);
  80. }
  81. SCM
  82. gh_new_procedure2_0 (const char *proc_name, SCM (*fn) ())
  83. {
  84. return gh_new_procedure (proc_name, fn, 2, 0, 0);
  85. }
  86. SCM
  87. gh_new_procedure2_1 (const char *proc_name, SCM (*fn) ())
  88. {
  89. return gh_new_procedure (proc_name, fn, 2, 1, 0);
  90. }
  91. SCM
  92. gh_new_procedure2_2 (const char *proc_name, SCM (*fn) ())
  93. {
  94. return gh_new_procedure (proc_name, fn, 2, 2, 0);
  95. }
  96. SCM
  97. gh_new_procedure3_0 (const char *proc_name, SCM (*fn) ())
  98. {
  99. return gh_new_procedure (proc_name, fn, 3, 0, 0);
  100. }
  101. SCM
  102. gh_new_procedure4_0 (const char *proc_name, SCM (*fn) ())
  103. {
  104. return gh_new_procedure (proc_name, fn, 4, 0, 0);
  105. }
  106. SCM
  107. gh_new_procedure5_0 (const char *proc_name, SCM (*fn) ())
  108. {
  109. return gh_new_procedure (proc_name, fn, 5, 0, 0);
  110. }
  111. /* some (possibly most) Scheme functions available from C */
  112. SCM
  113. gh_define (const char *name, SCM val)
  114. {
  115. return scm_sysintern (name, val);
  116. }
  117. /* Calling Scheme functions from C. */
  118. SCM
  119. gh_apply (SCM proc, SCM args)
  120. {
  121. return scm_apply (proc, args, SCM_EOL);
  122. }
  123. SCM
  124. gh_call0 (SCM proc)
  125. {
  126. return scm_apply (proc, SCM_EOL, SCM_EOL);
  127. }
  128. SCM
  129. gh_call1 (SCM proc, SCM arg)
  130. {
  131. return scm_apply (proc, arg, scm_listofnull);
  132. }
  133. SCM
  134. gh_call2 (SCM proc, SCM arg1, SCM arg2)
  135. {
  136. return scm_apply (proc, arg1, scm_cons (arg2, scm_listofnull));
  137. }
  138. SCM
  139. gh_call3 (SCM proc, SCM arg1, SCM arg2, SCM arg3)
  140. {
  141. return scm_apply (proc, arg1, scm_cons2 (arg2, arg3, scm_listofnull));
  142. }
  143. /*
  144. Local Variables:
  145. c-file-style: "gnu"
  146. End:
  147. */