Ignore:
Timestamp:
Mar 2, 2018, 6:52:37 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, resolv-new, with_gc
Children:
000ff2c
Parents:
ab3251e
Message:

update CFA evaluation code

File:
1 edited

Legend:

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

    rab3251e 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)* 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;
    1620                crnt = &acrnt->next;
    1721        }
     
    1923}
    2024
    21 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
    22         if ( s->head == t.head ) return *s;
    23         clear(s);
     25forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) {
     26        if ( s.head == t.head ) return s;
     27        clear( s );
    2428        s{ t };
    25         return *s;
     29        return s;
    2630}
    2731
    28 forall(otype T) void ^?{}(stack(T)* s) { clear(s); }
     32forall(otype T) void ^?{}( stack(T) & s) { clear( s ); }
    2933
    30 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; }
    3135
    32 forall(otype T) void push(stack(T)* s, T value) {
    33         s->head = ((stack_node(T)*)malloc()){ value, s->head }; /***/
     36forall(otype T) void push( stack(T) & s, T value ) {
     37    s.head = new( value, s.head );
    3438}
    3539
    36 forall(otype T) T pop(stack(T)* s) {
    37         stack_node(T)* n = s->head;
    38         s->head = n->next;
    39         T x = n->value;
    40         ^n{};
    41         free(n);
    42         return x;
     40forall(otype T) T pop( stack(T) & s ) {
     41        stack_node(T) * n = s.head;
     42        s.head = n->next;
     43        T v = n->value;
     44//      ^n{};
     45        free( n );
     46        return v;
    4347}
    4448
    45 forall(otype T) void clear(stack(T)* s) {
    46     for ( stack_node(T)* next = s->head; next; ) {
    47                 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;
    4852                next = crnt->next;
    49                 delete(crnt);
     53                delete( crnt );
    5054        }
    51         s->head = 0;
     55        s.head = 0;
    5256}
Note: See TracChangeset for help on using the changeset viewer.