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 55b2f5a was
309be81,
checked in by Aaron Moss <a3moss@…>, 8 years ago
|
Started evaluation benchmarks for paper (CFA version doesn't compile yet)
|
-
Property mode set to
100644
|
File size:
725 bytes
|
Rev | Line | |
---|
[309be81] | 1 | #include <stdlib.h> |
---|
| 2 | #include "c-stack.h" |
---|
| 3 | |
---|
| 4 | struct stack_node { |
---|
| 5 | void* value; |
---|
| 6 | struct stack_node* next; |
---|
| 7 | }; |
---|
| 8 | |
---|
| 9 | struct stack new_stack() { |
---|
| 10 | return (struct stack){ NULL }; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | void clear_stack(struct stack* s) { |
---|
| 14 | struct stack_node* next = s->head; |
---|
| 15 | while ( next ) { |
---|
| 16 | struct stack_node* crnt = next; |
---|
| 17 | next = crnt->next; |
---|
| 18 | free(crnt->value); |
---|
| 19 | free(crnt); |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | _Bool stack_empty(const struct stack* s) { |
---|
| 24 | return s->head == NULL; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void push_stack(struct stack* s, void* value) { |
---|
| 28 | struct stack_node* n = malloc(sizeof(struct stack_node)); |
---|
| 29 | *n = (struct stack_node){ value, s->head }; |
---|
| 30 | s->head = n; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | void* pop_stack(struct stack* s) { |
---|
| 34 | struct stack_node* n = s->head; |
---|
| 35 | s->head = n->next; |
---|
| 36 | void* x = n->value; |
---|
| 37 | free(n); |
---|
| 38 | return x; |
---|
| 39 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.