gh_eval.c 3.9 KB

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