/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%{ 11 12#include <stdio.h> 13GSCM_status guile_init(); 14 15int main(int argc, char **argv) { 16 GSCM_status status; 17 GSCM_top_level toplev; 18 char *eval_answer; 19 char input_str[16384]; 20 int done; 21 22 /* start a scheme interpreter */ 23 status = gscm_run_scm(argc, argv, 0, stdout, stderr, guile_init, 0, "#t"); 24 if (status != GSCM_OK) { 25 fputs(gscm_error_msg(status), stderr); 26 fputc('\n', stderr); 27 printf("Error in startup.\n"); 28 exit(1); 29 } 30 31 /* create the top level environment */ 32 status = gscm_create_top_level(&toplev); 33 if (status != GSCM_OK) { 34 fputs(gscm_error_msg(status), stderr); 35 fputc('\n', stderr); 36 exit(1); 37 } 38 39 /* now sit in a scheme eval loop: I input the expressions, have guile 40 * evaluate them, and then get another expression. 41 */ 42 done = 0; 43 fprintf(stdout,"Guile > "); 44 while (!done) { 45 if (fgets(input_str,16384,stdin) == NULL) { 46 exit(1); 47 } else { 48 if (strncmp(input_str,"quit",4) == 0) exit(1); 49 status = gscm_eval_str(&eval_answer, toplev, input_str); 50 fprintf(stdout,"%s\n", eval_answer); 51 fprintf(stdout,"Guile > "); 52 } 53 } 54 55 /* now clean up and quit */ 56 gscm_destroy_top_level(toplev); 57} 58 59%} 60 61 62