PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/guile/interpreter.i

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