Changeset 8fe7a85 for doc/theses/fangren_yu_MMath/features.tex
- Timestamp:
- May 12, 2025, 8:33:55 PM (10 months ago)
- Branches:
- master, stuck-waitfor-destruct
- Children:
- edd11bd
- Parents:
- 98c77b2
- File:
-
- 1 edited
-
doc/theses/fangren_yu_MMath/features.tex (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/fangren_yu_MMath/features.tex
r98c77b2 r8fe7a85 13 13 Here, manipulating the pointer address is the primary operation, while dereferencing the pointer to its value is the secondary operation. 14 14 For example, \emph{within} a data structure, \eg stack or queue, all operations involve pointer addresses and the pointer may never be dereferenced because the referenced object is opaque. 15 Alternatively, use a reference when its primary purpose is to alias a value, \eg a function parameter that does not copy the argument (performance reason).15 Alternatively, use a reference when its primary purpose is to alias a value, \eg a function parameter that does not copy the argument, for performance reasons. 16 16 Here, manipulating the value is the primary operation, while changing the pointer address is the secondary operation. 17 17 Succinctly, if the address changes often, use a pointer; … … 64 64 The call applies an implicit dereference once to @x@ so the call is typed @f( int & )@ with @T = int@, rather than with @T = int &@. 65 65 66 As fora pointer type, a reference type may have qualifiers, where @const@ is most common.66 As with a pointer type, a reference type may have qualifiers, where @const@ is most common. 67 67 \begin{cfa} 68 68 int x = 3; $\C{// mutable}$ … … 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 contexts 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. 191 191 \begin{cfa} 192 192 [x, y, z] = 3; $\C[2in]{// x = 3; y = 3; z = 3, where types may be different}$ … … 205 205 Only when returning a tuple from a function is there the notion of a tuple value. 206 206 207 Overloading in the \CFA type-system must support complex composition of tuples and C type conversions using a co stingscheme giving lower cost to widening conversions that do not truncate a value.207 Overloading in the \CFA type-system must support complex composition of tuples and C type conversions using a conversion cost scheme giving lower cost to widening conversions that do not truncate a value. 208 208 \begin{cfa} 209 209 [ int, int ] foo$\(_1\)$( int ); $\C{// overloaded foo functions}$ … … 223 223 bar( foo( 3 ) ) // only one tuple returning call 224 224 \end{lstlisting} 225 Hence, program ers cannot take advantage of the full power of tuples but type match is straightforward.225 Hence, programmers cannot take advantage of the full power of tuples but type match is straightforward. 226 226 227 227 K-W C also supported tuple variables, but with a strong distinction between tuples and tuple values/variables. … … 356 356 \end{figure} 357 357 358 Interestingly, in the third implementation of \CFA tuples by Robert Schluntz~\cite[\S~3]{Schluntz17}, the MVR functions revert back to structure based, where itremains in the current version of \CFA.358 Interestingly, in the third implementation of \CFA tuples by Robert Schluntz~\cite[\S~3]{Schluntz17}, the MVR functions revert back to structure based, and this remains in the current version of \CFA. 359 359 The reason for the reversion is a uniform approach for tuple values/variables making tuples first-class types in \CFA, \ie allow tuples with corresponding tuple variables. 360 360 This reversion was possible, because in parallel with Schluntz's work, generic types were added independently by Moss~\cite{Moss19}, and the tuple variables leveraged the same implementation techniques as for generic variables~\cite[\S~3.7]{Schluntz17}. … … 512 512 looping is used to traverse the argument pack from left to right. 513 513 The @va_list@ interface is walking up the stack (by address) looking at the arguments pushed by the caller. 514 ( Magicknowledge is needed for arguments pushed using registers.)514 (Compiler-specific ABI knowledge is needed for arguments pushed using registers.) 515 515 516 516 \begin{figure} … … 683 683 684 684 Nested \emph{named} aggregates are allowed in C but there is no qualification operator, like the \CC type operator `@::@', to access an inner type. 685 \emph{To compensate for the missing type operator, all named nested aggregates are hoisted to global scope, regardless of the nesting depth, and type usages within the nested type are replaced with global type name.} 685 To compensate for the missing type operator, all named nested aggregates are hoisted to global scope, regardless of the nesting depth, and type usages within the nested type are replaced with global type name. 686 686 Hoisting nested types can result in name collisions among types at the global level, which defeats the purpose of nesting the type. 687 687 \VRef[Figure]{f:NestedNamedAggregate} shows the nested type @T@ is hoisted to the global scope and the declaration rewrites within structure @S@. … … 729 729 \end{figure} 730 730 731 For good reasons,\CC chose to change this semantics:731 \CC chose to change this semantics: 732 732 \begin{cquote} 733 733 \begin{description}[leftmargin=*,topsep=0pt,itemsep=0pt,parsep=0pt] … … 769 769 Like an anonymous nested type, a named Plan-9 nested type has its field names hoisted into @struct S@, so there is direct access, \eg @s.x@ and @s.i@. 770 770 Hence, the field names must be unique, unlike \CC nested types, but the type names are at a nested scope level, unlike type nesting in C. 771 In addition, a pointer to a structure is automatically converted to a pointer to an anonymous field for assignments and function calls, providing containment inheritance with implicit subtyping, \ie @U@ $ \subset$ @S@ and @W@ $\subset$ @S@, \eg:771 In addition, a pointer to a structure is automatically converted to a pointer to an anonymous field for assignments and function calls, providing containment inheritance with implicit subtyping, \ie @U@ $<:$ @S@ and @W@ $<:$ @S@, \eg: 772 772 \begin{cfa} 773 773 void f( union U * u ); … … 781 781 Note, there is no value assignment, such as, @w = s@, to copy the @W@ field from @S@. 782 782 783 Unfortunately, the Plan-9 designers did not look ahead to other useful features, specifically nested types.783 Unfortunately, the Plan-9 designers did not look ahead to other useful features, specifically nested types. 784 784 This nested type compiles in \CC and \CFA. 785 785 \begin{cfa} … … 808 808 In addition, a semi-non-compatible change is made so that Plan-9 syntax means a forward declaration in a nested type. 809 809 Since the Plan-9 extension is not part of C and rarely used, this change has minimal impact. 810 Hence, all Plan-9 semantics are denoted by the @inline@ qualifier, which is good ``eye-candy'' when reading a structure definition to spotPlan-9 definitions.810 Hence, all Plan-9 semantics are denoted by the @inline@ qualifier, which clearly indicates the usage of Plan-9 definitions. 811 811 Finally, the following code shows the value and pointer polymorphism. 812 812 \begin{cfa} … … 847 847 \end{c++} 848 848 and again the expression @d.x@ is ambiguous. 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@.849 While \CC has no direct syntax to disambiguate @x@, \eg @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 851 While ambiguous definitions are allowed, duplicate field names are poor practice and should be avoided if possible.
Note:
See TracChangeset
for help on using the changeset viewer.