Ignore:
File:
1 edited

Legend:

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

    r986dd36 r604e76d  
    77};
    88
    9 forall(otype T) void ?{}(stack(T)& s) { (s.head){ 0 }; }
     9forall(otype T) void ?{}(stack(T)* s) { (&s->head){ 0 }; }
    1010
    11 forall(otype T) void ?{}(stack(T)& s, stack(T) t) {
    12         stack_node(T)** crnt = &s.head;
     11forall(otype T) void ?{}(stack(T)* s, stack(T) t) {
     12        stack_node(T)** crnt = &s->head;
    1313        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 
     14                *crnt = ((stack_node(T)*)malloc()){ next->value }; /***/
    1915                stack_node(T)* acrnt = *crnt;
    2016                crnt = &acrnt->next;
     
    2319}
    2420
    25 forall(otype T) stack(T) ?=?(stack(T)& s, stack(T) t) {
    26         if ( s.head == t.head ) return s;
     21forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
     22        if ( s->head == t.head ) return *s;
    2723        clear(s);
    2824        s{ t };
    29         return s;
     25        return *s;
    3026}
    3127
    32 forall(otype T) void ^?{}(stack(T)& s) { clear(s); }
     28forall(otype T) void ^?{}(stack(T)* s) { clear(s); }
    3329
    34 forall(otype T) _Bool empty(const stack(T)& s) { return s.head == 0; }
     30forall(otype T) _Bool empty(const stack(T)* s) { return s->head == 0; }
    3531
    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;
     32forall(otype T) void push(stack(T)* s, T value) {
     33        s->head = ((stack_node(T)*)malloc()){ value, s->head }; /***/
    4134}
    4235
    43 forall(otype T) T pop(stack(T)& s) {
    44         stack_node(T)* n = s.head;
    45         s.head = n->next;
     36forall(otype T) T pop(stack(T)* s) {
     37        stack_node(T)* n = s->head;
     38        s->head = n->next;
    4639        T x = n->value;
    4740        ^n{};
     
    5043}
    5144
    52 forall(otype T) void clear(stack(T)& s) {
    53     for ( stack_node(T)* next = s.head; next; ) {
     45forall(otype T) void clear(stack(T)* s) {
     46    for ( stack_node(T)* next = s->head; next; ) {
    5447                stack_node(T)* crnt = next;
    5548                next = crnt->next;
    5649                delete(crnt);
    5750        }
    58         s.head = 0;
     51        s->head = 0;
    5952}
Note: See TracChangeset for help on using the changeset viewer.