home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / SOURCE / LIFE.C < prev    next >
C/C++ Source or Header  |  1996-06-16  |  5KB  |  219 lines

  1. /* Copyright 1991 Digital Equipment Corporation.
  2. ** All Rights Reserved.
  3. *****************************************************************/
  4. /*     $Id: life.c,v 1.2 1994/12/08 23:27:02 duchier Exp $     */
  5.  
  6. #ifndef lint
  7. static char vcid[] = "$Id: life.c,v 1.2 1994/12/08 23:27:02 duchier Exp $";
  8. #endif /* lint */
  9.  
  10. #include "extern.h"
  11. #include "trees.h"
  12. #include "print.h"
  13. #include "parser.h"
  14. #include "info.h"
  15. #include "login.h"
  16. #include "lefun.h"
  17. #ifndef OS2_PORT
  18. #include "built_ins.h"
  19. #else
  20. #include "built_in.h"
  21. #endif
  22.  
  23. #include "types.h"
  24. #include "copy.h"
  25. #include "token.h"
  26. #ifndef OS2_PORT
  27. #include "interrupt.h"
  28. #else
  29. #include "interrup.h"
  30. #endif
  31. #include "error.h"
  32. #include "modules.h" /*  RM: Jan  8 1993  */
  33. #include "memory.h"
  34.  
  35. #ifdef X11
  36. #include "xpred.h"
  37. #endif
  38.  
  39. #ifdef SOLARIS
  40. #include <stdlib.h>
  41. static unsigned int lifeseed;
  42. #endif
  43.  
  44.  
  45. /*  RM: Mar 31 1993  All defined in lib.c
  46.   long noisy=TRUE;
  47.   long file_date=3;
  48.   long types_done=FALSE;
  49.   
  50.   struct tms life_start,life_end;
  51.   float garbage_time=0;
  52.   
  53.   long arg_c;
  54.   char **arg_v;
  55.  
  56.   extern int rand_array[256];
  57.   */
  58.  
  59.  
  60. extern jmp_buf env;
  61.  
  62. extern int rand_array[];
  63.  
  64.  
  65. /******** MAIN(argc,argv)
  66. This routine contains the Read-Solve-Prlong loop.
  67. */
  68. main(argc, argv)
  69. long argc;
  70. #ifndef OS2_PORT
  71. char **argv;
  72. #else
  73. char *argv[];
  74. #endif
  75. {
  76.   ptr_psi_term s;  
  77.   ptr_stack save_undo_stack;
  78.   long sort,exitflag;
  79.   long c; /* 21.12 (prev. char) */ 
  80.  
  81.   int i;
  82. #ifdef SOLARIS
  83.   for(i=0;i<256;i++)
  84.     rand_array[i]=rand_r(&lifeseed);
  85. #else
  86.   for(i=0;i<256;i++)
  87.     rand_array[i]=random();
  88. #endif
  89.  
  90.   
  91.   arg_c=argc;
  92.   arg_v=argv;
  93.   
  94.   quietflag = GetBoolOption("q");
  95.  
  96.   init_io();
  97.   init_memory();
  98.   exit_if_true(!mem_base || !other_base);
  99.   assert(stack_pointer==mem_base); /* 8.10 */
  100.   init_copy();
  101.   assert(stack_pointer==mem_base); /* 8.10 */
  102.   init_print();
  103.   assert(stack_pointer==mem_base); /* 8.10 */
  104.  
  105.   /* Timekeeping initialization */
  106.   tzset();
  107.   times(&life_start);
  108.   assert(stack_pointer==mem_base); /* 8.10 */
  109.  
  110.   init_modules(); /*  RM: Jan  8 1993  */
  111.   
  112.   init_built_in_types();
  113.   assert(stack_pointer==mem_base); /* 8.10 */
  114. #ifdef X11
  115.   x_setup_builtins();
  116.   assert(stack_pointer==mem_base); /* 8.10 */
  117. #endif
  118.   init_interrupt();
  119.   assert(stack_pointer==mem_base); /* 8.10 */
  120.   title();
  121.   assert(stack_pointer==mem_base); /* 8.10 */
  122.   init_trace();
  123.   noisy=FALSE;
  124.  
  125.   assert(stack_pointer==mem_base); /* 8.10 */
  126.  
  127.  
  128.   set_current_module(user_module); /*  RM: Jan 27 1993  */
  129.   
  130.   /* Read in the .set_up file */
  131.   init_system();
  132.   
  133. #ifdef ARITY  /*  RM: Mar 29 1993  */
  134.   arity_init();
  135. #endif
  136.  
  137. #ifndef OS2_PORT  
  138.   open_input_file("+SETUP+");
  139. #else
  140.   open_input_file("~SETUP");
  141. #endif
  142.   push_goal(load,input_state,file_date,heap_copy_string("+SETUP+"));
  143.   file_date+=2;
  144.   main_prove();
  145.  
  146.  
  147.   /* Main loop of interpreter */
  148.   do {
  149.     setjmp(env);
  150.     /* printf("%ld\n",(long)(stack_pointer-mem_base)); */ /* 8.10 */
  151.     init_system(); 
  152.     init_trace();
  153.  
  154.     begin_terminal_io();
  155.     var_occurred=FALSE;
  156.     save_undo_stack=undo_stack;
  157.     stdin_cleareof();
  158.     c=read_char();
  159.     /* Wait until an EOF or a good character */
  160.     while (c!=EOF && !(c>32 && c!='.' && c!=';')) c=read_char();
  161.     if (c==EOF)
  162.       exitflag=TRUE;
  163.     else {
  164.       put_back_char(c);
  165.       s=stack_copy_psi_term(parse(&sort));
  166.       exitflag=(s->type==eof);
  167.     }
  168.     end_terminal_io();
  169.  
  170.     if (!exitflag) {
  171.       if (sort==QUERY) {
  172.  
  173.     /* clear_already_loaded(symbol_table);     RM: Feb  3 1993  */
  174.     
  175.         push_goal(what_next,TRUE,var_occurred,1);
  176.         ignore_eff=TRUE;
  177.         goal_count=0;
  178.         push_goal(prove,s,DEFRULES,NULL);
  179.         reset_step();
  180.         start_chrono();
  181.         main_prove();
  182.         /* assert(goal_stack==NULL); */
  183.         /* assert(choice_stack==NULL); */
  184.     if (undo_stack) {
  185.       undo(NULL);
  186.           Errorline("non-NULL undo stack.\n");
  187.     }
  188.         /* assert(undo_stack==NULL); */
  189.       }
  190.       else if (sort==FACT) {
  191.         assert_first=FALSE;
  192.         assert_clause(s);
  193.         undo(save_undo_stack); /* 17.8 */
  194.         var_occurred=FALSE; /* 18.8 */
  195.         encode_types();
  196.         Infoline(assert_ok?"\n*** Yes\n":"\n*** No\n"); /* 21.1 */
  197.       }
  198.     }
  199.   } while (!exitflag);
  200.  
  201.   /* hash_display(x_module->symbol_table); */
  202.   
  203.   exit_life(TRUE);
  204. }
  205. #ifdef OS2_PORT
  206. float times(float *fit)
  207. {
  208.    clock_t it;
  209.    
  210.    it = clock();
  211.    *fit = (((float)it)/CLOCKS_PER_SEC);
  212.    return (*fit);
  213. }
  214. void tzset()
  215. {
  216. }
  217.  
  218. #endif
  219.