Changeset 986dd36 for doc/papers/general/evaluation/cfastack.c
 Timestamp:
 Mar 2, 2018, 5:34:51 PM (4 years ago)
 Branches:
 aaronthesis, armeh, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, resolvnew, with_gc
 Children:
 dd05e12
 Parents:
 244b934
 gitauthor:
 Rob Schluntz <rschlunt@…> (03/02/18 09:47:18)
 gitcommitter:
 Rob Schluntz <rschlunt@…> (03/02/18 17:34:51)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

doc/papers/general/evaluation/cfastack.c
r244b934 r986dd36 7 7 }; 8 8 9 forall(otype T) void ?{}(stack(T) * s) { (&s>head){ 0 }; }9 forall(otype T) void ?{}(stack(T)& s) { (s.head){ 0 }; } 10 10 11 forall(otype T) void ?{}(stack(T) *s, stack(T) t) {12 stack_node(T)** crnt = &s >head;11 forall(otype T) void ?{}(stack(T)& s, stack(T) t) { 12 stack_node(T)** crnt = &s.head; 13 13 for ( stack_node(T)* next = t.head; next; next = next>next ) { 14 *crnt = ((stack_node(T)*)malloc()){ next>value }; /***/ 14 // *crnt = &(*(stack_node(T)*)malloc()){ next>value }; /***/ 15 stack_node(T)* new_node = ((stack_node(T)*)malloc()); 16 (*new_node){ next>value }; /***/ 17 *crnt = new_node; 18 15 19 stack_node(T)* acrnt = *crnt; 16 20 crnt = &acrnt>next; … … 19 23 } 20 24 21 forall(otype T) stack(T) ?=?(stack(T) *s, stack(T) t) {22 if ( s >head == t.head ) return *s;25 forall(otype T) stack(T) ?=?(stack(T)& s, stack(T) t) { 26 if ( s.head == t.head ) return s; 23 27 clear(s); 24 28 s{ t }; 25 return *s;29 return s; 26 30 } 27 31 28 forall(otype T) void ^?{}(stack(T) *s) { clear(s); }32 forall(otype T) void ^?{}(stack(T)& s) { clear(s); } 29 33 30 forall(otype T) _Bool empty(const stack(T) * s) { return s>head == 0; }34 forall(otype T) _Bool empty(const stack(T)& s) { return s.head == 0; } 31 35 32 forall(otype T) void push(stack(T)* s, T value) { 33 s>head = ((stack_node(T)*)malloc()){ value, s>head }; /***/ 36 forall(otype T) void push(stack(T)& s, T value) { 37 // s.head = &(*(stack_node(T)*)malloc()){ value, s.head }; /***/ 38 stack_node(T)* new_node = ((stack_node(T)*)malloc()); 39 (*new_node){ value, s.head }; /***/ 40 s.head = new_node; 34 41 } 35 42 36 forall(otype T) T pop(stack(T) *s) {37 stack_node(T)* n = s >head;38 s >head = n>next;43 forall(otype T) T pop(stack(T)& s) { 44 stack_node(T)* n = s.head; 45 s.head = n>next; 39 46 T x = n>value; 40 47 ^n{}; … … 43 50 } 44 51 45 forall(otype T) void clear(stack(T) *s) {46 for ( stack_node(T)* next = s >head; next; ) {52 forall(otype T) void clear(stack(T)& s) { 53 for ( stack_node(T)* next = s.head; next; ) { 47 54 stack_node(T)* crnt = next; 48 55 next = crnt>next; 49 56 delete(crnt); 50 57 } 51 s >head = 0;58 s.head = 0; 52 59 }
Note: See TracChangeset
for help on using the changeset viewer.