source: doc/papers/general/evaluation/cfa-stack.c @ 9d6f011

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 9d6f011 was 28bc8c8, checked in by Aaron Moss <a3moss@…>, 6 years ago

Update evaluation section of paper

  • Property mode set to 100644
File size: 1.1 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) stack(T) ?=?( stack(T) & s, stack(T) t ) {
22        if ( s.head == t.head ) return s;
23        clear( s );
24        s{ t };
25        return s;
26}
27
28forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
29
30forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }
31
32forall(otype T) void push( stack(T) & s, T value ) with( s ) {
33        stack_node(T)* n = alloc();
34        (*n){ value, head };
35        head = n;
36}
37
38forall(otype T) T pop( stack(T) & s ) with( s ) {
39        stack_node(T) * n = head;
40        head = n->next;
41        T x = n->value;
42        ^(*n){};
43        free( n );
44        return x;
45}
46
47forall(otype T) void clear( stack(T) & s ) with( s ) {
48        for ( stack_node(T) * next = head; next; ) {
49                stack_node(T) * crnt = next;
50                next = crnt->next;
51                ^(*crnt){};
52                free(crnt);
53        }
54        head = 0;
55}
Note: See TracBrowser for help on using the repository browser.