Commit 73c43d6c4adb85d5f53bde2610194faada7687e8

Authored by Alain Prouté
1 parent a832582f

*** empty log message ***

anubis_dev/compiler2/src/common.anubis
@@ -38,7 +38,8 @@ @@ -38,7 +38,8 @@
38 interpretations are computed. 38 interpretations are computed.
39 39
40 public type WeakExpr:... 40 public type WeakExpr:...
41 - 41 +public type StrongType:...
  42 +public type StrongTerm:...
42 43
43 44
44 45
@@ -57,6 +58,7 @@ public type WeakExpr:... @@ -57,6 +58,7 @@ public type WeakExpr:...
57 58
58 59
59 public type Position: 60 public type Position:
  61 + predefined,
60 position(String absolute_path, 62 position(String absolute_path,
61 Nat line_number, 63 Nat line_number,
62 Nat column_number). 64 Nat column_number).
@@ -203,8 +205,12 @@ public type WeakExpr: @@ -203,8 +205,12 @@ public type WeakExpr:
203 local_def (Position position, 205 local_def (Position position,
204 WeakExpr symbol, 206 WeakExpr symbol,
205 WeakExpr value, 207 WeakExpr value,
206 - WeakExpr body). 208 + WeakExpr body),
  209 +
  210 + strong_type (StrongType),
  211 + strong_term (StrongTerm).
207 212
  213 + The alternatives 'strong_type' and 'strong_term' are needed by predefinitions.
208 214
209 The list of valid signs may be found in the file 'lexer_1.anubis'. 215 The list of valid signs may be found in the file 'lexer_1.anubis'.
210 216
anubis_dev/compiler2/src/dictionary_1.anubis
@@ -29,13 +29,22 @@ @@ -29,13 +29,22 @@
29 Dictionaries are the places where the compiler stores its 'knowledge'. These 29 Dictionaries are the places where the compiler stores its 'knowledge'. These
30 dictionaries are saved to files, so as to be used at the next compilation. When a 30 dictionaries are saved to files, so as to be used at the next compilation. When a
31 dictionary is retrieved at the next compilation, obsolete entries are discarded. This 31 dictionary is retrieved at the next compilation, obsolete entries are discarded. This
32 - is decided according to dependancies between modules and dates of last modifications.  
33 - Hence, unchanged modules are not recompiled. 32 + is decided according to dependancies between modules and dates of last modifications.
  33 +
  34 + Hence, unmodified modules are not recompiled.
34 35
35 36
36 37
37 ----------------------------------- Table of Contents --------------------------------- 38 ----------------------------------- Table of Contents ---------------------------------
38 39
  40 + *** (1) Creating dictionaries.
  41 + *** (2) Getting the size of a dictionary (number of non empty entries).
  42 + *** (3) Updating all non empty entries in a dictionary according to a method.
  43 + *** (4) Adding entries to a dictionary.
  44 + *** (5) Getting entries from a dictionary.
  45 + *** (6) Saving a dictionary.
  46 + *** (7) Renumberings.
  47 + *** (8) Retrieving a dictionary.
39 48
40 --------------------------------------------------------------------------------------- 49 ---------------------------------------------------------------------------------------
41 50
@@ -64,7 +73,8 @@ public define Dictionary1($Entry,$Key1) @@ -64,7 +73,8 @@ public define Dictionary1($Entry,$Key1)
64 ( 73 (
65 Int32 bits_of_hash, 74 Int32 bits_of_hash,
66 String dictionary_name, 75 String dictionary_name,
67 - $Entry -> $Key1 compute_key1 76 + $Entry -> $Key1 compute_key1,
  77 + $Entry empty_entry
68 ). 78 ).
69 79
70 The integer 'bits_of_hash' is the number of bits used for hashing keys. A value between 80 The integer 'bits_of_hash' is the number of bits used for hashing keys. A value between
@@ -80,13 +90,14 @@ public define Dictionary2($Entry,$Key1,$Key2) @@ -80,13 +90,14 @@ public define Dictionary2($Entry,$Key1,$Key2)
80 Int32 bits_of_hash, 90 Int32 bits_of_hash,
81 String dictionary_name, 91 String dictionary_name,
82 $Entry -> $Key1 compute_key1, 92 $Entry -> $Key1 compute_key1,
83 - $Entry -> $Key2 compute_key2 93 + $Entry -> $Key2 compute_key2,
  94 + $Entry empty_entry
84 ). 95 ).
85 96
86 97
87 98
88 99
89 - *** (2) Getting the size of a dictionary (number of non empty entries): 100 + *** (2) Getting the size of a dictionary (number of non empty entries).
90 101
91 Dictionaries are always filled up from slot 0. Free slots are above the most recently 102 Dictionaries are always filled up from slot 0. Free slots are above the most recently
92 filled up one. The next functions return the number of filled up (non empty) entries. 103 filled up one. The next functions return the number of filled up (non empty) entries.
@@ -128,10 +139,11 @@ public define One @@ -128,10 +139,11 @@ public define One
128 139
129 140
130 141
  142 +
131 143
132 *** (4) Adding entries to a dictionary. 144 *** (4) Adding entries to a dictionary.
133 145
134 - One may add a new entry to a dictionary, using the following tools: 146 + We can add a new entry to a dictionary, using the following tools:
135 147
136 public define One 148 public define One
137 add_entry 149 add_entry
@@ -154,18 +166,18 @@ public define One @@ -154,18 +166,18 @@ public define One
154 166
155 *** (5) Getting entries from a dictionary. 167 *** (5) Getting entries from a dictionary.
156 168
157 - Entries may be got by id or by key. If an entry is got by id, it is unique or does'nt  
158 - exist, hence a result of type 'Maybe($Entry)'. If it is got by key, the number of  
159 - entries is arbitrary (including 0), hence a result of type 'List($Entry)'. 169 + Entries may be got by id or by key. If an entry is got by id, it is unique (and must
  170 + exist), hence a result of type '$Entry'. If it is got by key, the number of entries is
  171 + arbitrary (including 0), hence a result of type 'List($Entry)'.
160 172
161 -public define Maybe($Entry) 173 +public define $Entry
162 get_entry 174 get_entry
163 ( 175 (
164 Dictionary1($Entry,$Key1) dictionary, 176 Dictionary1($Entry,$Key1) dictionary,
165 Int32 id 177 Int32 id
166 ). 178 ).
167 179
168 -public define Maybe($Entry) 180 +public define $Entry
169 get_entry 181 get_entry
170 ( 182 (
171 Dictionary2($Entry,$Key1,$Key2) dictionary, 183 Dictionary2($Entry,$Key1,$Key2) dictionary,
@@ -199,8 +211,8 @@ public define List($Entry) @@ -199,8 +211,8 @@ public define List($Entry)
199 *** (6) Saving a dictionary. 211 *** (6) Saving a dictionary.
200 212
201 The dictionary is saved in the current directory in the sens of the host system, 213 The dictionary is saved in the current directory in the sens of the host system,
202 - i.e. in the directory from where the compiler has been started. The name of the file is  
203 - the name of the dictionary, with the extension ".dictionary" appended. 214 + i.e. in the directory the compiler has been started from. The name of the file is the
  215 + name of the dictionary, with the extension ".dictionary" appended.
204 216
205 public define One 217 public define One
206 save 218 save
@@ -223,9 +235,9 @@ public define One @@ -223,9 +235,9 @@ public define One
223 235
224 When a dictionary is retrieved at the beginning of a new compilation, source modules 236 When a dictionary is retrieved at the beginning of a new compilation, source modules
225 may have changed since the last compilation. Hence, some entries in the dictionary may 237 may have changed since the last compilation. Hence, some entries in the dictionary may
226 - be obsolete. For this reason, we must provide a function for dicarding or updating an  
227 - entry. This has the effect of renumbering the entries. The correspondance between old  
228 - ids and new ids is given by a datum of type 'Renumbering($Entry)'. 238 + be obsolete. For this reason, we must provide a function for dicarding obsolete
  239 + entries. This has the effect of renumbering the entries. The correspondance between
  240 + old ids and new ids is given by a datum of type 'Renumbering($Entry)'.
229 241
230 public type Renumbering($Entry):... 242 public type Renumbering($Entry):...
231 243
@@ -239,7 +251,8 @@ public define Renumbering($Entry) @@ -239,7 +251,8 @@ public define Renumbering($Entry)
239 Int32 number_of_entries 251 Int32 number_of_entries
240 ). 252 ).
241 253
242 - The next tool gives the size (number of old ids) in a renumbering. 254 + The next tool gives the size (number of old ids, including those which have no
  255 + corresponding new id) in a renumbering.
243 256
244 public define Int32 257 public define Int32
245 size 258 size
@@ -250,17 +263,17 @@ public define Int32 @@ -250,17 +263,17 @@ public define Int32
250 263
251 264
252 For getting a new id knowing the old id, we use one of the following, depending on the 265 For getting a new id knowing the old id, we use one of the following, depending on the
253 - fact that we knwo that the new id exists or not. 266 + fact that we know that the new id exists or not.
254 267
255 public define Int32 268 public define Int32
256 - new_id 269 + new_id // if we know that the new id exists
257 ( 270 (
258 Renumbering($Entry) renumbering, 271 Renumbering($Entry) renumbering,
259 Int32 old_id 272 Int32 old_id
260 ). 273 ).
261 274
262 public define Maybe(Int32) 275 public define Maybe(Int32)
263 - maybe_new_id 276 + maybe_new_id // if we don't know if the new id exists
264 ( 277 (
265 Renumbering($Entry) renumbering, 278 Renumbering($Entry) renumbering,
266 Int32 old_id 279 Int32 old_id
@@ -286,7 +299,8 @@ public define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry))) @@ -286,7 +299,8 @@ public define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry)))
286 Int32 bits_of_hash, 299 Int32 bits_of_hash,
287 String name, 300 String name,
288 $Entry -> $Key compute_key, 301 $Entry -> $Key compute_key,
289 - $Entry -> KeepOrDiscard discard 302 + $Entry -> KeepOrDiscard discard,
  303 + $Entry empty_entry
290 ). 304 ).
291 305
292 public define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry))) 306 public define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry)))
@@ -296,12 +310,13 @@ public define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry))) @@ -296,12 +310,13 @@ public define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry)))
296 String name, 310 String name,
297 $Entry -> $Key1 compute_key1, 311 $Entry -> $Key1 compute_key1,
298 $Entry -> $Key2 compute_key2, 312 $Entry -> $Key2 compute_key2,
299 - $Entry -> KeepOrDiscard discard 313 + $Entry -> KeepOrDiscard discard,
  314 + $Entry empty_entry
300 ). 315 ).
301 316
302 A result of 'failure' means that some problem has been encountered, and that the 317 A result of 'failure' means that some problem has been encountered, and that the
303 dictionary must be regenerated. Otherwise, we get the retrieved dictionary together 318 dictionary must be regenerated. Otherwise, we get the retrieved dictionary together
304 - with the correponding 'Renumbering($Entry)'. 319 + with the correponding 'Renumbering'.
305 320
306 Dictionaries usually depend on each other. For example, an entry in the dictionary of 321 Dictionaries usually depend on each other. For example, an entry in the dictionary of
307 types contains references by id to entries in the dictionary of modules. When all 322 types contains references by id to entries in the dictionary of modules. When all
@@ -321,6 +336,24 @@ read tools/basis.anubis @@ -321,6 +336,24 @@ read tools/basis.anubis
321 336
322 ----------------------------------- Table of Contents --------------------------------- 337 ----------------------------------- Table of Contents ---------------------------------
323 338
  339 + *** [1] Dictionaries.
  340 + *** [2] Creating a dictionary.
  341 + *** [3] Updating all entries in a dictionary.
  342 + *** [4] Adding an entry to the dictionary.
  343 + *** [5] Getting an entry from a dictionary.
  344 + *** [5.1] Getting an entry by id.
  345 + *** [5.2] Getting the list of ids associated to a key.
  346 + *** [5.3] Getting an entry by key.
  347 + *** [6] Saving a dictionary.
  348 + *** [6.1] Writing bytes.
  349 + *** [6.2] Saving all entries.
  350 + *** [6.3] Saving the whole dictionary.
  351 + *** [7] Retrieving a dictionary.
  352 + *** [7.1] Renumberings.
  353 + *** [7.2] Reading a given number of bytes.
  354 + *** [7.3] Retrieving a single entry.
  355 + *** [7.4] Retrieving a whole dictionary.
  356 + *** [7.5] The two interfaces.
324 357
325 --------------------------------------------------------------------------------------- 358 ---------------------------------------------------------------------------------------
326 359
@@ -341,17 +374,18 @@ public type Dictionary1($Entry,$Key1): @@ -341,17 +374,18 @@ public type Dictionary1($Entry,$Key1):
341 374
342 The reason why 'main_table' has a double level of 'Var' is that we must first be able 375 The reason why 'main_table' has a double level of 'Var' is that we must first be able
343 to add an entry (this is enabled by the 'MVar'), and also to change the whole table 376 to add an entry (this is enabled by the 'MVar'), and also to change the whole table
344 - when it needs to be enlarged (this is enabled by the 'Var'). Of course, since an entry  
345 - may be 'empty', we use 'Maybe($Entry)' instead of '$Entry'.  
346 -  
347 - 'next' is the position of the next free (empty) slot in the table. The main table is  
348 - always filled up from the bottom, and an entry is never discarded. 377 + when it needs to be enlarged (this is enabled by the 'Var'). '*next' is the position
  378 + of the next free (empty) slot in the table. The main table is always filled up from the
  379 + bottom, and an entry is never discarded. All slots starting at index '*next' are
  380 + 'empty'. Actually they are filled up with a default 'empty entry'.
349 381
350 'index1' is a 'hashtable'. The size of the table is '2^b' where 'b' is the given number 382 'index1' is a 'hashtable'. The size of the table is '2^b' where 'b' is the given number
351 of bits of hash. In each slot, we have a (usually small) association list, giving the 383 of bits of hash. In each slot, we have a (usually small) association list, giving the
352 correspondance between a key and the list of corresponding ids. 384 correspondance between a key and the list of corresponding ids.
353 385
354 386
  387 + The same one with 2 keys:
  388 +
355 public type Dictionary2($Entry,$Key1,$Key2): 389 public type Dictionary2($Entry,$Key1,$Key2):
356 dict 390 dict
357 ( 391 (
@@ -438,23 +472,25 @@ public define Int32 @@ -438,23 +472,25 @@ public define Int32
438 472
439 473
440 474
441 - *** [] Updating all entries in a dictionary. 475 + *** [3] Updating all entries in a dictionary.
442 476
443 define One 477 define One
444 update_all_entries // auxiliary function 478 update_all_entries // auxiliary function
445 ( 479 (
446 MVar(Maybe($Entry)) table, 480 MVar(Maybe($Entry)) table,
447 $Entry -> $Entry method, 481 $Entry -> $Entry method,
448 - Int32 i // increasing index 482 + Int32 i, // increasing index
  483 + Int32 next // number of non empty entries
449 ) = 484 ) =
450 - if i >= length(table) then unique else // end of the table 485 + if i >= next then unique else
451 if *table(i) is 486 if *table(i) is
452 { 487 {
453 - failure then unique, // end of the table 488 + failure then unique,
454 success(entry) then 489 success(entry) then
455 table(i) <- success(method(entry)); 490 table(i) <- success(method(entry));
456 - update_all_entries(table,method,i+1) 491 + update_all_entries(table,method,i+1,next)
457 }. 492 }.
  493 +
458 494
459 public define One 495 public define One
460 update_all_entries 496 update_all_entries
@@ -463,8 +499,9 @@ public define One @@ -463,8 +499,9 @@ public define One
463 $Entry -> $Entry method 499 $Entry -> $Entry method
464 ) = 500 ) =
465 if dictionary is dict(name,main_tab,next,idx,ckey,hkey) then 501 if dictionary is dict(name,main_tab,next,idx,ckey,hkey) then
466 - update_all_entries(*main_tab,method,0). 502 + update_all_entries(*main_tab,method,0,*next).
467 503
  504 +
468 public define One 505 public define One
469 update_all_entries 506 update_all_entries
470 ( 507 (
@@ -476,7 +513,7 @@ public define One @@ -476,7 +513,7 @@ public define One
476 513
477 514
478 515
479 - *** [3] Adding an entry to the dictionary. 516 + *** [4] Adding an entry to the dictionary.
480 517
481 First we have auxiliary functions for updating the index. The first one adds an index 518 First we have auxiliary functions for updating the index. The first one adds an index
482 entry into a A-list with the index. 519 entry into a A-list with the index.
@@ -557,13 +594,47 @@ public define One @@ -557,13 +594,47 @@ public define One
557 594
558 595
559 596
560 - *** [4] Getting an entry from a dictionary. 597 + *** [5] Getting an entry from a dictionary.
  598 +
  599 +
  600 +
  601 +
  602 + *** [5.1] Getting an entry by id.
  603 +
  604 +public define $Entry
  605 + get_entry
  606 + (
  607 + Dictionary1($Entry,$Key1) dictionary,
  608 + Int32 id
  609 + ) =
  610 + if dictionary is dict(name,main_tab,next,idx,ckey,hkey) then
  611 + if *(*main_tab)(id) is
  612 + {
  613 + failure then alert,
  614 + success(entry) then entry
  615 + }.
  616 +
  617 +
  618 +public define $Entry
  619 + get_entry
  620 + (
  621 + Dictionary2($Entry,$Key1,$Key2) dictionary,
  622 + Int32 id
  623 + ) =
  624 + if dictionary is dict(name,main_tab,next,idx1,idx2,ckey1,ckey2,hkey1,hkey2) then
  625 + if *(*main_tab)(id) is
  626 + {
  627 + failure then alert,
  628 + success(entry) then entry
  629 + }.
  630 +
  631 +
561 632
562 633
563 - *** [4.1] Tools. 634 + *** [5.2] Getting the list of ids associated to a key.
564 635
565 - This tool ('get_ids_from_index') retrieves the list of ids associated with a key, using  
566 - an index. 636 + The tool 'get_ids_from_index' retrieves the list of ids associated with a key, using an
  637 + index.
567 638
568 define List($U) 639 define List($U)
569 assoc 640 assoc
@@ -592,31 +663,7 @@ define List(Int32) @@ -592,31 +663,7 @@ define List(Int32)
592 663
593 664
594 665
595 -  
596 - *** [4.2] Getting an entry by id.  
597 -  
598 -public define Maybe($Entry)  
599 - get_entry  
600 - (  
601 - Dictionary1($Entry,$Key1) dictionary,  
602 - Int32 id  
603 - ) =  
604 - if dictionary is dict(name,main_tab,next,idx,ckey,hkey) then  
605 - *(*main_tab)(id).  
606 -  
607 -  
608 -public define Maybe($Entry)  
609 - get_entry  
610 - (  
611 - Dictionary2($Entry,$Key1,$Key2) dictionary,  
612 - Int32 id  
613 - ) =  
614 - if dictionary is dict(name,main_tab,next,idx1,idx2,ckey1,ckey2,hkey1,hkey2) then  
615 - *(*main_tab)(id).  
616 -  
617 -  
618 -  
619 - *** [4.3] Getting an entry by key. 666 + *** [5.3] Getting an entry by key.
620 667
621 'map_select' is defined in 'tools/basis.anubis'. 668 'map_select' is defined in 'tools/basis.anubis'.
622 669
@@ -660,7 +707,7 @@ public define List($Entry) @@ -660,7 +707,7 @@ public define List($Entry)
660 707
661 708
662 709
663 - *** [5] Saving a dictionary. 710 + *** [6] Saving a dictionary.
664 711
665 Dictionaries are saved as follows into the file 'name.dictionary', where 'name' is the 712 Dictionaries are saved as follows into the file 'name.dictionary', where 'name' is the
666 name of the dictionary: 713 name of the dictionary:
@@ -673,10 +720,12 @@ public define List($Entry) @@ -673,10 +720,12 @@ public define List($Entry)
673 720
674 721
675 722
676 - *** [5.1] Writing bytes. 723 + *** [6.1] Writing bytes.
677 724
678 The tool below writes all bytes of the given 'ByteArray' into the given file (recall 725 The tool below writes all bytes of the given 'ByteArray' into the given file (recall
679 - that 'write' may not write all bytes; see predefined.anubis). 726 + that 'write' may not write all bytes; see predefined.anubis). If some problem arises,
  727 + there is just nothing to do, because the file will be inconsistant and at the next
  728 + compilation the dictionary will be regenerated.
680 729
681 define One 730 define One
682 write_all_bytes 731 write_all_bytes
@@ -695,7 +744,7 @@ define One @@ -695,7 +744,7 @@ define One
695 744
696 745
697 746
698 - *** [5.2] Saving all entries. 747 + *** [6.2] Saving all entries.
699 748
700 The next function saves all entries (the number of entries is already saved). 749 The next function saves all entries (the number of entries is already saved).
701 750
@@ -719,7 +768,7 @@ define One @@ -719,7 +768,7 @@ define One
719 768
720 769
721 770
722 - *** [5.3] Saving the whole dictionary. 771 + *** [6.3] Saving the whole dictionary.
723 772
724 The next function saves the whole dictionary. 773 The next function saves the whole dictionary.
725 774
@@ -764,25 +813,27 @@ public define One @@ -764,25 +813,27 @@ public define One
764 813
765 814
766 815
767 - *** [6] Retrieving a dictionary. 816 + *** [7] Retrieving a dictionary.
768 817
769 818
770 - *** [6.1] Renumberings. 819 + *** [7.1] Renumberings.
771 820
772 public type Renumbering($Entry): 821 public type Renumbering($Entry):
773 renum(MVar(Int32)). 822 renum(MVar(Int32)).
774 823
775 As one may see, the parameter $Entry is not used. However, it enhances the safety, 824 As one may see, the parameter $Entry is not used. However, it enhances the safety,
776 - because it becomes it links the renumbering to a specific type. Since all dictionaries  
777 - have distinct types, it becomes impossible to use one renumbering instead of another  
778 - one. 825 + because it links the renumbering to a specific type. Since all dictionaries have
  826 + distinct types, it becomes impossible to use one renumbering instead of another one.
779 827
780 By convention, within a 'Renumbering', 0 represents an invalid id, and each valid id, 828 By convention, within a 'Renumbering', 0 represents an invalid id, and each valid id,
781 - say 'n' is represented as 'n+1'. 829 + say 'n' is represented as 'n+1'. It would have been cleaner to use 'Maybe(Int32)'
  830 + instead of 'Int32', not using this trick. However, the trick is encapsulated into this
  831 + section, and needs not be known from the outside. Using 'Int32' is better for
  832 + performances, because 'Maybe(Int32)' is implemented as a 'mixed' type.
782 833
783 834
784 public define Int32 835 public define Int32
785 - new_id 836 + new_id // when we are sure the new id exists
786 ( 837 (
787 Renumbering($Entry) renumbering, 838 Renumbering($Entry) renumbering,
788 Int32 old_id 839 Int32 old_id
@@ -796,7 +847,7 @@ public define Int32 @@ -796,7 +847,7 @@ public define Int32
796 else val - 1. 847 else val - 1.
797 848
798 public define Maybe(Int32) 849 public define Maybe(Int32)
799 - maybe_new_id 850 + maybe_new_id // when we are not sure the new id exists
800 ( 851 (
801 Renumbering($Entry) renumbering, 852 Renumbering($Entry) renumbering,
802 Int32 old_id 853 Int32 old_id
@@ -844,7 +895,7 @@ public define Int32 @@ -844,7 +895,7 @@ public define Int32
844 895
845 896
846 897
847 - *** [6.2] Reading a given number of bytes. 898 + *** [7.2] Reading a given number of bytes.
848 899
849 Reading exactly 'n' bytes from a file (this may fail of course). 900 Reading exactly 'n' bytes from a file (this may fail of course).
850 901
@@ -877,7 +928,7 @@ define Maybe(ByteArray) @@ -877,7 +928,7 @@ define Maybe(ByteArray)
877 928
878 929
879 930
880 - *** [6.3] Retrieving a single entry. 931 + *** [7.3] Retrieving a single entry.
881 932
882 For retrieving an entry we must: 933 For retrieving an entry we must:
883 934
@@ -921,7 +972,7 @@ define Maybe($Entry) @@ -921,7 +972,7 @@ define Maybe($Entry)
921 972
922 973
923 974
924 - *** [6.4] Retrieving a whole dictionary. 975 + *** [7.4] Retrieving a whole dictionary.
925 976
926 When calling this auxiliary function, the number of entries has already been read, and 977 When calling this auxiliary function, the number of entries has already been read, and
927 the dictionary is already created and empty (partially filled up for recursive calls). 978 the dictionary is already created and empty (partially filled up for recursive calls).
@@ -974,15 +1025,15 @@ define Maybe(($Dict,Renumbering($Entry))) @@ -974,15 +1025,15 @@ define Maybe(($Dict,Renumbering($Entry)))
974 1025
975 1026
976 1027
977 - The two interfaces: 1028 + *** [7.5] The two interfaces.
978 1029
979 -define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry)))  
980 - retrieve_dict 1030 +public define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry)))
  1031 + retrieve_dictionary
981 ( 1032 (
982 Int32 bits_of_hash, 1033 Int32 bits_of_hash,
983 String name, 1034 String name,
984 $Entry -> $Key compute_key, 1035 $Entry -> $Key compute_key,
985 - $Entry -> KeepOrDiscard discard 1036 + $Entry -> KeepOrDiscard discard
986 ) = 1037 ) =
987 with file_name = name+".dictionary", 1038 with file_name = name+".dictionary",
988 if file(file_name,read) is 1039 if file(file_name,read) is
@@ -1009,14 +1060,14 @@ define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry))) @@ -1009,14 +1060,14 @@ define Maybe((Dictionary1($Entry,$Key),Renumbering($Entry)))
1009 }. 1060 }.
1010 1061
1011 1062
1012 -define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry)))  
1013 - retrieve_dict 1063 +public define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry)))
  1064 + retrieve_dictionary
1014 ( 1065 (
1015 Int32 bits_of_hash, 1066 Int32 bits_of_hash,
1016 String name, 1067 String name,
1017 $Entry -> $Key1 compute_key1, 1068 $Entry -> $Key1 compute_key1,
1018 $Entry -> $Key2 compute_key2, 1069 $Entry -> $Key2 compute_key2,
1019 - $Entry -> KeepOrDiscard discard 1070 + $Entry -> KeepOrDiscard discard
1020 ) = 1071 ) =
1021 with file_name = name+".dictionary", 1072 with file_name = name+".dictionary",
1022 if file(file_name,read) is 1073 if file(file_name,read) is
@@ -1035,7 +1086,8 @@ define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry))) @@ -1035,7 +1086,8 @@ define Maybe((Dictionary2($Entry,$Key1,$Key2),Renumbering($Entry)))
1035 0, // initial old_id 1086 0, // initial old_id
1036 0, // initial new_id 1087 0, // initial new_id
1037 discard, 1088 discard,
1038 - create_dictionary(bits_of_hash,name,compute_key1,compute_key2), 1089 + create_dictionary(bits_of_hash,name,
  1090 + compute_key1,compute_key2),
1039 add_entry, 1091 add_entry,
1040 create_renumbering(number_of_entries)) 1092 create_renumbering(number_of_entries))
1041 } 1093 }
anubis_dev/compiler2/src/memory_1.anubis
@@ -27,6 +27,7 @@ read tools/basis.anubis @@ -27,6 +27,7 @@ read tools/basis.anubis
27 read tools/streams.anubis 27 read tools/streams.anubis
28 read common.anubis 28 read common.anubis
29 read dictionary_1.anubis 29 read dictionary_1.anubis
  30 +read src_files_1.anubis
30 31
31 32
32 ----------------------------------- Table of Contents --------------------------------- 33 ----------------------------------- Table of Contents ---------------------------------
@@ -151,7 +152,8 @@ public type State: @@ -151,7 +152,8 @@ public type State:
151 ( 152 (
152 List(Option) options, 153 List(Option) options,
153 Dictionaries dictionaries, 154 Dictionaries dictionaries,
154 - Var(List(OpenModule)) read_stack 155 + Var(List(OpenModule)) read_stack,
  156 + List(List(String)) read_paths
155 ). 157 ).
156 158
157 159
@@ -522,7 +524,7 @@ public define One @@ -522,7 +524,7 @@ public define One
522 ( 524 (
523 State state 525 State state
524 ) = 526 ) =
525 - if state is cstate(options,dictionaries,read_stack) then 527 + if state is cstate(options,dictionaries,read_stack,read_paths) then
526 save(dictionaries). 528 save(dictionaries).
527 529
528 530
@@ -557,6 +559,16 @@ define List(Int32) @@ -557,6 +559,16 @@ define List(Int32)
557 559
558 Create an 'empty' state: 560 Create an 'empty' state:
559 561
  562 +define List(List(String))
  563 + get_read_paths
  564 + =
  565 + [
  566 + split_path(get_current_directory),
  567 + split_path(my_anubis_directory),
  568 + split_path(anubis_directory)
  569 + ].
  570 +
  571 +
560 define State 572 define State
561 new_state 573 new_state
562 ( 574 (
@@ -570,7 +582,9 @@ define State @@ -570,7 +582,9 @@ define State
570 create_dictionary(12, dat_dict_name,name), 582 create_dictionary(12, dat_dict_name,name),
571 create_dictionary(12, thm_dict_name,pattern) 583 create_dictionary(12, thm_dict_name,pattern)
572 ), 584 ),
573 - var([])). 585 + var([]),
  586 + get_read_paths
  587 + ).
574 588
575 589
576 590
@@ -837,7 +851,8 @@ public define State @@ -837,7 +851,8 @@ public define State
837 update_thm_dictionary(thm_dict,mod_renum,typ_renum,dat_renum); 851 update_thm_dictionary(thm_dict,mod_renum,typ_renum,dat_renum);
838 cstate(options, 852 cstate(options,
839 dictionaries(mod_dict,typ_dict,dat_dict,thm_dict), 853 dictionaries(mod_dict,typ_dict,dat_dict,thm_dict),
840 - var([])) 854 + var([]),
  855 + get_read_paths)
841 }. 856 }.
842 857
843 858
anubis_dev/compiler2/src/shift_replace_2.anubis 0 → 100644
  1 +
  2 +
  3 + _____ ___. .__ ________
  4 + / _ \ ____ __ _\_ |__ |__| ______ \_____ \
  5 + / /_\ \ / \| | \ __ \| |/ ___/ / ____/
  6 + / | \ | \ | / \_\ \ |\___ \ / \
  7 + \____|__ /___| /____/|___ /__/____ > \_______ \
  8 + \/ The \/ Anubis \/ 2 \/ Project \/
  9 +
  10 +
  11 + Name of this file: shift_replace_2.anubis
  12 +
  13 + Purpose of this file: Tools for shifting strong items and replacing de Bruijn
  14 + symbols in strong items.
  15 +
  16 +
  17 +
  18 + Authors (Name [initials]): Alain Proute' [AP]
  19 +
  20 + Updates ([initials] (date) comment):
  21 + [AP] (2007 jul 04) Creation of this file.
  22 +
  23 + ---------------------------------------------------------------------------------------
  24 +
  25 +read common.anubis
  26 +
  27 +
  28 + There two fundamental operations we must be able to perform on strong items (strong
  29 + terms and strong types). They are named 'shifting' and 'replacing'.
  30 +
  31 +
  32 +
  33 + *** (1) Shifting.
  34 +
  35 + A strong item contains occurrences of 'de Bruijn symbols'. These symbols represent
  36 + depths into the stack of the virtual machine. It is sometimes necessary to 'shift' a
  37 + strong item by a certain number, say 'n'. The result is meaningful relative to any
  38 + extention of the original stack obtained by pushing 'n' data on top of the
  39 + stack. Notice that the stack is heterogeneous, which means that the slots in the stack
  40 + do not have the same size. Their size depends only of the type of the content of the
  41 + slot.
  42 +
  43 + For example, if 'E' is statement (strong term of type 'Omega'), meaningful relative to
  44 + some strong context 'G' (representing the stack), the result of shifting 'E' by '1' is
  45 + meaningful relative to any strong context of the form '[T . G]', where 'T' is any type.
  46 +
  47 +public define StrongType shift(Int32 n, StrongType t).
  48 +public define StrongTerm shift(Int32 n, StrongTerm t).
  49 +
  50 + Actually, the operation of shifting by 'n' just amounts to add 'n' to all depths
  51 + encountered in the strong item.
  52 +
  53 +
  54 +
  55 +
  56 + *** (2) Replacing.
  57 +
  58 + Given a strong item 'E', we may need to replace all occurences of a given de Bruijn
  59 + symbol by a given strong term. The result of replacing all occurrences of the de Bruijn
  60 + symbol 'x' by the strong term 'a' in a strong item 'E' is generally denoted 'E[a/x]' by
  61 + logicians (read: 'E' within which 'a' replaces 'x'). The strong item 'E[a/x]' is
  62 + represented in this compiler by 'replace(E,a,x)'.
  63 +
  64 +public define StrongType replace(StrongType t, StrongTerm a, Int32 i).
  65 +public define StrongTerm replace(StrongTerm t, StrongTerm a, Int32 i).
  66 +
  67 + Notice hat 'E[a/x]' is meaningful relative to the same strong context as 'E'.
  68 +
  69 +
  70 +
  71 + --- That's all for the public part ! --------------------------------------------------
  72 +
  73 +
  74 +
  75 + Shifting a strong type.
  76 +
  77 +public define StrongType
  78 + shift
  79 + (
  80 + Int32 n,
  81 + StrongType t
  82 + ) =
  83 + if t is
  84 + {
  85 + _Parameter(String name) then
  86 + t,
  87 +
  88 + _Defined(Int32 type_id,List(StrongType) operands) then
  89 + _Defined(type_id,
  90 + map((StrongType st) |-> shift(n,st),
  91 + operands)),
  92 +
  93 + _Product(List(StrongType) l) then
  94 + _Product(map((StrongType st) |-> shift(n,st),
  95 + l)),
  96 +
  97 + _Functional(StrongType source,StrongType target) then
  98 + _Functional(shift(n,source),shift(n,target)),
  99 +
  100 + _Omega then
  101 + _Omega,
  102 +
  103 + _Witness(StrongTerm statement) then
  104 + _Witness(shift(n,statement)),
  105 +
  106 + _Quantified(String parameter,StrongType _T) then
  107 + _Quantified(parameter,shift(n,_T))
  108 + }.
  109 +
  110 +
  111 +
  112 + Shifting a strong term. 'n' is added to a depth at the unique place where depths are
  113 + found, i.e. in the alternative 'symbol'. Furthermore, shifting the declarative terms
  114 + 'lambda(...)' and 'forall(...)' requires a replacement because the symbol 'symbol(0)'
  115 + must not be shifted (the replacement 'undoes' the shifting for this symbol).
  116 +
  117 +public define StrongTerm
  118 + shift
  119 + (
  120 + Int32 n,
  121 + StrongTerm t
  122 + ) =
  123 + if t is
  124 + {
  125 + global(Int32 id) then
  126 + global(id),
  127 +
  128 + symbol(Int32 depth) then
  129 + symbol(depth + n),
  130 +
  131 + tuple(List(StrongTerm) l) then
  132 + tuple(map((StrongTerm st) |-> shift(n,st),l)),
  133 +
  134 + proj(Int32 i,StrongTerm st) then
  135 + proj(i,shift(n,st)),
  136 +
  137 + incl(StrongType _T,Int32 i,StrongTerm st) then
  138 + incl(shift(n,_T),i,shift(n,st)),
  139 +
  140 + cond(StrongType _T,StrongTerm test,List(StrongTerm) cases) then
  141 + cond(shift(n,_T),shift(n,test),
  142 + map((StrongTerm st) |-> shift(n,st),cases)),
  143 +
  144 + lambda(StrongType _T,StrongTerm st) then
  145 + lambda(shift(n,_T),replace(shift(n,st),symbol(0),n)),
  146 +
  147 + app(StrongTerm f,StrongTerm a) then
  148 + app(shift(n,f),shift(n,a)),
  149 +
  150 + forall(StrongType _T,StrongTerm _E) then
  151 + forall(shift(n,_T),replace(shift(n,_E),symbol(0),n)),
  152 +
  153 + description(StrongTerm p) then
  154 + description(shift(n,p)),
  155 +
  156 + property(StrongTerm p) then
  157 + property(shift(n,p)),
  158 +
  159 + choice(StrongTerm p) then
  160 + choice(shift(n,p)),
  161 +
  162 + parametric(String parameter,StrongTerm st) then
  163 + parametric(parameter,shift(n,st)),
  164 +
  165 + parametric_app(StrongTerm st,StrongType _T) then
  166 + parametric_app(shift(n,st),shift(n,_T))
  167 + }.
  168 +
  169 +
  170 +
  171 + *** [] Replacement in strong types.
  172 +
  173 + _Parameter(N)[a/i] is _Parameter(N)
  174 + _Defined(N,T_1,...,T_k)[a/i] is _Defined(N,T_1[a/i],...,T_k[a/i])
  175 + _Product(T_1,...,T_k)[a/i] is _Product(T_1[a/i],...,T_k[a/i])
  176 + _Functional(T,U)[a/i] is _Functional(T[a/i],U[a/i+1])
  177 + _Omega[a/i] is _Omega
  178 + _Witness(E)[a/i] is _Witness(E[a/i])
  179 + _Quantified($X T)[a/i] is _Quantified($X T[a/i])
  180 +
  181 +
  182 +public define StrongType
  183 + replace // computes 't[a/s(i)]'
  184 + (
  185 + StrongType t,
  186 + StrongTerm a,
  187 + Int32 i
  188 + ) =
  189 + if t is
  190 + {
  191 + _Parameter(String name) then
  192 + t,
  193 +
  194 + _Defined(Int32 type_id,List(StrongType) operands) then
  195 + _Defined(type_id,
  196 + map((StrongType st) |-> replace(st,a,i),
  197 + operands)),
  198 +
  199 + _Product(List(StrongType) l) then
  200 + _Product(map((StrongType st) |-> replace(st,a,i),l)),
  201 +
  202 + _Functional(StrongType source,StrongType target) then
  203 + _Functional(replace(source,a,i),replace(target,a,i+1)),
  204 +
  205 + _Omega then
  206 + _Omega,
  207 +
  208 + _Witness(StrongTerm statement) then
  209 + _Witness(replace(statement,a,i)),
  210 +
  211 + _Quantified(String parameter,StrongType _T) then
  212 + _Quantified(parameter,replace(_T,a,i))
  213 + }.
  214 +
  215 +
  216 +
  217 +
  218 + *** [] Replacement in strong terms.
  219 +
  220 + global(n)[a/i] is global(n)
  221 + symbol(i)[a/i] is a
  222 + symbol(i)[a/j] is symbol(i) (if i != j)
  223 + tuple(t_1,...,t_k)[a/i] is tuple(t_1[a/i],...,t_k[a/i])
  224 + proj(n,t)[a/i] is proj(n,t[a/i])
  225 + incl(U,n,t)[a/i] is incl(U[a/i],n,t[a/i])
  226 + cond(T,t,c_1,...,c_k)[a/i] is cond(T[a/i],t[a/i],c_1[a/i],...,c_k[a/i])
  227 + lambda(T,E)[a/i] is lambda(T[a/i],E[a/i+1])
  228 + app(f,b)[a/i] is app(f[a/i],b[a/i])
  229 + forall(T,E)[a/i] is forall(T[a/i],E[a/i+1])
  230 + description(p)[a/i] is description(p[a/i])
  231 + property(p)[a/i] is property(p[a/i])
  232 + choice(p)[a/i] is choice(p[a/i])
  233 + parametric($X,t)[a/i] is parametric($X,t[a/i])
  234 + parametric_app(t,T)[a/i] is parametric_app(t[a/i],T[a/i])
  235 +
  236 +
  237 +public define StrongTerm
  238 + replace // computes 't[a/i]'
  239 + (
  240 + StrongTerm t,
  241 + StrongTerm a,
  242 + Int32 i
  243 + ) =
  244 + if t is
  245 + {
  246 + global(Int32 id) then
  247 + t,
  248 +
  249 + symbol(Int32 depth) then
  250 + if depth = i then a else t,
  251 +
  252 + tuple(List(StrongTerm) l) then
  253 + tuple(map((StrongTerm st) |-> replace(st,a,i),l)),
  254 +
  255 + proj(Int32 i,StrongTerm st) then
  256 + proj(i,replace(st,a,i)),
  257 +
  258 + incl(StrongType _T,Int32 j,StrongTerm st) then
  259 + incl(replace(_T,a,i),j,replace(st,a,i)),
  260 +
  261 + cond(StrongType _T,StrongTerm test,List(StrongTerm) cases) then
  262 + cond(replace(_T,a,i),replace(test,a,i),
  263 + map((StrongTerm c) |-> replace(c,a,i),cases)),
  264 +
  265 + lambda(StrongType _T,StrongTerm _E) then
  266 + lambda(replace(_T,a,i),replace(_E,a,i+1)),
  267 +
  268 + app(StrongTerm f,StrongTerm b) then
  269 + app(replace(f,a,i),replace(b,a,i)),
  270 +
  271 + forall(StrongType _T,StrongTerm _E) then
  272 + forall(replace(_T,a,i),replace(_E,a,i+1)),
  273 +
  274 + description(StrongTerm p) then
  275 + description(replace(p,a,i)),
  276 +
  277 + property(StrongTerm p) then
  278 + property(replace(p,a,i)),
  279 +
  280 + choice(StrongTerm p) then
  281 + choice(replace(p,a,i)),
  282 +
  283 + parametric(String parameter,StrongTerm st) then
  284 + parametric(parameter,replace(st,a,i)),
  285 +
  286 + parametric_app(StrongTerm st,StrongType _T) then
  287 + parametric_app(replace(st,a,i),replace(_T,a,i))
  288 + }.
  289 +
  290 +
  291 +
  292 +
  293 +
0 \ No newline at end of file 294 \ No newline at end of file