gh_eval.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (C) 1995,1996,1997,1998, 2000, 2001 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., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301 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. /* routines to evaluate Scheme code */
  41. #include "libguile/gh.h"
  42. typedef SCM (*gh_eval_t) (void *data, SCM jmpbuf);
  43. /* Evaluate the string; toss the value. */
  44. SCM
  45. gh_eval_str (const char *scheme_code)
  46. {
  47. return scm_c_eval_string (scheme_code);
  48. }
  49. /* evaluate the file by passing it to the lower level scm_primitive_load() */
  50. SCM
  51. gh_eval_file (const char *fname)
  52. {
  53. return scm_primitive_load (gh_str02scm (fname));
  54. }
  55. static SCM
  56. eval_str_wrapper (void *data)
  57. {
  58. /* gh_eval_t real_eval_proc = (gh_eval_t) (* ((gh_eval_t *) data)); */
  59. char *scheme_code = (char *) data;
  60. return gh_eval_str (scheme_code);
  61. }
  62. SCM
  63. gh_eval_str_with_catch (const char *scheme_code, scm_t_catch_handler handler)
  64. {
  65. /* FIXME: not there yet */
  66. return gh_catch (SCM_BOOL_T, (scm_t_catch_body) eval_str_wrapper, (void *) scheme_code,
  67. (scm_t_catch_handler) handler, (void *) scheme_code);
  68. }
  69. SCM
  70. gh_eval_str_with_standard_handler (const char *scheme_code)
  71. {
  72. return gh_eval_str_with_catch (scheme_code, gh_standard_handler);
  73. }
  74. SCM
  75. gh_eval_str_with_stack_saving_handler (const char *scheme_code)
  76. {
  77. return scm_internal_stack_catch (SCM_BOOL_T,
  78. (scm_t_catch_body) eval_str_wrapper,
  79. (void *) scheme_code,
  80. (scm_t_catch_handler)
  81. gh_standard_handler,
  82. (void *) scheme_code);
  83. }
  84. static SCM
  85. eval_file_wrapper (void *data)
  86. {
  87. /* gh_eval_t real_eval_proc = (gh_eval_t) (* ((gh_eval_t *) data)); */
  88. char *scheme_code = (char *) data;
  89. return gh_eval_file (scheme_code);
  90. }
  91. SCM
  92. gh_eval_file_with_catch (const char *scheme_code, scm_t_catch_handler handler)
  93. {
  94. /* FIXME: not there yet */
  95. return gh_catch (SCM_BOOL_T, (scm_t_catch_body) eval_file_wrapper,
  96. (void *) scheme_code, (scm_t_catch_handler) handler,
  97. (void *) scheme_code);
  98. }
  99. SCM
  100. gh_eval_file_with_standard_handler (const char *scheme_code)
  101. {
  102. return gh_eval_file_with_catch (scheme_code, gh_standard_handler);
  103. }
  104. /*
  105. Local Variables:
  106. c-file-style: "gnu"
  107. End:
  108. */