source: doc/papers/general/evaluation/cfa-stack.c@ 81e8ab0

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 81e8ab0 was 81e8ab0, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

more updates

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <stdlib>
2#include "cfa-stack.h"
3
4forall( otype T ) struct stack_node {
5 T value;
6 stack_node(T) * next;
7};
8
9forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
10
11forall( 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 = alloc();
15 ((*crnt)->value){ next->value };
16 crnt = &(*crnt)->next;
17 }
18 *crnt = 0;
19}
20
21forall( otype T ) void clear( stack(T) & s ) with( s ) {
22 for ( stack_node(T) * next = head; next; ) {
23 stack_node(T) * crnt = next;
24 next = crnt->next;
25 ^(*crnt){};
26 free(crnt);
27 }
28 head = 0;
29}
30
31forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {
32 if ( s.head == t.head ) return s;
33 clear( s );
34 s{ t };
35 return s;
36}
37
38forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
39
40forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
41
42forall( otype T ) void push( stack(T) & s, T value ) with( s ) {
43 stack_node(T) * n = alloc();
44 (*n){ value, head };
45 head = n;
46}
47
48forall( otype T ) T pop( stack(T) & s ) with( s ) {
49 stack_node(T) * n = head;
50 head = n->next;
51 T v = n->value;
52 ^(*n){};
53 free( n );
54 return v;
55}
Note: See TracBrowser for help on using the repository browser.