00001
00002
00003
00004
00005
00006 #ifndef _LIFE_EXTERN_H_
00007 #define _LIFE_EXTERN_H_
00008
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <math.h>
00012 #include <sys/types.h>
00013 #ifndef OS2_PORT
00014 #include <sys/stat.h>
00015 #include <sys/time.h>
00016 #include <sys/times.h>
00017 #else
00018 #include <time.h>
00019 #define OS2_HOME "/home/dennis/src/lang/Life/life-1.02/lf/";
00020 #define bzero(p,l) memset(p,0,l)
00021 #define bcopy memcpy
00022 #define bcmp memcmp
00023 #define random rand
00024 #define srandom srand
00025
00026 #endif
00027 #include <assert.h>
00028 #include <errno.h>
00029 #include <setjmp.h>
00030
00031
00032 #define WORD sizeof(long)
00033
00034 #ifdef WORDALIGN
00035 #define ALIGN WORD
00036 #else
00037 #define ALIGN 8
00038 #endif
00039
00040
00041
00042 #define TS
00043
00044 #ifdef CLIFE
00045 #include "blockdef.h"
00046 #endif
00047
00048
00049
00050
00051
00052
00053 #define LOCALSETUP
00054 #define LOCALSETUPFILE "./.set_up"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 extern int mem_size;
00067 extern int alloc_words;
00068
00069
00070
00071
00072 #define GC_THRESHOLD (alloc_words>>3)
00073
00074
00075 #define COPY_THRESHOLD (GC_THRESHOLD>>3)
00076
00077
00078
00079 #define REAL double
00080
00081
00082
00083 #define WL_MAXINT 9007199254740991.0
00084
00085
00086 #define PRETTY_SIZE 20000
00087
00088
00089 #define MAX_BUILT_INS 300
00090
00091
00092
00093 #define STRLEN 10000
00094
00095
00096 #define PAGE_WIDTH 80
00097
00098
00099 #define PRINT_DEPTH 1000000000
00100
00101
00102 #define PRINT_SPLIT 1000000000
00103 #define PRINT_POWER 9
00104
00105
00106
00107 #define PARSER_STACK_SIZE 10000
00108
00109
00110 #define MAX_PRECEDENCE 1200
00111
00112
00113 #define PRINT_BUFFER 100000
00114
00115
00116 #define PROMPT "> "
00117
00118
00119 #define PROMPT_BUFFER 200
00120 #define MAX_LEVEL ((PROMPT_BUFFER-4-strlen(PROMPT))/2)
00121
00122
00123
00124 #define XEVENTDELAY 1000
00125
00126
00127 #define MAX_TRACE_INDENT 40
00128
00129 #define HEAP_ALLOC(A) (A *)heap_alloc(sizeof(A))
00130 #define STACK_ALLOC(A) (A *)stack_alloc(sizeof(A))
00131
00132
00133 #define QUOTED_TRUE 1
00134 #define UNFOLDED_TRUE 2
00135
00136
00137 #define TRUE 1
00138 #define FALSE 0
00139 #define TRUEMASK 1
00140
00141
00142 #define UNDEF 2
00143
00144 #define NOT_CODED 0
00145 #define UN_CODED (CODE)0
00146
00147
00148
00149 #define DEFRULES -1
00150
00151 #define EOLN 10
00152
00153
00154
00155 #define INT_SIZE 8*sizeof(unsigned long)
00156
00157
00158 #define HEAP TRUE
00159 #define STACK FALSE
00160
00161
00162 #define FACT 100
00163 #define QUERY 200
00164 #define ERROR 999
00165
00166
00167
00168
00169
00170 #define RMASK 256
00171 #define SMASK 255
00172
00173
00174 #ifdef TS
00175 #define INIT_TIME_STAMP 1
00176 #endif
00177
00178
00179
00180
00181
00182
00183 #define FUNC_ARG(t) ((t)<match_date || (GENERIC)(t)>=heap_pointer)
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 #define DIGIT(C) (C>='0' && C<='9')
00195
00196 #define UPPER(C) ((C>='A' && C<='Z') || C=='_')
00197
00198 #define LOWER(C) (C>='a' && C<='z')
00199
00200 #define ISALPHA(C) (DIGIT(C) || UPPER(C) || LOWER(C))
00201
00202
00203
00204 #define SINGLE(C) (C=='(' || C==')' || C=='[' || C==']' || C=='{' || C=='`' ||\
00205 C=='}' || C==',' || C=='.' || C==';' || C=='@' ||\
00206 C=='!')
00207
00208
00209 #define SYMBOL(C) (C=='#' || C=='$' || C=='%' || C=='&' ||\
00210 C=='*' || C=='+' || C=='-' || C=='>' || C=='/' ||\
00211 C==':' || C=='<' || C=='=' ||\
00212 C=='~' || C=='^' || C=='|' || C=='\\' ||\
00213 C=='.' || C=='?' \
00214 )
00215
00216
00217
00218
00219 #define equ_tok(A,B) (!strcmp(A.type->keyword->symbol,B))
00220 #define equ_tok3(A,B,Q) (Q?FALSE:equ_tok(A,B))
00221
00222
00223 #define equ_tokch(A,B) (A.type->keyword->symbol[0]==B && A.type->keyword->symbol[1]==0)
00224 #define equ_tokch3(A,B,Q) (Q?FALSE:equ_tokch(A,B))
00225
00226
00227
00228 #define equ_tokc(A,B) (B?equ_tokch(A,B):A.type->keyword->symbol[0]==0)
00229 #define equ_tokc3(A,B,Q) (Q?FALSE:equ_tokc(A,B))
00230
00231
00232
00233
00234
00235
00236
00237 #define cut_to(C) { ptr_choice_point cp=choice_stack; \
00238 while ((GENERIC)cp>(GENERIC)(C)) cp=cp->next; \
00239 choice_stack=cp; \
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 #define deref_ptr(P) while(P->coref) P=P->coref
00253
00254
00255 #define noneval(T) (T->type==quote || T->type==listingsym || T->type==loadsym)
00256
00257
00258
00259 #define wl_const(S) ((S).value==NULL && (S).type!=variable)
00260
00261 #define equal_types(A,B) ((A)==(B))
00262
00263 #define is_top(T) ((T)!=NULL && (T)->type==top && (T)->attr_list==NULL)
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 #define VALID_RANGE(A) ((GENERIC)A>=mem_base && (GENERIC)A<mem_limit)
00278
00279
00280 #ifdef X11
00281 #define VALID_ADDRESS(A) ( VALID_RANGE(A) \
00282 || (GENERIC)A==(GENERIC)&xevent_list \
00283 || (GENERIC)A==(GENERIC)&xevent_existing \
00284 || (GENERIC)A==(GENERIC)&var_tree \
00285 )
00286 #else
00287 #define VALID_ADDRESS(A) ( VALID_RANGE(A) \
00288 || (GENERIC)A==(GENERIC)&var_tree \
00289 )
00290 #endif
00291
00292
00293
00294
00295
00296
00297
00298
00299 typedef unsigned long * GENERIC;
00300
00301
00302
00303 typedef char string[STRLEN];
00304 typedef struct wl_operator_data * ptr_operator_data;
00305 typedef struct wl_int_list * ptr_int_list;
00306 typedef struct wl_resid_list * ptr_resid_list;
00307 typedef struct wl_definition * ptr_definition;
00308 typedef struct wl_residuation * ptr_residuation;
00309 typedef struct wl_psi_term * ptr_psi_term;
00310 typedef struct wl_node * ptr_node;
00311 typedef struct wl_pair_list * ptr_pair_list;
00312 typedef struct wl_triple_list * ptr_triple_list;
00313 typedef struct wl_list * ptr_list;
00314 typedef struct wl_stack * ptr_stack;
00315 typedef struct wl_goal * ptr_goal;
00316 typedef struct wl_choice_point * ptr_choice_point;
00317
00318
00319
00320
00321
00322 typedef enum { nop, xf, fx, yf, fy, xfx, xfy, yfx } operator;
00323
00324 typedef struct wl_operator_data {
00325 operator type;
00326 long precedence;
00327 ptr_operator_data next;
00328 } operator_data;
00329
00330
00331 typedef struct wl_int_list {
00332 GENERIC value;
00333 ptr_int_list next;
00334 } int_list;
00335
00336
00337 typedef struct wl_resid_list {
00338 ptr_psi_term var;
00339 ptr_psi_term othervar;
00340 ptr_resid_list next;
00341 } resid_list;
00342
00343 typedef enum { undef,
00344 predicate,
00345 function,
00346 type,
00347 global
00348 #ifdef CLIFE
00349 ,block
00350 #endif
00351 } def_type;
00352
00353
00354
00355
00356 typedef struct wl_hash_table * ptr_hash_table;
00357
00358
00359
00360
00361
00362 struct wl_module {
00363 char *module_name;
00364 char *source_file;
00365 ptr_int_list open_modules;
00366 ptr_int_list inherited_modules;
00367 ptr_hash_table symbol_table;
00368 };
00369
00370
00371 typedef struct wl_module * ptr_module;
00372
00373 extern ptr_node module_table;
00374 extern ptr_module current_module;
00375
00376
00377 struct wl_keyword {
00378 ptr_module module;
00379 char *symbol;
00380 char *combined_name;
00381 int public;
00382 int private_feature;
00383 ptr_definition definition;
00384 };
00385
00386 typedef struct wl_keyword * ptr_keyword;
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 struct wl_hash_table {
00399 int size;
00400 int used;
00401 ptr_keyword *data;
00402 };
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 void hash_insert();
00414 ptr_keyword hash_lookup();
00415 ptr_hash_table hash_create();
00416 void hash_expand();
00417 int hash_code();
00418 void hash_display();
00419
00420 extern ptr_definition first_definition;
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 typedef struct wl_definition {
00431 long date;
00432
00433 ptr_keyword keyword;
00434
00435 ptr_pair_list rule;
00436 ptr_triple_list properties;
00437
00438 ptr_int_list code;
00439 ptr_int_list parents;
00440 ptr_int_list children;
00441
00442 def_type type;
00443 char always_check;
00444 char protected;
00445 char evaluate_args;
00446 char already_loaded;
00447
00448 ptr_operator_data op_data;
00449
00450 ptr_psi_term global_value;
00451 ptr_psi_term init_value;
00452
00453 #ifdef CLIFE
00454 ptr_block_definition block_def;
00455 #endif
00456
00457 ptr_definition next;
00458 } definition;
00459
00460
00461 typedef struct wl_residuation {
00462 long sortflag;
00463 GENERIC bestsort;
00464 GENERIC value;
00465 ptr_goal goal;
00466 ptr_residuation next;
00467 } residuation;
00468
00469
00470 typedef struct wl_psi_term {
00471 #ifdef TS
00472 unsigned long time_stamp;
00473 #endif
00474 ptr_definition type;
00475 long status;
00476
00477
00478 long flags;
00479 GENERIC value;
00480 ptr_node attr_list;
00481 ptr_psi_term coref;
00482 ptr_residuation resid;
00483 } psi_term;
00484
00485
00486
00487
00488
00489
00490 typedef struct wl_node {
00491 char *key;
00492 ptr_node left;
00493 ptr_node right;
00494 GENERIC data;
00495 } node;
00496
00497 typedef struct wl_pair_list {
00498 ptr_psi_term a;
00499 ptr_psi_term b;
00500 ptr_pair_list next;
00501 } pair_list;
00502
00503
00504 typedef struct wl_triple_list {
00505 ptr_psi_term a;
00506 ptr_psi_term b;
00507 ptr_definition c;
00508 ptr_triple_list next;
00509 } triple_list;
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 #ifdef CLIFE
00520 #ifdef OS2_PORT
00521 #include "blockstr.h"
00522 #else
00523 #include "blockstruct.h"
00524 #endif
00525 #endif
00526
00527
00528
00529
00530 typedef long type_ptr;
00531 #define psi_term_ptr 0
00532 #define resid_ptr 1
00533 #define int_ptr 2
00534 #define def_ptr 3
00535 #define code_ptr 4
00536 #define goal_ptr 5
00537 #define cut_ptr 6
00538
00539 #ifdef CLIFE
00540 #define block_ptr 12
00541 #define value_ptr 13
00542 #endif
00543
00544 #define destroy_window 7+32
00545 #define show_window 8+32
00546 #define hide_window 9+32
00547 #define show_subwindow 10+32
00548 #define hide_subwindow 11+32
00549 #define undo_action 32
00550
00551 typedef struct wl_stack {
00552 type_ptr type;
00553 GENERIC a;
00554 GENERIC b;
00555 ptr_stack next;
00556 } stack;
00557
00558 typedef enum {
00559 fail,
00560 prove,
00561 unify,
00562 unify_noeval,
00563 disj,
00564 what_next,
00565 eval,
00566 eval_cut,
00567 freeze_cut,
00568 implies_cut,
00569 general_cut,
00570 match,
00571 type_disj,
00572 clause,
00573 del_clause,
00574 retract,
00575 load,
00576 c_what_next
00577 } goals;
00578
00579 typedef struct wl_goal {
00580 goals type;
00581 ptr_psi_term a;
00582 ptr_psi_term b;
00583 GENERIC c;
00584 ptr_goal next;
00585 long pending;
00586 } goal;
00587
00588 typedef struct wl_choice_point {
00589 unsigned long time_stamp;
00590 ptr_stack undo_point;
00591 ptr_goal goal_stack;
00592 ptr_choice_point next;
00593 GENERIC stack_top;
00594 } choice_point;
00595
00596
00597
00598
00599
00600
00601
00602
00603 extern int arg_c;
00604 extern char **arg_v;
00605
00606 extern GENERIC mem_base;
00607 extern GENERIC heap_pointer;
00608 extern GENERIC mem_limit;
00609 extern GENERIC stack_pointer;
00610 extern GENERIC stack_alloc();
00611 extern GENERIC heap_alloc();
00612
00613 extern float garbage_time;
00614 #ifndef OS2_PORT
00615 extern struct tms life_start,life_end;
00616 #else
00617 extern float life_start,life_end;
00618 extern float times(float*);
00619 #endif
00620
00621 extern GENERIC other_base;
00622 extern GENERIC other_limit;
00623 extern GENERIC other_pointer;
00624
00625 extern ptr_psi_term error_psi_term;
00626 extern long parser_stack_index;
00627
00628 extern ptr_node var_tree;
00629 extern ptr_node printed_vars;
00630 extern ptr_node printed_pointers;
00631 extern ptr_node pointer_names;
00632 extern long gen_sym_counter;
00633
00634 extern long warningflag;
00635 extern long verbose;
00636 extern long trace,noisy;
00637 extern long types_done;
00638 extern long interrupted;
00639
00640 extern FILE *input_stream;
00641 extern long line_count;
00642 extern string input_file_name;
00643 extern FILE *output_stream;
00644 extern char *prompt;
00645 extern long page_width;
00646
00647
00648 extern ptr_definition *gamma_table;
00649 extern long type_count;
00650 extern long types_modified;
00651
00652 extern long main_loop_ok;
00653 extern ptr_goal aim;
00654 extern ptr_goal goal_stack;
00655 extern ptr_choice_point choice_stack;
00656
00657 extern ptr_stack undo_stack;
00658 #ifdef TS
00659 extern unsigned long global_time_stamp;
00660 #endif
00661
00662 extern long assert_first;
00663 extern long assert_ok;
00664 extern long file_date;
00665
00666
00667
00668 extern ptr_definition abortsym;
00669 extern ptr_definition aborthooksym;
00670
00671 extern ptr_definition add_module1;
00672 extern ptr_definition add_module2;
00673 extern ptr_definition add_module3;
00674
00675 extern ptr_definition and;
00676 extern ptr_definition apply;
00677 extern ptr_definition boolean;
00678 extern ptr_definition boolpredsym;
00679 extern ptr_definition built_in;
00680 extern ptr_definition colonsym;
00681 extern ptr_definition commasym;
00682 extern ptr_definition comment;
00683
00684 extern ptr_definition constant;
00685 extern ptr_definition cut;
00686 extern ptr_definition disjunction;
00687 extern ptr_definition disj_nil;
00688 extern ptr_definition eof;
00689 extern ptr_definition eqsym;
00690 extern ptr_definition leftarrowsym;
00691 extern ptr_definition false;
00692 extern ptr_definition funcsym;
00693 extern ptr_definition functor;
00694 extern ptr_definition iff;
00695 extern ptr_definition integer;
00696 extern ptr_definition alist;
00697 extern ptr_definition life_or;
00698 extern ptr_definition minus_symbol;
00699 extern ptr_definition nil;
00700 extern ptr_definition nothing;
00701 extern ptr_definition predsym;
00702 extern ptr_definition quote;
00703 extern ptr_definition quoted_string;
00704 extern ptr_definition real;
00705 extern ptr_definition stream;
00706 extern ptr_definition succeed;
00707 extern ptr_definition such_that;
00708 extern ptr_definition top;
00709 extern ptr_definition true;
00710 extern ptr_definition timesym;
00711 extern ptr_definition tracesym;
00712 extern ptr_definition typesym;
00713 extern ptr_definition variable;
00714 extern ptr_definition opsym;
00715 extern ptr_definition loadsym;
00716 extern ptr_definition dynamicsym;
00717 extern ptr_definition staticsym;
00718 extern ptr_definition encodesym;
00719 extern ptr_definition listingsym;
00720 extern ptr_definition delay_checksym;
00721 extern ptr_definition eval_argsym;
00722 extern ptr_definition inputfilesym;
00723 extern ptr_definition call_handlersym;
00724 extern ptr_definition xf_sym;
00725 extern ptr_definition fx_sym;
00726 extern ptr_definition yf_sym;
00727 extern ptr_definition fy_sym;
00728 extern ptr_definition xfx_sym;
00729 extern ptr_definition xfy_sym;
00730 extern ptr_definition yfx_sym;
00731 extern ptr_definition nullsym;
00732 extern ptr_definition sys_bytedata;
00733 extern ptr_definition sys_bitvector;
00734 extern ptr_definition sys_regexp;
00735 extern ptr_definition sys_stream;
00736 extern ptr_definition sys_file_stream;
00737 extern ptr_definition sys_socket_stream;
00738
00739
00740 extern ptr_definition final_dot;
00741 extern ptr_definition final_question;
00742
00743 extern ptr_psi_term null_psi_term;
00744
00745 extern char *one;
00746 extern char *two;
00747 extern char *three;
00748 extern char *year_attr;
00749 extern char *month_attr;
00750 extern char *day_attr;
00751 extern char *hour_attr;
00752 extern char *minute_attr;
00753 extern char *second_attr;
00754 extern char *weekday_attr;
00755
00756
00757 extern ptr_psi_term old_state;
00758
00759
00760
00761 extern void init_system();
00762
00763 extern long (* c_rule[])();
00764
00765 extern ptr_psi_term stack_psi_term();
00766 extern ptr_psi_term real_stack_psi_term();
00767 extern ptr_psi_term heap_psi_term();
00768
00769 #define stack_empty_list() stack_nil()
00770
00771
00772
00773
00774
00775 #include "types.h"
00776 #include "error.h"
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 #ifndef OS2_PORT
00788
00789 #if !defined(wl_SETH_H_FILE_)
00790 #define wl_SETH_H_FILE_
00791
00792 #include <varargs.h>
00793
00794
00795
00796 #if defined(__STDC__) || defined(ds3100)
00797 # define ARGS(args) args
00798 #else
00799 # define ARGS(args) ()
00800 #endif
00801
00802
00803
00804 #define VarArgBase va_alist
00805 #define VarArgBaseDecl va_dcl
00806 #define VarArg ___va_lp___
00807 #define VarArgDecl va_list VarArg
00808
00809 #if defined(_VARARGS_H) || defined(__VARARGS_H__) || defined(_VARARGS_) || defined(_sys_varargs_h) || __alpha
00810 # define VarArgInit(l) va_start(VarArg)
00811 #else
00812 # define VarArgInit(l) va_start(VarArg, l)
00813 #endif
00814 #define VarArgNext(t) va_arg(VarArg, t)
00815 #define VarArgEnd() va_end(VarArg)
00816 #endif
00817 #if 0
00818
00819
00820 foo(var1, var2, VarArgBase)
00821 type var1;
00822 type var2;
00823 VarArgBaseDecl;
00824 {
00825 VarArgDecl;
00826
00827
00828
00829 typename var3;
00830
00831
00832
00833 VarArgInit(var2);
00834
00835
00836
00837
00838
00839
00840
00841 vfprintf(of, format, VarArg);
00842
00843
00844
00845 var3 = VarArgNext(typename);
00846
00847
00848
00849 VarArgEnd();
00850 }
00851 #endif
00852
00853 #endif
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00879 #ifdef CLIFE
00880 #include "block.h"
00881 #endif
00882
00883 #endif