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

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 5600747 was 79d4186, checked in by Aaron Moss <a3moss@…>, 6 years ago

Update evaluation code for paper

  • 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                stack_node(T)* new_node = (stack_node(T)*)malloc(); /***/
15                (*new_node){ next->value };
16                *crnt = new_node;
17                crnt = &(*crnt)->next;
18        }
19        *crnt = 0;
20}
21
22forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
23        if ( s.head == t.head ) return s;
24        clear( s );
25        s{ t };
26        return s;
27}
28
29forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
30
31forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }
32
33forall(otype T) void push( stack(T) & s, T value ) {
34        stack_node(T)* new_node = (stack_node(T)*)malloc(); /***/
35        (*new_node){ value, s.head };
36        s.head = new_node;
37}
38
39forall(otype T) T pop( stack(T) & s ) {
40        stack_node(T) * n = s.head;
41        s.head = n->next;
42        T v = n->value;
43        ^(*n){};
44        free( n );
45        return v;
46}
47
48forall(otype T) void clear( stack(T) & s ) {
49        for ( stack_node(T) * next = s.head; next; ) {
50                stack_node(T) * crnt = next;
51                next = crnt->next;
52                ^(*crnt){};
53                free(crnt);
54        }
55        s.head = 0;
56}
Note: See TracBrowser for help on using the repository browser.