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