Changes in doc/uC++toCFA/uC++toCFA.tex [946a6e4:697c957]
- File:
-
- 1 edited
-
doc/uC++toCFA/uC++toCFA.tex (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/uC++toCFA/uC++toCFA.tex
r946a6e4 r697c957 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun Oct 15 23:09:58202314 %% Update Count : 5 92613 %% Last Modified On : Sun Sep 17 09:10:12 2023 14 %% Update Count : 5883 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 119 119 120 120 \title{\vspace*{-0.5in} 121 \ uC to \CFA Cheat Sheet}121 \CC/\uC to \CFA Cheat Sheet} 122 122 %\author{Peter A. Buhr} 123 123 \date{} … … 195 195 \end{cfa} 196 196 \noindent 197 In subsequent code examples, the left example is \uC and the right example is \CFA. 197 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA. 198 199 200 \section{Looping} 201 202 \begin{cquote} 203 \begin{tabular}{l|l} 204 \begin{uC++} 205 for ( ;; ) { ... } / while ( true ) { ... } 206 for ( int i = 0; i < 10; i += 1 ) { ... } 207 for ( int i = 5; i < 15; i += 2 ) { ... } 208 int i = 0 209 for ( i = 0; i < 10; i += 1 ) { ... } 210 if ( i == 10 ) { ... } 211 \end{uC++} 212 & 213 \begin{cfa} 214 for () { ... } / while () { ... } 215 for ( 10 ) { ... } / for ( i; 10 ) { ... } 216 for ( i; 5~15~2 ) { ... } 217 218 for ( i; 10 ) { ... } 219 else { ... } // i == 10 220 \end{cfa} 221 \end{tabular} 222 \end{cquote} 223 224 225 \section{Exceptions} 226 227 Currently, \CFA uses macros @ExceptionDecl@ and @ExceptionInst@ to declare and instantiate an exception. 228 \begin{cquote} 229 \begin{tabular}{l|ll} 230 \begin{uC++} 231 232 struct E { // local or global scope 233 ... // exception fields 234 }; 235 try { 236 ... 237 if ( ... ) _Resume E( /* initialization */ ); 238 if ( ... ) _Throw E( /* initialization */ ); 239 ... 240 } _CatchResume( E & ) { // should be reference 241 ... 242 } catch( E & ) { 243 ... 244 } 245 \end{uC++} 246 & 247 \begin{cfa} 248 #include <Exception.hfa> 249 @ExceptionDecl@( E, // must be global scope 250 ... // exception fields 251 ); 252 try { 253 ... 254 if ( ... ) throwResume @ExceptionInst@( E, /* intialization */ ); 255 if ( ... ) throw @ExceptionInst@( E, /* intialization */ ); 256 ... 257 } catchResume( E * ) { // must be pointer 258 ... 259 } catch( E * ) { 260 ... 261 } 262 \end{cfa} 263 \end{tabular} 264 \end{cquote} 198 265 199 266 … … 218 285 sin | i | d | c; 219 286 sout | i | d | c 220 \end{cfa}221 \end{tabular}222 \end{cquote}223 224 225 \section{Looping}226 227 \begin{cquote}228 \begin{tabular}{l|l}229 \begin{uC++}230 for ( @;;@ ) { ... } / while ( @true@ ) { ... }231 for ( int i = 0; i < @10@; i += 1 ) { ... }232 for ( int i = @5@; i < @15@; i += @2@ ) { ... }233 for ( int i = -1; i <@=@ 10; i += 3 ) { ... }234 for ( int i = 10; i > 0; i @-@= 1 ) { ... }235 \end{uC++}236 &237 \begin{cfa}238 for () { ... } / while () { ... }239 for ( @10@ ) { ... } / for ( i; @10@ ) { ... }240 for ( i; @5@ ~ @15@ ~ @2@ ) { ... }241 for ( i; -1 ~@=@ 10 ~ 3 ) { ... }242 for ( i; 0 @-@~ 10 ) { ... }243 \end{cfa}244 \\245 \hline246 \begin{uC++}247 int i = 0248 for ( i = 0; i < 10; i += 1 ) { ... }249 @if ( i == 10 )@ { ... }250 \end{uC++}251 &252 \begin{cfa}253 254 for ( i; 10 ) { ... }255 @else@ { ... } // i == 10256 \end{cfa}257 \\258 \hline259 \begin{uC++}260 L1: for ( ;; ) {261 L2: for ( ;; ) {262 ... @break L1@; ... @break L2@; ...263 }264 }265 \end{uC++}266 &267 \begin{cfa}268 L1: for () {269 L2: for () {270 ... @break L1@; ... @break L2@; ...271 }272 }273 \end{cfa}274 \end{tabular}275 \end{cquote}276 277 278 \section{Exception}279 280 Currently, \CFA uses macros @ExceptionDecl@ and @ExceptionInst@ to declare and instantiate an exception.281 \begin{cquote}282 \begin{tabular}{l|ll}283 \begin{uC++}284 285 @_Exception@ E { // local or global scope286 ... // exception fields287 };288 try {289 ...290 if ( ... ) @_Resume@ E( /* initialization */ );291 if ( ... ) @_Throw@ E( /* initialization */ );292 ...293 } @_CatchResume@( E & ) { // should be reference294 ...295 } catch( E & ) {296 ...297 }298 \end{uC++}299 &300 \begin{cfa}301 #include <Exception.hfa>302 @ExceptionDecl@( E, // must be global scope303 ... // exception fields304 );305 try {306 ...307 if ( ... ) @throwResume@ @ExceptionInst@( E, /* intialization */ );308 if ( ... ) @throw@ @ExceptionInst@( E, /* intialization */ );309 ...310 } @catchResume@( E * ) { // must be pointer311 ...312 } catch( E * ) {313 ...314 }315 \end{cfa}316 \end{tabular}317 \end{cquote}318 319 320 \section{Non-local Exception}321 322 \begin{cquote}323 \begin{tabular}{l|ll}324 \begin{uC++}325 326 327 void main() {328 try {329 _Enable {330 ... suspend(); ...331 }332 } @_CatchResume@( E & ) { // reference333 ...334 } catch( E & ) {335 ...336 }337 }338 \end{uC++}339 &340 \begin{cfa}341 #define resumePoll( coroutine ) resume( coroutine ); checked_poll()342 #define suspendPoll suspend; checked_poll()343 void main() {344 try {345 enable_ehm();346 ... suspendPoll ...347 disable_ehm();348 } @catchResume@( E * ) { // pointer349 ...350 } catch( E & ) {351 ...352 }353 }354 \end{cfa}355 \end{tabular}356 \end{cquote}357 358 359 \section{Constructor / Destructor}360 361 \begin{cquote}362 \begin{tabular}{l|l}363 \begin{uC++}364 struct S {365 ... // fields366 @S@(...) { ... }367 @~S@(...) { ... }368 };369 \end{uC++}370 &371 \begin{cfa}372 struct S {373 ... // fields374 };375 @?{}@( @S & s,@ ...) { ... }376 @^?{}@( @S & s@ ) { ... }377 287 \end{cfa} 378 288 \end{tabular} … … 422 332 423 333 334 \section{Constructor / Destructor} 335 336 \begin{cquote} 337 \begin{tabular}{l|l} 338 \begin{uC++} 339 struct S { 340 ... // fields 341 @S@(...) { ... } 342 @~S@(...) { ... } 343 }; 344 \end{uC++} 345 & 346 \begin{cfa} 347 struct S { 348 ... // fields 349 }; 350 @?{}@( @S & s,@ ...) { ... } 351 @^?{}@( @S & s@ ) { ... } 352 \end{cfa} 353 \end{tabular} 354 \end{cquote} 355 356 424 357 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} 425 358
Note:
See TracChangeset
for help on using the changeset viewer.