Changeset e59f0bf


Ignore:
Timestamp:
Mar 9, 2018, 10:44:51 AM (6 years ago)
Author:
Aaron Moss <a3moss@…>
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:
12bbb367, 8b001bd
Parents:
29db723
Message:

Update benchmarks so that C has assign operator like others

Location:
doc/papers/general
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    r29db723 re59f0bf  
    26272627                                                                        & \CT{C}        & \CT{\CFA}     & \CT{\CC}      & \CT{\CCV}             \\ \hline
    26282628maximum memory usage (MB)                       & 10,001        & 2,502         & 2,503         & 11,253                \\
    2629 source code size (lines)                        & 187           & 186           & 133           & 303                   \\
    2630 redundant type annotations (lines)      & 25            & 0                     & 2                     & 16                    \\
     2629source code size (lines)                        & 197           & 186           & 133           & 303                   \\
     2630redundant type annotations (lines)      & 27            & 0                     & 2                     & 16                    \\
    26312631binary size (KB)                                        & 14            & 257           & 14            & 37                    \\
    26322632\end{tabular}
     
    27962796\lstset{basicstyle=\linespread{0.9}\sf\small}
    27972797
    2798 Throughout, @/***/@ designates a counted redundant type annotation.
     2798Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
    27992799
    28002800\smallskip\noindent
     
    28062806};
    28072807struct stack { struct stack_node* head; };
     2808void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
     2809        for ( struct stack_node * next = s->head; next; ) {
     2810                struct stack_node * crnt = next;
     2811                next = crnt->next;
     2812                free_el( crnt->value );
     2813                free( crnt );
     2814        }
     2815        s->head = NULL;
     2816}
    28082817struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    28092818void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
     
    28162825        *crnt = NULL;
    28172826}
     2827struct stack * assign_stack( struct stack * s, const struct stack * t,
     2828                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
     2829        if ( s->head == t->head ) return s;
     2830        clear_stack( s, free_el ); /***/
     2831        copy_stack( s, t, copy_el ); /***/
     2832        return s;
     2833}
    28182834_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    28192835void push_stack( struct stack * s, void * value ) {
     
    28282844        free( n );
    28292845        return x;
    2830 }
    2831 void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
    2832         for ( struct stack_node * next = s->head; next; ) {
    2833                 struct stack_node * crnt = next;
    2834                 next = crnt->next;
    2835                 free_el( crnt->value );
    2836                 free( crnt );
    2837         }
    2838         s->head = NULL;
    28392846}
    28402847\end{cfa}
     
    28482855};
    28492856forall( otype T ) struct stack { stack_node(T) * head; };
     2857forall( otype T ) void clear( stack(T) & s ) with( s ) {
     2858        for ( stack_node(T) * next = head; next; ) {
     2859                stack_node(T) * crnt = next;
     2860                next = crnt->next;
     2861                ^(*crnt){};
     2862                free(crnt);
     2863        }
     2864        head = 0;
     2865}
    28502866forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    28512867forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
     
    28782894        free( n );
    28792895        return v;
    2880 }
    2881 forall( otype T ) void clear( stack(T) & s ) with( s ) {
    2882         for ( stack_node(T) * next = head; next; ) {
    2883                 stack_node(T) * crnt = next;
    2884                 next = crnt->next;
    2885                 ^(*crnt){};
    2886                 free(crnt);
    2887         }
    2888         head = 0;
    28892896}
    28902897\end{cfa}
     
    29002907        };
    29012908        node * head;
     2909        void clear() {
     2910                for ( node * next = head; next; ) {
     2911                        node * crnt = next;
     2912                        next = crnt->next;
     2913                        delete crnt;
     2914                }
     2915                head = nullptr;
     2916        }
    29022917        void copy( const stack<T> & o) {
    29032918                node ** crnt = &head;
     
    29332948                return x;
    29342949        }
    2935         void clear() {
    2936                 for ( node * next = head; next; ) {
    2937                         node * crnt = next;
    2938                         next = crnt->next;
    2939                         delete crnt;
    2940                 }
    2941                 head = nullptr;
    2942         }
    29432950};
    29442951\end{cfa}
     
    29542961        };
    29552962        node* head;
     2963        void clear() {
     2964                for ( node * next = head; next; ) {
     2965                        node * crnt = next;
     2966                        next = crnt->next;
     2967                        delete crnt;
     2968                }
     2969                head = nullptr;
     2970        }
    29562971        void copy( const stack & o ) {
    29572972                node ** crnt = &head;
     
    29873002                return x;
    29883003        }
    2989         void clear() {
    2990                 for ( node * next = head; next; ) {
    2991                         node * crnt = next;
    2992                         next = crnt->next;
    2993                         delete crnt;
    2994                 }
    2995                 head = nullptr;
    2996         }
    29973004};
    29983005\end{cfa}
  • doc/papers/general/evaluation/c-stack.c

    r29db723 re59f0bf  
    1717        }
    1818        *crnt = NULL;
     19}
     20
     21struct stack* assign_stack(struct stack* s, const struct stack* t,
     22                void* (*copy_el)(const void*), void (*free_el)(void*)) {
     23        if ( s->head == t->head ) return s;
     24        clear_stack( s, free_el ); /***/
     25        copy_stack( s, t, copy_el ); /***/
     26        return s;
    1927}
    2028
  • doc/papers/general/evaluation/c-stack.h

    r29db723 re59f0bf  
    88struct stack new_stack();
    99void copy_stack(struct stack* dst, const struct stack* src, void* (*copy)(const void*));
     10struct stack* assign_stack(struct stack* dst, const struct stack* src,
     11        void* (*copy_el)(const void*), void (*free_el)(void*));
    1012void clear_stack(struct stack* s, void (*free_el)(void*));
    1113
Note: See TracChangeset for help on using the changeset viewer.