ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since dd05e12 was 986dd36, checked in by Rob Schluntz <rschlunt@…>, 8 years ago |
Update CFA evaluation code
|
-
Property mode
set to
100644
|
File size:
1.3 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 | for ( stack_node(T)* next = t.head; next; next = next->next ) {
|
---|
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 |
|
---|
19 | stack_node(T)* acrnt = *crnt;
|
---|
20 | crnt = &acrnt->next;
|
---|
21 | }
|
---|
22 | *crnt = 0;
|
---|
23 | }
|
---|
24 |
|
---|
25 | forall(otype T) stack(T) ?=?(stack(T)& s, stack(T) t) {
|
---|
26 | if ( s.head == t.head ) return s;
|
---|
27 | clear(s);
|
---|
28 | s{ t };
|
---|
29 | return s;
|
---|
30 | }
|
---|
31 |
|
---|
32 | forall(otype T) void ^?{}(stack(T)& s) { clear(s); }
|
---|
33 |
|
---|
34 | forall(otype T) _Bool empty(const stack(T)& s) { return s.head == 0; }
|
---|
35 |
|
---|
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;
|
---|
41 | }
|
---|
42 |
|
---|
43 | forall(otype T) T pop(stack(T)& s) {
|
---|
44 | stack_node(T)* n = s.head;
|
---|
45 | s.head = n->next;
|
---|
46 | T x = n->value;
|
---|
47 | ^n{};
|
---|
48 | free(n);
|
---|
49 | return x;
|
---|
50 | }
|
---|
51 |
|
---|
52 | forall(otype T) void clear(stack(T)& s) {
|
---|
53 | for ( stack_node(T)* next = s.head; next; ) {
|
---|
54 | stack_node(T)* crnt = next;
|
---|
55 | next = crnt->next;
|
---|
56 | delete(crnt);
|
---|
57 | }
|
---|
58 | s.head = 0;
|
---|
59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.