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 0a84919 was
a381b46,
checked in by Aaron Moss <a3moss@…>, 8 years ago
|
Minor cleanup, also filled in benchmark source appendix
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
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) { (&s->head){ 0 }; } |
---|
10 | |
---|
11 | forall(otype T) void ?{}(stack(T)* s, stack(T) t) { |
---|
12 | stack_node(T)** crnt = &s->head; |
---|
13 | stack_node(T)* next = t.head; |
---|
14 | while ( next ) { |
---|
15 | *crnt = ((stack_node(T)*)malloc()){ next->value }; /***/ |
---|
16 | stack_node(T)* acrnt = *crnt; |
---|
17 | crnt = &acrnt->next; |
---|
18 | next = next->next; |
---|
19 | } |
---|
20 | *crnt = 0; |
---|
21 | } |
---|
22 | |
---|
23 | forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) { |
---|
24 | if ( s->head == t.head ) return *s; |
---|
25 | clear(s); |
---|
26 | s{ t }; |
---|
27 | return *s; |
---|
28 | } |
---|
29 | |
---|
30 | forall(otype T) void ^?{}(stack(T)* s) { clear(s); } |
---|
31 | |
---|
32 | forall(otype T) _Bool empty(const stack(T)* s) { return s->head == 0; } |
---|
33 | |
---|
34 | forall(otype T) void push(stack(T)* s, T value) { |
---|
35 | s->head = ((stack_node(T)*)malloc()){ value, s->head }; /***/ |
---|
36 | } |
---|
37 | |
---|
38 | forall(otype T) T pop(stack(T)* s) { |
---|
39 | stack_node(T)* n = s->head; |
---|
40 | s->head = n->next; |
---|
41 | T x = n->value; |
---|
42 | ^n{}; |
---|
43 | free(n); |
---|
44 | return x; |
---|
45 | } |
---|
46 | |
---|
47 | forall(otype T) void clear(stack(T)* s) { |
---|
48 | stack_node(T)* next = s->head; |
---|
49 | while ( next ) { |
---|
50 | stack_node(T)* crnt = next; |
---|
51 | next = crnt->next; |
---|
52 | delete(crnt); |
---|
53 | } |
---|
54 | s->head = 0; |
---|
55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.