-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathalib.pro
More file actions
executable file
·4949 lines (4228 loc) · 140 KB
/
alib.pro
File metadata and controls
executable file
·4949 lines (4228 loc) · 140 KB
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
%-*-Prolog-*-
% alib indented on 12/23/2001 by 'JOLI' 1.0.
%----------------------------------------------------------------------
% amzilib.pro
%
% Copyright (c) 1992-2002 Amzi! inc. All Rights Reserved.
%
% $Log: alib.pro,v $
% Revision 1.29 2007/01/29 22:01:40 dennis
% better flatten
%
% Revision 1.28 2006/07/25 15:12:05 dennis
% I don't know, maybe some thread stuff
%
% Revision 1.27 2006/05/31 22:15:56 mary
% Default to user: in alib. Prepare for 7.4.11 (10 is reserved for eoTek)
%
% Revision 1.26 2006/03/08 23:38:59 dennis
% fixed LNEW bug, MS uses bad_alloc now...
%
% Revision 1.25 2006/01/16 02:40:57 dennis
% minor fixes
%
% Revision 1.24 2006/01/04 04:31:30 dennis
% atom_concat bug fix
%
% Revision 1.23 2005/12/23 03:59:07 dennis
% string_termq3
%
% Revision 1.22 2005/12/21 21:45:37 dennis
% fixfix
%
% Revision 1.21 2005/07/28 13:33:19 dennis
% minor bug fixes
%
% Revision 1.20 2005/02/09 17:35:39 dennis
% ?var added
%
% Revision 1.19 2004/05/23 21:56:06 dennis
% fixed dcg debug bug
%
% Revision 1.18 2004/05/05 16:31:44 dennis
% added tcltk stuff
%
% Revision 1.17 2004/03/29 21:37:28 mary
% Always flush bug file on write.
%
% Revision 1.16 2004/03/26 21:37:10 dennis
% implemented occurs check
%
% Revision 1.15 2004/02/18 22:17:13 mary
% Lots of cpp and lsapi cleanups.
%
% Revision 1.14 2004/02/16 22:38:58 dennis
% fixed leaky broken streams
%
% Revision 1.13 2004/02/16 20:59:21 mary
% Added all the math functions and operators for predicate$info hover help.
%
% Revision 1.12 2004/02/01 13:25:56 mary
% Fix predicate_info to not return blank results, and some predicates were
% documented incorrectly.
%
% Revision 1.11 2004/01/31 04:01:39 mary
% More arguments and descriptions.
%
% Revision 1.10 2004/01/30 23:52:41 mary
% More hover text args and descriptions.
%
% Revision 1.9 2004/01/30 16:33:44 mary
% Added argument and description strings to PredicateHead and alib.
% Added predicate_info and predicate$enginfo to return this information.
%
% Revision 1.8 2004/01/21 22:03:29 dennis
% most of dcg working in reader
%
% Revision 1.7 2004/01/15 20:29:47 dennis
% fixed nasty unifycopy gc bug
%
% Revision 1.6 2003/12/26 18:26:14 dennis
% some reader fixes
%
% Revision 1.5 2003/12/23 21:46:18 dennis
% moved unify_vars to alib
%
% Revision 1.4 2003/10/14 01:45:08 dennis
% keys/license stuff in engine
%
% Revision 1.3 2003/10/03 03:57:35 dennis
% fixed, broke, fixed, broke, fixed I hope the source debugger
%
% Revision 1.2 2003/09/22 13:23:01 dennis
% stuff
%
% Revision 1.1.1.1 2003/09/11 02:15:10 dennis
% Starting release 7.0
%
% Revision 1.117 2003/09/11 02:07:44 dennis
% fixed memory leak problem with dynamic iterators
%
% Revision 1.116 2003/09/01 01:24:58 dennis
% bigdig and minor fixes
%
% Revision 1.115 2003/08/30 16:31:08 dennis
% loads all go to ensure_loaded now
%
% Revision 1.114 2003/08/30 12:40:47 dennis
% *** empty log message ***
%
% Revision 1.113 2003/08/27 03:04:43 dennis
% added initialization support for remote debugging LSX
%
% Revision 1.112 2003/08/21 18:24:01 dennis
% latest fixes to debug64
%
% Revision 1.111 2003/07/24 17:30:40 dennis
% support for debugging compiled code, reorg of alib etc to support that
%
% Revision 1.110 2003/06/16 17:02:46 dennis
% debug64 fixes, working pretty good now
%
% Revision 1.109 2003/06/13 18:37:00 dennis
% date_time and other fixes
%
% Revision 1.108 2003/04/14 18:15:21 dennis
% fixed setof bug, new date_time functions
%
% Revision 1.107 2003/04/10 17:35:36 dennis
% more 6.4 stuff, new date_time features added for vaccine project
%
% Revision 1.106 2003/03/24 15:49:01 dennis
% getting read for 6.4.0 alpha
%
% Revision 1.105 2003/03/15 14:34:04 dennis
% Many changes in debug64 and proto_debug, source code
% debugging is closer to a reality
%
% Revision 1.104 2003/02/13 23:44:35 dennis
% latest debug64 stuff
%
% Revision 1.103 2003/01/25 18:49:23 dennis
% debug64 preliminary stuff added in various places
%
% Revision 1.102 2002/10/20 14:55:23 dennis
% bug fixes
%
% Revision 1.101 2002/08/12 16:36:15 dennis
% a6-2-11 changes
%
% Revision 1.100 2002/07/16 00:41:09 dennis
% minor changes
%
% Revision 1.99 2002/06/19 04:04:39 dennis
% alib missing exports added, fixed gc/0
%
% Revision 1.98 2002/06/09 03:07:56 dennis
% added locking
%
% Revision 1.97 2002/06/02 03:50:55 dennis
% all the XStr forms of logic server calls call strterm and grow the
% heap, so made new ExecProve and CallProve that to the strterm inside
% so that the heap can rolled back to before the Exec/Call. Important
% that this be done in the Prove, so that if heapgc is encountered,
% the new heap is used for the rollback.
%
% Revision 1.96 2002/05/20 04:34:11 dennis
% final changes
%
% Revision 1.95 2002/05/18 14:16:03 dennis
% First 6.2.1 - TA DA!
%
% Revision 1.94 2002/05/15 16:59:06 dennis
% Final fixes for last 6.1 build, 80
%
% Revision 1.93 2002/05/08 16:14:53 dennis
% final a6-1-78 build, OK for chinese lsapi calls
%
% Revision 1.92 2002/05/05 17:29:14 dennis
% more fixes to wcstombs, need to added ending null if string
% didn't fit
%
% Revision 1.91 2002/05/04 15:21:43 dennis
% fixed chinese character bug, wcstombs must have len*2, not len!
%
% Revision 1.90 2002/05/02 19:50:37 dennis
% fixed small recent bug
%
% Revision 1.89 2002/05/02 17:39:29 dennis
% various minor bug fixes, added locale as a settable prolog flag
%
% Revision 1.88 2002/04/25 03:42:22 dennis
% more documentation, logicbase.htm, and some fiddling with sources
%
% Revision 1.87 2002/04/20 17:25:10 dennis
% minor changes
%
% Revision 1.86 2002/04/19 19:41:42 dennis
% fixed retract bug with sorted/indexed clauses, implemented abolish for
% those types as well
%
% Revision 1.85 2002/04/17 19:31:15 ray
% Extended q_cf to convert periodic cfs to rational
%
% Revision 1.84 2002/04/09 17:31:18 ray
% corrected error in divide and mod arith
%
% Revision 1.83 2002/04/02 22:52:42 dennis
% Moved the hotel two feet to the right, changing arity and xi
% in .plm files to be 2 bytes rather than 1.
%
% Revision 1.82 2002/03/21 01:25:08 dennis
% allow separator in file names to be either tilt on slash, converts
% to correct one for Unix or Windows
%
% Revision 1.81 2002/03/11 15:21:13 dennis
% ok
%
% Revision 1.80 2002/03/10 22:18:57 dennis
% fixed some small bugs, updated documentation
%
% Revision 1.79 2002/03/07 04:37:42 dennis
% updated tutorial and duckworld samples
%
% Revision 1.78 2002/03/01 22:06:08 dennis
% more documentation for 6.2, also timings added to apitrace functions
% execstr and friends.
%
% Revision 1.77 2002/02/21 21:08:31 dennis
% changed to floats/single for number defaults
%
% Revision 1.76 2002/02/21 04:50:04 dennis
% added :- include processing for consult and compile
%
% Revision 1.75 2002/02/19 19:38:09 ray
% Reaffirmation
%
% Revision 1.74 2002/02/19 04:11:39 dennis
% changed reals to use pass by reference, eliminating almost all needs
% for new and delete, seems to have eliminated most all leaks due to math,
% put in memcpy, memmove etc. for copying gigit arrays around.
%
% Revision 1.73 2002/02/15 02:28:15 dennis
% unicode I/O working again
%
% Revision 1.72 2002/02/13 03:19:58 dennis
% reals changed to have a LReal class, moved to file of same name,
% math functions moved out of termsvc and into lmath.cpp/h, eval rewritten
% to reflect various options for numbers, lexcept modified so anyone, even
% non-engine objects, can throw LExcept objects.
%
% Revision 1.71 2002/02/04 17:20:58 dennis
% New lreal wrapper class on reals, start of number options:
% decimals: real/float, floats: single/double. Created lmath.h/cpp
% but nothing in them yet. Work to be done on sorting out mixed mode
% arithmetic for different options. Also - casts removed, as they
% were causing problems.
%
% Revision 1.70 2002/01/28 06:29:18 dennis
% changes for parsing numbers, handling different options
%
% Revision 1.69 2002/01/27 22:52:04 ray
% Corrections to power and fixed
%
% Revision 1.68 2002/01/20 20:48:04 ray
% revised real divide, printReal
%
% Revision 1.67 2002/01/06 20:31:26 dennis
% put in new memory leak LNEW that reports on lines of code, had
% to take out std:: classes from engine and replace with pointers
% to classes to get it to work, due to various news and deletes in
% the stl class libraries.
%
% Revision 1.66 2001/12/22 18:50:19 dennis
% allowed for repositioning of text streams, a bit of a tricky business.
%
% Revision 1.65 2001/12/08 03:48:21 dennis
% fixed bugs with reconsult, added unicode support
%
% Revision 1.64 2001/12/03 20:20:52 dennis
% fixed copyterm to allow infinite variables, not limited to maxvars.
%
% Revision 1.63 2001/11/21 00:31:50 dennis
% removed mode stuff, filled out prolog flags
%
% Revision 1.62 2001/11/17 18:40:23 dennis
% fixed reconsult and error handling in ide
%
% Revision 1.61 2001/11/17 12:38:14 dennis
% working on reconsult
%
% Revision 1.60 2001/11/16 02:11:38 dennis
% fixed bugs in positions, streams, get0 for stdin
%
% Revision 1.59 2001/11/15 13:54:06 dennis
% Fixed logging and apitrace, made logfile into its own entity,
% removed from the Prolog stream IO.
%
% Revision 1.58 2001/11/13 00:41:17 dennis
% updated documentation and use of .cfg and mode parameters, and
% created an documented amzi.cfg file.
%
% Revision 1.57 2001/11/11 13:47:56 dennis
% fixed bug in meta$ processing of consulted clauses
%
% Revision 1.56 2001/11/09 14:54:23 mary
% removed debugging stuff
%
% Revision 1.55 2001/11/09 02:28:09 dennis
% Finished, I hope, sorted and indexed predicates. Needed to rethink
% how mscws worked, given the new itertors for moving from clause to
% clause.
%
% Revision 1.54 2001/10/30 01:01:03 dennis
% sorted and indexed clauses supported in dynamic database
%
% Revision 1.53 2001/10/27 03:24:36 dennis
% sorted dynamic predicates working, with optimized queries
% when they fit the right pattern, of vars last
%
% Revision 1.52 2001/10/26 01:28:15 dennis
% sorted predicates partially implemented
%
% Revision 1.51 2001/10/21 14:37:59 dennis
% fixed open bug, wouldn't take strings as names, and then
% fixed string_atom, put back to C built-in rather than alib
%
% Revision 1.50 2001/10/19 01:37:59 dennis
% compiler bugs, still not found, but noted that X registers
% are really restricted to 255 because of flewrite in assemb.pro,
% should change some day.
%
% Revision 1.49 2001/10/13 12:36:37 dennis
% see/tell bugs
%
% Revision 1.48 2001/10/13 05:06:10 dennis
% speeded up system metapredicates with hard-wired properties
%
% Revision 1.47 2001/10/13 02:58:12 dennis
% see/tell bugs, used to close function streams
%
% Revision 1.46 2001/10/06 17:29:22 dennis
% fixed sort bug, compare put back in
%
% Revision 1.45 2001/10/05 17:08:55 ray
% Changed mode code for streams
%
% Revision 1.44 2001/09/19 02:39:48 dennis
% fixed is_list
%
% Revision 1.43 2001/09/19 02:35:33 dennis
% fixed io stuff
%
% Revision 1.42 2001/09/11 04:34:55 dennis
% cleaned up some io stuff, got consult working, etc.
%
% Revision 1.41 2001/09/08 16:11:52 dennis
% a6-1-44 fopen and fleopen removed, 61-44 set to current compatible version
%
% Revision 1.40 2001/09/08 15:27:56 dennis
% compiler working without calling fopen or fleopen, all open calls
%
% Revision 1.39 2001/09/04 01:57:00 dennis
% changed stream vector to reuse empty slots
%
% Revision 1.38 2001/08/29 19:34:33 ray
% Corrections to 'seen' in alib etc.
%
% Revision 1.37 2001/08/02 18:51:00 dennis
% merge of new streams complete
%
% Revision 1.36 2001/08/01 20:17:58 ray
% removed tswrite.cpp & sio.cpp, added streams.cpp sowrite.cpp
%
% Revision 1.35 2001/07/24 02:52:46 dennis
% discontiguous/multifile working again for 6.1
%
% Revision 1.34 2001/06/30 02:40:34 dennis
% added stream I/O version of loader from 5.0 work
%
% Revision 1.33 2001/06/27 15:15:09 dennis
% miscellaneous changes and bug fixes, work with leak detection
%
% Revision 1.32 2001/04/16 13:02:43 ray
% Restored primeFactors/2
%
% Revision 1.31 2001/04/16 05:21:12 dennis
% hacked together some fixes for sio/lex to be better friends,
% merged other changes, added new samples
%
% Revision 1.30 2001/04/15 14:51:46 ray
% changed list_real to real_list
%
% Revision 1.29 2001/04/04 03:12:35 dennis
% minor cleanups
%
% Revision 1.28 2001/04/02 21:50:12 dennis
% got debugger working again
%
% Revision 1.27 2001/04/01 15:54:51 ray
% Modified compiler and loader for fixed data.
%
% Revision 1.26 2001/03/28 15:07:21 ray
% char_code/2, number_chars/2 added
% 1 char macros proscribed
%
% Revision 1.25 2001/03/26 19:16:56 ray
% moved various string_ builtins to alib
% repaired arithmetic.
%
% Revision 1.24 2001/03/26 02:29:34 dennis
% Ray's fixed numbers in.
%
% Revision 1.23 2001/03/25 15:29:50 ray
% Implemented fixed
% repaired #include
%
% Revision 1.22 2001/03/16 00:29:06 dennis
% compiled metapredicates
%
% Revision 1.20 2001/03/13 22:04:02 dennis
% changed is$code
%
% Revision 1.19 2001/03/13 20:05:17 dennis
% added meta$call to try and isolate meta calls.
%
% Revision 1.18 2001/03/09 20:13:59 dennis
% consolidating for KW delivery, fixed jni memory leak
%
% Revision 1.17 2001/02/28 02:22:38 dennis
% fixed some number bugs, some assert/retract bugs
%
% Revision 1.16 2001/02/24 19:53:50 ray
% alib was modified
%
% Revision 1.15 2001/02/23 23:06:45 dennis
% fixed srcbuf bug
%
% Revision 1.14 2001/02/21 04:46:42 dennis
% debugger working, updated documentation for 6.1
%
% Revision 1.13 2001/02/18 18:47:14 ray
% Substituted end_of_file for !EOS
% Replaced 0' with 0' for char code denotation
% Introduced 0' quote mark as default for strings
%
% Revision 1.12 2001/02/08 22:56:45 dennis
% string bug fixes, modularized compiler and listener
%
% Revision 1.11 2001/02/06 04:06:34 dennis
% fixed throw bug, added puctuation error checking to alib.
%
% Revision 1.10 2001/02/05 20:17:08 dennis
% fixed some bugs
%
% Revision 1.9 2001/02/05 03:11:43 dennis
% Fixed nasty heap GC bug, other minor fixes
%
% Revision 1.8 2001/01/30 16:47:27 dennis
% Made, after many trials, alib into amzi_system module.
%
% Revision 1.7 2001/01/21 23:02:34 ray
% Rewrote real divide
% Added real sqrt
%
% Revision 1.6 2001/01/11 03:39:00 dennis
% Made metapredicates more efficient with is$meta/3
%
% Revision 1.5 2001/01/11 01:49:22 dennis
% Implemented rest of import/export and metapredicates, working
% for test cases.
%
% Revision 1.4 2001/01/06 03:46:01 dennis
% listener working with import/export
%
% Revision 1.3 2001/01/05 06:05:53 dennis
% fixed minor discrepancies
%
% Revision 1.2 2000/12/29 22:39:48 dennis
% added first cut at a system module
%
% Revision 1.1.1.1 2000/12/29 02:18:05 dennis
% moved to a6
%
% Revision 1.37 2000/12/28 16:30:35 dennis
% fixed nasty pets bug, true/false on CallInterp()
% and other changes, merged with ray's new stuff
% calling this a6-1-6
%
% Revision 1.36 2000/12/13 21:13:59 ray
% Added epsilon flag for reals.
%
% Revision 1.35 2000/11/30 15:47:27 ray
% made arg, nth and prime bilateral.
% made real length and exponent 12 bits for maximum range
%
% Revision 1.34 2000/11/10 17:09:18 ray
% Restricted real length to 255 in order to add max length, for protection
%
% Revision 1.33 2000/11/09 17:18:47 ray
% added primeFactors/2
%
% Revision 1.32 2000/11/08 17:13:54 ray
% Added makePrimes/4, primes/1, prime/2
%
% Revision 1.31 2000/10/30 15:11:45 ray
% Extended compiler, loader and linker for real data.
% Added arithmetic primitives for rational data in alib.pro
%
% Revision 1.30 2000/10/21 03:02:41 dennis
% temp fix of .pro.pro problem in compiler
%
% Revision 1.29 2000/10/20 12:40:51 ray
% Moved =:= out of alib to accomodate reals.
% Various repairs and enhancements
%
% Revision 1.28 2000/10/15 17:57:05 ray
% Eliminated 'L' notation
%
% Revision 1.27 2000/10/07 17:47:19 ray
% added q_cf and fourierPrime
%
% Revision 1.26 2000/10/01 16:20:03 dennis
% cleaned up modules, ddb, got defined, abolish and friends working
%
% Revision 1.25 2000/09/28 03:24:39 dennis
% debugger working for command line listener
%
% Revision 1.24 2000/09/27 01:42:02 dennis
% implemented listing, needed current_predicate, predicate_property,
% and current_module
%
% Revision 1.23 2000/09/25 02:11:18 dennis
% first version of modules working, runs the modular version of
% duck world. still needs import and export. release 6.1.1
%
% Revision 1.22 2000/09/15 21:42:24 dennis
% 12->13
%
% Revision 1.21 2000/09/02 02:10:18 dennis
% new version of get$db replacing dbrefgen for getting clauses
% from dynamic database
%
% Revision 1.20 2000/08/21 21:48:27 ray
% *** empty log message ***
%
% Revision 1.19 2000/06/11 05:22:56 ray
% added number_codes
%
% Revision 1.18 2000/05/15 11:24:46 dennis
% fixed some minor bugs, started modules
%
% Revision 1.17 2000/05/15 07:45:51 dennis
% new alib with iso stuff from Ray
%
% Revision 1.15 2000/05/11 00:52:16 ray
% open, close, put_char,get_char, put_code, get_code, write_term,
% current_input, current_output, write_canonical
%
% Revision 1.14 2000/05/04 21:28:11 ray
% directives initialization, include, ensure_loaded
%
% Revision 1.13 2000/04/21 02:36:59 ray
%
% new current_prolog_flags
%
% Revision 1.12 2000/04/10 01:00:43 ray
% *** empty log message ***
%
% Revision 1.11 2000/03/28 01:05:14 dennis
% merged Ray's changes with bigdig. bigdig is at point where
% new Cell class is used, but there are no modules in the system.
%
% Revision 1.10 2000/03/16 02:20:03 ray
%
% alib
%
% Revision 1.9 2000/03/06 18:32:55 ray
% *** empty log message ***
%
% Revision 1.8.2.3 2000/03/23 12:36:10 dennis
% *** empty log message ***
%
% Revision 1.8.2.2 2000/03/08 04:11:59 dennis
% builtin.cpp compiles
%
% Revision 1.8.2.1 2000/02/26 20:56:12 dennis
% Removed local atoms from compiler, and old module support, so
% compiler and listener are all global for now. Also made member/2
% and friends built-ins as well as the bug predicates.
%
% Revision 1.8 2000/02/14 04:06:04 dennis
% Everything working on Solaris, need "C" linkage for LSX entry
% point, InitPreds, and fixed bug with load/1 predicate, so it
% can load library .plm's from alib.
%
% Revision 1.7 2000/02/13 05:09:48 dennis
% Merging other changes with NT
%
% Revision 1.6 2000/01/31 14:13:09 dennis
% Cleaned up system dependent code, creating new module, lenv,
% that has it all, or at least most of it.
%
% Revision 1.5 2000/01/28 11:05:42 dennis
% Fixed 'listing' bug caused by cur$atom wanting a short int
% (as it should for an atom) but being fed a long one from the
% new for/4, which drives the cur_atom loop.
%
%
%
% - library of built-in predicates implemented in Prolog
% - initial operator definitions
% - main entry point for .xpl files (cp$top/0)
% - dynamic database evaluator (guts of interpreter)
% - DCG evaluator
%
% 12/15/99 Ray added properNames, properQuotes, controls, prep
% & largeInts to mode$
% a4lib indented on 4/17/1999 by 'JOLI' 1.0.
% 08/20/99 Ray add ed catch and throw to DCG specials
% 01/20/99 Ray addded catch/4
% 11/16/99 Ray lib$ver(22) modified =:=
%----------------------------------------------------------------------
% Contents
% --------
% Imports & Exports
% Operator Definitions
% Main Entry Point
% Interpreter
% Built-Ins
% Arithmetic comparison predicates
% Consulting files
% Counter Manipulation
% Database predicates
% Display predicates
% File handling
% I/O predicates
% List manipulation predicates
% Mode control
% Set gathering functions
% Stream handling predicates
% Term ordering predicates
% Miscellaneous built-in predicates
% DCG Translator
% Error Handling
% Debugging Tools
% Local Utilities to amzilib.pro
%
%
% Note on err$exec/4 used for error reporting:
% arg1 - typeE, instanceE, execE, syntaxE
% arg2 - message string
% arg3 - Prolog terms to be tacked onto message
% arg4 - the predicate which triggered the error
% But, arg4 not working correctly, needs to be rethought
:-module(amzi_system).
%----------------------------------------------------------------------
% Operator Definitions
%
% define operators first, so they can be used in latent expressions
% during loading if necessary
%----------------------------------------------------------------------
op(Prec, Class, []) :- !.
op(Prec, Class, Symbol) :-
atom(Symbol), !,
op_(Prec, Class, Symbol).
op(Prec, Class, [H|T]) :-
op(Prec, Class, H),
op(Prec, Class, T).
:- (op(1200, xfx, [:-, -->])).
:- (op(1200, fx, [?-, :-])).
:- (op(1100, fx, [import, export, dynamic, multifile, discontiguous, sorted,
indexed])).
:- (op(1100, xfy, ';')).
:- (op(1050, xfy, ->)).
:- (op(1000, xfy, ',')).
:- (op(900, fy, [\+, not, once])).
:- (op(900, fy, [?, bug])).
:- (op(700, xfx, [=, \=, is, =.., ==, \==, =:=, ~=, =\=, <, >, =<, >=, @<,
@>, @=<, @>=])).
:- (op(600, xfy, :)).
:- (op(500, yfx, [+, -, /\, \/, xor])). % moved \ here from 900 fy
:- (op(400, yfx, [rem, mod, divs, mods, divu, modu])). % new ones and mod
:- (op(400, yfx, [/, //, *, >>, <<])).
:- (op(200, xfx, **)).
:- (op(200, xfy, ^)).
:- (op(200, fy, [+, -, \])).
export(P/A) :- !,
export$(P, A).
export([]) :- !.
export([P/A|Z]) :-
export$(P, A), !,
export(Z).
export(X) :-
err$exec(instanceE, $Bad argument for export: $, X, export(X)).
:- export (->) /2.
:- export (?) /1.
:- export (@<) /2.
:- export (@=<) /2.
:- export (@>) /2.
:- export (@>=) /2.
:- export (\+) /1.
:- export (\=) /2.
:- export (=) /2.
:- export (=\=) /2.
:- export (=<) /2.
:- export (>=) /2.
:- export abolish/1.
:- export arg/3.
:- export assert/1.
:- export assert/2.
:- export asserta/1.
:- export asserta/2.
:- export assertz/1.
:- export assertz/2.
:- export at_end_of_stream/0.
:- export atom_concat/3.
:- export atomic/1.
:- export bagof/3.
:- export (bug)/1.
:- export bugclose/0.
:- export buginit/0.
:- export buginit/1.
:- export built_in/1.
:- export call/1.
:- export call_nometa/1.
:- export catch/3.
:- export char_code/2.
:- export clause/2.
:- export clause/5.
:- export close/1.
:- export cntr_dec/2.
:- export cntr_get/2.
:- export cntr_inc/2.
:- export cntr_set/2.
:- export compare/3.
:- export compound/1.
:- export consult/1.
:- export consult_project/1.
:- export current_module/1.
:- export current_op/3.
:- export current_predicate/1.
:- export current_prolog_flag/2.
:- export dcg$bug/3.
:- export dcg$call/3.
:- export dcg$terminal/3.
:- export debug_consult/1.
:- export debug_init/0.
:- export debug$call/7.
:- export debug$info/6.
:- export debug64/1.
:- export defined/1.
:- export display/1.
:- export expand_term/2.
:- export (export)/1.
:- export fclose/1.
:- export file_exists/1.
:- export file_exists/2.
:- export findall/3.
:- export findfiles/3.
:- export flow/1.
:- export flow/3.
:- export flush_in/0.
:- export flush_out/0.
:- export flush_output/0.
:- export flush_output/1.
:- export fopen/3.
:- export for/3.
:- export for/4.
:- export fseek/3.
:- export ftell/2.
:- export gc/0.
:- export gensym/2.
:- export get/1.
:- export get/2.
:- export get_char/1.
:- export get_char/2.
:- export get_code/1.
:- export get_code/2.
:- export get_debug_stack/1.
:- export get_mode/2.
:- export get_preds/1.
:- export get0/1.
:- export get0/2.
:- export get1/1.
:- export get1/2.
:- export halt/0.
:- export (import)/2.
:- export is_atom/1.
:- export is_float/1.
:- export is_list/1.
:- export is_number/1.
:- export is_string/1.
:- export islist/1.
:- export keysort/2.
:- export list/1.
:- export listing/0.
:- export listing/1.
:- export listing/2.
:- export load/1.
:- export load/4.
:- export makePrimes/0.
:- export meta$assert/1.
:- export meta$convert/4.
:- export nl/0.
:- export nl/1.
:- export nonvar/1.
:- export (not)/1.
:- export nth/3.
:- export number_codes/2.
:- export number_flags/2.
:- export numbervars/3.
:- export numeric_type/2.
:- export (once)/1.
:- export op/3.
:- export open/3.
:- export open/4.
:- export phrase/2.
:- export phrase/3.
:- export pp/1.
:- export pp/2.
:- export predicate_info/3.
:- export predicate_property/2.
:- export press_any_key/0.
:- export primeFactors/2.
:- export put/1.
:- export put/2.
:- export put_char/1.
:- export put_char/2.
:- export put_code/1.
:- export put_code/2.
:- export read/1.
:- export read/2.
:- export read_string/1.
:- export read_string/2.
:- export reconsult/1.
:- export reconsult_project/1.
:- export reload/1.
:- export repeat/0.
:- export respkey/1.
:- export retract/1.
:- export retract/2.
:- export retractall/1.
:- export retractall/2.
:- export see/1.
:- export seeing/1.
:- export seen/0.
:- export seentold/0.
:- export seetell/1.
:- export set_errors/1.
:- export set_mode/2.
:- export set_prolog_flag/2.
:- export setof/3.
:- export skip/1.
:- export skip/2.
:- export sort/2.
:- export stream_property/2.
:- export string_float/2.
:- export string_integer/2.
:- export string_number/2.
:- export stringlist_concat/3.
:- export string_query/2.
:- export structure/1.
:- export sub_atom/4.
:- export sub_string/4.
:- export substring/4.
:- export tab/1.
:- export tab/2.
:- export tell/1.
:- export tell/2.
:- export telling/1.
:- export term_type/2.
:- export throw/1.
:- export told/0.
:- export true/0.
:- export unget0/1.
:- export unget0/2.
:- export unify_with_occurs_check/2.
:- export unload/1.
:- export var/1.
:- export varlist_query/3.
:- export write/1.
:- export write/2.
:- export writeq/1.
:- export writeq/2.
set$discontiguous([]).
set$discontiguous([H|T]) :-
set$discontiguous(H),
set$discontiguous(T).
set$discontiguous( (A,B) ) :-
set$discontiguous(A),
set$discontiguous(B).
set$discontiguous(P/A) :-
set$discontiguous(P, A).
:- discontiguous predicate$info/3.
%predicate$info(/, ``, ``).
% Built-in math functions and operators
predicate$info((+)/2, `X + Y`, `Sum of values of X and Y`).
predicate$info((-)/2, `X - Y`, `Value of X minus value of Y`).
predicate$info((-)/1, `-X`, `Evaluates to the negative of X evaluated`).
predicate$info((*)/2, `X * Y`, `Value of X multiplied by value of Y`).
predicate$info((/)/2, `X / Y`, `Value of X divided by value of Y`).
predicate$info((**)/2, `X ** Y`, `Evaluates to X raised to the Y power`).
predicate$info((//)/2, `X // Y`, `Integer division of X by Y truncates the result to the absolute integer`).
predicate$info(divs/2, `X divs Y`, `Integer division with a rounded rather than truncated answer`).
predicate$info(divu/2, `X divu Y`, `Integer division that is truncated`).
predicate$info(max/2, `max(X, Y)`, `The maximum of X and Y`).
predicate$info(min/2, `min(X, Y)`, `The minimum of X and Y`).
predicate$info(mod/2, `X mod Y`, `The positive remainder after dividing the value of X by the value of Y`).
predicate$info(mods/2, `X mods Y`, `The remainder after rounded integer division (divs)`).
predicate$info(modu/2, `X modu Y`, `The remainder, constrained so that the result is positive`).
predicate$info((/\)/2, `X /\ Y`, `Bitwise "and" of value of X and value of Y`).
predicate$info((\/)/2, `X \/ Y`, `Bitwise "or" of value of X and value of Y`).
predicate$info((<<)/2, `X << Y`, `Evaluates to X bit-shifted left by Y places`).
predicate$info((>>)/2, `X >> Y`, `Evaluates to X bit-shifted right by Y places`).
predicate$info((\)/1, `\ X`, `Evaluates to the bitwise complement of X`).
predicate$info(xor/2, `X xor Y`, `Evaluates to X exclusively or'd with Y`).
predicate$info(sin/1, `sin(X)`, `Evaluates to the sine of X (in radians). `).
predicate$info(cos/1, `cos(X)`, `Evaluates to the cosine of X (in radians) `).
predicate$info(tan/1, `tan(X)`, `Evaluates to the tangent of X (in radians`).
predicate$info(asin/1, `asin(X)`, `Evaluates to the angle (in radians) whose arcsine is X`).
predicate$info(acos/1, `acos(X)`, `Evaluates to the angle (in radians) whose arccosine is X`).
predicate$info(atan/1, `atan(X)`, `Evaluates to the angle (in radians) whose arctangent is X`).
predicate$info(abs/1, `abs(X)`, `Evaluates to the absolute value of `).
predicate$info(ceiling/1, `ceiling(X)`, `Evaluates to the smallest integer >= X`).
predicate$info(exp/1, `exp(X)`, `Evaluates to e raised to the power of X evaluated`).
predicate$info(float/1, `float(X)`, `Converts X to a double precision floating point number`).
predicate$info(floor/1, `floor(X)`, `Evaluates to the largest integer =< X`).
predicate$info(integer/1, `integer(X)`, `Converts X to an integer (truncating any fractional part)`).
predicate$info(ln/1, `ln(X)`, `Evaluates to the natural log (loge()) of X evaluated`).
predicate$info(log/1, `log(X)`, `Evaluates to the natural log (loge()) of X evaluated`).
predicate$info(log10/1, `log10(X)`, `Evaluates to the natural log (loge()) of X evaluated for log base 10`).
predicate$info(real/1, `real(X)`, `Converts X to a real number`).
predicate$info(round/1, `round(X)`, `Rounds X to the nearest integer and returns that value`).
predicate$info(sign/1, `sign(X)`, `Evaluates to 1 for positive numbers and -1 for negative numbers`).
predicate$info(sqrt/1, `sqrt(X)`, `Evaluates to the square root of X`).
predicate$info(cpuclock/0, `cpuclock`, `An integer with the number of milliseconds ticks expired`).
predicate$info(cputime/0, `cputime`, `A floating point number with the number of CPU seconds expired`).
predicate$info(e/0, `e`, `The value "e" (2.718281828459045)`).
predicate$info(pi/0, `pi`, `The value "pi" (3.141592653589793)`).
predicate$info(degtorad/0, `degtorad`, `The constant for converting degrees to radians, useful for trig functions. 2*pi/360`).
predicate$info(radtodeg/0, `radtodeg`, `The constant for converting radians to degrees, useful for trig functions. 360/2*pi`).
predicate$info(random/0, `random`, `A random floating point number >= 0.0 and < 1.0`).
% Built-in constants
predicate$info(end_of_file/0, `end_of_file`, `The constant that is returned by read predicates when end-of-file is reached`).
%----------------------------------------------------------------------
% Metapredicate Support
%
% Metapredicates require that their arguments have the
% current context module added as a module on arguments
% that are so marked with a ':' in a metapredicate
% mode indicator. The mode indicators are kept in the
% dynamic database.
%
% These predicates must be defined before any metapredicate
% definitions are given for module amzi_system.
%
% They are used by the interpreter, and also the compiler
% which is why they are exported.
%
% meta$assert/2
% meta$convert/3
%----------------------------------------------------------------------
get$meta$props(amzi_system, PRED, AR, PATTERN_ARGS) :-
sys$meta$pred(PRED, AR, PATTERN_ARGS), !.
get$meta$props(MOD, PRED, AR, PATTERN_ARGS) :-
sys$clause('{sys}meta$predicate'(MOD, PRED, AR, PATTERN_ARGS)).
set$meta$props(amzi_system, PRED, AR, PATTERN_ARGS) :-
sys$meta$pred(PRED, AR, PATTERN_ARGS), !.
set$meta$props(MOD, PRED, AR, PATTERN_ARGS) :-
sys$clause('{sys}meta$predicate'(MOD, PRED, AR, PATTERN_ARGS)), !.
set$meta$props(MOD, PRED, AR, PATTERN_ARGS) :-
assert$(amzi_system, 0'a,
'{sys}meta$predicate'(MOD, PRED, AR, PATTERN_ARGS)).
% define system meta predicates here and below. this just hardwires
% their properties to avoid the ddb look up.
sys$meta$pred(dcg$bug, 3, [:,*,*]).
sys$meta$pred(dcg$call, 3, [:,*,*]).
sys$meta$pred(debug$call, 7, [:,*,*,*,*,*,*]).
sys$meta$pred(asserta, 1, [:]).
sys$meta$pred(assertz, 1, [:]).
sys$meta$pred(assert, 1, [:]).