Changes in doc/rob_thesis/tuples.tex [12d3187:0111dc7]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/rob_thesis/tuples.tex
r12d3187 r0111dc7 161 161 \end{cfacode} 162 162 163 \begin{sloppypar}164 163 In 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.164 Tuple 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. 166 165 \begin{cfacode} 167 166 [double, int] di; … … 170 169 \end{cfacode} 171 170 This 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}173 171 174 172 \subsection{Tuple Indexing} … … 214 212 The 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. 215 213 216 In \KWC \cite{Buhr94a,Till89}, there were 4 tuple coercions: opening, closing, flattening, and structuring.214 In \KWC \cite{Buhr94a,Till89}, a precursor to \CFA, there were 4 tuple coercions: opening, closing, flattening, and structuring. 217 215 Opening coerces a tuple value into a tuple of values, while closing converts a tuple of values into a single tuple value. 218 216 Flattening 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. … … 220 218 221 219 In \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.223 220 Specifically, the expression resolution algorithm examines all of the possible alternatives for an expression to determine the best match. 224 221 In resolving a function call expression, each combination of function value and list of argument alternatives is examined. … … 257 254 Let $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. 258 255 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$. 256 For 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$. 266 257 That is, @?=?(&$L_i$, $R_i$)@ must be a well-typed expression. 267 258 In 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. … … 274 265 275 266 Both 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 .267 As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function, 277 268 \begin{cfacode} 278 269 int x = 10, y = 20; … … 305 296 \subsection{Tuple Construction} 306 297 Tuple 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.308 298 \begin{cfacode} 309 299 struct S; … … 443 433 \section{Casting} 444 434 In 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 force sthe expression resolution algorithm to choose the lowest cost conversion to the target type.435 In \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. 446 436 That 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. 447 437 \begin{cfacode} … … 497 487 \section{Polymorphism} 498 488 Due 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.500 489 \begin{cfacode} 501 490 forall(otype T, dtype U) … … 535 524 It 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. 536 525 Still, 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 co nversion cost to the structuring and flattening conversions, which are currently 0-cost conversions in the expression resolver.526 These issues could be rectified by applying an appropriate cost to the structuring and flattening conversions, which are currently 0-cost conversions. 538 527 Care would be needed in this case to ensure that exact matches do not incur such a cost. 539 528 \begin{cfacode} … … 570 559 \section{Implementation} 571 560 Tuples 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 575 561 The first time an $N$-tuple is seen for each $N$ in a scope, a generic type with $N$ type parameters is generated. 576 562 For example,
Note: See TracChangeset
for help on using the changeset viewer.