This can be used to control the lifetime of unique terms quite effectively, eg. to free intermediate results of a computation, as follows. First, a `temporary' hashtable is created to hold the intermediate results. Then, just before the computation is started, replace the default hashtable with the temporary one. When the computation is finished, the intermediate results and the final result are in the `temporary' hashtable. Re-assign the `old' hashtable, and copy the final result2, to re-create the memory cells belonging to the final result in the `old' hashtable. Finally, free the `temporary' hashtable.
Often only a limited number of phyla appears in the intermediate results. To allow more precise control, the phyla maintained under unique storage can be partitioned over multiple storage-classes, that each can have its own hashtable assigned. The memory cells created for a phylum are created in the hashtable assigned to the phylum's storage-class. Usually, phyla with a different `lifetime' will be in different storage classes. There is one predefined storage-class: uniq. Other storage-classes can be defined and used as follows:
Here ID2 and ID3 belong to different storage-classes; if different hashtables are assigned to intermediate and wholeprogram, then the memory cells for Operator1 and Operator2 will be in another hashtable than those for Operator3.
%storageclass intermediate wholeprogram; /* the `%' is part of the keyword */
ID2 { intermediate }: Operator1( ... ) | Operator2( ... ) | ... ; ID3 { wholeprogram }: Operator3( ... );
A phylum can be in only one storage class. The term processor reports an error if this condition is violated. The %storageclass declaration is optional; if Kimwitu input does contain a storage class declaration, errors will be reported for all storage classes that were not explicitly declared.
For each storage class, Kimwitu creates statically (at compile time) a hashtable. Dynamically, hashtables can be created, (re)assigned to one or more storage classes, cleared and freed. The hashtable functions are listed in Section 2.2.
If the default (statically allocated) hashtable is not used, ie. if all storage classes are reassigned to dynamically created hashtables before they are used, it is useful to redefine LARGEPRIME :
or use the -DLARGEPRIME=0 flag with cc during compilation of file k.c (see Section 2.5), to avoid the creation of the statically allocated hashtable.
%{ KC_TYPES_HEADER #define LARGEPRIME 0 %}