Wild Life: life.c Source File

Wild Life 2.30

- 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
6 /* Copyright 1991 Digital Equipment Corporation.
7 ** All Rights Reserved.
8 *****************************************************************/
9
10 #include "defs.h"
11
12 #ifdef SOLARIS
13 #include <stdlib.h>
14 static unsigned int lifeseed;
15 #endif
16
17 char *numbers[21] = {"1","2","3","4","5","6","7","8","9","10",
18 "11","12","13","14","15","16","17","18","19","20",
19 NULL};
20
21
22 long set_extra_args[6] = {set_empty, set_1, set_2, set_1_2, set_1_2_3, set_1_2_3_4};
23
24
34 int main(int argc,char *argv[])
35 {
36 ptr_psi_term s;
37 ptr_stack save_undo_stack;
38 long sort,exitflag;
39 long c; /* 21.12 (prev. char) */
40
41 int i;
42 #ifdef SOLARIS
43 for(i=0;i<256;i++)
44 rand_array[i]=rand_r(&lifeseed);
45 #else
46 for(i=0;i<256;i++)
47 rand_array[i]=random();
48 #endif
49
50
51 arg_c=argc;
52 if (argc < 10)
53 {
54 for (i = 0; i < argc;i++)
55 {
56 arg_v[i]=argv[i];
57 }
58 }
59 else
60 Errorline("Too many command line arguments\n");
61
62 // arg_v=argv;
63 quietflag = GetBoolOption("q");
64 init_io();
65 init_memory();
66 exit_if_true(!mem_base || !other_base);
67 assert(stack_pointer==mem_base); /* 8.10 */
68 init_copy();
69 assert(stack_pointer==mem_base); /* 8.10 */
70 init_print();
71 assert(stack_pointer==mem_base); /* 8.10 */
72
73 /* Timekeeping initialization */
74 tzset();
75 (void)times(&life_start);
76 assert(stack_pointer==mem_base); /* 8.10 */
77
78 init_modules(); /* RM: Jan 8 1993 */
79
80 init_built_in_types();
81 assert(stack_pointer==mem_base); /* 8.10 */
82 #ifdef X11
83 x_setup_builtins();
84 assert(stack_pointer==mem_base); /* 8.10 */
85 #endif
86 init_interrupt();
87
88 assert(stack_pointer==mem_base); /* 8.10 */
89 title();
90 assert(stack_pointer==mem_base); /* 8.10 */
91 init_trace();
92 noisy=FALSE;
93
94 assert(stack_pointer==mem_base); /* 8.10 */
95
96
97 (void)set_current_module(user_module); /* RM: Jan 27 1993 */
98
99 /* Read in the .set_up file */
100 init_system();
101
102 #ifdef ARITY /* RM: Mar 29 1993 */
103 arity_init();
104 #endif
105
106
107 (void)open_input_file("+SETUP+");
108 push_goal(load,input_state,(ptr_psi_term)file_date,(GENERIC)heap_copy_string("+SETUP+"));
109 file_date+=2;
110 main_prove();
111
112
113 /* Main loop of interpreter */
114 do {
115 (void)setjmp(env);
116 /* printf("%ld\n",(long)(stack_pointer-mem_base)); */ /* 8.10 */
117 init_system();
118 init_trace();
119
120 begin_terminal_io();
121 var_occurred=FALSE;
122 save_undo_stack=undo_stack;
123 stdin_cleareof();
124 c=read_char();
125 /* Wait until an EOF or a good character */
126 while (c!=EOF && !(c>32 && c!='.' && c!=';')) c=read_char();
127 if (c==EOF)
128 exitflag=TRUE;
129 else {
130 put_back_char(c);
131 s=stack_copy_psi_term(parse(&sort));
132 exitflag=(s->type==eof);
133 }
134 end_terminal_io();
135
136 if (!exitflag) {
137 if (sort==QUERY) {
138
139 // clear_already_loaded(symbol_table); RM: Feb 3 1993
140
141 push_goal(what_next,(ptr_psi_term)TRUE,(ptr_psi_term)var_occurred,(GENERIC)1);
142
143 ignore_eff=TRUE;
144 goal_count=0;
145 push_goal(prove,s,(ptr_psi_term)DEFRULES,NULL);
146 reset_step();
147 start_chrono();
148 main_prove();
149 /* assert(goal_stack==NULL); */
150 /* assert(choice_stack==NULL); */
151 if (undo_stack) {
152 undo(NULL);
153 Errorline("non-NULL undo stack.\n");
154 }
155 /* assert(undo_stack==NULL); */
156 }
157 else if (sort==FACT) {
158 assert_first=FALSE;
159 assert_clause(s);
160 undo(save_undo_stack); /* 17.8 */
161 var_occurred=FALSE; /* 18.8 */
162 encode_types();
163
164 infoline(assert_ok?"\n*** Yes\n":"\n*** No\n"); /* 21.1 */
165 }
166 }
167 } while (!exitflag);
168
169 /* hash_display(x_module->symbol_table); */
170
171 exit_life(TRUE);
172 return 0;
173 }
stack_pointer
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
prove
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
init_trace
void init_trace()
init_trace
Definition: error.c:651
undo
void undo(ptr_stack limit)
undo
Definition: login.c:691
assert_first
long assert_first
Definition: def_glob.h:1032
main
int main(int argc, char *argv[])
main
Definition: life.c:34
put_back_char
void put_back_char(long c)
put_back_char
Definition: token.c:729
exit_life
void exit_life(long nl_flag)
exit_life
Definition: built_ins.c:2219
exit_if_true
void exit_if_true(long exitflag)
exit_if_true
Definition: lib.c:55
user_module
ptr_module user_module
Default module for user input.
Definition: def_glob.h:694
push_goal
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
parse
psi_term parse(long *q)
parse
Definition: parser.c:907
init_system
void init_system()
init_system
Definition: lib.c:83
reset_step
void reset_step()
reset_step
Definition: error.c:665
defs.h
includes
wl_psi_term
Definition: def_struct.h:177
wl_stack
Definition: def_struct.h:230
set_empty
#define set_empty
Set constants for deref_args in lefun.c.
Definition: def_const.h:493
file_date
long file_date
Definition: def_glob.h:1034
DEFRULES
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
FACT
#define FACT
Fact Kind of user input.
Definition: def_const.h:338
set_1
#define set_1
Set constants for deref_args in lefun.c.
Definition: def_const.h:500
numbers
char * numbers[21]
Definition: life.c:17
quietflag
long quietflag
Definition: def_glob.h:912
NULL
#define NULL
Definition: def_const.h:533
input_state
ptr_psi_term input_state
Definition: def_glob.h:856
ignore_eff
long ignore_eff
Definition: def_glob.h:677
QUERY
#define QUERY
Query Kind of user input.
Definition: def_const.h:345
noisy
long noisy
Definition: def_glob.h:1011
assert_ok
long assert_ok
Definition: def_glob.h:1033
init_io
void init_io()
void init_io
Definition: lib.c:69
life_start
struct tms life_start
time life started - seconds
Definition: def_glob.h:83
undo_stack
ptr_stack undo_stack
Definition: def_glob.h:1027
Errorline
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
GENERIC
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
set_1_2
#define set_1_2
Set constants for deref_args in lefun.c.
Definition: def_const.h:514
end_terminal_io
void end_terminal_io()
end_terminal_io
Definition: token.c:516
goal_count
long goal_count
Definition: def_glob.h:678
infoline
void infoline(char *format,...)
infoline
Definition: error.c:281
heap_copy_string
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
begin_terminal_io
void begin_terminal_io()
begin_terminal_io
Definition: token.c:493
arg_c
int arg_c
set from argc in either life.c or lib.c
Definition: def_glob.h:20
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
eof
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
what_next
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
other_base
GENERIC other_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:98
start_chrono
void start_chrono()
start_chrono
Definition: login.c:349
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
set_1_2_3
#define set_1_2_3
Set constants for deref_args in lefun.c.
Definition: def_const.h:521
init_print
void init_print()
init_print
Definition: print.c:52
init_memory
void init_memory()
init_memory ()
Definition: memory.c:1671
arg_v
char * arg_v[ARGNN]
set from argv in either life.c or lib.c
Definition: def_glob.h:27
stack_copy_psi_term
ptr_psi_term stack_copy_psi_term(psi_term t)
stack_copy_psi_term
Definition: parser.c:205
load
#define load
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1156
rand_array
long rand_array[256]
Definition: def_glob.h:920
encode_types
void encode_types()
encode_types
Definition: types.c:1091
env
jmp_buf env
Definition: def_glob.h:877
set_1_2_3_4
#define set_1_2_3_4
Set constants for deref_args in lefun.c.
Definition: def_const.h:528
main_prove
void main_prove()
main_prove
Definition: login.c:2333
x_setup_builtins
void x_setup_builtins()
x_setup_builtins
Definition: xpred.c:3374
init_built_in_types
void init_built_in_types()
init_built_in_types
Definition: built_ins.c:6155
read_char
long read_char()
read_char
Definition: token.c:680
mem_base
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
set_2
#define set_2
Set constants for deref_args in lefun.c.
Definition: def_const.h:507
init_modules
void init_modules()
init_modules
Definition: modules.c:34
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:181
stdin_cleareof
void stdin_cleareof()
stdin_cleareof
Definition: token.c:51
title
void title()
TITLE.
Definition: info.c:39
init_copy
void init_copy()
init_copy
Definition: copy.c:32
var_occurred
long var_occurred
???
Definition: def_glob.h:839
open_input_file
long open_input_file(char *file)
open_input_file
Definition: token.c:594
set_current_module
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
assert_clause
void assert_clause(ptr_psi_term t)
assert_clause
Definition: login.c:287
init_interrupt
void init_interrupt()
INIT_INTERRUPT.
Definition: interrupt.c:36
GetBoolOption
int GetBoolOption(char *name)
GetBoolOption.
Definition: memory.c:64
assert
#define assert(N)
Definition: memory.c:114
set_extra_args
long set_extra_args[6]
Definition: life.c:22