PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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