ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 8f5bf6d was
309be81,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Started evaluation benchmarks for paper (CFA version doesn't compile yet)
|
-
Property mode set to
100644
|
File size:
630 bytes
|
Rev | Line | |
---|
[309be81] | 1 | #include <stdlib> |
---|
| 2 | #include "cfa-stack.h" |
---|
| 3 | |
---|
| 4 | forall(otype T) struct stack_node { |
---|
| 5 | T value; |
---|
| 6 | stack_node(T)* next; |
---|
| 7 | }; |
---|
| 8 | |
---|
| 9 | forall(otype T) void ?{}(stack(T)* s) { |
---|
| 10 | ?{}( s->head, 0 ); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | forall(otype T) void ^?{}(stack(T)* s) { |
---|
| 14 | stack_node(T)* next = s->head; |
---|
| 15 | while ( next ) { |
---|
| 16 | stack_node(T)* crnt = next; |
---|
| 17 | next = crnt->next; |
---|
| 18 | delete(crnt); |
---|
| 19 | } |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | forall(otype T) _Bool empty(const stack(T)* s) { |
---|
| 23 | return s->head == 0; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | forall(otype T) void push(stack(T)* s, T value) { |
---|
| 27 | s->head = new( value, s->head ); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | forall(otype T) T pop(stack(T)* s) { |
---|
| 31 | stack_node(T)* n = s->head; |
---|
| 32 | s->head = n->next; |
---|
| 33 | T x = n->value; |
---|
| 34 | delete(n); |
---|
| 35 | return x; |
---|
| 36 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.