- Timestamp:
- Mar 8, 2018, 7:31:15 AM (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:
- 5600747, 87555b7
- Parents:
- f4abc58
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
rf4abc58 rfb11446e 507 507 The offset arrays are statically generated where possible. 508 508 If a dynamic generic-type is declared to be passed or returned by value from a polymorphic function, the translator can safely assume the generic type is complete (\ie has a known layout) at any call-site, and the offset array is passed from the caller; 509 if the generic type is concrete at the call site, the elements of this offset array can even be statically generated using the C @offsetof@ macro. 509 if the generic type is concrete at the call site, the elements of this offset array can even be statically generated using the C @offsetof@ macro. 510 510 As an example, the body of the second @value@ function is implemented like this: 511 511 \begin{cfa} … … 830 830 Hence, function parameter and return lists are flattened for the purposes of type unification allowing the example to pass expression resolution. 831 831 This relaxation is possible by extending the thunk scheme described by Bilson~\cite{Bilson03}. 832 Whenever a candidate's parameter structure does not exactly match the formal parameter's structure, a thunk is generated to specialize calls to the actual function:833 \begin{cfa}834 int _thunk( int _p0, double _p1, double _p2 ) { return f( [_p0, _p1], _p2 ); }835 \end{cfa}836 so the thunk provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism.837 These thunks take advantage of gcc C nested-functions to produce closures that have the usual function-pointer signature WHAT DOES THIS MEAN???.832 % Whenever a candidate's parameter structure does not exactly match the formal parameter's structure, a thunk is generated to specialize calls to the actual function: 833 % \begin{cfa} 834 % int _thunk( int _p0, double _p1, double _p2 ) { return f( [_p0, _p1], _p2 ); } 835 % \end{cfa} 836 % so the thunk provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism. 837 % These thunks are generated locally using gcc nested-functions, rather hositing them to the external scope, so they can easily access local state. 838 838 839 839 … … 1004 1004 \section{Control Structures} 1005 1005 1006 \CFA identifies inconsistent, problematic, and missing control structures in C, and extends, modifies, and adds tocontrol structures to increase functionality and safety.1006 \CFA identifies inconsistent, problematic, and missing control structures in C, and extends, modifies, and adds control structures to increase functionality and safety. 1007 1007 1008 1008 … … 1039 1039 \lstMakeShortInline@% 1040 1040 \end{cquote} 1041 for a contiguous list:\footnote{gcc provides the same mechanism with awkward syntax, \lstinline@2 ... 42@, where spaces are required around the ellipse.}1041 for a contiguous list:\footnote{gcc has the same mechanism but awkward syntax, \lstinline@2 ...42@, because a space is required after a number, otherwise the period is a decimal point.} 1042 1042 \begin{cquote} 1043 1043 \lstDeleteShortInline@% … … 1375 1375 Coroutines and tasks start with non-local exceptions disabled, allowing handlers to be put in place, before non-local exceptions are explicitly enabled. 1376 1376 \begin{cfa} 1377 void main( mytask & c ) { 1378 try { 1379 enable { $\C{// now allow non-local exception delivery}$ 1377 void main( mytask & c ) { $\C{// thread starts here}$ 1378 // non-local exceptions disabled 1379 try { $\C{// establish handles for non-local exceptions}$ 1380 enable { $\C{// allow non-local exception delivery}$ 1380 1381 // task body 1381 1382 } 1382 // appropriate catchResume/catch 1383 // appropriate catchResume/catch handlers 1383 1384 } 1384 1385 } … … 1800 1801 int & r = *new( int ); 1801 1802 ... $\C{// non-null reference}$ 1802 delete &r; 1803 delete &r; $\C{// unmanaged (programmer) memory-management}$ 1803 1804 r += 1; $\C{// undefined reference}$ 1804 1805 \end{cfa} … … 1947 1948 Constructor calls seamlessly integrate with existing C initialization syntax, providing a simple and familiar syntax to C programmers and allowing constructor calls to be inserted into legacy C code with minimal code changes. 1948 1949 1949 In \CFA, a constructor is named @?{}@ and a destructor is named @^?{}@. 1950 The name @{}@ comes from the syntax for the initializer: @struct S { int i, j; } s = `{` 2, 3 `}`@\footnote{% 1950 In \CFA, a constructor is named @?{}@ and a destructor is named @^?{}@\footnote{% 1951 1951 The symbol \lstinline+^+ is used for the destructor name because it was the last binary operator that could be used in a unary context.}. 1952 The name @{}@ comes from the syntax for the initializer: @struct S { int i, j; } s = `{` 2, 3 `}`@. 1952 1953 Like other \CFA operators, these names represent the syntax used to call the constructor or destructor, \eg @?{}(x, ...)@ or @^{}(x, ...)@. 1953 1954 The constructor and destructor have return type @void@, and the first parameter is a reference to the object type to be constructed or destructed. … … 2071 2072 \subsection{0/1} 2072 2073 2073 In C, @0@ has the special property that it is the only ``false'' value; by the standard, any value which compares equal to @0@ is false, while any value that compares unequal to @0@ is true. 2074 As such, an expression @x@ in any boolean context (such as the condition of an @if@ or @while@ statement, or the arguments to @&&@, @||@, or @?:@) can be rewritten as @x != 0@ without changing its semantics. 2075 The operator overloading feature of \CFA provides a natural means to implement this truth value comparison for arbitrary types, but the C type system is not precise enough to distinguish an equality comparison with @0@ from an equality comparison with an arbitrary integer or pointer. 2076 To provide this precision, \CFA introduces a new type @zero_t@ as type type of literal @0@ (somewhat analagous to @nullptr_t@ and @nullptr@ in \CCeleven); @zero_t@ can only take the value @0@, but has implicit conversions to the integer and pointer types so that C code involving @0@ continues to work properly. 2077 With this addition, the \CFA compiler rewrites @if (x)@ and similar expressions to @if ((x) != 0)@ or the appropriate analogue, and any type @T@ can be made ``truthy'' by defining an operator overload @int ?!=?(T, zero_t)@. 2078 \CC makes types truthy by adding a conversion to @bool@; prior to the addition of explicit cast operators in \CCeleven this approach had the pitfall of making truthy types transitively convertable to any numeric type; our design for \CFA avoids this issue. 2079 2080 \CFA also includes a special type for @1@, @one_t@; like @zero_t@, @one_t@ has built-in implicit conversions to the various integral types so that @1@ maintains its expected semantics in legacy code. 2081 The addition of @one_t@ allows generic algorithms to handle the unit value uniformly for types where that is meaningful. 2082 \TODO{Make this sentence true} In particular, polymorphic functions in the \CFA prelude define @++x@ and @x++@ in terms of @x += 1@, allowing users to idiomatically define all forms of increment for a type @T@ by defining the single function @T & ?+=(T &, one_t)@; analogous overloads for the decrement operators are present as well. 2074 In C, @0@ has the special property that it is the only ``false'' value; 2075 from the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true. 2076 As such, an expression @x@ in any boolean context (such as the condition of an @if@ or @while@ statement, or the arguments to @&&@, @||@, or @?:@\,) can be rewritten as @x != 0@ without changing its semantics. 2077 Operator overloading in \CFA provides a natural means to implement this truth-value comparison for arbitrary types, but the C type system is not precise enough to distinguish an equality comparison with @0@ from an equality comparison with an arbitrary integer or pointer. 2078 To provide this precision, \CFA introduces a new type @zero_t@ as the type of literal @0@ (somewhat analagous to @nullptr_t@ and @nullptr@ in \CCeleven); 2079 @zero_t@ can only take the value @0@, but has implicit conversions to the integer and pointer types so that C code involving @0@ continues to work. 2080 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ((x) != 0)@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?(T, zero_t)@. 2081 \CC makes types truthy by adding a conversion to @bool@; 2082 prior to the addition of explicit cast operators in \CCeleven, this approach had the pitfall of making truthy types transitively convertable to any numeric type; 2083 \CFA avoids this issue. 2084 2085 Similarly, \CFA also has a special type for @1@, @one_t@; 2086 like @zero_t@, @one_t@ has built-in implicit conversions to the various integral types so that @1@ maintains its expected semantics in legacy code for operations @++@ and @--@. 2087 The addition of @one_t@ allows generic algorithms to handle the unit value uniformly for types where it is meaningful. 2088 \TODO{Make this sentence true} 2089 In particular, polymorphic functions in the \CFA prelude define @++x@ and @x++@ in terms of @x += 1@, allowing users to idiomatically define all forms of increment for a type @T@ by defining the single function @T & ?+=(T &, one_t)@; 2090 analogous overloads for the decrement operators are present as well. 2083 2091 2084 2092 … … 2088 2096 The left of Figure~\ref{f:UserLiteral} shows the \CFA alternative call-syntax (literal argument before function name), using the backquote, to convert basic literals into user literals. 2089 2097 The backquote is a small character, making the unit (function name) predominate. 2090 For examples, the multi-precision integer s in Section~\ref{s:MultiPrecisionIntegers} make use ofuser literals:2098 For examples, the multi-precision integer-type in Section~\ref{s:MultiPrecisionIntegers} has user literals: 2091 2099 {\lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}} 2092 2100 \begin{cfa} … … 2308 2316 \lstMakeShortInline@% 2309 2317 \end{cquote} 2310 In additon, there are polymorphic functions, like @min@ and @max@, whichwork on any type with operators @?<?@ or @?>?@.2318 In additon, there are polymorphic functions, like @min@ and @max@, that work on any type with operators @?<?@ or @?>?@. 2311 2319 2312 2320 The following shows one example where \CFA \emph{extends} an existing standard C interface to reduce complexity and provide safety. … … 2319 2327 In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied. 2320 2328 For an increase in storage size, new storage after the copied data may be filled. 2321 \item[align ment]2329 \item[align] 2322 2330 an allocation on a specified memory boundary, \eg, an address multiple of 64 or 128 for cache-line purposes. 2323 2331 \item[array] 2324 allocation of thespecified number of elements.2332 allocation with a specified number of elements. 2325 2333 An array may be filled, resized, or aligned. 2326 2334 \end{description} … … 2334 2342 \lstMakeShortInline~% 2335 2343 \begin{tabular}{@{}r|r|l|l|l|l@{}} 2336 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & align ment& array \\2344 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & align & array \\ 2337 2345 \hline 2338 2346 C & ~malloc~ & no & no & no & no \\ … … 2562 2570 TIMED( "copy_int", ti = si; ) 2563 2571 TIMED( "clear_int", clear( si ); ) 2564 REPEAT_TIMED( "pop_int", N, 2565 int x = pop( ti ); if ( x > max ) max = x; ) 2572 REPEAT_TIMED( "pop_int", N, int x = pop( ti ); if ( x > max ) max = x; ) 2566 2573 2567 2574 pair( _Bool, char ) max = { (_Bool)0, '\0' }, val = { (_Bool)1, 'a' }; … … 2571 2578 TIMED( "copy_pair", tp = sp; ) 2572 2579 TIMED( "clear_pair", clear( sp ); ) 2573 REPEAT_TIMED( "pop_pair", N, 2574 pair(_Bool, char) x = pop( tp ); if ( x > max ) max = x; ) 2580 REPEAT_TIMED( "pop_pair", N, pair(_Bool, char) x = pop( tp ); if ( x > max ) max = x; ) 2575 2581 } 2576 2582 \end{cfa}
Note: See TracChangeset
for help on using the changeset viewer.