-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnpl.h
1551 lines (1484 loc) · 49.3 KB
/
npl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* N-Prolog
written by kenichi sasagawa 2016/9~
*/
#include <setjmp.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
/*
memory map
address
0 - 5,000,000 heap area
5,000,001 - 30,000,000 working area
30,000,001 - 32,000,000 variant area
*/
#define VERSION 4.05
#define CELLSIZE 30000000 // if raspberry PI set smaller size.
#define HEAPSIZE 5000000
#define FREESIZE 500
#define STACKSIZE 2000000
#define VARIANTSIZE 2000000
#define VARIANTMAX CELLSIZE + VARIANTSIZE
#define BIGSIZE 20000000
#define NTTBASE 1000
#define RECORDMAX 12
#define ATOMSIZE 2048
#define BUFSIZE 2048
#define STRSIZE 2048
#define CTRLSTK 10
#define PARASIZE 100
#define THREADSIZE 10
#define PROCSIZE 10
#define OPERATOR_NUMBER 24
#define FUNCTION_NUMBER 22
#define BUILTIN_NUMBER 220
#define COMPILED_NUMBER 23
#define EXTENDED_NUMBER 40
#define NIL 0
#define YES 2
#define NO 4
#define FEND 6
#define UNDEF 8
#define CUT 10
#define AND 12
#define OR 14
#define LEFTPAREN 16
#define RIGHTPAREN 18
#define CALL 20
#define QUEST 22
#define ANOYVAR 24
#define NECK 26
#define ATMARK 28
#define COLON 30
#define NTRUE 32
#define NFALSE 34
#define CURL 36
#define IFTHEN 38
#define IFTHENELSE 40
#define UNDERBAR 42
#define DOTOBJ 44
#define DCG 46
#define TIMERON 48
#define TIMEROFF 50
#define SLASH 52
#define ERROBJ 54
#define HASHTBSIZE 107
#define BIGNUM_BASE 1000000000
#define SMALL_INT_MAX 1000000000
#define SMALL_INT_MIN -1000000000
#define UNBIND -1000000001
#define INT_FLAG 1073741824 //#b1000000000000000000000000000000
#define INT_MASK 1073741823 //#b0111111111111111111111111111111
#define PI 3.141592653589793
#define LESS 0
#define NOTLESS 1
//following are for unicode<=>UTF-8 transform
#define UNI2ADD1 192 //#b11000000
#define UNI3ADD1 224 //#b11100000
#define UNI4ADD1 240 //#b11110000
#define UNIOADDO 128 //#b10000000
#define UNI2MSK1 1984 //#b0000011111000000
#define UNI2MSK2 63 //#b0000000000111111
#define UNI3MSK1 61440 //#b1111000000000000
#define UNI3MSK2 4032 //#b0000111111000000
#define UNI3MSK3 63 //#b0000000000111111
#define UNI4MSK1 1835008 //#b00000000000111000000000000000000
#define UNI4MSK2 258048 //#b00000000000000111111000000000000
#define UNI4MSK3 4032 //#b00000000000000000000111111000000
#define UNI4MSK4 63 //#b00000000000000000000000000111111
#define UTF2MSK1 63 //#b00111111
#define UTF3MSK1 31 //#b00011111
#define UTF4MSK1 15 //#b00001111
#define UTFOMSKO 127 //#b01111111
typedef enum tag {EMP,INTN,FLTN,LONGN,BIGX,STRUCT,SINGLE,STREAM,SOCKET,STR} tag;
typedef enum flag {FRE,USE} flag;
typedef struct {
int aux;
int var;
int arity;
char tag;
flag flag;
char *name;
unsigned char option;
char trace;
union{
struct{
union{
int intnum;
int ( *subr) (int, int, int);
FILE *port;
int record;
int socket;
} car;
union{
int intnum;
} cdr;
};
double fltnum;
long long int lngnum;
} val;
} cell;
typedef enum toktype {LPAREN,RPAREN,LBRACKET,RBRACKET,VERTICAL,LCURL,RCURL,SHARP,
STRING,INTEGER,FLOATN,CHARCODE,ATOMOBJ,BUILTIN,FUNCTION,
COMPILED,OPERATOR,VARIABLE,ANOYMOUS,VARIANT,QUOTE,DOT,BACKQUOTE,DBLQUOTE,
COMMA,SEMICOLON,LONGNUM,BIGNUM,BINNUM,OCTNUM,HEXNUM,
PERIOD,FILEEND,OTHER} toktype;
typedef enum backtrack {GO,BACK} backtrack;
typedef enum spaceskip {SKIP,NOTSKIP} spaceskip;
typedef struct token {
char ch;
char ahead;
backtrack flag;
spaceskip space;
toktype type;
char buf[BUFSIZE];
} token;
// for editable REPL
typedef struct result {
int type;
int length;
} result;
// for ansi_*
typedef struct cursor {
int row;
int col;
} cursor;
enum { CHECKGBC_IDX, GBC_IDX, FRESHCELL_IDX,
DEBUG_IDX,
NUM_FN0S
};
enum { CAR_IDX, CDR_IDX, CADR_IDX, CADDR_IDX, CAAR_IDX, CADAR_IDX, PRINT_IDX, MAKEINT_IDX,
LENGTH_IDX, GET_INT_IDX, INTEGER_IDX, ABS_IDX,
LISTP_IDX, STRUCTUREP_IDX, VARIABLEP_IDX, GET_SP_IDX, GET_WP_IDX, GET_AC_IDX, INC_PROOF_IDX,
MAKEVARIANT_IDX, ADD_DYNAMIC_IDX, BIGX_TO_PARMANENT_IDX,
NUM_FN1S
};
enum { CONS_IDX, EQP_IDX, EQUALP_IDX, NUMEQP_IDX, SMALLERP_IDX, EQSMALLERP_IDX,
GREATERP_IDX, EQGREATERP_IDX, LISTCONS_IDX,
LIST2_IDX, SET_CAR_IDX, SET_CDR_IDX, SET_AUX_IDX,
NOT_NUMEQP_IDX, SET_VAR_IDX, NTH_IDX,
UNBIND_IDX, SET_SP_IDX, SET_WP_IDX, SET_AC_IDX, DEREF_IDX, WLIST1_IDX,
SIN_IDX, ASIN_IDX, COS_IDX, ACOS_IDX, TAN_IDX, ATAN_IDX, EXP_IDX, LOG_IDX,
LN_IDX, LIST1_IDX, RANDOM_IDX, RANDI_IDX, UNIFY_NIL_IDX, SQRT_IDX, COMPLEMENT_IDX,
COPY_WORK_IDX,
NUM_FN2S
};
enum { LIST3_IDX, ERRORCOMP_IDX, WLISTCONS_IDX,UNIFY_IDX, UNIFY_PAIR_IDX,
UNIFY_INT_IDX, UNIFY_FLT_IDX, UNIFY_LONG_IDX, UNIFY_BIG_IDX, UNIFY_STR_IDX,
UNIFY_VAR_IDX, UNIFY_ATOM_IDX, EXEC_ALL_IDX, WCONS_IDX,
WLIST2_IDX, ADDTAIL_BODY_IDX, PLUS_IDX, MINUS_IDX, MULT_IDX, DIVIDE_IDX, REMAINDER_IDX,
QUOTIENT_IDX, MOD_IDX, EXPT_IDX, DIV_IDX,
LEFTSHIFT_IDX, RIGHTSHIFT_IDX, LOGICALAND_IDX, LOGICALOR_IDX, ROUND_IDX,
CALL_IDX,
NUM_FN3S,
};
enum { MAKECONST_IDX, MAKEPRED_IDX, MAKEVAR_IDX, MAKESTRFLT_IDX, MAKECOMP_IDX,
MAKESYS_IDX, MAKEOPE_IDX, MAKEUSER_IDX, MAKESTRLONG_IDX, MAKEBIGX_IDX,
MAKESTR_IDX, MAKEFUNC_IDX,
NUM_FN4S
};
enum { CALLSUBR_IDX,
WLIST3_IDX,
NUM_FN5S,
};
extern cell heap[CELLSIZE];
extern int variant[VARIANTSIZE][THREADSIZE];
extern int bigcell[BIGSIZE];
extern int stack[STACKSIZE][THREADSIZE];
extern token stok;
extern jmp_buf buf;
extern jmp_buf buf1;
extern jmp_buf buf2;
extern __thread jmp_buf buf3;
extern jmp_buf catch_buf[CTRLSTK][THREADSIZE];
extern int cell_hash_table[HASHTBSIZE];
extern int record_hash_table[HASHTBSIZE][RECORDMAX];
extern int record_pt;
extern int counter[31];
extern int catch_data[CTRLSTK][2][THREADSIZE];
extern char bridge[BUFSIZE];
extern char transfer[BUFSIZE];
extern int variables[THREADSIZE];
extern int variables_save[THREADSIZE];
extern int end_of_file_answer;
extern int end_of_file_rest;
extern int predicates;
extern int builtins;
extern int spy_list;
extern int reconsult_list;
extern int execute_list;
extern int dynamic_list;
extern int op_list;
extern int key_list;
extern int error_code;
extern int eval_context;
extern int bag_list;
extern int nonfree_list;
extern int proof[THREADSIZE];
extern int parse_mode;
extern int left_margin;
extern int break_nest;
extern int leap_point;
extern int port;
extern int line;
extern int column;
extern int cursor_color;
extern int cursor_style;
extern int cursor_row_store;
extern int cursor_col_store;
extern int cursor_color_store;
extern int cursor_style_store;
extern int unread;
extern int paren_nest;
extern char operator[OPERATOR_NUMBER][5];
extern char function[FUNCTION_NUMBER][12];
extern char builtin[BUILTIN_NUMBER][30];
extern char compiled[COMPILED_NUMBER][30];
extern char extended[EXTENDED_NUMBER][30];
extern double timer;
//error_handler
extern int instantation_tag;
extern int uninstantation_tag;
extern int type_tag;
extern int domain_tag;
extern int exsistence_tag;
extern int permisson_tag;
extern int context_tag;
extern int syntax_tag;
extern int evaluation_tag;
extern int representation_tag;
extern int consistency_tag;
extern int resource_tag;
extern int system_tag;
// bignum pointer
extern int big_pt0;
extern int big_pt1;
//stream
extern int standard_input;
extern int standard_output;
extern int standard_error;
extern int input_stream;
extern int output_stream;
extern int error_stream;
enum Type {
NPL_OPEN,
NPL_INPUT,
NPL_OUTPUT,
NPL_INOUT,
NPL_TEXT,
NPL_BINARY,
NPL_SOCKET,
};
//trace mode
#define OFF 0
#define FULL 1
#define TIGHT 2
#define HALF 3
#define LOOSE 4
#define DBCALL 5
#define DBEXIT 6
#define DBREDO 7
#define DBFAIL 8
#define DBCUTFAIL 9
//debugger
#define OFF 0
#define ON 1
/* distributed parallel */
#define PORT 5000
extern int parent_sockfd[2];
extern int child_sockfd[PARASIZE];
extern socklen_t parent_len;
extern struct sockaddr_in parent_addr, child_addr[PARASIZE];
extern int child_num;
extern pthread_t receiver_thread;
extern int child_result[PARASIZE];
/* multi-thread */
extern pthread_mutex_t mutex;
extern pthread_mutex_t mutex1;
extern int mt_queue[PARASIZE];
extern int mt_queue_pt;
extern int mt_queue_num;
extern int thread_num;
extern int para_input[PARASIZE];
extern int para_output[PARASIZE];
extern pthread_t mt_para_thread[PARASIZE];
extern pthread_cond_t mt_cond_para[PARASIZE];
extern pthread_cond_t mt_cond_main;
extern pthread_cond_t mt_cond_queue;
extern pthread_attr_t mt_para_attr[PARASIZE];
extern size_t mt_para_size[PARASIZE];
/* -----TCPIP for server----------------*/
extern socklen_t server_len;
extern struct sockaddr_in server_addr, client_addr;
#ifdef __APPLE__
#define FLUSH fpurge(stdin);
#else
#define FLUSH __fpurge(stdin);
#endif
#define DEBUG printf("debug\n"); longjmp(buf,2);
#define GET_FLT(addr) heap[addr].val.fltnum
#define GET_CAR(addr) heap[addr].val.car.intnum
#define GET_CDR(addr) heap[addr].val.cdr.intnum
#define GET_AUX(addr) heap[addr].aux
#define GET_VAR(addr) heap[addr].var
#define GET_ATTR(addr) heap[addr].attr
#define GET_ARITY(addr) heap[addr].arity
#define GET_SUBR(addr) heap[addr].val.car.subr
#define GET_PORT(addr) heap[addr].val.car.port
#define GET_INT(addr) get_int(addr)
#define GET_NUMBER(addr) heap[addr].val.car.intnum
#define GET_FLT(addr) heap[addr].val.fltnum
#define GET_LONG(addr) heap[addr].val.lngnum
#define GET_NAME(addr) heap[addr].name
#define GET_NAME_ELT(addr,n) heap[addr].name[n]
#define GET_CHAR(addr) heap[addr].name[0]
#define GET_TAG(addr) get_tag(addr)
#define GET_CAR(addr) heap[addr].val.car.intnum
#define GET_OPT(addr) heap[addr].option
#define GET_TR(addr) heap[addr].trace
#define GET_FLAG(addr) heap[addr].flag
#define GET_RECORD(addr) heap[addr].val.car.record
#define GET_SOCKET(addr) heap[addr].val.car.socket
#define SET_TAG(addr,x) heap[addr].tag = x
#define SET_CAR(addr,x) heap[addr].val.car.intnum = x
#define SET_CDR(addr,x) heap[addr].val.cdr.intnum = x
#define SET_AUX(addr,x) heap[addr].aux = x
#define SET_VAR(addr,x) heap[addr].var = x
#define SET_ARITY(addr,x) heap[addr].arity = x
#define SET_INT(addr,x) heap[addr].val.car.intnum = x
#define SET_FLT(addr,x) heap[addr].val.fltnum = x
#define SET_LONG(addr,x) heap[addr].val.lngnum = x
#define SET_SUBR(addr,x) heap[addr].val.car.subr = x
#define SET_PORT(addr,x) heap[addr].val.car.port = x
#define SET_OPT(addr,x) heap[addr].option = x
#define SET_TR(addr,x) heap[addr].trace = x
#define SET_CHAR(addr,x) heap[addr].name[0] = x
#define SET(addr,x) heap[addr] = heap[x]
#define SET_RECORD(addr,x) heap[addr].val.car.record = x
#define SET_SOCKET(addr,x) heap[addr].val.car.socket = x
#define IS_INCELL(addr) (addr >= 0 && addr < CELLSIZE)
#define IS_OUTCELL(addr) (addr < 0 || addr >= CELLSIZE)
#define IS_ALPHA(addr) (addr < VARIANTMAX && addr > CELLSIZE)
#define IS_SINGLE(addr) heap[addr].tag == SINGLE
#define IS_BIGXNUM(addr) heap[addr].tag == BIGX
#define IS_LONGNUM(addr) heap[addr].tag == LONGN
#define IS_FLOAT(addr) heap[addr].tag == FLTN
#define IS_STRING(addr) heap[addr].tag == STR
#define IS_STRUCT(addr) heap[addr].tag == STRUCT
#define IS_NIL(addr) (addr == 0)
#define IS_T(addr) (addr == 2)
#define IS_EMPTY(addr) heap[addr].tag == EMP
#define IS_STREAM(addr) heap[addr].tag == STREAM
#define HAS_NAME(addr,x) strcmp(heap[addr].name,x) == 0
#define SAME_NAME(addr1,addr2) strcmp(heap[addr1].name, heap[addr2].name) == 0
#define GREATER_NAME(addr1,addr2) strcmp(heap[addr1].name, heap[addr2].name) > 0
#define SMALLER_NAME(addr1,addr2) strcmp(heap[addr1].name, heap[addr2].name) < 0
#define EQUAL_STR(x,y) strcmp(x,y) == 0
#define EQUAL_STR(x,y) strcmp(x,y) == 0
#define STRING_REF(addr,k) heap[addr].name[k]
#define STRING_SET(addr,k,c) heap[addr].name[k] = c
#define MARK_CELL(addr) heap[addr].flag = USE
#define NOMARK_CELL(addr) heap[addr].flag = FRE
#define USED_CELL(addr) heap[addr].flag == USE
#define FREE_CELL(addr) heap[addr].flag == FRE
#define isUni1(c) ((unsigned char)(c) <= 0x7f)
#define isUni2(c) (((unsigned char)(c) >= 0xc2) && \
((unsigned char)(c) <= 0xdf))
#define isUni3(c) (((unsigned char)(c) >= 0xe0) && \
((unsigned char)(c) <= 0xef))
#define isUni4(c) (((unsigned char)(c) >= 0xf0) && \
((unsigned char)(c) <= 0xf7))
#define isUni5(c) (((unsigned char)(c) >= 0xf8) && \
((unsigned char)(c) <= 0xfb))
#define isUni6(c) (((unsigned char)(c) >= 0xfc) && \
((unsigned char)(c) <= 0xfd))
//operator
#define FX 1 //0b0000001
#define FY 2 //0b0000010
#define XFX 4 //0b0000100
#define XFY 8 //0b0001000
#define YFX 16 //0b0010000
#define XF 32 //0b0100000
#define YF 64 //0b1000000
#define FX_XFX 5 //0b0000101
#define FY_XFX 6 //0b0000110
#define FX_XFY 9 //0b0001001
#define FY_XFY 10 //0b0001010
#define FX_YFX 17 //0b0010001
#define FY_YFX 18 //0b0010010
#define FX_XF 33 //0b0100001
#define FX_YF 65 //0b1000001
#define FY_XF 34 //0b0100010
#define FY_YF 66 //0b1000010
//clause option
#define HASCUT 100 //the clause has cut operator
#define CUTING 101 //the clause that has cut is now on executing.
#define HASLOOP 102 //the clause has simple loop
#define HASIFTHEN 103 // the clause has ih_then ->
//atom type
#define SIMP 1 //simple atom(constant)
#define VAR 2 //variable
#define ANOY 3 //anoimouse
#define USER 4 //user defined operator
#define OPE 5 //operator
#define PRED 6 //user defined predicate
#define SYS 7 //system predicate
#define CLAUSE 8 //clause
#define COMP 9 //compiled predicate
#define LIST 10 //list
#define FUNC 11 //function
//stream type
#define NORMAL 0
#define STDIO 1 //user_input user_output error
//------flag---
extern int trace_flag;
extern int open_flag;
extern int gbc_flag;
extern int simp_flag;
extern int assert_flag;
extern int debug_flag;
extern int fskip_flag;
extern int qskip_flag;
extern int sskip_flag;
extern int xskip_flag;
extern int semiskip_flag;
extern int sexp_flag;
extern int quoted_flag;
extern int ignore_flag;
extern int link_flag;
extern int listing_flag;
extern int prefix_flag;
extern int syntax_flag;
extern int fileerr_flag;
extern int exist_flag;
extern int bridge_flag;
extern int ctrl_c_flag;
extern int init_flag;
extern int script_flag;
extern int check_flag;
extern int break_flag;
extern int network_mode;
extern int parallel_exit_flag;
extern int process_flag;
extern int thread_flag;
extern int child_flag;
extern int connect_flag;
extern int receiver_exit_flag;
extern int child_busy_flag;
extern int parent_flag;
extern int pause_flag;
extern int shutdown_flag;
extern int active_thread;
extern int dynamic_flag;
extern int string_flag;
//------pointer----
extern int hp;
extern int sp[THREADSIZE];
extern int fc;
extern int ac[THREADSIZE];
extern int wp[THREADSIZE];
extern int gc;
extern int wp_min[THREADSIZE];
extern int wp_max[THREADSIZE];
extern int cp[THREADSIZE];
/* module */
extern int module_name;
extern int export_data[10][2];
extern int module_flag;
extern int export_pt;
//-----editor-----
extern int repl_flag;
extern char buffer[BUFSIZE][10];
extern int ed_row;
extern int ed_col;
extern int ed_start;
extern int ed_end;
extern int ed_ins;
extern int ed_tab;
extern int ed_indent;
extern int ed_name;
extern int ed_lparen_row;
extern int ed_lparen_col;
extern int ed_rparen_row;
extern int ed_rparen_col;
extern int ed_lbracket_row;
extern int ed_lbracket_col;
extern int ed_rbracket_row;
extern int ed_rbracket_col;
extern char ed_candidate[30][30];
extern int ed_candidate_pt;
extern int ed_operator_color;
extern int ed_builtin_color;
extern int ed_extended_color;
extern int ed_quote_color;
extern int ed_comment_color;
extern int ed_function_color;
extern int ed_incomment;
extern int ed_hight;
extern int ed_width;
extern result rtok;
static const int BIGNUM_WORK = BIGSIZE * 5 / 10; // from 50% to 90% of bigcell area is working area.
static const int BIGNUM_PARMA = BIGSIZE * 9 / 10; //from 90% to 100% of bigcell area is parmanent area
#define ESCHOME printf("\33[1;1H")
#define ESCTOP printf("\33[2;1H")
#define ESCCLS printf("\33[2J") //clear screen
#define ESCCLS1 printf("\33[0J")
#define ESCCLSL printf("\33[0K")
#define ESCCLSL1 printf("\033[K") //clear line from cursor
#define ESCMVLEFT(x) printf("\33[%dG", x)
#define ESCMVR printf("\33[1C")
#define ESCMVL printf("\33[1D")
#define ESCMVU printf("\33[1A")
#define ESCMVD printf("\33[1B")
#define ESCSCR printf("\33[S")
#define ESCMOVE(x,y) printf("\33[%d;%df", x,y)
#define ESCCOLOR(x) printf("\33[%dm",x)
#define ESCFBLACK printf("\33[30m")
#define ESCFRED printf("\33[31m")
#define ESCFGREEN printf("\33[32m")
#define ESCFYELLOW printf("\33[33m")
#define ESCFBLUE printf("\33[34m")
#define ESCFMAGENTA printf("\33[35m")
#define ESCFCYAN printf("\33[36m")
#define ESCFWHITE printf("\33[37m")
#define ESCFORG printf("\33[39m")
#define ESCBCYAN printf("\33[46m")
#define ESCBORG printf("\33[49m")
#define ESCREV printf("\33[7m")
#define ESCRST printf("\33[0m")
#define ESCBOLD printf("\33[1m")
//-------read--------
#define EOL '\n'
#define RET '\r'
#define TAB '\t'
#define SPACE ' '
#define ESCAPE 033
#define NUL '\0'
#define ESC 27
#define NUL '\0'
#define BEL '\a'
#define BS '\b'
#define DEL 127
#define FF 12
#define CR 13
#define VT 11
#define LEFT 'D'
#define UP 'A'
#define RIGHT 'C'
#define DOWN 'B'
#define INSERT '2'
#define DELETE '3'
#define PAGEUP '5'
#define PAGEDN '6'
#define HOME 'H'
#define END 'F'
//-------error code---
enum Error {
SYNTAX_ERR,
BUILTIN_EXIST,
CANT_READ,
NOT_COMPUTABLE,
OUT_OF_RANGE,
MALLOC_OVERF,
WRONG_ARGS,
NOT_NUM,
NOT_STR,
NOT_LIST,
NOT_ATOM,
NOT_ATOMIC,
NOT_INT,
NOT_STREAM,
NOT_CHAR,
NOT_FLT,
NOT_FUNCTION,
NOT_SOCKET,
NOT_CALLABLE,
NOT_VAR,
NOT_COMPOUND,
NOT_ORDER,
NOT_INDICATOR,
CANT_OPEN,
ILLEGAL_ARGS,
DIV_ZERO,
LESS_THAN_ZERO,
FLOAT_OVERF,
SYSTEM_ERR,
INSTANTATION_ERR,
EXISTENCE_ERR,
NON_EMPTY_LIST,
EVALUATION_ERR,
OPE_SPEC_ERR,
OPE_PRIORITY_ERR,
MODIFY_OPE_ERR,
RESOURCE_ERR,
NOT_RECORD,
ARITY_ERR,
};
double getETime(void);
int readc(void);
int absolute(int x, int th);
int addask(int x, int th);
int addatom(char *name, int property, int index);
int addtail(int x, int y);
int addtail_body(int x, int y,int th);
int addtail_operation(int x, int y);
int add_dynamic(int x);
int after_cut(int x);
int after_c_lang(int x);
int alias_option_p(int x);
int aliasp(int addr);
int alpha_variable_p(int addr);
int alpha_to_variable(int x);
int alphabeticalp(int addr);
int already_checked_p(int x);
int anonymousp(int x);
int anonymous_conversion(int x);
int append(int x, int y);
int append1(int x, int y);
int argumentsp(int addr);
int assq(int sym, int lis);
int assq1(int sym, int lis);
int atmarkp(int addr);
int atom_chars_list_p(int addr);
int atom_codes_list_p(int addr);
int atom_constant_p(int addr);
int atom_predicate_p(int addr);
int atom_quote_p(int addr);
int atom_variable_p(int addr);
int atom_length(int addr);
int atomp(int addr);
int atomicp(int addr);
int atsmaller(int x, int y);
int ateqsmaller(int x, int y);
int bcons(int car, int cdr);
int b_abolish(int arglist, int rest, int th);
int b_abort(int arglist, int rest, int th);
int b_after_cut(int arglist, int rest, int th);
int b_ansi_cup(int arglist, int rest, int th);
int b_ansi_cuu(int arglist, int rest, int th);
int b_ansi_cud(int arglist, int rest, int th);
int b_ansi_cuf(int arglist, int rest, int th);
int b_ansi_cub(int arglist, int rest, int th);
int b_ansi_sgr(int arglist, int rest, int th);
int b_ansi_cpr(int arglist, int rest, int th);
int b_ansi_scp(int arglist, int rest, int th);
int b_ansi_rcp(int arglist, int rest, int th);
int b_ansi_ed(int arglist, int rest, int th);
int b_ansi_el(int arglist, int rest, int th);
int b_append(int arglist, int rest, int th);
int b_arg(int arglist, int rest, int th);
int b_arg0(int arglist, int rest, int th);
int b_arity_count(int arglist, int rest, int th);
int b_ask(int arglist, int rest, int th);
int b_assert(int arglist, int rest, int th);
int b_asserta(int arglist, int rest, int th);
int b_assertz(int arglist, int rest, int th);
int b_ateqsmaller(int arglist, int rest, int th);
int b_atsmaller(int arglist, int rest, int th);
int b_atgreater(int arglist, int rest, int th);
int b_ateqgreater(int arglist, int rest, int th);
int b_atmark(int arglist, int rest, int th);
int b_atom(int arglist, int rest, int th);
int b_atom_string(int arglist, int rest, int th);
int b_atom_concat(int arglist, int rest, int th);
int b_atom_length(int arglist, int rest, int th);
int b_atom_codes(int arglist, int rest, int th);
int b_atom_chars(int arglist, int rest, int th);
int b_atomic(int arglist, int rest, int th);
int b_atom_convert(int arglist, int rest, int th);
int b_atsmaller(int arglist, int rest, int th);
int b_at_end_of_stream(int arglist, int rest, int th);
int b_before_cut(int arglist, int rest, int th);
int b_bagof(int arglist, int rest, int th);
int b_bagofhelper(int arglist, int rest, int th);
int b_between(int arglist, int rest, int th);
int b_bignum(int arglist, int rest, int th);
int b_break(int arglist, int rest, int th);
int b_call(int arglist, int rest, int th);
int b_catch(int arglist, int rest, int th);
int b_chdir(int arglist , int rest, int th);
int b_char_code(int arglist, int rest, int th);
int b_char_conversion(int arglist, int rest, int th);
int b_char_set(int arglist, int rest, int th);
int b_cinline(int arglist, int rest, int th);
int b_clause(int arglist, int rest, int th);
int b_clause_with_arity(int arglist, int rest, int th);
int b_create_client_socket(int arglist, int rest, int th);
int b_close(int arglist, int rest, int th);
int b_close_socket(int arglist, int rest, int th);
int b_compare(int arglist, int rest, int th);
int b_compiler_anonymous(int arglist, int rest, int th);
int b_compiler_variable(int arglist, int rest, int th);
int b_compound(int arglist, int rest, int th);
int b_concat(int arglist, int rest, int th);
int b_consult(int arglist, int rest, int th);
int b_constant(int arglist, int rest, int th);
int b_copy_term(int arglist, int rest, int th);
int b_create(int arglist, int rest, int th);
int b_create_server_socket(int arglist, int rest, int th);
int b_ctr_set(int arglist, int rest, int th);
int b_ctr_dec(int arglist, int rest, int th);
int b_ctr_inc(int arglist, int rest, int th);
int b_ctr_is(int artlist, int rest, int th);
int b_current_directory(int arglist , int rest, int th);
int b_current_input(int arglist, int rest, int th);
int b_current_output(int arglist, int rest, int th);
int b_current_op(int arglist, int rest, int th);
int b_current_predicate(int arglist, int rest, int th);
int b_cut(int arglist, int rest, int th);
int b_date_day(int arglist, int rest, int th);
int b_date(int arglist, int rest, int th);
int b_dec(int arglist, int rest, int th);
int b_debug(int arglist, int rest, int th);
int b_defined_predicate(int arglist, int rest, int th);
int b_defined_userop(int arglist, int rest, int th);
int b_delete(int arglist, int rest, int th);
int b_directory(int arglist, int rest, int th);
int b_display(int arglist, int rest, int th);
int b_dp_countup(int arglist, int rest, int th);
int b_dp_create(int arglist, int rest, int th);
int b_dp_close(int arglist, int rest, int th);
int b_dp_prove(int arglist ,int rest, int th);
int b_dp_and(int arglist, int rest, int th);
int b_dp_or(int arglist, int rest, int th);
int b_dp_transfer(int arglist, int rest, int th);
int b_dp_receive(int arglist ,int rest, int th);
int b_dp_compile(int arglist, int rest, int th);
int b_dp_consult(int arglist, int rest, int th);
int b_dp_report(int arglist, int rest, int th);
int b_dp_parent(int arglist, int rest, int th);
int b_dp_child(int arglist, int rest, int th);
int b_dp_wait(int arglist, int rest, int th);
int b_dp_pause(int arglist, int rest, int th);
int b_dp_resume(int arglist, int rest, int th);
int b_dup(int arglist, int rest, int th);
int b_dynamic(int arglist, int rest, int th);
int b_dynamic_predicate(int arglist, int rest, int th);
int b_edit(int arglist, int rest, int th);
int b_end_of_file(int arglist, int rest, int th);
int b_eq(int arglist, int rest, int th);
int b_eqgreater(int arglist, int rest, int th);
int b_eqsmaller(int arglist, int rest, int th);
int b_equalp(int arglist, int rest, int th);
int b_erase(int arglist, int rest, int th);
int b_eraseall(int arglist, int rest, int th);
int b_errcode(int arglist, int rest, int th);
int b_error(int arglist, int rest, int th);
int b_existerrors(int arglist, int rest, int th);
int b_fail(int arglist, int rest, int th);
int b_findall(int arglist, int rest, int th);
int b_findatom(int arglist, int rest, int th);
int b_fileerrors(int arglist, int rest, int th);
int b_filename(int arglist, int rest, int th);
int b_float_text(int arglist, int rest, int th);
int b_flush(int arglist, int rest, int th);
int b_flush_output(int arglist, int rest, int th);
int b_functor(int arglist, int rest, int th);
int b_gbc(int arglist, int rest, int th);
int b_generate_all_variable(int arglist, int rest, int th);
int b_generate_variable(int arglist, int rest, int th);
int b_get(int arglist, int rest, int th);
int b_get0(int arglist, int rest, int th);
int b_get0_noecho(int arglist, int rest, int th);
int b_get_byte(int arglist, int rest, int th);
int b_get_char(int arglist, int rest, int th);
int b_get_code(int arglist, int rest, int th);
int b_greater(int arglist, int rest, int th);
int b_ground(int arglist, int rest, int th);
int b_halt(int arglist, int rest, int th);
int b_has_cut(int arglist, int rest, int th);
int b_heapdump(int arglist, int rest, int th);
int b_inc(int arglist, int rest, int th);
int b_ifthen(int arglist, int rest, int th);
int b_ifthenelse(int arglist, int rest, int th);
int b_instance(int arglist, int rest, int th);
int b_integer(int arglist, int rest, int th);
int b_int_text(int arglist, int rest, int th);
int b_is(int arglist, int rest, int th);
int b_key(int arglist, int rest, int th);
int b_keysort(int arglist, int rest, int th);
int b_leash(int arglist, int rest, int th);
int b_length(int arglist, int rest, int th);
int b_list(int arglist, int rest, int th);
int b_listing(int arglist, int rest, int th);
int b_list_text(int arglist, int rest, int th);
int b_longnum(int arglist, int rest, int th);
int b_mkdir(int arglist, int rest, int th);
int b_member(int arglist, int rest, int th);
int b_measure(int arglist, int rest, int th);
int b_maplist(int arglist, int rest, int th);
int b_module(int arglist, int rest, int th);
int b_mt_create(int arglist, int rest, int th);
int b_mt_close(int arglist, int rest, int th);
int b_mt_and(int arglist, int rest, int th);
int b_mt_or(int arglist, int rest, int th);
int b_mt_prove(int arglist, int rest, int th);
int b_nl(int arglist, int rest, int th);
int b_nonvar(int arglist, int rest, int th);
int b_nospy(int arglist, int rest, int th);
int b_not(int arglist, int rest, int th);
int b_notequalp(int arglist, int rest, int th);
int b_notnumeq(int arglist, int rest, int th);
int b_notrace(int arglist, int rest, int th);
int b_notunify(int arglist, int rest, int th);
int b_name(int arglist, int rest, int th);
int b_number(int arglist, int rest, int th);
int b_number_chars(int arglist, int rest, int th);
int b_number_codes(int arglist, int rest, int th);
int b_numbervars(int arglist, int rest, int th);
int b_numeq(int arglist, int rest, int th);
int b_nth_char(int arglist, int rest, int th);
int b_nref(int arglist, int rest, int th);
int b_nth_ref(int arglist, int rest, int th);
int b_once(int arglist, int rest, int th);
int b_op(int arglist, int rest, int th);
int b_open(int arglist, int rest, int th);
int b_pair_list(int arglist, int rest, int th);
int b_peek_byte(int arglist, int rest, int th);
int b_peek_char(int arglist, int rest, int th);
int b_peek_code(int arglist, int rest, int th);
int b_peek_byte(int arglist, int rest, int th);
int b_predicate_property(int arglist, int rest, int th);
int b_pref(int arglist, int rest, int th);
int b_property(int arglist, int rest, int th);
int b_put(int arglist, int rest, int th);
int b_put_char(int arglist, int rest, int th);
int b_put_code(int arglist, int rest, int th);
int b_put_byte(int arglist, int rest, int th);
int b_read(int arglist, int rest, int th);
int b_read_line(int arglist, int rest, int th);
int b_read_string(int arglist, int rest, int th);
int b_real(int arglist, int rest, int th);
int b_record_after(int arglist, int rest, int th);
int b_recorda(int arglist, int rest, int th);
int b_recordz(int arglist, int rest, int th);
int b_recorded(int arglist, int rest, int th);
int b_recordh(int arglist, int rest, int th);
int b_reconsult(int arglist, int rest, int th);
int b_ref(int arglist, int rest, int th);
int b_rename(int arglist, int rest, int th);
int b_repeat(int arglist, int rest, int th);
int b_reset_op(int arglist, int rest, int th);
int b_retract(int arglist, int rest, int th);
int b_retrieveh(int arglist, int rest, int th);
int b_recv_socket(int arglist, int rest, int th);
int b_reconsult_predicate(int arglist, int rest, int th);
int b_reconsult_abolish(int arglist, int rest, int th);
int b_rmdir(int arglist, int rest, int th);
int b_removeh(int arglist, int rest, int th);
int b_removeallh(int arglist, int rest, int th);
int b_replace(int arglist, int rest, int th);
int b_save(int arglist, int rest, int th);
int b_see(int arglist, int rest, int th);
int b_seeing(int arglist, int rest, int th);
int b_seen(int arglist, int rest, int th);
int b_select(int arglist, int rest, int th);
int b_send_socket(int arglist, int rest, int th);
int b_setof(int arglist, int rest, int th);
int b_set_input(int arglist, int rest, int th);
int b_set_output(int arglist, int rest, int th);
int b_set_prolog_flag(int arglist, int rest, int th);
int b_shell(int arglist, int rest, int th);
int b_skip(int arglist, int rest, int th);
int b_smaller(int arglist, int rest, int th);
int b_sort(int arglist, int rest, int th);
int b_spy(int arglist, int rest, int th);
int b_statistics(int arglist, int rest, int th);
int b_stdin(int arglist, int rest, int th);
int b_stdout(int arglist, int rest, int th);
int b_stdinout(int arglist, int rest, int th);
int b_stream_property(int arglist, int rest, int th);
int b_string(int arglist, int rest, int th);
int b_string_length(int arglist, int rest, int th);
int b_string_term(int arglist, int rest, int th);
int b_substring(int arglist, int rest, int th);
int b_succ(int arglist, int rest, int th);
int b_syntaxerrors(int arglist, int rest, int th);
int b_system(int arglist, int rest, int th);
int b_tab(int arglist, int rest, int th);
int b_tell(int arglist, int rest, int th);
int b_telling(int arglist, int rest, int th);
int b_term_variables(int arglist, int rest, int th);
int b_throw(int arglist, int rest, int th);
int b_time(int arglist, int rest, int th);
int b_told(int arglist, int rest, int th);
int b_trace(int arglist, int rest, int th);
int b_true(int arglist, int rest, int th);
int b_unify(int arglist, int rest, int th);
int b_univ(int arglist, int rest, int th);
int b_use_module(int arglist, int rest, int th);
int b_var(int arglist, int rest, int th);
int b_variable_convert(int arglist, int rest, int th);
int b_unify_with_occurs_check(int arglist, int rest, int th);
int b_write(int arglist, int rest, int th);
int b_writeln(int arglist, int rest, int th);
int b_writeq(int arglist, int rest, int th);
int before_cut(int x);
int before_cut1(int x, int y);
int before_c_lang(int x);
int bignump(int x);
int bigx_abs(int x);
int bigx_abs_smallerp(int arg1, int arg2);
int bigx_big_to_flt(int x);
int bigx_div (int arg1, int arg2);
int bigx_div1 (int arg1, int arg2);
int bigx_div_i (int x, int y);
int bigx_eqp(int x, int y);
int bigx_greaterp(int arg1, int arg2);
int bigx_int_to_big(int x);
int bigx_length(int x);
int bigx_long_to_big(int x);
int bigx_minus(int arg1, int arg2);
int bigx_minus1(int arg1, int arg2);
int bigx_mult(int arg1, int arg2);
int bigx_mult_i(int x, int y);