Ignore:
Timestamp:
Apr 17, 2018, 12:01:09 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
3265399
Parents:
b2fe1c9 (diff), 81bb114 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rb2fe1c9 r32cab5b  
    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};
    88
    9 forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     9forall( otype T ) void clear( stack(T) & s ) with( s ) {
     10        for ( stack_node(T) * next = head; next; ) {
     11                stack_node(T) * crnt = next;
     12                next = crnt->next;
     13                ^(*crnt){};
     14                free(crnt);
     15        }
     16        head = 0;
     17}
    1018
    11 forall(otype T) void ?{}( stack(T) & s, stack(T) t ) {
     19forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     20
     21forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
    1222        stack_node(T) ** crnt = &s.head;
    1323        for ( stack_node(T) * next = t.head; next; next = next->next ) {
    14                 stack_node(T)* new_node = (stack_node(T)*)malloc(); /***/
    15                 (*new_node){ next->value };
    16                 *crnt = new_node;
     24                *crnt = alloc();
     25                ((*crnt)->value){ next->value };
    1726                crnt = &(*crnt)->next;
    1827        }
     
    2029}
    2130
    22 forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
     31forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {
    2332        if ( s.head == t.head ) return s;
    2433        clear( s );
     
    2736}
    2837
    29 forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
     38forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
    3039
    31 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; }
    3241
    33 forall(otype T) void push( stack(T) & s, T value ) {
    34         stack_node(T)* new_node = (stack_node(T)*)malloc(); /***/
    35         (*new_node){ value, s.head };
    36         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;
    3746}
    3847
    39 forall(otype T) T pop( stack(T) & s ) {
    40         stack_node(T) * n = s.head;
    41         s.head = n->next;
     48forall( otype T ) T pop( stack(T) & s ) with( s ) {
     49        stack_node(T) * n = head;
     50        head = n->next;
    4251        T v = n->value;
    4352        ^(*n){};
     
    4554        return v;
    4655}
    47 
    48 forall(otype T) void clear( stack(T) & s ) {
    49         for ( stack_node(T) * next = s.head; next; ) {
    50                 stack_node(T) * crnt = next;
    51                 next = crnt->next;
    52                 ^(*crnt){};
    53                 free(crnt);
    54         }
    55         s.head = 0;
    56 }
Note: See TracChangeset for help on using the changeset viewer.