Changeset 8b001bd


Ignore:
Timestamp:
Mar 9, 2018, 1:08:32 PM (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:
3d8f2f8
Parents:
81e8ab0 (diff), e59f0bf (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:

more changes

Location:
doc/papers/general
Files:
8 edited

Legend:

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

    r81e8ab0 r8b001bd  
    368368Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    369369
     370Unconstruction is a mechanism to distribute @forall@ over related routines/types (see @stack@ examples in Section~\ref{sec:eval}):
     371\begin{cfa}
     372forall( otype T ) {                                                     $\C{// forall block}$
     373        struct stack { stack_node(T) * head; }; $\C{// generic type}$
     374        void push( stack(T) & s, T value ) ...  $\C{// generic operations}$
     375        T pop( stack(T) & s ) ...
     376}
     377\end{cfa}
     378Each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication.
     379
    370380
    371381\subsection{Traits}
     
    21552165\begin{cfa}
    21562166struct W {
    2157     double stones;
    2158     W() { stones = 0.0; }
    2159     W( double w ) { stones = w; }
     2167        double stones;
     2168        W() { stones = 0.0; }
     2169        W( double w ) { stones = w; }
    21602170};
    21612171W operator+( W l, W r ) {
     
    26272637                                                                        & \CT{C}        & \CT{\CFA}     & \CT{\CC}      & \CT{\CCV}             \\ \hline
    26282638maximum 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                    \\
     2639source code size (lines)                        & 197           & 186           & 133           & 303                   \\
     2640redundant type annotations (lines)      & 27            & 0                     & 2                     & 16                    \\
    26312641binary size (KB)                                        & 14            & 257           & 14            & 37                    \\
    26322642\end{tabular}
     
    27962806\lstset{basicstyle=\linespread{0.9}\sf\small}
    27972807
    2798 Throughout, @/***/@ designates a counted redundant type annotation.
     2808Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
    27992809
    28002810\smallskip\noindent
     
    28062816};
    28072817struct stack { struct stack_node* head; };
    2808 struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    28092818void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
    28102819        for ( struct stack_node * next = s->head; next; ) {
     
    28162825        s->head = NULL;
    28172826}
     2827struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    28182828void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
    28192829        struct stack_node ** crnt = &s->head;
     
    28252835        *crnt = NULL;
    28262836}
     2837struct stack * assign_stack( struct stack * s, const struct stack * t,
     2838                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
     2839        if ( s->head == t->head ) return s;
     2840        clear_stack( s, free_el ); /***/
     2841        copy_stack( s, t, copy_el ); /***/
     2842        return s;
     2843}
    28272844_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    28282845void push_stack( struct stack * s, void * value ) {
     
    28482865};
    28492866forall( otype T ) struct stack { stack_node(T) * head; };
     2867forall( otype T ) void clear( stack(T) & s ) with( s ) {
     2868        for ( stack_node(T) * next = head; next; ) {
     2869                stack_node(T) * crnt = next;
     2870                next = crnt->next;
     2871                ^(*crnt){};
     2872                free(crnt);
     2873        }
     2874        head = 0;
     2875}
    28502876forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    28512877forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
     
    28572883        }
    28582884        *crnt = 0;
    2859 }
    2860 forall( otype T ) void clear( stack(T) & s ) with( s ) {
    2861         for ( stack_node(T) * next = head; next; ) {
    2862                 stack_node(T) * crnt = next;
    2863                 next = crnt->next;
    2864                 ^(*crnt){};
    2865                 free(crnt);
    2866         }
    2867         head = 0;
    28682885}
    28692886forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {
     
    29032920        stack( const stack<T> & o) { copy( o ); }
    29042921        stack( stack<T> && o ) : head( o.head ) { o.head = nullptr; }
     2922        void clear() {
     2923                for ( node * next = head; next; ) {
     2924                        node * crnt = next;
     2925                        next = crnt->next;
     2926                        delete crnt;
     2927                }
     2928                head = nullptr;
     2929        }
    29052930        void copy( const stack<T> & o ) {
    29062931                node ** crnt = &head;
     
    29102935                }
    29112936                *crnt = nullptr;
    2912         }
    2913         void clear() {
    2914                 for ( node * next = head; next; ) {
    2915                         node * crnt = next;
    2916                         next = crnt->next;
    2917                         delete crnt;
    2918                 }
    2919                 head = nullptr;
    29202937        }
    29212938        ~stack() { clear(); }
     
    29542971        };
    29552972        node * head;
     2973        void clear() {
     2974                for ( node * next = head; next; ) {
     2975                        node * crnt = next;
     2976                        next = crnt->next;
     2977                        delete crnt;
     2978                }
     2979                head = nullptr;
     2980        }
    29562981        void copy( const stack & o ) {
    29572982                node ** crnt = &head;
     
    29612986                }
    29622987                *crnt = nullptr;
    2963         }
    2964         void clear() {
    2965                 for ( node * next = head; next; ) {
    2966                         node * crnt = next;
    2967                         next = crnt->next;
    2968                         delete crnt;
    2969                 }
    2970                 head = nullptr;
    29712988        }
    29722989        stack() : head( nullptr ) {}
  • doc/papers/general/evaluation/c-stack.c

    r81e8ab0 r8b001bd  
    66        struct stack_node * next;
    77};
    8 
    9 struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    108
    119void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
     
    1917}
    2018
     19struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     20
    2121void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
    2222        struct stack_node ** crnt = &s->head;
     
    2727        }
    2828        *crnt = NULL;
     29}
     30struct stack * assign_stack( struct stack * s, const struct stack * t,
     31                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
     32        if ( s->head == t->head ) return s;
     33        clear_stack( s, free_el ); /***/
     34        copy_stack( s, t, copy_el ); /***/
     35        return s;
    2936}
    3037
  • doc/papers/general/evaluation/c-stack.h

    r81e8ab0 r8b001bd  
    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
  • doc/papers/general/evaluation/cfa-stack.c

    r81e8ab0 r8b001bd  
    66        stack_node(T) * next;
    77};
     8
     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}
    818
    919forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     
    1727        }
    1828        *crnt = 0;
    19 }
    20 
    21 forall( otype T ) void clear( stack(T) & s ) with( s ) {
    22         for ( stack_node(T) * next = head; next; ) {
    23                 stack_node(T) * crnt = next;
    24                 next = crnt->next;
    25                 ^(*crnt){};
    26                 free(crnt);
    27         }
    28         head = 0;
    2929}
    3030
  • doc/papers/general/evaluation/cpp-stack.hpp

    r81e8ab0 r8b001bd  
    1414        stack( stack<T> && o ) : head( o.head ) { o.head = nullptr; }
    1515
     16        void clear() {
     17                for ( node * next = head; next; ) {
     18                        node * crnt = next;
     19                        next = crnt->next;
     20                        delete crnt;
     21                }
     22                head = nullptr;
     23        }
     24
    1625        void copy( const stack<T> & o ) {
    1726                node ** crnt = &head;
     
    2130                }
    2231                *crnt = nullptr;
    23         }
    24 
    25         void clear() {
    26                 for ( node * next = head; next; ) {
    27                         node * crnt = next;
    28                         next = crnt->next;
    29                         delete crnt;
    30                 }
    31                 head = nullptr;
    3232        }
    3333
  • doc/papers/general/evaluation/cpp-vstack.cpp

    r81e8ab0 r8b001bd  
    33
    44stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
     5
     6void stack::clear() {
     7        for ( node * next = head; next; ) {
     8                node * crnt = next;
     9                next = crnt->next;
     10                delete crnt;
     11        }
     12        head = nullptr;
     13}
    514
    615void stack::copy( const stack & o ) {
     
    1120        }
    1221        *crnt = nullptr;
    13 }
    14 
    15 void stack::clear() {
    16         for ( node * next = head; next; ) {
    17                 node * crnt = next;
    18                 next = crnt->next;
    19                 delete crnt;
    20         }
    21         head = nullptr;
    2222}
    2323
     
    4141}
    4242
    43 
    4443bool stack::empty() const { return head == nullptr; }
    4544
  • doc/papers/general/evaluation/cpp-vstack.hpp

    r81e8ab0 r8b001bd  
    1010        node * head;
    1111
     12        void clear();
    1213        void copy( const stack & o );
    1314
     
    1920        stack& operator=( stack && o );
    2021
    21         void clear();
    2222        bool empty() const;
    2323        void push( const object & value );
Note: See TracChangeset for help on using the changeset viewer.