Wild Life: life.c Source File

Wild Life 2.29

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros
life.c
Go to the documentation of this file.
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 #include "defs.h"
7
8 #ifdef SOLARIS
9 #include <stdlib.h>
10 static unsigned int lifeseed;
11 #endif
12
13 char *numbers[21] = {"1","2","3","4","5","6","7","8","9","10",
14 "11","12","13","14","15","16","17","18","19","20",
15 NULL};
16
17
18 long set_extra_args[6] = {set_empty, set_1, set_2, set_1_2, set_1_2_3, set_1_2_3_4};
19
20
21 /* RM: Mar 31 1993 All defined in lib.c
22 long noisy=TRUE;
23 long file_date=3;
24 long types_done=FALSE;
25
26 struct tms life_start,life_end;
27 float garbage_time=0;
28
29 long arg_c;
30 char **arg_v;
31
32 extern int rand_array[256];
33 */
34
35
36 /******** MAIN(argc,argv)
37 This routine contains the Read-Solve-Prlong loop.
38 */
39
40 int main(int argc,char *argv[])
41 {
42 ptr_psi_term s;
43 ptr_stack save_undo_stack;
44 long sort,exitflag;
45 long c; /* 21.12 (prev. char) */
46
47 int i;
48 #ifdef SOLARIS
49 for(i=0;i<256;i++)
50 rand_array[i]=rand_r(&lifeseed);
51 #else
52 for(i=0;i<256;i++)
53 rand_array[i]=random();
54 #endif
55
56
57 arg_c=argc;
58 if (argc < 10)
59 {
60 for (i = 0; i < argc;i++)
61 {
62 arg_v[i]=argv[i];
63 }
64 }
65 else
66 Errorline("Too many command line arguments\n");
67
68 // arg_v=argv;
69 quietflag = GetBoolOption("q");
70 init_io();
71 init_memory();
72 exit_if_true(!mem_base || !other_base);
73 assert(stack_pointer==mem_base); /* 8.10 */
74 init_copy();
75 assert(stack_pointer==mem_base); /* 8.10 */
76 init_print();
77 assert(stack_pointer==mem_base); /* 8.10 */
78
79 /* Timekeeping initialization */
80 tzset();
81 (void)times(&life_start);
82 assert(stack_pointer==mem_base); /* 8.10 */
83
84 init_modules(); /* RM: Jan 8 1993 */
85
86 init_built_in_types();
87 assert(stack_pointer==mem_base); /* 8.10 */
88 #ifdef X11
89 x_setup_builtins();
90 assert(stack_pointer==mem_base); /* 8.10 */
91 #endif
92 init_interrupt();
93
94 assert(stack_pointer==mem_base); /* 8.10 */
95 title();
96 assert(stack_pointer==mem_base); /* 8.10 */
97 init_trace();
98 noisy=FALSE;
99
100 assert(stack_pointer==mem_base); /* 8.10 */
101
102
103 (void)set_current_module(user_module); /* RM: Jan 27 1993 */
104
105 /* Read in the .set_up file */
106 init_system();
107
108 #ifdef ARITY /* RM: Mar 29 1993 */
109 arity_init();
110 #endif
111
112
113 (void)open_input_file("+SETUP+");
114 push_goal(load,input_state,(ptr_psi_term)file_date,(GENERIC)heap_copy_string("+SETUP+"));
115 file_date+=2;
116 main_prove();
117
118
119 /* Main loop of interpreter */
120 do {
121 (void)setjmp(env);
122 /* printf("%ld\n",(long)(stack_pointer-mem_base)); */ /* 8.10 */
123 init_system();
124 init_trace();
125
126 begin_terminal_io();
127 var_occurred=FALSE;
128 save_undo_stack=undo_stack;
129 stdin_cleareof();
130 c=read_char();
131 /* Wait until an EOF or a good character */
132 while (c!=EOF && !(c>32 && c!='.' && c!=';')) c=read_char();
133 if (c==EOF)
134 exitflag=TRUE;
135 else {
136 put_back_char(c);
137 s=stack_copy_psi_term(parse(&sort));
138 exitflag=(s->type==eof);
139 }
140 end_terminal_io();
141
142 if (!exitflag) {
143 if (sort==QUERY) {
144
145 // clear_already_loaded(symbol_table); RM: Feb 3 1993
146
147 push_goal(what_next,(ptr_psi_term)TRUE,(ptr_psi_term)var_occurred,(GENERIC)1);
148
149 ignore_eff=TRUE;
150 goal_count=0;
151 push_goal(prove,s,(ptr_psi_term)DEFRULES,NULL);
152 reset_step();
153 start_chrono();
154 main_prove();
155 /* assert(goal_stack==NULL); */
156 /* assert(choice_stack==NULL); */
157 if (undo_stack) {
158 undo(NULL);
159 Errorline("non-NULL undo stack.\n");
160 }
161 /* assert(undo_stack==NULL); */
162 }
163 else if (sort==FACT) {
164 assert_first=FALSE;
165 assert_clause(s);
166 undo(save_undo_stack); /* 17.8 */
167 var_occurred=FALSE; /* 18.8 */
168 encode_types();
169
170 infoline(assert_ok?"\n*** Yes\n":"\n*** No\n"); /* 21.1 */
171 }
172 }
173 } while (!exitflag);
174
175 /* hash_display(x_module->symbol_table); */
176
177 exit_life(TRUE);
178 return 0;
179 }
prove
#define prove
Definition: def_const.h:273
init_trace
void init_trace()
Definition: error.c:587
undo
void undo(ptr_stack limit)
Definition: login.c:646
assert_first
long assert_first
Definition: def_glob.h:58
main
int main(int argc, char *argv[])
Definition: life.c:40
put_back_char
void put_back_char(long c)
Definition: token.c:633
exit_life
void exit_life(long nl_flag)
Definition: built_ins.c:2090
exit_if_true
void exit_if_true(long exitflag)
Definition: lib.c:40
push_goal
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
Definition: login.c:555
parse
psi_term parse(long *q)
Definition: parser.c:877
init_system
void init_system()
Definition: lib.c:77
reset_step
void reset_step()
Definition: error.c:596
defs.h
wl_psi_term
Definition: def_struct.h:161
wl_stack
Definition: def_struct.h:215
set_empty
#define set_empty
Definition: def_const.h:193
file_date
long file_date
Definition: def_glob.h:60
DEFRULES
#define DEFRULES
Definition: def_const.h:138
FACT
#define FACT
Definition: def_const.h:151
set_1
#define set_1
Definition: def_const.h:194
user_module
ptr_module user_module
Definition: def_glob.h:156
other_base
GENERIC other_base
Definition: def_glob.h:19
numbers
char * numbers[21]
Definition: life.c:13
quietflag
long quietflag
Definition: def_glob.h:271
NULL
#define NULL
Definition: def_const.h:203
input_state
ptr_psi_term input_state
Definition: def_glob.h:199
ignore_eff
long ignore_eff
Definition: def_glob.h:151
QUERY
#define QUERY
Definition: def_const.h:152
noisy
long noisy
Definition: def_glob.h:35
assert_ok
long assert_ok
Definition: def_glob.h:59
init_io
void init_io()
Definition: lib.c:53
undo_stack
ptr_stack undo_stack
Definition: def_glob.h:53
Errorline
void Errorline(char *format,...)
Definition: error.c:414
heap_copy_string
char * heap_copy_string(char *s)
Definition: trees.c:147
set_1_2
#define set_1_2
Definition: def_const.h:196
end_terminal_io
void end_terminal_io()
Definition: token.c:431
goal_count
long goal_count
Definition: def_glob.h:152
infoline
void infoline(char *format,...)
Definition: error.c:245
begin_terminal_io
void begin_terminal_io()
Definition: token.c:410
eof
ptr_definition eof
Definition: def_glob.h:86
TRUE
#define TRUE
Definition: def_const.h:127
what_next
#define what_next
Definition: def_const.h:277
start_chrono
void start_chrono()
Definition: login.c:330
FALSE
#define FALSE
Definition: def_const.h:128
arg_c
int arg_c
Definition: def_glob.h:5
set_1_2_3
#define set_1_2_3
Definition: def_const.h:197
init_print
void init_print()
Definition: print.c:48
var_occurred
long var_occurred
Definition: def_glob.h:189
mem_base
GENERIC mem_base
Definition: def_glob.h:11
init_memory
void init_memory()
Definition: memory.c:1572
arg_v
char * arg_v[10]
Definition: def_glob.h:6
stack_copy_psi_term
ptr_psi_term stack_copy_psi_term(psi_term t)
Definition: parser.c:183
load
#define load
Definition: def_const.h:288
rand_array
long rand_array[256]
Definition: def_glob.h:279
encode_types
void encode_types()
Definition: types.c:1015
env
jmp_buf env
Definition: def_glob.h:236
set_1_2_3_4
#define set_1_2_3_4
Definition: def_const.h:198
main_prove
void main_prove()
Definition: login.c:2205
init_built_in_types
void init_built_in_types()
Definition: built_ins.c:5805
read_char
long read_char()
Definition: token.c:587
stack_pointer
GENERIC stack_pointer
Definition: def_glob.h:14
set_2
#define set_2
Definition: def_const.h:195
init_modules
void init_modules()
Definition: modules.c:30
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:165
stdin_cleareof
void stdin_cleareof()
Definition: token.c:42
GENERIC
unsigned long * GENERIC
Definition: def_struct.h:17
title
void title()
Definition: info.c:31
init_copy
void init_copy()
Definition: copy.c:34
open_input_file
long open_input_file(char *file)
Definition: token.c:504
set_current_module
ptr_module set_current_module(ptr_module module)
Definition: modules.c:95
assert_clause
void assert_clause(ptr_psi_term t)
Definition: login.c:267
init_interrupt
void init_interrupt()
Definition: interrupt.c:28
GetBoolOption
int GetBoolOption(char *name)
Definition: memory.c:54
assert
#define assert(N)
Definition: memory.c:104
set_extra_args
long set_extra_args[6]
Definition: life.c:18