Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/cfa-stack.c

    rb2e8841 r81e8ab0  
    22#include "cfa-stack.h"
    33
    4 forall(otype T) struct stack_node {
     4forall( otype T ) struct stack_node {
    55        T value;
    66        stack_node(T) * next;
    77};
    8 forall(otype T) void ?{}( stack_node(T) & node, T value, stack_node(T) * next ) {
    9     node.value = value;
    10     node.next = next;
    11 }
    128
    13 forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     9forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    1410
    15 forall(otype T) void ?{}( stack(T) & s, stack(T) t ) {
     11forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
    1612        stack_node(T) ** crnt = &s.head;
    1713        for ( stack_node(T) * next = t.head; next; next = next->next ) {
    18                 // *crnt = new( next->value, (stack_node(T)*)0 );
    19                 stack_node(T)* new_node = ((stack_node(T)*)malloc());
    20                 (*new_node){ next->value }; /***/
    21                 *crnt = new_node;
    22                 stack_node(T) * acrnt = *crnt;
    23                 crnt = &acrnt->next;
     14                *crnt = alloc();
     15                ((*crnt)->value){ next->value };
     16                crnt = &(*crnt)->next;
    2417        }
    2518        *crnt = 0;
    2619}
    2720
    28 forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
     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 ) {
    2932        if ( s.head == t.head ) return s;
    3033        clear( s );
     
    3336}
    3437
    35 forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
     38forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
    3639
    37 forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }
     40forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
    3841
    39 forall(otype T) void push( stack(T) & s, T value ) {
    40         // s.head = new( value, s.head );
    41         stack_node(T)* new_node = ((stack_node(T)*)malloc());
    42         (*new_node){ value, s.head }; /***/
    43         s.head = new_node;
     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;
    4446}
    4547
    46 forall(otype T) T pop( stack(T) & s ) {
    47         stack_node(T) * n = s.head;
    48         s.head = n->next;
     48forall( otype T ) T pop( stack(T) & s ) with( s ) {
     49        stack_node(T) * n = head;
     50        head = n->next;
    4951        T v = n->value;
    50         delete( n );
     52        ^(*n){};
     53        free( n );
    5154        return v;
    5255}
    53 
    54 forall(otype T) void clear( stack(T) & s ) {
    55         for ( stack_node(T) * next = s.head; next; ) {
    56                 stack_node(T) * crnt = next;
    57                 next = crnt->next;
    58                 delete( crnt );
    59         }
    60         s.head = 0;
    61 }
Note: See TracChangeset for help on using the changeset viewer.