- Timestamp:
- May 3, 2016, 9:30:55 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7937abf, a1d6d80
- Parents:
- e945826
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
re945826 r0638c44 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sat Apr 30 13:54:32201614 %% Update Count : 2 2113 %% Last Modified On : Tue May 3 08:05:33 2016 14 %% Update Count : 246 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 17 17 % requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended 18 18 19 % red highlighting ®...® (registered trademark sumbol)20 % blue highlighting ©...© (copyright symbol)21 % latex escape §...§ (section symbol) 22 % keyword escape ¶...¶ (pilcrow symbol) 19 % inline code ©...© (copyright symbol) emacs: C-q M-) 20 % red highlighting ®...® (registered trademark sumbol) emacs: C-q M-. 21 % latex escape §...§ (section symbol) emacs: C-q M-' 22 % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^ 23 23 % math escape $...$ (dollar symbol) 24 24 … … 180 180 \CC~\cite{c++,ANSI14:C++} is an example of a similar project; 181 181 however, it largely extended the language, and did not address existing problems.\footnote{% 182 Two important existing problems addressed were changing the type of character literals from \lstinline@int@ to \lstinline@char@ and enumerator from \lstinline@int@to the type of its enumerators.}182 Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.} 183 183 Fortran~\cite{Fortran08}, Ada~\cite{Ada12}, and Cobol~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language features are added and problems fixed within the framework of the existing language. 184 184 Java~\cite{Java8}, Go~\cite{Go}, Rust~\cite{Rust} and D~\cite{D} are examples of the revolutionary approach for modernizing C/\CC, resulting in a new language rather than an extension of the descendent. … … 205 205 206 206 However, it is necessary to differentiate between C and \CFA code because of name overloading, as for \CC. 207 For example, the C math-library provides the following routines for computing the absolute value of the basic type: \lstinline@abs@, \lstinline@labs@, \lstinline@llabs@, \lstinline@fabs@, \lstinline@fabsf@, \lstinline@fabsl@, \lstinline@cabsf@, \lstinline@cabs@, and \lstinline@cabsl@.208 Whereas, \CFA wraps each of these routines into one with the common name \lstinline@abs@.207 For example, the C math-library provides the following routines for computing the absolute value of the basic type: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©. 208 Whereas, \CFA wraps each of these routines into one with the common name ©abs©. 209 209 \begin{lstlisting} 210 210 char abs( char ); … … 221 221 long double _Complex abs( long double _Complex ); 222 222 \end{lstlisting} 223 The problem is the name clash between the library routine \lstinline@abs@ and the \CFA names \lstinline@abs@.224 Hence, names appearing in an \lstinline@extern "C"@block have \newterm{C linkage}.223 The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©. 224 Hence, names appearing in an ©extern "C"© block have \newterm{C linkage}. 225 225 Then overloading polymorphism uses a mechanism called \newterm{name mangling} to create unique names that are different from C names, which are not mangled. 226 226 Hence, there is the same need as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed. 227 227 There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type. 228 228 This example strongly illustrates a core idea in \CFA: \emph{the power of a name}. 229 The name `` \lstinline@abs@'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.230 Hence, knowing the name \lstinline@abs@should be sufficient to apply it to any type where it is applicable.229 The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value. 230 Hence, knowing the name ©abs© should be sufficient to apply it to any type where it is applicable. 231 231 The time savings and safety of using one name uniformly versus $N$ unique names should not be underestimated. 232 232 … … 234 234 \section[Compiling CFA Program]{Compiling \CFA Program} 235 235 236 The command \lstinline@cfa@ is used to compile \CFA program(s). 237 This command works like the GNU \lstinline@gcc@\index{gcc} command, e.g.: 238 \begin{lstlisting} 239 cfa [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ] 240 \end{lstlisting} 241 \indexc{cfa}\index{compilation!cfa@\lstinline$cfa$} 242 By default, \CFA programs having the following \lstinline@gcc@ flags turned on: 236 The command ©cfa© is used to compile \CFA program(s). 237 This command works like the GNU ©gcc©\index{gcc} command, e.g.: 238 \begin{lstlisting} 239 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ] 240 \end{lstlisting} 241 By default, \CFA programs having the following ©gcc© flags turned on: 243 242 \begin{description} 244 \item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{ \lstinline$-std=gnu99$}}243 \item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{©-std=gnu99©}} 245 244 The 1999 C standard plus GNU extensions. 246 \item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{ \lstinline$-fgnu89-¶inline¶$}}245 \item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{©-fgnu89-¶inline¶©}} 247 246 Use the traditional GNU semantics for inline routines in C99 mode. 248 247 \end{description} 249 248 The following new \CFA option is available: 250 249 \begin{description} 251 \item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{ \lstinline$-CFA$}}250 \item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{©-CFA©}} 252 251 Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator. 253 252 \end{description} … … 255 254 The following preprocessor variables are available: 256 255 \begin{description} 257 \item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{ \lstinline$__CFA__$}}256 \item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{©__CFA__©}} 258 257 is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{ 259 258 The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed. 260 259 Hence, the need to have three variables for the major, minor and patch version number.} 261 260 262 \item\hspace*{-4pt}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{ \lstinline$__CFA_MINOR__$}}261 \item\hspace*{-4pt}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{©__CFA_MINOR__©}} 263 262 is always available during preprocessing and its value is the current minor \Index{version number} of \CFA. 264 263 265 \item\hspace*{-4pt}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@ \lstinline$__CFA_PATCH__$}264 \item\hspace*{-4pt}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@©__CFA_PATCH__©} 266 265 is always available during preprocessing and its value is the current patch \Index{version number} of \CFA. 267 266 268 \item\hspace*{-4pt}\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@ \lstinline$__CFORALL__$}267 \item\hspace*{-4pt}\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@©__CFORALL__©} 269 268 is always available during preprocessing and it has no value. 270 269 \end{description} … … 279 278 #endif 280 279 \end{lstlisting} 281 which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.280 which conditionally includes the correct header file, if the program is compiled using ©gcc© or ©cfa©. 282 281 283 282 … … 300 299 \begin{enumerate} 301 300 \item 302 A sequence of underscores is disallowed, e.g., \lstinline@12__34@is invalid.301 A sequence of underscores is disallowed, e.g., ©12__34© is invalid. 303 302 \item 304 303 Underscores may only appear within a sequence of digits (regardless of the digit radix). 305 In other words, an underscore cannot start or end a sequence of digits, e.g., \lstinline@_1@, \lstinline@1_@ and \lstinline@_1_@are invalid (actually, the 1st and 3rd examples are identifier names).304 In other words, an underscore cannot start or end a sequence of digits, e.g., ©_1©, ©1_© and ©_1_© are invalid (actually, the 1st and 3rd examples are identifier names). 306 305 \item 307 306 A numeric prefix may end with an underscore; 308 307 a numeric infix may begin and/or end with an underscore; 309 308 a numeric suffix may begin with an underscore. 310 For example, the octal \lstinline@0@ or hexadecimal \lstinline@0x@ prefix may end with an underscore \lstinline@0_377@ or \lstinline@0x_ff@;311 the exponent infix \lstinline@E@ may start or end with an underscore \lstinline@1.0_E10@, \lstinline@1.0E_10@ or \lstinline@1.0_E_10@;312 the type suffixes \lstinline@U@, \lstinline@L@, etc. may start with an underscore \lstinline@1_U@, \lstinline@1_ll@ or \lstinline@1.0E10_f@.309 For example, the octal ©0© or hexadecimal ©0x© prefix may end with an underscore ©0_377© or ©0x_ff©; 310 the exponent infix ©E© may start or end with an underscore ©1.0_E10©, ©1.0E_10© or ©1.0_E_10©; 311 the type suffixes ©U©, ©L©, etc. may start with an underscore ©1_U©, ©1_ll© or ©1.0E10_f©. 313 312 \end{enumerate} 314 313 It is significantly easier to read and enter long constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose). … … 345 344 C and the new \CFA declarations may appear together in the same program block, but cannot be mixed within a specific declaration. 346 345 347 In \CFA declarations, the same tokens are used as in C: the character \lstinline@*@ is used to indicate a pointer, square brackets \lstinline@[@\,\lstinline@]@ are used to represent an array, and parentheses \lstinline@()@are used to indicate a routine parameter.346 In \CFA declarations, the same tokens are used as in C: the character ©*© is used to indicate a pointer, square brackets ©[©\,©]© are used to represent an array, and parentheses ©()© are used to indicate a routine parameter. 348 347 However, unlike C, \CFA type declaration tokens are specified from left to right and the entire type specification is distributed across all variables in the declaration list. 349 For instance, variables \lstinline@x@ and \lstinline@y@of type pointer to integer are defined in \CFA as follows:348 For instance, variables ©x© and ©y© of type pointer to integer are defined in \CFA as follows: 350 349 \begin{quote2} 351 350 \begin{tabular}{@{}l@{\hspace{30pt}}l@{}} … … 399 398 \end{quote2} 400 399 401 All type qualifiers, i.e., \lstinline@const@ and \lstinline@volatile@, are used in the normal way with the new declarations but appear left to right, e.g.:400 All type qualifiers, i.e., ©const© and ©volatile©, are used in the normal way with the new declarations but appear left to right, e.g.: 402 401 \begin{quote2} 403 402 \begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}} … … 419 418 \end{tabular} 420 419 \end{quote2} 421 All declaration qualifiers, i.e., \lstinline@extern@, \lstinline@static@, etc., are used in the normal way with the new declarations but can only appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier}420 All declaration qualifiers, i.e., ©extern©, ©static©, etc., are used in the normal way with the new declarations but can only appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier} 422 421 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.~\cite[\S~6.11.5(1)]{C11}} e.g.: 423 422 \begin{quote2} … … 441 440 \end{quote2} 442 441 443 Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{442 Unsupported are K\&R C declarations where the base type defaults to ©int©, if no type is specified\footnote{ 444 443 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}, 445 444 e.g.: … … 458 457 \section{Type Operators} 459 458 460 The new declaration syntax can be used in other contexts where types are required, e.g., casts and the pseudo-routine \lstinline@sizeof@:459 The new declaration syntax can be used in other contexts where types are required, e.g., casts and the pseudo-routine ©sizeof©: 461 460 \begin{quote2} 462 461 \begin{tabular}{@{}l@{\hspace{30pt}}l@{}} … … 484 483 } 485 484 \end{lstlisting} 486 where routine \lstinline@f@has three output (return values) and three input parameters.485 where routine ©f© has three output (return values) and three input parameters. 487 486 Existing C syntax cannot be extended with multiple return types because it is impossible to embed a single routine name within multiple return type specifications. 488 487 489 In detail, the brackets, \lstinline@[]@, enclose the result type, where each return value is named and that name is a local variable of the particular return type.\footnote{488 In detail, the brackets, ©[]©, enclose the result type, where each return value is named and that name is a local variable of the particular return type.\footnote{ 490 489 Michael Tiemann, with help from Doug Lea, provided named return values in g++, circa 1989.} 491 490 The value of each local return variable is automatically returned at routine termination. … … 511 510 int (*f(x))[ 5 ] int x; {} 512 511 \end{lstlisting} 513 The string `` \lstinline@int (*f(x))[ 5 ]@'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``\lstinline@[ 5 ] int x@'' declares a \CFA style parameter x of type array of 5 integers.514 Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string.512 The string ``©int (*f(x))[ 5 ]©'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``©[ 5 ] int x©'' declares a \CFA style parameter x of type array of 5 integers. 513 Since the strings overlap starting with the open bracket, ©[©, there is an ambiguous interpretation for the string. 515 514 As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity: 516 515 \begin{lstlisting} … … 518 517 int f( int (* foo) ); // foo is redefined as a parameter name 519 518 \end{lstlisting} 520 The string `` \lstinline@int (* foo)@'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.521 The redefinition of a type name in a parameter list is the only context in C where the character \lstinline@*@can appear to the left of a type name, and \CFA relies on all type modifier characters appearing to the right of the type name.519 The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo. 520 The redefinition of a type name in a parameter list is the only context in C where the character ©*© can appear to the left of a type name, and \CFA relies on all type modifier characters appearing to the right of the type name. 522 521 The inability to use \CFA declarations in these two contexts is probably a blessing because it precludes programmers from arbitrarily switching between declarations forms within a declaration contexts. 523 522 … … 538 537 \subsection{Returning Values} 539 538 540 Named return values handle the case where it is necessary to define a local variable whose value is then returned in a \lstinline@return@statement, as in:539 Named return values handle the case where it is necessary to define a local variable whose value is then returned in a ©return© statement, as in: 541 540 \begin{lstlisting} 542 541 int f() { … … 546 545 } 547 546 \end{lstlisting} 548 Because the value in the return variable is automatically returned when a \CFA routine terminates, the \lstinline@return@statement \emph{does not} contain an expression, as in:547 Because the value in the return variable is automatically returned when a \CFA routine terminates, the ©return© statement \emph{does not} contain an expression, as in: 549 548 \begin{lstlisting} 550 549 ®[ int x ]® f() { … … 553 552 } 554 553 \end{lstlisting} 555 When the return is encountered, the current value of \lstinline@x@is returned to the calling routine.556 As well, ``falling off the end'' of a routine without a \lstinline@return@statement is permitted, as in:554 When the return is encountered, the current value of ©x© is returned to the calling routine. 555 As well, ``falling off the end'' of a routine without a ©return© statement is permitted, as in: 557 556 \begin{lstlisting} 558 557 [ int x ] f() { … … 560 559 } // implicitly return x 561 560 \end{lstlisting} 562 In this case, the current value of \lstinline@x@ is returned to the calling routine just as if a \lstinline@return@had been encountered.561 In this case, the current value of ©x© is returned to the calling routine just as if a ©return© had been encountered. 563 562 564 563 … … 836 835 \end{tabular} 837 836 \end{quote2} 838 In the left example in C, types \lstinline@C@, \lstinline@U@ and \lstinline@T@ are implicitly hoisted outside of type \lstinline@S@into the containing block scope.839 In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator `` \lstinline@.@'' for type qualification, as does Java, rather than the \CC type-selection operator ``\lstinline@::@''.837 In the left example in C, types ©C©, ©U© and ©T© are implicitly hoisted outside of type ©S© into the containing block scope. 838 In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``©.©'' for type qualification, as does Java, rather than the \CC type-selection operator ``©::©''. 840 839 841 840 … … 862 861 Nested routines are not first-class, meaning a nested routine cannot be returned if it has references to variables in its enclosing blocks; 863 862 the only exception is references to the external block of the translation unit, as these variables persist for the duration of the program. 864 The following program in undefined in \CFA (and \lstinline@gcc@\index{gcc})863 The following program in undefined in \CFA (and ©gcc©\index{gcc}) 865 864 \begin{lstlisting} 866 865 [* [int]( int )] foo() { // int (*foo())( int ) … … 891 890 [ §\emph{exprlist}§ ] 892 891 \end{lstlisting} 893 where \lstinline@$\emph{exprlist}$@is a list of one or more expressions separated by commas.894 The brackets, \lstinline$[]$, allow differentiating between tuples and expressions containing the C comma operator.892 where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas. 893 The brackets, ©[]©, allow differentiating between tuples and expressions containing the C comma operator. 895 894 The following are examples of tuples: 896 895 \begin{lstlisting} … … 899 898 [ v+w, x*y, 3.14159, f() ] 900 899 \end{lstlisting} 901 Tuples are permitted to contain sub-tuples (i.e., nesting), such as \lstinline@[ [ 14, 21 ], 9 ]@, which is a 2-element tuple whose first element is itself a tuple.900 Tuples are permitted to contain sub-tuples (i.e., nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple. 902 901 Note, a tuple is not a record (structure); 903 902 a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure (see flattening coercion in Section 12.1). … … 911 910 [ §\emph{typelist}§ ] 912 911 \end{lstlisting} 913 where \lstinline@$\emph{typelist}$@is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.912 where ©$\emph{typelist}$© is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications. 914 913 Examples of tuple types include: 915 914 \begin{lstlisting} … … 919 918 [ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ] 920 919 \end{lstlisting} 921 Like tuples, tuple types may be nested, such as \lstinline@[ [ int, int ], int ]@, which is a 2-element tuple type whose first element is itself a tuple type.920 Like tuples, tuple types may be nested, such as ©[ [ int, int ], int ]©, which is a 2-element tuple type whose first element is itself a tuple type. 922 921 923 922 Examples of declarations using tuple types are: … … 955 954 tuple does not have structure like a record; a tuple is simply converted into a list of components. 956 955 \begin{rationale} 957 The present implementation of \CFA does not support nested routine calls when the inner routine returns multiple values; i.e., a statement such as \lstinline@g( f() )@is not supported.956 The present implementation of \CFA does not support nested routine calls when the inner routine returns multiple values; i.e., a statement such as ©g( f() )© is not supported. 958 957 Using a temporary variable to store the results of the inner routine and then passing this variable to the outer routine works, however. 959 958 \end{rationale} … … 984 983 \begin{rationale} 985 984 Unfortunately, C's syntax for subscripts precluded treating them as tuples. 986 The C subscript list has the form \lstinline@[i][j]...@ and not \lstinline@i, j, ...]@.987 Therefore, there is no syntactic way for a routine returning multiple values to specify the different subscript values, e.g., \lstinline@f[g()]@always means a single subscript value because there is only one set of brackets.988 Fixing this requires a major change to C because the syntactic form \lstinline@M[i, j, k]@ already has a particular meaning: \lstinline@i, j, k@is a comma expression.985 The C subscript list has the form ©[i][j]...© and not ©[i, j, ...]©. 986 Therefore, there is no syntactic way for a routine returning multiple values to specify the different subscript values, e.g., ©f[g()]© always means a single subscript value because there is only one set of brackets. 987 Fixing this requires a major change to C because the syntactic form ©M[i, j, k]© already has a particular meaning: ©i, j, k© is a comma expression. 989 988 \end{rationale} 990 989 … … 1005 1004 [ a, b, c, d ] = w 1006 1005 \end{lstlisting} 1007 \lstinline@w@is implicitly opened to yield a tuple of four values, which are then assigned individually.1006 ©w© is implicitly opened to yield a tuple of four values, which are then assigned individually. 1008 1007 1009 1008 A \newterm{flattening coercion} coerces a nested tuple, i.e., a tuple with one or more components, which are themselves tuples, into a flattened tuple, which is a tuple whose components are not tuples, as in: … … 1013 1012 First the right-hand tuple is flattened and then the values are assigned individually. 1014 1013 Flattening is also performed on tuple types. 1015 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type \lstinline@[ int, int, int, int ]@.1014 For example, the type ©[ int, [ int, int ], int ]© can be coerced, using flattening, into the type ©[ int, int, int, int ]©. 1016 1015 1017 1016 A \newterm{structuring coercion} is the opposite of flattening; 1018 1017 a tuple is structured into a more complex nested tuple. 1019 For example, structuring the tuple \lstinline@[ 1, 2, 3, 4 ]@ into the tuple \lstinline@[ 1, [ 2, 3 ], 4 ]@ or the tuple type \lstinline@[ int, int, int, int ]@ into the tuple type \lstinline@[ int, [ int, int ], int ]@.1018 For example, structuring the tuple ©[ 1, 2, 3, 4 ]© into the tuple ©[ 1, [ 2, 3 ], 4 ]© or the tuple type ©[ int, int, int, int ]© into the tuple type ©[ int, [ int, int ], int ]©. 1020 1019 In the following example, the last assignment illustrates all the tuple coercions: 1021 1020 \begin{lstlisting} … … 1025 1024 \end{lstlisting} 1026 1025 Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values; 1027 therefore, the right-hand tuple is now the tuple \lstinline@[ [ 1, 2, 3, 4 ], 5 ]@.1028 This tuple is then flattened, yielding \lstinline@[ 1, 2, 3, 4, 5 ]@, which is structured into \lstinline@[ 1, [ 2, 3, 4, 5 ] ]@to match the tuple type of the left-hand side.1029 The tuple \lstinline@[ 2, 3, 4, 5 ]@is then closed to create a tuple value.1030 Finally, \lstinline@x@ is assigned \lstinline@1@ and \lstinline@w@is assigned the tuple value using multiple assignment (see Section 14).1026 therefore, the right-hand tuple is now the tuple ©[ [ 1, 2, 3, 4 ], 5 ]©. 1027 This tuple is then flattened, yielding ©[ 1, 2, 3, 4, 5 ]©, which is structured into ©[ 1, [ 2, 3, 4, 5 ] ]© to match the tuple type of the left-hand side. 1028 The tuple ©[ 2, 3, 4, 5 ]© is then closed to create a tuple value. 1029 Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using multiple assignment (see Section 14). 1031 1030 \begin{rationale} 1032 1031 A possible additional language extension is to use the structuring coercion for tuples to initialize a complex record with a tuple. … … 1042 1041 \end{lstlisting} 1043 1042 The left-hand side is a tuple of \emph{lvalues}, which is a list of expressions each yielding an address, i.e., any data object that can appear on the left-hand side of a conventional assignment statement. 1044 \lstinline@$\emph{expr}$@is any standard arithmetic expression.1043 ©$\emph{expr}$© is any standard arithmetic expression. 1045 1044 Clearly, the types of the entities being assigned must be type compatible with the value of the expression. 1046 1045 … … 1068 1067 *a1 = t; *a2 = t; *a3 = t; 1069 1068 \end{lstlisting} 1070 The temporary \lstinline@t@is necessary to store the value of the expression to eliminate conversion issues.1069 The temporary ©t© is necessary to store the value of the expression to eliminate conversion issues. 1071 1070 The temporaries for the addresses are needed so that locations on the left-hand side do not change as the values are assigned. 1072 In this case, \lstinline@y[i]@ uses the previous value of \lstinline@i@and not the new value set at the beginning of the mass assignment.1071 In this case, ©y[i]© uses the previous value of ©i© and not the new value set at the beginning of the mass assignment. 1073 1072 1074 1073 … … 1086 1085 [ x, y, z ] = [ 1, 2, 3 ]; 1087 1086 \end{lstlisting} 1088 Here, the values \lstinline@1@, \lstinline@2@ and \lstinline@3@ are assigned, respectively, to the variables \lstinline@x@, \lstinline@y@ and \lstinline@z@.1087 Here, the values ©1©, ©2© and ©3© are assigned, respectively, to the variables ©x©, ©y© and ©z©. 1089 1088 A more complex example is: 1090 1089 \begin{lstlisting} 1091 1090 [ i, y[ i ], z ] = [ 1, i, a + b ]; 1092 1091 \end{lstlisting} 1093 Here, the values \lstinline@1@, \lstinline@i@ and \lstinline@a + b@ are assigned to the variables \lstinline@i@, \lstinline@y[i]@ and \lstinline@z@, respectively.1092 Here, the values ©1©, ©i© and ©a + b© are assigned to the variables ©i©, ©y[i]© and ©z©, respectively. 1094 1093 Note, the parallel semantics of 1095 1094 multiple assignment ensures: … … 1097 1096 [ x, y ] = [ y, x ]; 1098 1097 \end{lstlisting} 1099 correctly interchanges (swaps) the values stored in \lstinline@x@ and \lstinline@y@.1098 correctly interchanges (swaps) the values stored in ©x© and ©y©. 1100 1099 The following cases are errors: 1101 1100 \begin{lstlisting} … … 1139 1138 §\emph{expr}§ -> [ §\emph{fieldlist}§ ] 1140 1139 \end{lstlisting} 1141 \emph{expr} is any expression yielding a value of type record, e.g., \lstinline@struct@, \lstinline@union@.1140 \emph{expr} is any expression yielding a value of type record, e.g., ©struct©, ©union©. 1142 1141 Each element of \emph{ fieldlist} is an element of the record specified by \emph{expr}. 1143 1142 A record-field tuple may be used anywhere a tuple can be used. An example of the use of a record-field tuple is … … 1155 1154 also, it is unnecessary to specify all the fields of a struct in a multiple record-field tuple. 1156 1155 1157 If a field of a \lstinline@struct@ is itself another \lstinline@struct@, multiple fields of this subrecord can be specified using a nested record-field tuple, as in the following example:1156 If a field of a ©struct© is itself another ©struct©, multiple fields of this subrecord can be specified using a nested record-field tuple, as in the following example: 1158 1157 \begin{lstlisting} 1159 1158 struct inner { … … 1172 1171 \section{Labelled Break/Continue} 1173 1172 1174 While C provides \lstinline@break@ and \lstinline@continue@statements for altering control flow, both are restricted to one level of nesting for a particular control structure.1175 Unfortunately, this restriction forces programmers to use \lstinline@goto@to achieve the equivalent for more than one level of nesting.1176 To prevent having to make this switch, the \lstinline@break@ and \lstinline@continue@are extended with a target label to support static multi-level exit~\cite{Buhr85,Java}.1177 For the labelled \lstinline@break@, it is possible to specify which control structure is the target for exit, as in:1173 While C provides ©break© and ©continue© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 1174 Unfortunately, this restriction forces programmers to use ©goto© to achieve the equivalent for more than one level of nesting. 1175 To prevent having to make this switch, the ©break© and ©continue© are extended with a target label to support static multi-level exit~\cite{Buhr85,Java}. 1176 For the labelled ©break©, it is possible to specify which control structure is the target for exit, as in: 1178 1177 \begin{quote2} 1179 1178 \begin{tabular}{@{}l@{\hspace{30pt}}l@{}} … … 1205 1204 \end{quote2} 1206 1205 The inner most loop has three exit points, which cause termination of one or more of the three nested loops, respectively. 1207 For the labelled \lstinline@continue@, it is possible to specify which control structure is the target for the next loop iteration, as in:1206 For the labelled ©continue©, it is possible to specify which control structure is the target for the next loop iteration, as in: 1208 1207 \begin{quote2} 1209 1208 \begin{tabular}{@{}l@{\hspace{30pt}}l@{}} … … 1241 1240 \end{quote2} 1242 1241 The inner most loop has three restart points, which cause the next loop iteration to begin, respectively. 1243 For both \lstinline@break@ and \lstinline@continue@, the target label must be directly associated with a \lstinline@for@, \lstinline@while@ or \lstinline@do@statement;1244 for \lstinline@break@, the target label can also be associated with a \lstinline@switch@statement.1245 Both \lstinline@break@ and \lstinline@continue@ with target labels are simply a \lstinline@goto@restricted in the following ways:1242 For both ©break© and ©continue©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 1243 for ©break©, the target label can also be associated with a ©switch© statement. 1244 Both ©break© and ©continue© with target labels are simply a ©goto© restricted in the following ways: 1246 1245 \begin{itemize} 1247 1246 \item … … 1252 1251 Since they always transfers out of containing control structures, they cannot be used to branch into a control structure. 1253 1252 \end{itemize} 1254 The advantage of the labelled \lstinline@break@/\lstinline@continue@ is that it allows static multi-level exits without having to use the \lstinline@goto@statement and ties control flow to the target control structure rather than an arbitrary point in a program.1253 The advantage of the labelled ©break©/©continue© is that it allows static multi-level exits without having to use the ©goto© statement and ties control flow to the target control structure rather than an arbitrary point in a program. 1255 1254 Furthermore, the location of the label at the beginning of the target control structure informs the reader that complex control-flow is occurring in the body of the control structure. 1256 With \lstinline@goto@, the label at the end of the control structure fails to convey this important clue early enough to the reader.1255 With ©goto©, the label at the end of the control structure fails to convey this important clue early enough to the reader. 1257 1256 Finally, using an explicit target for the transfer instead of an implicit target allows new nested loop or switch constructs to be added or removed without affecting other constructs. 1258 The implicit targets of the current \lstinline@break@ and \lstinline@continue@, i.e., the closest enclosing loop or \lstinline@switch@, change as certain constructs are added or removed.1257 The implicit targets of the current ©break© and ©continue©, i.e., the closest enclosing loop or ©switch©, change as certain constructs are added or removed. 1259 1258 1260 1259 1261 1260 \section{Switch Statement} 1262 1261 1263 C allows a number of questionable forms for the \lstinline@switch@statement:1262 C allows a number of questionable forms for the ©switch© statement: 1264 1263 \begin{enumerate} 1265 1264 \item 1266 By default, the end of a \lstinline@case@clause\footnote{1267 In this section, the term \emph{case clause} refers to either a \lstinline@case@ or \lstinline@default@clause.}1268 \emph{falls through} to the next \lstinline@case@ clause in the \lstinline@switch@statement;1269 to exit a \lstinline@switch@ statement from a \lstinline@case@ clause requires explicitly terminating the clause with a transfer statement, most commonly \lstinline@break@, as in:1265 By default, the end of a ©case© clause\footnote{ 1266 In this section, the term \emph{case clause} refers to either a ©case© or ©default© clause.} 1267 \emph{falls through} to the next ©case© clause in the ©switch© statement; 1268 to exit a ©switch© statement from a ©case© clause requires explicitly terminating the clause with a transfer statement, most commonly ©break©, as in: 1270 1269 \begin{lstlisting} 1271 1270 switch ( i ) { … … 1292 1291 \end{lstlisting} 1293 1292 In this example, case 2 is always done if case 3 is done. 1294 This control flow is difficult to simulate with if statements or a \lstinline@switch@statement without fall-through as code must be duplicated or placed in a separate routine.1293 This control flow is difficult to simulate with if statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine. 1295 1294 C also uses fall-through to handle multiple case-values resulting in the same action, as in: 1296 1295 \begin{lstlisting} … … 1305 1304 \end{lstlisting} 1306 1305 However, this situation is handled in other languages without fall-through by allowing a list of case values. 1307 While fall-through itself is not a problem, the problem occurs when fall-through is the \lstinline@default@, as this semantics is not intuitive to most programmers and is different from virtually all other programming languages with a \lstinline@switch@statement.1308 Hence, \lstinline@default@ fall-through semantics results in a large number of programming errors as programmers often forget the \lstinline@break@ statement at the end of a \lstinline@case@clause, resulting in inadvertent fall-through.1309 1310 \item 1311 It is possible to place \lstinline@case@ clauses on statements nested \emph{within} the body of the \lstinline@switch@statement, as in:1306 While fall-through itself is not a problem, the problem occurs when fall-through is the ©default©, as this semantics is not intuitive to most programmers and is different from virtually all other programming languages with a ©switch© statement. 1307 Hence, ©default© fall-through semantics results in a large number of programming errors as programmers often forget the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through. 1308 1309 \item 1310 It is possible to place ©case© clauses on statements nested \emph{within} the body of the ©switch© statement, as in: 1312 1311 \begin{lstlisting} 1313 1312 switch ( i ) { … … 1350 1349 } 1351 1350 \end{lstlisting} 1352 which unrolls a loop N times (N = 8 above) and uses the \lstinline@switch@statement to deal with any iterations not a multiple of N.1351 which unrolls a loop N times (N = 8 above) and uses the ©switch© statement to deal with any iterations not a multiple of N. 1353 1352 While efficient, this sort of special purpose usage is questionable: 1354 1353 \begin{quote} … … 1357 1356 \end{quote} 1358 1357 \item 1359 It is possible to place the \lstinline@default@ clause anywhere in the list of labelled clauses for a \lstinline@switch@statement, rather than only at the end.1360 Virtually all programming languages with a \lstinline@switch@ statement require the \lstinline@default@clause to appear last in the case-clause list.1361 The logic for this semantics is that after checking all the \lstinline@case@ clauses without success, the \lstinline@default@clause is selected;1362 hence, physically placing the \lstinline@default@ clause at the end of the \lstinline@case@clause list matches with this semantics.1363 This physical placement can be compared to the physical placement of an \lstinline@else@ clause at the end of a series of connected \lstinline@if@/\lstinline@else@statements.1364 1365 \item 1366 It is possible to place unreachable code at the start of a \lstinline@switch@statement, as in:1358 It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end. 1359 Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list. 1360 The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected; 1361 hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics. 1362 This physical placement can be compared to the physical placement of an ©else© clause at the end of a series of connected ©if©/©else© statements. 1363 1364 \item 1365 It is possible to place unreachable code at the start of a ©switch© statement, as in: 1367 1366 \begin{lstlisting} 1368 1367 switch ( x ) { … … 1374 1373 } 1375 1374 \end{lstlisting} 1376 While the declaration of the local variable \lstinline@y@ is useful and its scope is across all \lstinline@case@clauses, the initialization for such a variable is defined to never be executed because control always transfers over it.1377 Furthermore, any statements before the first \lstinline@case@ clause can only be executed if labelled and transfered to using a \lstinline@goto@, either from outside or inside of the \lstinline@switch@.1375 While the declaration of the local variable ©y© is useful and its scope is across all ©case© clauses, the initialization for such a variable is defined to never be executed because control always transfers over it. 1376 Furthermore, any statements before the first ©case© clause can only be executed if labelled and transfered to using a ©goto©, either from outside or inside of the ©switch©. 1378 1377 As mentioned, transfer into control structures should be forbidden. 1379 Transfers from within the \lstinline@switch@ body using a \lstinline@goto@are equally unpalatable.1378 Transfers from within the ©switch© body using a ©goto© are equally unpalatable. 1380 1379 \end{enumerate} 1381 1380 Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program: 1382 1381 \begin{itemize} 1383 1382 \item 1384 the number of \lstinline@switch@statements is small,1385 \item 1386 most \lstinline@switch@statements are well formed (i.e., no Duff's device),1387 \item 1388 the \lstinline@default@clause is usually written as the last case-clause,1389 \item 1390 and there is only a medium amount of fall-through from one \lstinline@case@clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound.1383 the number of ©switch© statements is small, 1384 \item 1385 most ©switch© statements are well formed (i.e., no Duff's device), 1386 \item 1387 the ©default© clause is usually written as the last case-clause, 1388 \item 1389 and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound. 1391 1390 \end{itemize} 1392 1391 These observations should help to put the effects of suggested changes into perspective. … … 1394 1393 \begin{enumerate} 1395 1394 \item 1396 Eliminating the \lstinline@default@fall-through problem has the greatest potential for affecting existing code.1397 However, even if fall-through is removed, most \lstinline@switch@ statements would continue to work because of the explicit transfers already present at the end of each \lstinline@case@ clause, and the common placement of the \lstinline@default@clause at the end of the case list.1398 In addition, the above grammar provides for the most common use of fall-through, i.e., a list of \lstinline@case@clauses executing common code, e.g.:1395 Eliminating the ©default© fall-through problem has the greatest potential for affecting existing code. 1396 However, even if fall-through is removed, most ©switch© statements would continue to work because of the explicit transfers already present at the end of each ©case© clause, and the common placement of the ©default© clause at the end of the case list. 1397 In addition, the above grammar provides for the most common use of fall-through, i.e., a list of ©case© clauses executing common code, e.g.: 1399 1398 \begin{lstlisting} 1400 1399 case 1: case 2: case 3: ... 1401 1400 \end{lstlisting} 1402 1401 Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments. 1403 Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of \lstinline@switch@ statement, called \lstinline@choose@, with no fall-through semantics.1404 The \lstinline@choose@ statement is identical to the new \lstinline@switch@ statement, except there is no implicit fall-through between case-clauses and the \lstinline@break@ statement applies to the enclosing loop construct (as for the continue statement in a \lstinline@switch@statement).1402 Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called ©choose©, with no fall-through semantics. 1403 The ©choose© statement is identical to the new ©switch© statement, except there is no implicit fall-through between case-clauses and the ©break© statement applies to the enclosing loop construct (as for the continue statement in a ©switch© statement). 1405 1404 It is still possible to fall-through if a case-clause ends with the new keyword fallthru, e.g.: 1406 1405 \begin{lstlisting} … … 1418 1417 \item 1419 1418 Eliminating Duff's device is straightforward and only invalidates a small amount of very questionable code. 1420 The solution is to allow \lstinline@case@ clauses to only appear at the same nesting level as the \lstinline@switch@ body, as is done in most other programming languages with \lstinline@switch@statements.1421 \item 1422 The issue of \lstinline@default@ at locations other than at the end of the cause clause can be solved by using good programming style, and there are a few reasonable situations involving fall-through where the \lstinline@default@clause may appear is locations other than at the end.1419 The solution is to allow ©case© clauses to only appear at the same nesting level as the ©switch© body, as is done in most other programming languages with ©switch© statements. 1420 \item 1421 The issue of ©default© at locations other than at the end of the cause clause can be solved by using good programming style, and there are a few reasonable situations involving fall-through where the ©default© clause may appear is locations other than at the end. 1423 1422 Therefore, no language change is made for this issue. 1424 1423 \item 1425 Dealing with unreachable code at the start of a \lstinline@switch@ statement is solved by defining the declaration-list, including any associated initialization, at the start of a \lstinline@switch@ statement body to be executed before the transfer to the appropriate \lstinline@case@clause.1424 Dealing with unreachable code at the start of a ©switch© statement is solved by defining the declaration-list, including any associated initialization, at the start of a ©switch© statement body to be executed before the transfer to the appropriate ©case© clause. 1426 1425 This semantics is the same as for declarations at the start of a loop body, which are executed before each iteration of the loop body. 1427 As well, this grammar does not allow statements to appear before the first \lstinline@case@clause.1426 As well, this grammar does not allow statements to appear before the first ©case© clause. 1428 1427 The change is compatible for declarations with initialization in this context because existing code cannot assume the initialization has occurred. 1429 1428 The change is incompatible for statements, but any existing code using it is highly questionable, as in: … … 1435 1434 } 1436 1435 \end{lstlisting} 1437 The statement after the \lstinline@switch@can never be executed unless it is labelled.1438 If it is labelled, it must be transfered to from outside or inside the \lstinline@switch@statement, neither of which is acceptable control flow.1436 The statement after the ©switch© can never be executed unless it is labelled. 1437 If it is labelled, it must be transfered to from outside or inside the ©switch© statement, neither of which is acceptable control flow. 1439 1438 \end{enumerate} 1440 1439 … … 1442 1441 \section{Case Clause} 1443 1442 1444 C restricts the \lstinline@case@ clause of a \lstinline@switch@statement to a single value.1445 For multiple \lstinline@case@ clauses associated with the same statement, it is necessary to have multiple \lstinline@case@clauses rather than multiple values.1446 Requiring a \lstinline@case@clause for each value does not seem to be in the spirit of brevity normally associated with C.1447 Therefore, the \lstinline@case@clause is extended with a list of values, as in:1443 C restricts the ©case© clause of a ©switch© statement to a single value. 1444 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values. 1445 Requiring a ©case© clause for each value does not seem to be in the spirit of brevity normally associated with C. 1446 Therefore, the ©case© clause is extended with a list of values, as in: 1448 1447 \begin{quote2} 1449 1448 \begin{tabular}{@{}l@{\hspace{30pt}}l@{\hspace{20pt}}l@{}} … … 1740 1739 1741 1740 The syntax for using references in \CFA is the same as \CC with the exception of reference initialization. 1742 Use \lstinline@&@to specify a reference, and access references just like regular objects, not like pointers (use dot notation to access fields).1741 Use ©&© to specify a reference, and access references just like regular objects, not like pointers (use dot notation to access fields). 1743 1742 When initializing a reference, \CFA uses a different syntax which differentiates reference initialization from assignment to a reference. 1744 The \lstinline@&@is used on both sides of the expression to clarify that the address of the reference is being set to the address of the variable to which it refers.1743 The ©&© is used on both sides of the expression to clarify that the address of the reference is being set to the address of the variable to which it refers. 1745 1744 1746 1745 \begin{figure} … … 1815 1814 In \CFA, as in C, all scalar types can be incremented and 1816 1815 decremented, which is defined in terms of adding or subtracting 1. 1817 The operations \lstinline@&&@, \lstinline@||@, and \lstinline@!@ can be applied to any scalar arguments and are defined in terms of comparison against 0 (ex. \lstinline@(a && b)@ becomes \lstinline@(a != 0 && b != 0)@).1816 The operations ©&&©, ©||©, and ©!© can be applied to any scalar arguments and are defined in terms of comparison against 0 (ex. ©(a && b)© becomes ©(a != 0 && b != 0)©). 1818 1817 1819 1818 In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any … … 1824 1823 polymorphic parameters, and user-defined pointer-like types may need a null value. 1825 1824 Defining special 1826 constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline@_Bool@.1825 constants for a user-defined type is more efficient than defining a conversion to the type from ©_Bool©. 1827 1826 1828 1827 Why just 0 and 1? Why not other integers? No other integers have special status in C. … … 1907 1906 \begin{tabular}[t]{ll} 1908 1907 %identifier & operation \\ \hline 1909 \lstinline@?[?]@& subscripting \impl{?[?]}\\1910 \lstinline@?()@& function call \impl{?()}\\1911 \lstinline@?++@& postfix increment \impl{?++}\\1912 \lstinline@?--@& postfix decrement \impl{?--}\\1913 \lstinline@++?@& prefix increment \impl{++?}\\1914 \lstinline@--?@& prefix decrement \impl{--?}\\1915 \lstinline@*?@& dereference \impl{*?}\\1916 \lstinline@+?@& unary plus \impl{+?}\\1917 \lstinline@-?@& arithmetic negation \impl{-?}\\1918 \lstinline@~?@& bitwise negation \impl{~?}\\1919 \lstinline@!?@& logical complement \impl{"!?}\\1920 \lstinline@?*?@& multiplication \impl{?*?}\\1921 \lstinline@?/?@& division \impl{?/?}\\1908 ©?[?]© & subscripting \impl{?[?]}\\ 1909 ©?()© & function call \impl{?()}\\ 1910 ©?++© & postfix increment \impl{?++}\\ 1911 ©?--© & postfix decrement \impl{?--}\\ 1912 ©++?© & prefix increment \impl{++?}\\ 1913 ©--?© & prefix decrement \impl{--?}\\ 1914 ©*?© & dereference \impl{*?}\\ 1915 ©+?© & unary plus \impl{+?}\\ 1916 ©-?© & arithmetic negation \impl{-?}\\ 1917 ©~?© & bitwise negation \impl{~?}\\ 1918 ©!?© & logical complement \impl{"!?}\\ 1919 ©?*?© & multiplication \impl{?*?}\\ 1920 ©?/?© & division \impl{?/?}\\ 1922 1921 \end{tabular}\hfil 1923 1922 \begin{tabular}[t]{ll} 1924 1923 %identifier & operation \\ \hline 1925 \lstinline@?%?@& remainder \impl{?%?}\\1926 \lstinline@?+?@& addition \impl{?+?}\\1927 \lstinline@?-?@& subtraction \impl{?-?}\\1928 \lstinline@?<<?@& left shift \impl{?<<?}\\1929 \lstinline@?>>?@& right shift \impl{?>>?}\\1930 \lstinline@?<?@& less than \impl{?<?}\\1931 \lstinline@?<=?@& less than or equal \impl{?<=?}\\1932 \lstinline@?>=?@& greater than or equal \impl{?>=?}\\1933 \lstinline@?>?@& greater than \impl{?>?}\\1934 \lstinline@?==?@& equality \impl{?==?}\\1935 \lstinline@?!=?@& inequality \impl{?"!=?}\\1936 \lstinline@?&?@& bitwise AND \impl{?&?}\\1924 ©?%?© & remainder \impl{?%?}\\ 1925 ©?+?© & addition \impl{?+?}\\ 1926 ©?-?© & subtraction \impl{?-?}\\ 1927 ©?<<?© & left shift \impl{?<<?}\\ 1928 ©?>>?© & right shift \impl{?>>?}\\ 1929 ©?<?© & less than \impl{?<?}\\ 1930 ©?<=?© & less than or equal \impl{?<=?}\\ 1931 ©?>=?© & greater than or equal \impl{?>=?}\\ 1932 ©?>?© & greater than \impl{?>?}\\ 1933 ©?==?© & equality \impl{?==?}\\ 1934 ©?!=?© & inequality \impl{?"!=?}\\ 1935 ©?&?© & bitwise AND \impl{?&?}\\ 1937 1936 \end{tabular}\hfil 1938 1937 \begin{tabular}[t]{ll} 1939 1938 %identifier & operation \\ \hline 1940 \lstinline@?^?@& exclusive OR \impl{?^?}\\1941 \lstinline@?|?@& inclusive OR \impl{?"|?}\\1942 \lstinline@?=?@& simple assignment \impl{?=?}\\1943 \lstinline@?*=?@& multiplication assignment \impl{?*=?}\\1944 \lstinline@?/=?@& division assignment \impl{?/=?}\\1945 \lstinline@?%=?@& remainder assignment \impl{?%=?}\\1946 \lstinline@?+=?@& addition assignment \impl{?+=?}\\1947 \lstinline@?-=?@& subtraction assignment \impl{?-=?}\\1948 \lstinline@?<<=?@& left-shift assignment \impl{?<<=?}\\1949 \lstinline@?>>=?@& right-shift assignment \impl{?>>=?}\\1950 \lstinline@?&=?@& bitwise AND assignment \impl{?&=?}\\1951 \lstinline@?^=?@& exclusive OR assignment \impl{?^=?}\\1952 \lstinline@?|=?@& inclusive OR assignment \impl{?"|=?}\\1939 ©?^?© & exclusive OR \impl{?^?}\\ 1940 ©?|?© & inclusive OR \impl{?"|?}\\ 1941 ©?=?© & simple assignment \impl{?=?}\\ 1942 ©?*=?© & multiplication assignment \impl{?*=?}\\ 1943 ©?/=?© & division assignment \impl{?/=?}\\ 1944 ©?%=?© & remainder assignment \impl{?%=?}\\ 1945 ©?+=?© & addition assignment \impl{?+=?}\\ 1946 ©?-=?© & subtraction assignment \impl{?-=?}\\ 1947 ©?<<=?© & left-shift assignment \impl{?<<=?}\\ 1948 ©?>>=?© & right-shift assignment \impl{?>>=?}\\ 1949 ©?&=?© & bitwise AND assignment \impl{?&=?}\\ 1950 ©?^=?© & exclusive OR assignment \impl{?^=?}\\ 1951 ©?|=?© & inclusive OR assignment \impl{?"|=?}\\ 1953 1952 \end{tabular} 1954 1953 \hfil … … 1959 1958 These identifiers are defined such that the question marks in the name identify the location of the operands. 1960 1959 These operands represent the parameters to the functions, and define how the operands are mapped to the function call. 1961 For example, \lstinline@a + b@ becomes \lstinline@?+?(a, b)@.1960 For example, ©a + b© becomes ©?+?(a, b)©. 1962 1961 1963 1962 In the example below, a new type, myComplex, is defined with an overloaded constructor, + operator, and string operator. … … 2002 2001 \begin{quote2} 2003 2002 \begin{tabular}{@{}l@{\hspace{30pt}}ll@{}} 2004 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}} & \multicolumn{1}{c}{ \lstinline@gcc@}\index{gcc} \\2003 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}} & \multicolumn{1}{c}{©gcc©}\index{gcc} \\ 2005 2004 \begin{lstlisting} 2006 2005 … … 2033 2032 \end{itemize} 2034 2033 2035 In \CFA, \lstinline@typedef@provides a mechanism to alias long type names with short ones, both globally and locally, but not eliminate the use of the short name.2036 \lstinline@gcc@ provides \lstinline@typeof@to declare a secondary variable from a primary variable.2034 In \CFA, ©typedef© provides a mechanism to alias long type names with short ones, both globally and locally, but not eliminate the use of the short name. 2035 ©gcc© provides ©typeof© to declare a secondary variable from a primary variable. 2037 2036 \CFA also relies heavily on the specification of the left-hand side of assignment for type inferencing, so in many cases it is crucial to specify the type of the left-hand side to select the correct type of the right-hand expression. 2038 2037 Only for overloaded routines with the same return type is variable type-inferencing possible. 2039 Finally, \lstinline@auto@presents the programming problem of tracking down a type when the type is actually needed.2038 Finally, ©auto© presents the programming problem of tracking down a type when the type is actually needed. 2040 2039 For example, given 2041 2040 \begin{lstlisting} 2042 2041 auto j = ®...® 2043 2042 \end{lstlisting} 2044 and the need to write a routine to compute using \lstinline@j@2043 and the need to write a routine to compute using ©j© 2045 2044 \begin{lstlisting} 2046 2045 void rtn( ®...® parm ); 2047 2046 rtn( j ); 2048 2047 \end{lstlisting} 2049 A programmer must work backwards to determine the type of \lstinline@j@'s initialization expression, reconstructing the possibly long generic type-name.2048 A programmer must work backwards to determine the type of ©j©'s initialization expression, reconstructing the possibly long generic type-name. 2050 2049 In this situation, having the type name or a short alias is very useful. 2051 2050 … … 2055 2054 At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes. 2056 2055 2057 Given \lstinline@typedef@ and \lstinline@typeof@in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time.2056 Given ©typedef© and ©typeof© in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time. 2058 2057 Should a significant need arise, this feature can be revisited. 2059 2058 … … 2357 2356 } s; 2358 2357 \end{lstlisting} 2359 The problem occurs in accesing these fields using the selection operation `` \lstinline@.@'':2358 The problem occurs in accesing these fields using the selection operation ``©.©'': 2360 2359 \begin{lstlisting} 2361 2360 s.0 = 0; // ambiguity with floating constant .0 … … 2368 2367 \end{lstlisting} 2369 2368 While this sytact is awkward, it is unlikely many programers will name fields of a structure 0 or 1. 2370 Like the \CC lexical problem with closing template-syntax, e.g, \lstinline@Foo<Bar<int®>>®@, this issue can be solved with a more powerful lexer/parser.2371 2372 There are several ambiguous cases with operator identifiers, e.g., \lstinline@int *?*?()@, where the string \lstinline@*?*?@ can be lexed as \lstinline@*@/\lstinline@?*?@ or \lstinline@*?@/\lstinline@*?@.2373 Since it is common practise to put a unary operator juxtaposed to an identifier, e.g., \lstinline@*i@, users will be annoyed if they cannot do this with respect to operator identifiers.2369 Like the \CC lexical problem with closing template-syntax, e.g, ©Foo<Bar<int®>>®©, this issue can be solved with a more powerful lexer/parser. 2370 2371 There are several ambiguous cases with operator identifiers, e.g., ©int *?*?()©, where the string ©*?*?© can be lexed as ©*©/©?*?© or ©*?©/©*?©. 2372 Since it is common practise to put a unary operator juxtaposed to an identifier, e.g., ©*i©, users will be annoyed if they cannot do this with respect to operator identifiers. 2374 2373 Even with this special hack, there are 5 general cases that cannot be handled. 2375 The first case is for the function-call identifier \lstinline@?()@:2374 The first case is for the function-call identifier ©?()©: 2376 2375 \begin{lstlisting} 2377 2376 int *§\textvisiblespace§?()(); // declaration: space required after '*' 2378 2377 *§\textvisiblespace§?()(); // expression: space required after '*' 2379 2378 \end{lstlisting} 2380 Without the space, the string \lstinline@*?()@is ambiguous without N character look ahead;2381 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument/parameter list.2379 Without the space, the string ©*?()© is ambiguous without N character look ahead; 2380 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument/parameter list. 2382 2381 2383 2382 The 4 remaining cases occur in expressions: … … 2388 2387 i§\textvisiblespace§?--i:0; // space required after '?' 2389 2388 \end{lstlisting} 2390 In the first two cases, the string \lstinline@i++?@ is ambiguous, where this string can be lexed as \lstinline@i@ / \lstinline@++?@ or \lstinline@i++@ / \lstinline@?@;2391 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.2392 In the second two cases, the string \lstinline@?++x@ is ambiguous, where this string can be lexed as \lstinline@?++@ / \lstinline@x@ or \lstinline@?@ / y\lstinline@++x@;2393 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.2389 In the first two cases, the string ©i++?© is ambiguous, where this string can be lexed as ©i© / ©++?© or ©i++© / ©?©; 2390 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list. 2391 In the second two cases, the string ©?++x© is ambiguous, where this string can be lexed as ©?++© / ©x© or ©?© / y©++x©; 2392 it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list. 2394 2393 2395 2394 … … 4007 4006 \begin{enumerate} 4008 4007 \item 4009 Change type of character literal \lstinline@int@ to \lstinline@char@.4008 Change type of character literal ©int© to ©char©. 4010 4009 This change allows overloading differentiation argument type matching, e.g.: 4011 4010 \begin{lstlisting} … … 4024 4023 4025 4024 \item 4026 Change: String literals made \lstinline@const@\\4027 The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.4028 The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\4025 Change: String literals made ©const© \\ 4026 The type of a string literal is changed from ©array of char© to ©array of const char©. 4027 The type of a wide string literal is changed from ©array of wchar_t© to ©array of const wchar_t©. \\ 4029 4028 Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument. 4030 4029 Effect on original feature: Change to semantics of well-defined feature. \\ 4031 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@(4.2).4030 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to ©char*;© (4.2). 4032 4031 The most common cases are handled by a new but deprecated standard conversion: 4033 4032 \begin{lstlisting} … … 4068 4067 4069 4068 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC. 4070 Nested types are not hoisted and can be referenced using the field selection operator `` \lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.4069 Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''. 4071 4070 Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility. 4072 4071 … … 4174 4173 %$ 4175 4174 \item 4176 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline@,.:;!?)]}%¢»@4175 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: ©,.:;!?)]}%¢»© 4177 4176 \begin{lstlisting}[belowskip=0pt] 4178 4177 sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"
Note: See TracChangeset
for help on using the changeset viewer.