Changeset 57c7e6c4 for doc/theses/fangren_yu_MMath/features.tex
- Timestamp:
- May 3, 2025, 12:46:23 AM (6 months ago)
- Branches:
- master
- Children:
- c9c1a7e6
- Parents:
- ef05cf0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/fangren_yu_MMath/features.tex
ref05cf0 r57c7e6c4 23 23 \CFA adopts a uniform policy between pointers and references where mutability is a separate property made at the declaration. 24 24 25 The following examples show show pointers and references are treated uniformly in \CFA.25 The following examples show how pointers and references are treated uniformly in \CFA. 26 26 \begin{cfa}[numbers=left,numberblanklines=false] 27 27 int x = 1, y = 2, z = 3;$\label{p:refexamples}$ … … 36 36 @&@r3 = @&@y; @&&@r3 = @&&@r4; $\C{// change r1, r2}$ 37 37 \end{cfa} 38 Like pointers, reference can be cascaded, \ie a reference to a reference, \eg @&& r2@.\footnote{38 Like pointers, references can be cascaded, \ie a reference to a reference, \eg @&& r2@.\footnote{ 39 39 \CC uses \lstinline{&&} for rvalue reference, a feature for move semantics and handling the \lstinline{const} Hell problem.} 40 40 Usage of a reference variable automatically performs the same number of dereferences as the number of references in its declaration, \eg @r2@ becomes @**r2@. … … 101 101 Interestingly, C does not give a warning/error if a @const@ pointer is not initialized, while \CC does. 102 102 Hence, type @& const@ is similar to a \CC reference, but \CFA does not preclude initialization with a non-variable address. 103 For example, in system 's programming, there are cases where an immutable address is initialized to a specific memory location.103 For example, in systems programming, there are cases where an immutable address is initialized to a specific memory location. 104 104 \begin{cfa} 105 105 int & const mem_map = *0xe45bbc67@p@; $\C{// hardware mapped registers ('p' for pointer)}$ … … 157 157 \end{cfa} 158 158 While it is possible to write a reference type as the argument to a generic type, it is disallowed in assertion checking, if the generic type requires the object trait \see{\VPageref{p:objecttrait}} for the type argument, a fairly common use case. 159 Even if the object trait can be made optional, the current type systemoften misbehaves by adding undesirable auto-dereference on the referenced-to value rather than the reference variable itself, as intended.159 Even if the object trait can be made optional, the current compiler implementation often misbehaves by adding undesirable auto-dereference on the referenced-to value rather than the reference variable itself, as intended. 160 160 Some tweaks are necessary to accommodate reference types in polymorphic contexts and it is unclear what can or cannot be achieved. 161 161 Currently, there are contexts where the \CFA programmer is forced to use a pointer type, giving up the benefits of auto-dereference operations and better syntax with reference types. … … 188 188 @[x, y, z]@ = foo( 3, 4 ); // return 3 values into a tuple 189 189 \end{cfa} 190 Along with making returning multiple values a first-class feature, tuples were extended to simplify a number of other common context that normally require multiple statements and/or additional declarations, all of which reduces coding time and errors.190 Along with making returning multiple values a first-class feature, tuples were extended to simplify a number of other common contexts that normally require multiple statements and/or additional declarations, all of which reduces coding time and errors. 191 191 \begin{cfa} 192 192 [x, y, z] = 3; $\C[2in]{// x = 3; y = 3; z = 3, where types may be different}$ … … 213 213 \end{cfa} 214 214 The type resolver only has the tuple return types to resolve the call to @bar@ as the @foo@ parameters are identical. 215 The resul tion involves unifying the flattened @foo@ return values with @bar@'s parameter list.215 The resulution involves unifying the flattened @foo@ return values with @bar@'s parameter list. 216 216 However, no combination of @foo@s is an exact match with @bar@'s parameters; 217 217 thus, the resolver applies C conversions to obtain a best match. … … 303 303 \section{Tuple Implementation} 304 304 305 As noted, tradition languages manipulate multiple values by in/out parameters and/or structures.305 As noted, traditional languages manipulate multiple values by in/out parameters and/or structures. 306 306 K-W C adopted the structure for tuple values or variables, and as needed, the fields are extracted by field access operations. 307 307 As well, for the tuple-assignment implementation, the left-hand tuple expression is expanded into assignments of each component, creating temporary variables to avoid unexpected side effects. … … 576 576 Unfortunately, packing the variadic arguments into a rigid @struct@ type and generating all the required wrapper functions is significant work and largely wasted because most are never called. 577 577 Interested readers can refer to pages 77-80 of Robert Schluntz's thesis to see how verbose the translator output is to implement a simple variadic call with 3 arguments. 578 As the number of arguments increases, \eg a call with 5 arguments, the translator generates aconcrete @struct@ types for a 4-tuple and a 3-tuple along with all the polymorphic type data for them.578 As the number of arguments increases, \eg a call with 5 arguments, the translator generates concrete @struct@ types for a 4-tuple and a 3-tuple along with all the polymorphic type data for them. 579 579 An alternative approach is to put the variadic arguments into an array, along with an offset array to retrieve each individual argument. 580 580 This method is similar to how the C @va_list@ object is used (and how \CFA accesses polymorphic fields in a generic type), but the \CFA variadics generate the required type information to guarantee type safety (like the @printf@ format string). … … 849 849 While \CC has no direct syntax to disambiguate @x@, \ie @d.B.x@ or @d.C.x@, it is possible with casts, @((B)d).x@ or @((C)d).x@. 850 850 Like \CC, \CFA compiles the Plan-9 version and provides direct qualification and casts to disambiguate @x@. 851 While ambiguous definitions are allowed, duplicate field names ispoor practice and should be avoided if possible.851 While ambiguous definitions are allowed, duplicate field names are poor practice and should be avoided if possible. 852 852 However, when a programmer does not control all code, this problem can occur and a naming workaround must exist.
Note:
See TracChangeset
for help on using the changeset viewer.