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

File:
1 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 ) {}
Note: See TracChangeset for help on using the changeset viewer.