PageRenderTime 16ms CodeModel.GetById 14ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/guile/interpreter.i

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