Changeset 8b001bd
- Timestamp:
- Mar 9, 2018, 1:08:32 PM (7 years ago)
- 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. - Location:
- doc/papers/general
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
r81e8ab0 r8b001bd 368 368 Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types. 369 369 370 Unconstruction is a mechanism to distribute @forall@ over related routines/types (see @stack@ examples in Section~\ref{sec:eval}): 371 \begin{cfa} 372 forall( 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} 378 Each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication. 379 370 380 371 381 \subsection{Traits} … … 2155 2165 \begin{cfa} 2156 2166 struct W { 2157 2158 2159 2167 double stones; 2168 W() { stones = 0.0; } 2169 W( double w ) { stones = w; } 2160 2170 }; 2161 2171 W operator+( W l, W r ) { … … 2627 2637 & \CT{C} & \CT{\CFA} & \CT{\CC} & \CT{\CCV} \\ \hline 2628 2638 maximum memory usage (MB) & 10,001 & 2,502 & 2,503 & 11,253 \\ 2629 source code size (lines) & 1 87 & 186 & 133 & 303 \\2630 redundant type annotations (lines) & 2 5& 0 & 2 & 16 \\2639 source code size (lines) & 197 & 186 & 133 & 303 \\ 2640 redundant type annotations (lines) & 27 & 0 & 2 & 16 \\ 2631 2641 binary size (KB) & 14 & 257 & 14 & 37 \\ 2632 2642 \end{tabular} … … 2796 2806 \lstset{basicstyle=\linespread{0.9}\sf\small} 2797 2807 2798 Throughout, @/***/@ designates a counted redundant type annotation .2808 Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity. 2799 2809 2800 2810 \smallskip\noindent … … 2806 2816 }; 2807 2817 struct stack { struct stack_node* head; }; 2808 struct stack new_stack() { return (struct stack){ NULL }; /***/ }2809 2818 void clear_stack( struct stack * s, void (*free_el)( void * ) ) { 2810 2819 for ( struct stack_node * next = s->head; next; ) { … … 2816 2825 s->head = NULL; 2817 2826 } 2827 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 2818 2828 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) { 2819 2829 struct stack_node ** crnt = &s->head; … … 2825 2835 *crnt = NULL; 2826 2836 } 2837 struct 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 } 2827 2844 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; } 2828 2845 void push_stack( struct stack * s, void * value ) { … … 2848 2865 }; 2849 2866 forall( otype T ) struct stack { stack_node(T) * head; }; 2867 forall( 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 } 2850 2876 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; } 2851 2877 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) { … … 2857 2883 } 2858 2884 *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;2868 2885 } 2869 2886 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) { … … 2903 2920 stack( const stack<T> & o) { copy( o ); } 2904 2921 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 } 2905 2930 void copy( const stack<T> & o ) { 2906 2931 node ** crnt = &head; … … 2910 2935 } 2911 2936 *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;2920 2937 } 2921 2938 ~stack() { clear(); } … … 2954 2971 }; 2955 2972 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 } 2956 2981 void copy( const stack & o ) { 2957 2982 node ** crnt = &head; … … 2961 2986 } 2962 2987 *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;2971 2988 } 2972 2989 stack() : head( nullptr ) {} -
doc/papers/general/evaluation/c-stack.c
r81e8ab0 r8b001bd 6 6 struct stack_node * next; 7 7 }; 8 9 struct stack new_stack() { return (struct stack){ NULL }; /***/ }10 8 11 9 void clear_stack( struct stack * s, void (*free_el)( void * ) ) { … … 19 17 } 20 18 19 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 20 21 21 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) { 22 22 struct stack_node ** crnt = &s->head; … … 27 27 } 28 28 *crnt = NULL; 29 } 30 struct 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; 29 36 } 30 37 -
doc/papers/general/evaluation/c-stack.h
r81e8ab0 r8b001bd 8 8 struct stack new_stack(); 9 9 void copy_stack(struct stack* dst, const struct stack* src, void* (*copy)(const void*)); 10 struct stack* assign_stack(struct stack* dst, const struct stack* src, 11 void* (*copy_el)(const void*), void (*free_el)(void*)); 10 12 void clear_stack(struct stack* s, void (*free_el)(void*)); 11 13 -
doc/papers/general/evaluation/cfa-stack.c
r81e8ab0 r8b001bd 6 6 stack_node(T) * next; 7 7 }; 8 9 forall( 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 } 8 18 9 19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; } … … 17 27 } 18 28 *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;29 29 } 30 30 -
doc/papers/general/evaluation/cpp-stack.hpp
r81e8ab0 r8b001bd 14 14 stack( stack<T> && o ) : head( o.head ) { o.head = nullptr; } 15 15 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 16 25 void copy( const stack<T> & o ) { 17 26 node ** crnt = &head; … … 21 30 } 22 31 *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;32 32 } 33 33 -
doc/papers/general/evaluation/cpp-vstack.cpp
r81e8ab0 r8b001bd 3 3 4 4 stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {} 5 6 void stack::clear() { 7 for ( node * next = head; next; ) { 8 node * crnt = next; 9 next = crnt->next; 10 delete crnt; 11 } 12 head = nullptr; 13 } 5 14 6 15 void stack::copy( const stack & o ) { … … 11 20 } 12 21 *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;22 22 } 23 23 … … 41 41 } 42 42 43 44 43 bool stack::empty() const { return head == nullptr; } 45 44 -
doc/papers/general/evaluation/cpp-vstack.hpp
r81e8ab0 r8b001bd 10 10 node * head; 11 11 12 void clear(); 12 13 void copy( const stack & o ); 13 14 … … 19 20 stack& operator=( stack && o ); 20 21 21 void clear();22 22 bool empty() const; 23 23 void push( const object & value );
Note: See TracChangeset
for help on using the changeset viewer.