home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 176_01 / xlisp.c < prev    next >
Text File  |  1985-12-21  |  2KB  |  97 lines

  1. /* xlisp - a small implementation of lisp with object-oriented programming */
  2. /*    Copyright (c) 1985, by David Michael Betz
  3.     All Rights Reserved
  4.     Permission is granted for unrestricted non-commercial use    */
  5.  
  6. #include "xlisp.h"
  7.  
  8. /* define the banner line string */
  9. #define BANNER    "XLISP version 1.6, Copyright (c) 1985, by David Betz"
  10.  
  11. /* external variables */
  12. extern NODE *s_stdin,*s_stdout;
  13. extern NODE *s_evalhook,*s_applyhook;
  14. extern int xldebug;
  15. extern NODE *true;
  16.  
  17. /* main - the main routine */
  18. main(argc,argv)
  19.   int argc; char *argv[];
  20. {
  21.     CONTEXT cntxt;
  22.     NODE *expr;
  23.     int i;
  24.  
  25.     /* initialize and print the banner line */
  26.     osinit(BANNER);
  27.  
  28.     /* setup initialization error handler */
  29.     xlbegin(&cntxt,CF_TOPLEVEL|CF_ERROR,(NODE *) 1);
  30.     if (setjmp(cntxt.c_jmpbuf)) {
  31.     printf("fatal initialization error\n");
  32.     exit();
  33.     }
  34.  
  35.     /* initialize xlisp */
  36.     xlinit();
  37.     xlend(&cntxt);
  38.  
  39.     /* reset the error handler */
  40.     xlbegin(&cntxt,CF_TOPLEVEL|CF_ERROR,true);
  41.  
  42.     /* load "init.lsp" */
  43.     if (setjmp(cntxt.c_jmpbuf) == 0)
  44.     xlload("init.lsp",FALSE,FALSE);
  45.  
  46.     /* load any files mentioned on the command line */
  47. #ifndef MEGAMAX
  48.     if (setjmp(cntxt.c_jmpbuf) == 0)
  49.     for (i = 1; i < argc; i++)
  50.         if (!xlload(argv[i],TRUE,FALSE))
  51.         xlfail("can't load file");
  52. #endif
  53.  
  54.     /* create a new stack frame */
  55.     xlsave(&expr,NULL);
  56.  
  57.     /* main command processing loop */
  58.     while (TRUE) {
  59.  
  60.     /* setup the error return */
  61.     if (i = setjmp(cntxt.c_jmpbuf)) {
  62.         if (i == CF_TOPLEVEL)
  63.         stdputstr("[ back to the top level ]\n");
  64.         setvalue(s_evalhook,NIL);
  65.         setvalue(s_applyhook,NIL);
  66.         xldebug = 0;
  67.         xlflush();
  68.     }
  69.  
  70.     /* read an expression */
  71.     if (!xlread(getvalue(s_stdin),&expr,FALSE))
  72.         break;
  73.  
  74.     /* evaluate the expression */
  75.     expr = xleval(expr);
  76.  
  77.     /* print it */
  78.     stdprint(expr);
  79.     }
  80.     xlend(&cntxt);
  81. }
  82.  
  83. /* stdprint - print to standard output */
  84. stdprint(expr)
  85.   NODE *expr;
  86. {
  87.     xlprint(getvalue(s_stdout),expr,TRUE);
  88.     xlterpri(getvalue(s_stdout));
  89. }
  90.  
  91. /* stdputstr - print a string to standard output */
  92. stdputstr(str)
  93.   char *str;
  94. {
  95.     xlputstr(getvalue(s_stdout),str);
  96. }
  97.