- Timestamp:
- Jul 13, 2017, 7:26:28 AM (8 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:
- 3f5a28b
- Parents:
- 4438281
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r4438281 re9bb0e5 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Jul 7 10:36:39201714 %% Update Count : 2 54713 %% Last Modified On : Thu Jul 13 07:08:58 2017 14 %% Update Count : 2673 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 57 57 \CFAStyle % use default CFA format-style 58 58 59 \lstnewenvironment{C++}[1][] 60 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®}#1}} 61 {} 62 59 63 % inline code ©...© (copyright symbol) emacs: C-q M-) 60 64 % red highlighting ®...® (registered trademark symbol) emacs: C-q M-. … … 137 141 138 142 \CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed as an evolutionary step forward for the C programming language. 139 The syntax of the \CFA language builds from C,and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.143 The syntax of \CFA builds from C and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers. 140 144 % Any language feature that is not described here can be assumed to be using the standard \Celeven syntax. 141 \CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving Cperformance.142 Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.145 \CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance. 146 Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible. 143 147 The primary new features include parametric-polymorphic routines and types, exceptions, concurrency, and modules. 144 148 145 One of the main design philosophies of \CFA is to ``describe not prescribe'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''. 146 Programmers can cautiously add \CFA extensions to their C programs in any order and at any time to incrementally move towards safer, higher-level programming features. 147 A programmer is always free to reach back to C from \CFA for any reason, and in many cases, new \CFA features have a fallback to a C mechanism. 148 There is no notion or requirement for rewriting a legacy C program in \CFA; 149 instead, a programmer evolves an existing C program into \CFA by incrementally incorporating \CFA features. 150 New programs can be written in \CFA using a combination of C and \CFA features. 151 \Index*[C++]{\CC{}} had a similar goal 30 years ago, but currently has the disadvantages of multiple legacy design-choices that cannot be updated and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project. 149 One of the main design philosophies of \CFA is to ``\Index{describe not prescribe}'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''. 150 Programmers can cautiously add \CFA extensions to their C programs in any order and at any time to incrementally move towards safer, higher-level programming. 151 A programmer is always free to reach back to C from \CFA, for any reason, and in many cases, new \CFA features can be locally switched back to there C counterpart. 152 There is no notion or requirement for \emph{rewriting} a legacy C program in \CFA; 153 instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features. 154 As well, new programs can be written in \CFA using a combination of C and \CFA features. 155 156 \Index*[C++]{\CC{}} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C. 157 However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that cannot be updated, and active divergence of the language model from C, all of which requires significant effort and training to incrementally add \CC to a C-based project. 152 158 In contrast, \CFA has 30 years of hindsight and a clean starting point. 153 159 … … 156 162 \begin{quote2} 157 163 \begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}} 158 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 159 \begin{cfa} 160 #include <fstream>§\indexc{fstream}§ 161 162 int main( void ) { 163 int x = 0, y = 1, z = 2; 164 ®sout | x | y | z | endl;® 165 } 166 \end{cfa} 167 & 168 \begin{lstlisting} 164 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 165 \begin{cfa} 169 166 #include <stdio.h>§\indexc{stdio.h}§ 170 167 … … 173 170 ®printf( "%d %d %d\n", x, y, z );® 174 171 } 175 \end{ lstlisting}172 \end{cfa} 176 173 & 177 \begin{lstlisting} 174 \begin{cfa} 175 #include <fstream>§\indexc{fstream}§ 176 177 int main( void ) { 178 int x = 0, y = 1, z = 2; 179 ®sout | x | y | z | endl;®§\indexc{sout}§ 180 } 181 \end{cfa} 182 & 183 \begin{cfa} 178 184 #include <iostream>§\indexc{iostream}§ 179 185 using namespace std; … … 182 188 ®cout<<x<<" "<<y<<" "<<z<<endl;® 183 189 } 184 \end{ lstlisting}190 \end{cfa} 185 191 \end{tabular} 186 192 \end{quote2} 187 193 While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}). 188 194 195 \subsection{Background} 196 189 197 This document is a programmer reference-manual for the \CFA programming language. 190 198 The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature. 191 199 The manual does not teach programming, i.e., how to combine the new constructs to build complex programs. 192 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented as well as some experience programming in C/\CC.193 Implementers mayrefer to the \CFA Programming Language Specification for details about the language syntax and semantics.200 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC. 201 Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics. 194 202 Changes to the syntax and additional features are expected to be included in later revisions. 195 203 … … 200 208 This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more. 201 209 Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction. 202 For system programming, where direct access to hardware and dealing with real-time issues is a requirement, C is usually thelanguage of choice.210 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice. 203 211 The TIOBE index~\cite{TIOBE} for March 2016 showed the following programming-language popularity: \Index*{Java} 20.5\%, C 14.5\%, \Index*[C++]{\CC{}} 6.7\%, \Csharp 4.3\%, \Index*{Python} 4.3\%, where the next 50 languages are less than 3\% each with a long tail. 204 212 As well, for 30 years, C has been the number 1 and 2 most popular programming language: … … 216 224 \end{center} 217 225 Hence, C is still an extremely important programming language, with double the usage of \Index*[C++]{\CC{}}; in many cases, \CC is often used solely as a better C. 218 Love it or hate it, C has been an important and influential part of computer science for 40 years and sitappeal is not diminishing.219 Unfortunately, C has too many problems and omissions to make it anacceptable programming language for modern needs.220 221 As stated, the goal of the \CFA project is to engineer modern language 226 Love it or hate it, C has been an important and influential part of computer science for 40 years and its appeal is not diminishing. 227 Unfortunately, C has many problems and omissions that make it an unacceptable programming language for modern needs. 228 229 As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way. 222 230 \CC~\cite{C++14,C++} is an example of a similar project; 223 however, it largely extended the language, and did not address manyexisting problems.\footnote{%231 however, it largely extended the C language, and did not address most of C's existing problems.\footnote{% 224 232 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.} 225 \Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language 233 \Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language. 226 234 \Index*{Java}~\cite{Java8}, \Index*{Go}~\cite{Go}, \Index*{Rust}~\cite{Rust} and \Index*{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. 227 These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because ofgarbage collection.235 These languages have different syntax and semantics from C, do not interoperate directly with C, and are not systems languages because of restrictive memory-management or garbage collection. 228 236 As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten. 229 These costs can be prohibitive for many companies with a large software base in C/\CC, and a significant number of programmers requiring retraining to anew programming language.230 231 The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fix ing some of the well known C problems and containing many modern languagefeatures.237 These costs can be prohibitive for many companies with a large software-base in C/\CC, and a significant number of programmers require retraining to the new programming language. 238 239 The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixes many of the well known C problems while containing modern language-features. 232 240 Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers; 233 241 as a result, it will fade into disuse. 234 242 Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language. 235 While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language 236 While some may argue that modern language 243 While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language-features. 244 While some may argue that modern language-features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today. 237 245 238 246 239 247 \section{History} 240 248 241 The \CFA project started with \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and extended assignment capabilities using the notion of tuples.249 The \CFA project started with \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples. 242 250 (See~\cite{Werther96} for similar work in \Index*[C++]{\CC{}}.) 243 A first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}. 244 The signature feature of \CFA is parametric-polymorphic functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name): 251 The first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}. 252 253 The signature feature of \CFA is \Index{overload}able \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name): 245 254 \begin{lstlisting} 246 255 ®forall( otype T )® T identity( T val ) { return val; } … … 250 259 \CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfiled~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}. 251 260 However, at that time, there was little interesting in extending C, so work did not continue. 252 As the saying goes, `` What goes around, comes around.'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.261 As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted. 253 262 254 263 … … 257 266 258 267 \CFA is designed to integrate directly with existing C programs and libraries. 259 The most important feature of \Index{interoperability} is using the same \Index{calling convention}s, so there is no overhead to call existing C routines.268 The most important feature of \Index{interoperability} is using the same \Index{calling convention}s, so there is no complex interface or overhead to call existing C routines. 260 269 This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features. 261 270 Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself. 262 271 Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost. 263 Hence, \CFA begins by leveraging the large repository of C libraries withlittle cost.272 Hence, \CFA begins by leveraging the large repository of C libraries at little cost. 264 273 265 274 \begin{comment} … … 304 313 \end{comment} 305 314 306 However, it is necessary to differentiate between C and \CFA code because of name overloading, as for \CC.315 However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC. 307 316 For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©. 308 Whereas, \CFA wraps each of these routines into ones with the commonname ©abs©:317 Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©: 309 318 \begin{cfa} 310 319 char abs( char ); … … 326 335 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. 327 336 There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type. 328 This example strongly illustrates a core idea in \CFA: \emph{the power of a name}.337 This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}. 329 338 The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value. 330 Hence, knowing the name ©abs© should besufficient to apply it to any type where it is applicable.331 The time savings and safety of using one name uniformly versus $N$ unique names shouldnot be underestimated.332 333 334 \section[Compiling CFA Program]{Compiling\CFA Program}339 Hence, knowing the name ©abs© is sufficient to apply it to any type where it is applicable. 340 The time savings and safety of using one name uniformly versus $N$ unique names cannot be underestimated. 341 342 343 \section[Compiling a CFA Program]{Compiling a \CFA Program} 335 344 336 345 The command ©cfa© is used to compile \CFA program(s), and is based on the GNU \Indexc{gcc} command, \eg: 337 346 \begin{cfa} 338 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA §-files [ assembler/loader-files ]347 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA{}§-files [ assembler/loader-files ] 339 348 \end{cfa} 340 349 \CFA programs having the following ©gcc© flags turned on: … … 359 368 \Indexc{-debug}\index{compilation option!-debug@©-debug©} 360 369 The program is linked with the debugging version of the runtime system. 361 The debug version performs runtime checks to help during the debugging phase of a \CFA program, but substantially slows the execution of the program.370 The debug version performs runtime checks to help during the debugging phase of a \CFA program, but can substantially slow program execution. 362 371 The runtime checks should only be removed after the program is completely debugged. 363 372 \textbf{This option is the default.} … … 415 424 \end{description} 416 425 These preprocessor variables allow conditional compilation of programs that must work differently in these situations. 417 For example, to toggle between C and \CFA extensions, us ingthe following:426 For example, to toggle between C and \CFA extensions, use the following: 418 427 \begin{cfa} 419 428 #ifndef __CFORALL__ … … 426 435 427 436 428 \section{Constant sUnderscores}429 430 Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, \eg:437 \section{Constant Underscores} 438 439 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg: 431 440 \begin{cfa} 432 441 2®_®147®_®483®_®648; §\C{// decimal constant}§ … … 441 450 L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§ 442 451 \end{cfa} 443 The rules for placement of underscores is as follows:444 \begin{enumerate} 452 The rules for placement of underscores are: 453 \begin{enumerate}[topsep=5pt,itemsep=5pt,parsep=0pt] 445 454 \item 446 455 A sequence of underscores is disallowed, \eg ©12__34© is invalid. … … 463 472 \label{s:BackquoteIdentifiers} 464 473 465 \CFA accommodates keyword clashes with existing C variable-names by syntactic transformations using the \CFA backquote escape-mechanism: 474 \CFA introduces in new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code. 475 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism: 466 476 \begin{cfa} 467 477 int ®`®otype®`® = 3; §\C{// make keyword an identifier}§ … … 495 505 While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 496 506 Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting. 497 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85 ,Java}.507 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}. 498 508 For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 499 509 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. 500 510 \VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©. 501 511 The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s. 512 Java supports both labelled ©continue© and ©break© statements. 502 513 503 514 \begin{figure} … … 663 674 ®// open input file 664 675 ®} else if ( argc == 2 ) { 665 ®// open input file 676 ®// open input file (duplicate) 666 677 667 678 ®} else { … … 676 687 \begin{cfa} 677 688 switch ( i ) { 678 case 1: case 3: case 5:// odd values679 // sameaction689 ®case 1: case 3: case 5:® // odd values 690 // odd action 680 691 break; 681 case 2: case 4: case 6:// even values682 // sameaction692 ®case 2: case 4: case 6:® // even values 693 // even action 683 694 break; 684 695 } … … 686 697 However, this situation is handled in other languages without fall-through by allowing a list of case values. 687 698 While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from virtually all other programming languages with a ©switch© statement. 688 Hence, default fall-through semantics results in a large number of programming errors as programmers often forgetthe ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.699 Hence, default fall-through semantics results in a large number of programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through. 689 700 690 701 \item … … 770 781 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. 771 782 \end{itemize} 772 These observations help to put the \CFA changes to the ©switch© into perspective.783 These observations put into perspective the \CFA changes to the ©switch©. 773 784 \begin{enumerate} 774 785 \item … … 791 802 case 7: 792 803 ... 793 ®break® §\C{// explicit end of switch}§804 ®break® §\C{// redundant explicit end of switch}§ 794 805 default: 795 806 j = 3; … … 797 808 \end{cfa} 798 809 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses; 799 theimplicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.800 Theexplicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement.810 An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause. 811 An explicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement. 801 812 As well, allowing an explicit ©break© from the ©choose© is a carry over from the ©switch© statement, and expected by C programmers. 802 813 \item … … 902 913 \end{cfa} 903 914 915 916 \section{\protect\lstinline{with} Clause / Statement} 917 \label{s:WithClauseStatement} 918 919 In \Index{object-oriented} programming, there is an implicit first parameter, often names \textbf{©self©} or \textbf{©this©}, which is elided. 920 \begin{C++} 921 class C { 922 int i, j; 923 int mem() { 924 i = 1; ®// this->i 925 ® j = 3; ®// this->j 926 ® } 927 } 928 \end{C++} 929 Since CFA is non-object-oriented, the equivalent object-oriented program looks like: 930 \begin{cfa} 931 struct C { 932 int i, j; 933 }; 934 int mem( C &this ) { 935 ®this.®i = 1; // "this" is not elided 936 ®this.®j = 2; 937 } 938 \end{cfa} 939 but it is cumbersome having to write "©this.©" many times in a member. 940 \CFA provides a ©with© clause/statement to elided the "©this.©". 941 \begin{cfa} 942 int mem( C &this ) ®with this® { 943 i = 1; ®// this.i 944 ® j = 2; ®// this.j 945 ®} 946 \end{cfa} 947 which extends to multiple routine parameters: 948 \begin{cfa} 949 struct D { 950 double m, n; 951 }; 952 int mem2( C &this1, D &this2 ) ®with this1, this2® { 953 i = 1; j = 2; 954 m = 1.0; n = 2.0; 955 } 956 \end{cfa} 957 The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}. 958 959 The statement form is used within a block: 960 \begin{cfa} 961 int foo() { 962 struct S1 { ... } s1; 963 struct S2 { ... } s2; 964 ®with s1® { 965 // access fields of s1 without qualification 966 ®with s2® { // nesting 967 // access fields of s2 without qualification 968 } 969 } 970 ®with s1, s2® { 971 // access unambiguous fields of s1 and s2 without qualification 972 } 973 } 974 \end{cfa} 975 976 Names clashes when opening multiple structures are ambiguous. 977 \begin{cfa} 978 struct A { int i; int j; } a, c; 979 struct B { int i; int k; } b, c; 980 ®with a, b® { 981 j + k; §\C{// unambiguous}§ 982 i; §\C{// ambiguous}§ 983 a.i + b.i; §\C{// unambiguous}§ 984 } 985 ®with c® { §\C{// ambiguous}§ 986 // ... 987 } 988 \end{cfa} 904 989 905 990 \section{Exception Handling} … … 5261 5346 \label{s:CFAKeywords} 5262 5347 5348 \CFA introduces the following new keywords. 5349 5263 5350 \begin{quote2} 5264 \begin{tabular}{llll }5351 \begin{tabular}{lllll} 5265 5352 \begin{tabular}{@{}l@{}} 5266 ©_A T© \\5353 ©_At© \\ 5267 5354 ©catch© \\ 5268 5355 ©catchResume© \\ 5269 5356 ©choose© \\ 5270 5357 ©coroutine© \\ 5271 ©disable© \\5272 5358 \end{tabular} 5273 5359 & 5274 5360 \begin{tabular}{@{}l@{}} 5361 ©disable© \\ 5275 5362 ©dtype© \\ 5276 5363 ©enable© \\ 5277 5364 ©fallthrough© \\ 5278 5365 ©fallthru© \\ 5279 ©finally© \\5280 ©forall© \\5281 5366 \end{tabular} 5282 5367 & 5283 5368 \begin{tabular}{@{}l@{}} 5369 ©finally© \\ 5370 ©forall© \\ 5284 5371 ©ftype© \\ 5285 5372 ©lvalue© \\ 5286 5373 ©monitor© \\ 5374 \end{tabular} 5375 & 5376 \begin{tabular}{@{}l@{}} 5287 5377 ©mutex© \\ 5288 5378 ©one_t© \\ 5289 5379 ©otype© \\ 5380 ©throw© \\ 5381 ©throwResume© \\ 5290 5382 \end{tabular} 5291 5383 & 5292 5384 \begin{tabular}{@{}l@{}} 5293 ©throw© \\5294 ©throwResume© \\5295 5385 ©trait© \\ 5296 5386 ©try© \\ 5297 5387 ©ttype© \\ 5298 5388 ©zero_t© \\ 5389 \\ 5299 5390 \end{tabular} 5300 5391 \end{tabular}
Note: See TracChangeset
for help on using the changeset viewer.