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

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 4271a1e 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
RevLine 
[604e76d]1#include <stdlib>
2#include "cfa-stack.h"
3
4forall(otype T) struct stack_node {
5        T value;
[c9b3a41]6        stack_node(T) * next;
[604e76d]7};
8
[c9b3a41]9forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
[604e76d]10
[c9b3a41]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 ) {
[28bc8c8]14                *crnt = alloc();
[f1f8e55]15                ((*crnt)->value){ next->value };
[79d4186]16                crnt = &(*crnt)->next;
[604e76d]17        }
18        *crnt = 0;
19}
20
[c9b3a41]21forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
[986dd36]22        if ( s.head == t.head ) return s;
[c9b3a41]23        clear( s );
[604e76d]24        s{ t };
[986dd36]25        return s;
[604e76d]26}
27
[c9b3a41]28forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
[604e76d]29
[c9b3a41]30forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }
[604e76d]31
[f1f8e55]32forall(otype T) void push( stack(T) & s, T value ) with( s ) {
[28bc8c8]33        stack_node(T)* n = alloc();
[fb2ce27]34        (*n){ value, head };
35        head = n;
[604e76d]36}
37
[f1f8e55]38forall(otype T) T pop( stack(T) & s ) with( s ) {
39        stack_node(T) * n = head;
40        head = n->next;
[fb2ce27]41        T x = n->value;
[79d4186]42        ^(*n){};
43        free( n );
[fb2ce27]44        return x;
[604e76d]45}
46
[f1f8e55]47forall(otype T) void clear( stack(T) & s ) with( s ) {
48        for ( stack_node(T) * next = head; next; ) {
[c9b3a41]49                stack_node(T) * crnt = next;
[604e76d]50                next = crnt->next;
[79d4186]51                ^(*crnt){};
52                free(crnt);
[604e76d]53        }
[fb2ce27]54        head = 0;
[604e76d]55}
Note: See TracBrowser for help on using the repository browser.