Changeset 000ff2c for doc/papers/general/evaluation/cfastack.c
 Timestamp:
 Mar 2, 2018, 6:22:52 PM (6 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 2097cd4, 82c367d
 Parents:
 938dd75 (diff), c9b3a41 (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/cfastack.c
r938dd75 r000ff2c 4 4 forall(otype T) struct stack_node { 5 5 T value; 6 stack_node(T) * next;6 stack_node(T) * next; 7 7 }; 8 forall(otype T) void ?{}( stack_node(T) & node, T value, stack_node(T) * next ) { 9 node.value = value; 10 node.next = next; 11 } 8 12 9 forall(otype T) void ?{}( stack(T)& s) { (s.head){ 0 }; }13 forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; } 10 14 11 forall(otype T) void ?{}( stack(T)& s, stack(T) t) {12 stack_node(T) ** crnt = &s.head;13 for ( stack_node(T) * next = t.head; next; next = next>next ) {14 // *crnt = &(*(stack_node(T)*)malloc()){ next>value }; /***/15 forall(otype T) void ?{}( stack(T) & s, stack(T) t ) { 16 stack_node(T) ** crnt = &s.head; 17 for ( stack_node(T) * next = t.head; next; next = next>next ) { 18 // *crnt = new( next>value, 0 ); 15 19 stack_node(T)* new_node = ((stack_node(T)*)malloc()); 16 20 (*new_node){ next>value }; /***/ 17 21 *crnt = new_node; 18 19 stack_node(T)* acrnt = *crnt; 22 stack_node(T) * acrnt = *crnt; 20 23 crnt = &acrnt>next; 21 24 } … … 23 26 } 24 27 25 forall(otype T) stack(T) ?=?( stack(T)& s, stack(T) t) {28 forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) { 26 29 if ( s.head == t.head ) return s; 27 clear( s);30 clear( s ); 28 31 s{ t }; 29 32 return s; 30 33 } 31 34 32 forall(otype T) void ^?{}( stack(T)& s) { clear(s); }35 forall(otype T) void ^?{}( stack(T) & s) { clear( s ); } 33 36 34 forall(otype T) _Bool empty( const stack(T)& s) { return s.head == 0; }37 forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; } 35 38 36 forall(otype T) void push( stack(T)& s, T value) {37 // s.head = &(*(stack_node(T)*)malloc()){ value, s.head }; /***/39 forall(otype T) void push( stack(T) & s, T value ) { 40 // s.head = new( value, s.head ); 38 41 stack_node(T)* new_node = ((stack_node(T)*)malloc()); 39 42 (*new_node){ value, s.head }; /***/ … … 41 44 } 42 45 43 forall(otype T) T pop( stack(T)& s) {44 stack_node(T) * n = s.head;46 forall(otype T) T pop( stack(T) & s ) { 47 stack_node(T) * n = s.head; 45 48 s.head = n>next; 46 T x = n>value; 47 ^n{}; 48 free(n); 49 return x; 49 T v = n>value; 50 delete( n ); 51 return v; 50 52 } 51 53 52 forall(otype T) void clear( stack(T)& s) {53 for ( stack_node(T)* next = s.head; next; ) {54 stack_node(T) * crnt = next;54 forall(otype T) void clear( stack(T) & s ) { 55 for ( stack_node(T) * next = s.head; next; ) { 56 stack_node(T) * crnt = next; 55 57 next = crnt>next; 56 delete( crnt);58 delete( crnt ); 57 59 } 58 60 s.head = 0;
Note: See TracChangeset
for help on using the changeset viewer.