changes
[cdsspec-compiler.git] / grammer / spec.txt
1 /**
2 @Begin
3                 @Options:
4                         LANG = C;
5                         CLASS = cliffc_hashtable;
6                 @Global_define:
7                         @DeclareVar:
8                         spec_hashtable<TypeK, TypeV*> map;
9                         spec_hashtable<TypeK, Tag> id_map;
10                         Tag tag;
11                         @InitVar:
12                                 map = spec_hashtable<TypeK, TypeV*>();
13                                 id_map = spec_hashtable<TypeK, TypeV*>();
14                                 tag = Tag();
15                         @DefineFunc:
16                         static bool equals_val(TypeV *ptr1, TypeV *ptr2) {
17                                 // ...
18                         }
19                         
20                         # Update the tag for the current key slot if the corresponding tag
21                         # is NULL, otherwise just return that tag. It will update the next
22                         # available tag too if it requires a new tag for that key slot.
23                         static Tag getKeyTag(TypeK &key) {
24                                 if (id_map.get(key) == NULL) {
25                                         Tag cur_tag = tag.current();
26                                         id_map.put(key, cur_tag);
27                                         tag.next();
28                                         return cur_tag;
29                                 } else {
30                                         return id_map.get(key);
31                                 }
32                         }
33                 
34                 @Interface_cluster:
35                         Read_interface = {
36                                 Get,
37                                 PutIfAbsent,
38                                 RemoveAny,
39                                 RemoveIfMatch,
40                                 ReplaceAny,
41                                 ReplaceIfMatch
42                         }
43                         
44                         Write_interface = {
45                                 Put,
46                                 PutIfAbsent(COND_PutIfAbsentSucc),
47                                 RemoveAny,
48                                 RemoveIfMatch(COND_RemoveIfMatchSucc),
49                                 ReplaceAny,
50                                 ReplaceIfMatch(COND_ReplaceIfMatchSucc)
51                         }
52                 @Happens_before:
53                         Write_interface -> Read_interface
54                 @End
55         */