Changeset e84382b for doc/papers/general/Paper.tex
- Timestamp:
- Mar 9, 2018, 1:34:04 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:
- 860f19f
- Parents:
- b51e5fdb (diff), 3d8f2f8 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
rb51e5fdb re84382b 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} … … 836 846 % \end{cfa} 837 847 % so the thunk provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism. 838 % These thunks are generated locally using gcc nested-functions, rather ho siting them to the external scope, so they can easily access local state.848 % These thunks are generated locally using gcc nested-functions, rather hoisting them to the external scope, so they can easily access local state. 839 849 840 850 … … 1167 1177 \lstMakeShortInline@% 1168 1178 \end{cquote} 1169 The target label must be below the @fallthrough@, \ie @fallthrough@ cannot form a loop, and the label may not be nested in a control struct or, \ie it must be at the same level as the @case@ clauses;1179 The target label must be below the @fallthrough@, \ie @fallthrough@ cannot form a loop, and the label may not be nested in a control structure, \ie it must be at the same level as the @case@ clauses; 1170 1180 the target label may be case @default@. 1171 1181 … … 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 ) { … … 2719 2729 2720 2730 \CC is the best known C-based language, and is similar to \CFA in that both are extensions to C with source and runtime backwards compatibility. 2721 Specific difference between \CFA and \CC have been identified in prior sections, with a final observation that \CFA has equal or few tokens to express the same notion in severalcases.2722 The key difference between design philosophies is that \CFA is easier for C programmers to understand,by maintaining a procedural paradigm and avoiding complex interactions among extensions.2731 Specific difference between \CFA and \CC have been identified in prior sections, with a final observation that \CFA has equal or fewer tokens to express the same notion in many cases. 2732 The key difference in design philosophies is that \CFA is easier for C programmers to understand by maintaining a procedural paradigm and avoiding complex interactions among extensions. 2723 2733 \CC, on the other hand, has multiple overlapping features (such as the three forms of polymorphism), many of which have complex interactions with its object-oriented design. 2724 As a result, \CC has a steep learning curve for even experienced C programmers, especially when attempting to maintain performance equivalent to C legacy 2734 As a result, \CC has a steep learning curve for even experienced C programmers, especially when attempting to maintain performance equivalent to C legacy-code. 2725 2735 2726 2736 There are several other C extension-languages with less usage and even more dramatic changes than \CC. … … 2728 2738 Other languages extend C with more focused features. 2729 2739 CUDA~\cite{Nickolls08}, ispc~\cite{Pharr12}, and Sierra~\cite{Leissa14} add data-parallel primitives to C or \CC; 2730 such features have not yet been added to \CFA, but are not precluded by thedesign.2731 Final y, some C extensions (or suggested extensions) attempt to provide a more memory-safe C~\cite{Boehm88};2732 type-checked polymorphism in \CFA covers several of C's memory-safety holes, but more aggressive approaches such as annotating all pointer types with their nullability are contradictory to \CFA's backwards compatibility goals.2740 such features have not yet been added to \CFA, but are easily incorporated within its design. 2741 Finally, some C extensions (or suggested extensions) attempt to provide a more memory-safe C~\cite{Boehm88,Rafkind09}; 2742 type-checked polymorphism in \CFA covers several of C's memory-safety issues, but more aggressive approaches such as annotating all pointer types with their nullability are contradictory to \CFA's backwards compatibility goals. 2733 2743 2734 2744 … … 2841 2851 struct stack_node * n = s->head; 2842 2852 s->head = n->next; 2843 void * x= n->value;2853 void * v = n->value; 2844 2854 free( n ); 2845 return x;2855 return v; 2846 2856 } 2847 2857 \end{cfa} … … 2897 2907 \end{cfa} 2898 2908 2909 \begin{comment} 2910 forall( otype T ) { 2911 struct stack_node { 2912 T value; 2913 stack_node(T) * next; 2914 }; 2915 struct stack { stack_node(T) * head; }; 2916 void clear( stack(T) & s ) with( s ) { 2917 for ( stack_node(T) * next = head; next; ) { 2918 stack_node(T) * crnt = next; 2919 next = crnt->next; 2920 ^(*crnt){}; 2921 free(crnt); 2922 } 2923 head = 0; 2924 } 2925 void ?{}( stack(T) & s ) { (s.head){ 0 }; } 2926 void ?{}( stack(T) & s, stack(T) t ) { 2927 stack_node(T) ** crnt = &s.head; 2928 for ( stack_node(T) * next = t.head; next; next = next->next ) { 2929 *crnt = alloc(); 2930 ((*crnt)->value){ next->value }; 2931 crnt = &(*crnt)->next; 2932 } 2933 *crnt = 0; 2934 } 2935 stack(T) ?=?( stack(T) & s, stack(T) t ) { 2936 if ( s.head == t.head ) return s; 2937 clear( s ); 2938 s{ t }; 2939 return s; 2940 } 2941 void ^?{}( stack(T) & s) { clear( s ); } 2942 _Bool empty( const stack(T) & s ) { return s.head == 0; } 2943 void push( stack(T) & s, T value ) with( s ) { 2944 stack_node(T) * n = alloc(); 2945 (*n){ value, head }; 2946 head = n; 2947 } 2948 T pop( stack(T) & s ) with( s ) { 2949 stack_node(T) * n = head; 2950 head = n->next; 2951 T v = n->value; 2952 ^(*n){}; 2953 free( n ); 2954 return v; 2955 } 2956 } 2957 \end{comment} 2958 2899 2959 \medskip\noindent 2900 2960 \CC … … 2907 2967 }; 2908 2968 node * head; 2969 stack() : head( nullptr ) {} 2970 stack( const stack<T> & o) { copy( o ); } 2971 stack( stack<T> && o ) : head( o.head ) { o.head = nullptr; } 2909 2972 void clear() { 2910 2973 for ( node * next = head; next; ) { … … 2923 2986 *crnt = nullptr; 2924 2987 } 2925 stack() : head( nullptr) {}2926 stack( const stack<T> & o ) { copy( o ); }2927 2988 ~stack() { clear(); } 2928 stack & operator= ( const stack<T> & o ) {2989 stack & operator= ( const stack<T> & o ) { 2929 2990 if ( this == &o ) return *this; 2930 2991 clear(); … … 2937 2998 node * n = head; 2938 2999 head = n->next; 2939 T x= std::move( n->value );3000 T v = std::move( n->value ); 2940 3001 delete n; 2941 return x;3002 return v; 2942 3003 } 2943 3004 }; … … 2950 3011 struct node { 2951 3012 ptr<object> value; 2952 node * next;2953 node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}3013 node * next; 3014 node( const object & v, node * n = nullptr ) : value( v.new_copy() ), next( n ) {} 2954 3015 }; 2955 node * head;3016 node * head; 2956 3017 void clear() { 2957 3018 for ( node * next = head; next; ) { … … 2972 3033 stack() : head( nullptr ) {} 2973 3034 stack( const stack & o ) { copy( o ); } 2974 3035 ~stack() { clear(); } 2975 3036 stack & operator= ( const stack & o ) { 2976 3037 if ( this == &o ) return *this; … … 2984 3045 node * n = head; 2985 3046 head = n->next; 2986 ptr<object> x= std::move( n->value );3047 ptr<object> v = std::move( n->value ); 2987 3048 delete n; 2988 return x;3049 return v; 2989 3050 } 2990 3051 };
Note: See TracChangeset
for help on using the changeset viewer.