PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Lib/guile/interpreter.i

#
Swig | 62 lines | 37 code | 11 blank | 14 comment | 0 complexity | c8270c48ca2a4c6116cf5510b0540a97 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * interpreter.i
  6. *
  7. * SWIG file for a simple Guile interpreter
  8. * ----------------------------------------------------------------------------- */
  9. %{
  10. #include <stdio.h>
  11. GSCM_status guile_init();
  12. int main(int argc, char **argv) {
  13. GSCM_status status;
  14. GSCM_top_level toplev;
  15. char *eval_answer;
  16. char input_str[16384];
  17. int done;
  18. /* start a scheme interpreter */
  19. status = gscm_run_scm(argc, argv, 0, stdout, stderr, guile_init, 0, "#t");
  20. if (status != GSCM_OK) {
  21. fputs(gscm_error_msg(status), stderr);
  22. fputc('\n', stderr);
  23. printf("Error in startup.\n");
  24. exit(1);
  25. }
  26. /* create the top level environment */
  27. status = gscm_create_top_level(&toplev);
  28. if (status != GSCM_OK) {
  29. fputs(gscm_error_msg(status), stderr);
  30. fputc('\n', stderr);
  31. exit(1);
  32. }
  33. /* now sit in a scheme eval loop: I input the expressions, have guile
  34. * evaluate them, and then get another expression.
  35. */
  36. done = 0;
  37. fprintf(stdout,"Guile > ");
  38. while (!done) {
  39. if (fgets(input_str,16384,stdin) == NULL) {
  40. exit(1);
  41. } else {
  42. if (strncmp(input_str,"quit",4) == 0) exit(1);
  43. status = gscm_eval_str(&eval_answer, toplev, input_str);
  44. fprintf(stdout,"%s\n", eval_answer);
  45. fprintf(stdout,"Guile > ");
  46. }
  47. }
  48. /* now clean up and quit */
  49. gscm_destroy_top_level(toplev);
  50. }
  51. %}