Changeset 32cab5b for doc/papers/general/evaluation/cfa-stack.c
- Timestamp:
- Apr 17, 2018, 12:01:09 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 3265399
- Parents:
- b2fe1c9 (diff), 81bb114 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/cfa-stack.c
rb2fe1c9 r32cab5b 2 2 #include "cfa-stack.h" 3 3 4 forall( otype T) struct stack_node {4 forall( otype T ) struct stack_node { 5 5 T value; 6 6 stack_node(T) * next; 7 7 }; 8 8 9 forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; } 9 forall( otype T ) void clear( stack(T) & s ) with( s ) { 10 for ( stack_node(T) * next = head; next; ) { 11 stack_node(T) * crnt = next; 12 next = crnt->next; 13 ^(*crnt){}; 14 free(crnt); 15 } 16 head = 0; 17 } 10 18 11 forall(otype T) void ?{}( stack(T) & s, stack(T) t ) { 19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; } 20 21 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) { 12 22 stack_node(T) ** crnt = &s.head; 13 23 for ( stack_node(T) * next = t.head; next; next = next->next ) { 14 stack_node(T)* new_node = (stack_node(T)*)malloc(); /***/ 15 (*new_node){ next->value }; 16 *crnt = new_node; 24 *crnt = alloc(); 25 ((*crnt)->value){ next->value }; 17 26 crnt = &(*crnt)->next; 18 27 } … … 20 29 } 21 30 22 forall( otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {31 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) { 23 32 if ( s.head == t.head ) return s; 24 33 clear( s ); … … 27 36 } 28 37 29 forall( otype T) void ^?{}( stack(T) & s) { clear( s ); }38 forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); } 30 39 31 forall( otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }40 forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; } 32 41 33 forall( otype T) void push( stack(T) & s, T value) {34 stack_node(T) * new_node = (stack_node(T)*)malloc(); /***/35 (*n ew_node){ value, s.head };36 s.head = new_node;42 forall( otype T ) void push( stack(T) & s, T value ) with( s ) { 43 stack_node(T) * n = alloc(); 44 (*n){ value, head }; 45 head = n; 37 46 } 38 47 39 forall( otype T) T pop( stack(T) &s ) {40 stack_node(T) * n = s.head;41 s.head = n->next;48 forall( otype T ) T pop( stack(T) & s ) with( s ) { 49 stack_node(T) * n = head; 50 head = n->next; 42 51 T v = n->value; 43 52 ^(*n){}; … … 45 54 return v; 46 55 } 47 48 forall(otype T) void clear( stack(T) & s ) {49 for ( stack_node(T) * next = s.head; next; ) {50 stack_node(T) * crnt = next;51 next = crnt->next;52 ^(*crnt){};53 free(crnt);54 }55 s.head = 0;56 }
Note:
See TracChangeset
for help on using the changeset viewer.