Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/rob_thesis/tuples.tex

    r12d3187 r0111dc7  
    161161\end{cfacode}
    162162
    163 \begin{sloppypar}
    164163In addition to variables of tuple type, it is also possible to have pointers to tuples, and arrays of tuples.
    165 Tuple types can be composed of any types, except for array types, since array assignment is disallowed, which makes tuple assignment difficult when a tuple contains an array.
     164Tuple types can be composed of any types, except for array types, since arrays do not carry their size around, which makes tuple assignment difficult when a tuple contains an array.
    166165\begin{cfacode}
    167166[double, int] di;
     
    170169\end{cfacode}
    171170This examples declares a variable of type @[double, int]@, a variable of type pointer to @[double, int]@, and an array of ten @[double, int]@.
    172 \end{sloppypar}
    173171
    174172\subsection{Tuple Indexing}
     
    214212The flexible structure of tuples permits a simple and expressive function-call syntax to work seamlessly with both single- and multiple-return-value functions, and with any number of arguments of arbitrarily complex structure.
    215213
    216 In \KWC \cite{Buhr94a,Till89}, there were 4 tuple coercions: opening, closing, flattening, and structuring.
     214In \KWC \cite{Buhr94a,Till89}, a precursor to \CFA, there were 4 tuple coercions: opening, closing, flattening, and structuring.
    217215Opening coerces a tuple value into a tuple of values, while closing converts a tuple of values into a single tuple value.
    218216Flattening coerces a nested tuple into a flat tuple, \ie it takes a tuple with tuple components and expands it into a tuple with only non-tuple components.
     
    220218
    221219In \CFA, the design has been simplified to require only the two conversions previously described, which trigger only in function call and return situations.
    222 This simplification is a primary contribution of this thesis to the design of tuples in \CFA.
    223220Specifically, the expression resolution algorithm examines all of the possible alternatives for an expression to determine the best match.
    224221In resolving a function call expression, each combination of function value and list of argument alternatives is examined.
     
    257254Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
    258255
    259 For a multiple assignment to be valid, both tuples must have the same number of elements when flattened.
    260 For example, the following is invalid because the number of components on the left does not match the number of components on the right.
    261 \begin{cfacode}
    262 [int, int] x, y, z;
    263 [x, y] = z;   // multiple assignment, invalid 4 != 2
    264 \end{cfacode}
    265 Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     256For a multiple assignment to be valid, both tuples must have the same number of elements when flattened. Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
    266257That is, @?=?(&$L_i$, $R_i$)@ must be a well-typed expression.
    267258In the previous example, @[x, y] = z@, @z@ is flattened into @z.0, z.1@, and the assignments @x = z.0@ and @y = z.1@ happen.
     
    274265
    275266Both kinds of tuple assignment have parallel semantics, such that each value on the left side and right side is evaluated \emph{before} any assignments occur.
    276 As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function.
     267As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function,
    277268\begin{cfacode}
    278269int x = 10, y = 20;
     
    305296\subsection{Tuple Construction}
    306297Tuple construction and destruction follow the same rules and semantics as tuple assignment, except that in the case where there is no right side, the default constructor or destructor is called on each component of the tuple.
    307 As constructors and destructors did not exist in previous versions of \CFA or in \KWC, this is a primary contribution of this thesis to the design of tuples.
    308298\begin{cfacode}
    309299struct S;
     
    443433\section{Casting}
    444434In C, the cast operator is used to explicitly convert between types.
    445 In \CFA, the cast operator has a secondary use, which is type ascription, since it forces the expression resolution algorithm to choose the lowest cost conversion to the target type.
     435In \CFA, the cast operator has a secondary use, which is type ascription, since it force the expression resolution algorithm to choose the lowest cost conversion to the target type.
    446436That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
    447437\begin{cfacode}
     
    497487\section{Polymorphism}
    498488Due to the implicit flattening and structuring conversions involved in argument passing, @otype@ and @dtype@ parameters are restricted to matching only with non-tuple types.
    499 The integration of polymorphism, type assertions, and monomorphic specialization of tuple-assertions are a primary contribution of this thesis to the design of tuples.
    500489\begin{cfacode}
    501490forall(otype T, dtype U)
     
    535524It is also important to note that these calls could be disambiguated if the function return types were different, as they likely would be for a reasonable implementation of @?+?@, since the return type is used in overload resolution.
    536525Still, these semantics are a deficiency of the current argument matching algorithm, and depending on the function, differing return values may not always be appropriate.
    537 These issues could be rectified by applying an appropriate conversion cost to the structuring and flattening conversions, which are currently 0-cost conversions in the expression resolver.
     526These issues could be rectified by applying an appropriate cost to the structuring and flattening conversions, which are currently 0-cost conversions.
    538527Care would be needed in this case to ensure that exact matches do not incur such a cost.
    539528\begin{cfacode}
     
    570559\section{Implementation}
    571560Tuples are implemented in the \CFA translator via a transformation into generic types.
    572 Generic types are an independent contribution developed at the same time.
    573 The transformation into generic types and the generation of tuple-specific code are primary contributions of this thesis to tuples.
    574 
    575561The first time an $N$-tuple is seen for each $N$ in a scope, a generic type with $N$ type parameters is generated.
    576562For example,
Note: See TracChangeset for help on using the changeset viewer.