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

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 b51e5fdb was 29db723, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

additional changes

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[604e76d]1#include <stdlib>
2#include "cfa-stack.h"
3
[29db723]4forall( otype T ) struct stack_node {
[604e76d]5        T value;
[c9b3a41]6        stack_node(T) * next;
[604e76d]7};
8
[29db723]9forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
[604e76d]10
[29db723]11forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
[c9b3a41]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
[29db723]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
[29db723]28forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
[604e76d]29
[29db723]30forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
[604e76d]31
[29db723]32forall( otype T ) void push( stack(T) & s, T value ) with( s ) {
33        stack_node(T) * n = alloc();
[fb2ce27]34        (*n){ value, head };
35        head = n;
[604e76d]36}
37
[29db723]38forall( otype T ) T pop( stack(T) & s ) with( s ) {
[f1f8e55]39        stack_node(T) * n = head;
40        head = n->next;
[29db723]41        T v = n->value;
[79d4186]42        ^(*n){};
43        free( n );
[29db723]44        return v;
[604e76d]45}
46
[29db723]47forall( otype T ) void clear( stack(T) & s ) with( s ) {
[f1f8e55]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.