Ignore:
File:
1 edited

Legend:

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

    r986dd36 rc9b3a41  
    44forall(otype T) struct stack_node {
    55        T value;
    6         stack_node(T)* next;
     6        stack_node(T) * next;
    77};
     8forall(otype T) void ?{}( stack_node(T) & node, T value, stack_node(T) * next ) {
     9    node.value = value;
     10    node.next = next;
     11}
    812
    9 forall(otype T) void ?{}(stack(T)& s) { (s.head){ 0 }; }
     13forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    1014
    11 forall(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 }; /***/
    15                 stack_node(T)* new_node = ((stack_node(T)*)malloc());
    16                 (*new_node){ next->value }; /***/
    17                 *crnt = new_node;
    18 
    19                 stack_node(T)* acrnt = *crnt;
     15forall(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, 0 );
     19                stack_node(T) * acrnt = *crnt;
    2020                crnt = &acrnt->next;
    2121        }
     
    2323}
    2424
    25 forall(otype T) stack(T) ?=?(stack(T)& s, stack(T) t) {
     25forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
    2626        if ( s.head == t.head ) return s;
    27         clear(s);
     27        clear( s );
    2828        s{ t };
    2929        return s;
    3030}
    3131
    32 forall(otype T) void ^?{}(stack(T)& s) { clear(s); }
     32forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
    3333
    34 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; }
    3535
    36 forall(otype T) void push(stack(T)& s, T value) {
    37         // s.head = &(*(stack_node(T)*)malloc()){ value, s.head }; /***/
    38         stack_node(T)* new_node = ((stack_node(T)*)malloc());
    39         (*new_node){ value, s.head }; /***/
    40         s.head = new_node;
     36forall(otype T) void push( stack(T) & s, T value ) {
     37    s.head = new( value, s.head );
    4138}
    4239
    43 forall(otype T) T pop(stack(T)& s) {
    44         stack_node(T)* n = s.head;
     40forall(otype T) T pop( stack(T) & s ) {
     41        stack_node(T) * n = s.head;
    4542        s.head = n->next;
    46         T x = n->value;
    47         ^n{};
    48         free(n);
    49         return x;
     43        T v = n->value;
     44//      ^n{};
     45        free( n );
     46        return v;
    5047}
    5148
    52 forall(otype T) void clear(stack(T)& s) {
    53     for ( stack_node(T)* next = s.head; next; ) {
    54                 stack_node(T)* crnt = next;
     49forall(otype T) void clear( stack(T) & s ) {
     50        for ( stack_node(T) * next = s.head; next; ) {
     51                stack_node(T) * crnt = next;
    5552                next = crnt->next;
    56                 delete(crnt);
     53                delete( crnt );
    5754        }
    5855        s.head = 0;
Note: See TracChangeset for help on using the changeset viewer.