Changeset 5544465 for doc/rob_thesis/tuples.tex
- Timestamp:
- May 1, 2017, 6:27:38 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:
- 5783e94
- Parents:
- ad1a8dd (diff), 2055098 (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/rob_thesis/tuples.tex
rad1a8dd r5544465 161 161 \end{cfacode} 162 162 163 \begin{sloppypar} 163 164 In addition to variables of tuple type, it is also possible to have pointers to tuples, and arrays of tuples. 164 Tuple types can be composed of any types, except for array types, since array s do not carry their size around, which makes tuple assignment difficult when a tuple contains an array.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. 165 166 \begin{cfacode} 166 167 [double, int] di; … … 169 170 \end{cfacode} 170 171 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} 171 173 172 174 \subsection{Tuple Indexing} … … 212 214 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. 213 215 214 In \KWC \cite{Buhr94a,Till89}, a precursor to \CFA,there were 4 tuple coercions: opening, closing, flattening, and structuring.216 In \KWC \cite{Buhr94a,Till89}, there were 4 tuple coercions: opening, closing, flattening, and structuring. 215 217 Opening coerces a tuple value into a tuple of values, while closing converts a tuple of values into a single tuple value. 216 218 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. … … 218 220 219 221 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. 220 223 Specifically, the expression resolution algorithm examines all of the possible alternatives for an expression to determine the best match. 221 224 In resolving a function call expression, each combination of function value and list of argument alternatives is examined. … … 254 257 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. 255 258 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$. 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$. 257 266 That is, @?=?(&$L_i$, $R_i$)@ must be a well-typed expression. 258 267 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. … … 265 274 266 275 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. 267 As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function ,276 As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function. 268 277 \begin{cfacode} 269 278 int x = 10, y = 20; … … 296 305 \subsection{Tuple Construction} 297 306 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. 298 308 \begin{cfacode} 299 309 struct S; … … 433 443 \section{Casting} 434 444 In C, the cast operator is used to explicitly convert between types. 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.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. 436 446 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. 437 447 \begin{cfacode} … … 487 497 \section{Polymorphism} 488 498 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. 489 500 \begin{cfacode} 490 501 forall(otype T, dtype U) … … 524 535 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. 525 536 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. 526 These issues could be rectified by applying an appropriate co st to the structuring and flattening conversions, which are currently 0-cost conversions.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. 527 538 Care would be needed in this case to ensure that exact matches do not incur such a cost. 528 539 \begin{cfacode} … … 559 570 \section{Implementation} 560 571 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 561 575 The first time an $N$-tuple is seen for each $N$ in a scope, a generic type with $N$ type parameters is generated. 562 576 For example,
Note: See TracChangeset
for help on using the changeset viewer.