Ignore:
File:
1 edited

Legend:

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

    rb2e8841 r986dd36  
    44forall(otype T) struct stack_node {
    55        T value;
    6         stack_node(T) * next;
     6        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 ) {
    16         stack_node(T) ** crnt = &s.head;
    17         for ( stack_node(T) * next = t.head; next; next = next->next ) {
    18                 // *crnt = new( next->value, (stack_node(T)*)0 );
     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 = &(*(stack_node(T)*)malloc()){ next->value }; /***/
    1915                stack_node(T)* new_node = ((stack_node(T)*)malloc());
    2016                (*new_node){ next->value }; /***/
    2117                *crnt = new_node;
    22                 stack_node(T) * acrnt = *crnt;
     18
     19                stack_node(T)* acrnt = *crnt;
    2320                crnt = &acrnt->next;
    2421        }
     
    2623}
    2724
    28 forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
     25forall(otype T) stack(T) ?=?(stack(T)& s, stack(T) t) {
    2926        if ( s.head == t.head ) return s;
    30         clear( s );
     27        clear(s);
    3128        s{ t };
    3229        return s;
    3330}
    3431
    35 forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
     32forall(otype T) void ^?{}(stack(T)& s) { clear(s); }
    3633
    37 forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; }
     34forall(otype T) _Bool empty(const stack(T)& s) { return s.head == 0; }
    3835
    39 forall(otype T) void push( stack(T) & s, T value ) {
    40         // s.head = new( value, s.head );
     36forall(otype T) void push(stack(T)& s, T value) {
     37        // s.head = &(*(stack_node(T)*)malloc()){ value, s.head }; /***/
    4138        stack_node(T)* new_node = ((stack_node(T)*)malloc());
    4239        (*new_node){ value, s.head }; /***/
     
    4441}
    4542
    46 forall(otype T) T pop( stack(T) & s ) {
    47         stack_node(T) * n = s.head;
     43forall(otype T) T pop(stack(T)& s) {
     44        stack_node(T)* n = s.head;
    4845        s.head = n->next;
    49         T v = n->value;
    50         delete( n );
    51         return v;
     46        T x = n->value;
     47        ^n{};
     48        free(n);
     49        return x;
    5250}
    5351
    54 forall(otype T) void clear( stack(T) & s ) {
    55         for ( stack_node(T) * next = s.head; next; ) {
    56                 stack_node(T) * crnt = next;
     52forall(otype T) void clear(stack(T)& s) {
     53    for ( stack_node(T)* next = s.head; next; ) {
     54                stack_node(T)* crnt = next;
    5755                next = crnt->next;
    58                 delete( crnt );
     56                delete(crnt);
    5957        }
    6058        s.head = 0;
Note: See TracChangeset for help on using the changeset viewer.