- Timestamp:
- Dec 8, 2025, 11:29:33 AM (2 months ago)
- Branches:
- master, stuck-waitfor-destruct
- Children:
- 79ba50c
- Parents:
- 8f448e0 (diff), 79ec8c3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- doc
- Files:
-
- 8 edited
-
LaTeXmacros/common.sty (modified) (2 diffs)
-
LaTeXmacros/common.tex (modified) (2 diffs)
-
bibliography/pl.bib (modified) (37 diffs)
-
proposals/autogen.md (modified) (1 diff)
-
theses/fangren_yu_MMath/test.adb (modified) (1 diff)
-
theses/mike_brooks_MMath/intro.tex (modified) (9 diffs)
-
theses/mike_brooks_MMath/uw-ethesis-frontpgs.tex (modified) (1 diff)
-
uC++toCFA/uC++toCFA.tex (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/common.sty
r8f448e0 r5e0b6657 11 11 %% Created On : Sat Apr 9 10:06:17 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon May 5 21:37:13202514 %% Update Count : 66 613 %% Last Modified On : Sun Sep 21 22:17:15 2025 14 %% Update Count : 667 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 325 325 {<-}{$\leftarrow$}2 326 326 {=>}{$\Rightarrow$}2 327 {/*}{/{\raisebox{-2pt}{*}}}2 328 {*/}{{\raisebox{-2pt}{*}}/}2 327 329 % {->}{\raisebox{-1pt}{\texttt{-}}\kern-0.1ex\textgreater}2, 328 330 }% lstset -
doc/LaTeXmacros/common.tex
r8f448e0 r5e0b6657 11 11 %% Created On : Sat Apr 9 10:06:17 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon May 5 21:34:53 202514 %% Update Count : 7 0913 %% Last Modified On : Sun Sep 21 22:16:43 2025 14 %% Update Count : 710 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 329 329 {<-}{$\leftarrow$}2 330 330 {=>}{$\Rightarrow$}2 331 {/*}{/{\raisebox{-2pt}{*}}}2 332 {*/}{{\raisebox{-2pt}{*}}/}2 331 333 % {->}{\raisebox{-1pt}{\texttt{-}}\kern-0.1ex\textgreater}2, 332 334 }% lstset -
doc/bibliography/pl.bib
r8f448e0 r5e0b6657 362 362 school = {University of Waterloo}, 363 363 year = 1991, 364 address = {Waterloo, Ontario, Canada , N2L 3G1},364 address = {Waterloo, Ontario, Canada}, 365 365 } 366 366 … … 426 426 year = 2010, 427 427 month = dec, 428 address = {Waterloo, Ontario, Canada , N2L 3G1},428 address = {Waterloo, Ontario, Canada}, 429 429 optnote = {\textsf{http://uwspace.uwaterloo.ca/\-bitstream/10012/\-5751\-/1/Krischer\_Roy.pdf}}, 430 430 note = {\url{http://uwspace.uwaterloo.ca/bitstream/10012/5751/1/Krischer_Roy.pdf}}, … … 929 929 930 930 % B 931 932 @misc{ONCD, 933 keywords = {programming lnaguage safety}, 934 contributer = {pabuhr@plg}, 935 key = {Final-ONCD-Technical-Report}, 936 title = {Back to the Building Blocks: A Path Toward Secure and Measurable Software}, 937 author = {}, 938 howpublished= {\url{https://bidenwhitehouse.archives.gov/wp-content/uploads/2024/02/Final-ONCD-Technical-Report.pdf}}, 939 year = 2024, 940 } 931 941 932 942 @article{Michael13, … … 1154 1164 % C 1155 1165 1166 @mastersthesis{HummelViirola25, 1167 keywords = {C, Rust, conversion}, 1168 contributer = {pabuhr@plg}, 1169 author = {Johan Hummel and Ella Viirola}, 1170 title = {From C 2 Rust: Evaluating the Feasibility of Translating C to a Memory-Safe Programming Language at Ericsson}, 1171 school = {Lund University}, 1172 year = 2025, 1173 address = {Lund, Sweden}, 1174 } 1175 1156 1176 @book{C, 1157 1177 keywords = {C}, … … 1247 1267 title = {\textsf{C}$\mathbf{\forall}$ Container Library}, 1248 1268 school = {School of Computer Science, University of Waterloo}, 1249 address = {Waterloo, Ontario, Canada , N2L 3G1},1269 address = {Waterloo, Ontario, Canada}, 1250 1270 publisher = {UWSpace}, 1251 1271 year = {2025}, 1252 note = {\url{https://hdl.handle.net/10012/ XXXXX}},1272 note = {\url{https://hdl.handle.net/10012/12345}}, 1253 1273 } 1254 1274 … … 1324 1344 title = {The \textsf{C}$\mathbf{\forall}$ Scheduler}, 1325 1345 school = {School of Computer Science, University of Waterloo}, 1326 address = {Waterloo, Ontario, Canada , N2L 3G1},1346 address = {Waterloo, Ontario, Canada}, 1327 1347 publisher = {UWSpace}, 1328 1348 year = 2022, … … 1345 1365 school = {School of Computer Science, University of Waterloo}, 1346 1366 year = 2004, 1347 address = {Waterloo, Ontario, Canada , N2L 3G1},1367 address = {Waterloo, Ontario, Canada}, 1348 1368 note = {\url{http://plg.uwaterloo.ca/theses/EstevesThesis.pdf}}, 1349 1369 } … … 1355 1375 school = {School of Computer Science, University of Waterloo}, 1356 1376 year = 2019, 1357 address = {Waterloo, Ontario, Canada , N2L 3G1},1377 address = {Waterloo, Ontario, Canada}, 1358 1378 note = {\url{https://hdl.handle.net/10012/14584}}, 1359 1379 } … … 1510 1530 title = {\textsf{C}$\mathbf{\forall}$ Users Guide, Version 0.1}, 1511 1531 institution = {Department of Computer Science, University of Waterloo}, 1512 address = {Waterloo, Ontario, Canada , N2L 3G1},1532 address = {Waterloo, Ontario, Canada}, 1513 1533 month = oct, 1514 1534 year = 2001, … … 1833 1853 year = 1997, 1834 1854 month = sep, 1835 address = {Waterloo, Ontario, Canada , N2L 3G1},1855 address = {Waterloo, Ontario, Canada}, 1836 1856 note = {\url{http://plg.uwaterloo.ca/theses/MokThesis.pdf}}, 1837 1857 } … … 2058 2078 school = {School of Computer Sc., University of Waterloo}, 2059 2079 year = 2015, 2060 address = {Waterloo, Ontario, Canada , N2L 3G1},2080 address = {Waterloo, Ontario, Canada}, 2061 2081 note = {\url{https://hdl.handle.net/10012/10013}}, 2062 2082 } … … 2104 2124 title = {Concurrency in \textsf{C}$\mathbf{\forall}$}, 2105 2125 school = {School of Computer Science, University of Waterloo}, 2106 address = {Waterloo, Ontario, Canada , N2L 3G1},2126 address = {Waterloo, Ontario, Canada}, 2107 2127 publisher = {UWSpace}, 2108 2128 year = 2018, … … 2116 2136 title = {Concurrency in {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}}}, 2117 2137 institution = {Department of Computer Science, University of Waterloo}, 2118 address = {Waterloo, Ontario, Canada , N2L 3G1},2138 address = {Waterloo, Ontario, Canada}, 2119 2139 number = {CS-90-18}, 2120 2140 month = may, … … 2209 2229 school = {Department of Computer Science, University of Waterloo}, 2210 2230 year = 1992, 2211 address = {Waterloo, Ontario, Canada , N2L 3G1},2231 address = {Waterloo, Ontario, Canada}, 2212 2232 note = {\url{http://plg.uwaterloo.ca/theses/DitchfieldThesis.pdf}} 2213 2233 } … … 3289 3309 title = {Enumerated Types in \textsf{C}$\mathbf{\forall}$}, 3290 3310 school = {School of Computer Science, University of Waterloo}, 3291 address = {Waterloo, Ontario, Canada , N2L 3G1},3311 address = {Waterloo, Ontario, Canada}, 3292 3312 publisher = {UWSpace}, 3293 3313 year = {2024}, … … 3496 3516 title = {Exception Handling in \textsf{C}$\mathbf{\forall}$}, 3497 3517 school = {School of Computer Science, University of Waterloo}, 3498 address = {Waterloo, Ontario, Canada , N2L 3G1},3518 address = {Waterloo, Ontario, Canada}, 3499 3519 publisher = {UWSpace}, 3500 3520 year = {2021}, … … 3752 3772 year = 2008, 3753 3773 month = jan, 3754 address = {Waterloo, Ontario, Canada , N2L 3G1},3774 address = {Waterloo, Ontario, Canada}, 3755 3775 note = {\url{http://uwspace.uwaterloo.ca/bitstream/10012/3501/1/Thesis.pdf}}, 3756 3776 } … … 4209 4229 year = 2009, 4210 4230 month = sep, 4211 address = {Waterloo, Ontario, Canada , N2L 3G1},4231 address = {Waterloo, Ontario, Canada}, 4212 4232 note = {\textsf{http://uwspace.uwaterloo.ca/bitstream/\-10012/\-4735/\-1/\-Chen-Jun.pdf}}, 4213 4233 } … … 4230 4250 author = {Haskell}, 4231 4251 title = {Haskell 2010 Language Report}, 4232 edition = {{S}imon {M}arlow},4252 optedition = {{S}imon {M}arlow}, 4233 4253 year = 2010, 4234 4254 note = {\url{https://haskell.org/definition/haskell2010.pdf}}, … … 4291 4311 title = {High Level Concurrency in \textsf{C}$\mathbf{\forall}$}, 4292 4312 school = {School of Computer Science, University of Waterloo}, 4293 address = {Waterloo, Ontario, Canada , N2L 3G1},4313 address = {Waterloo, Ontario, Canada}, 4294 4314 publisher = {UWSpace}, 4295 4315 year = {2023}, … … 4302 4322 author = {Mubeen Zulfiqar}, 4303 4323 title = {High-Performance Concurrent Memory Allocation}, 4304 school = {School of Comp uter Science, Universityof Waterloo},4324 school = {School of Comp. Sc., Univ. of Waterloo}, 4305 4325 year = 2022, 4306 address = {Waterloo, Ontario, Canada , N2L 3G1},4326 address = {Waterloo, Ontario, Canada}, 4307 4327 note = {\url{https://hdl.handle.net/10012/18329}}, 4308 4328 } … … 4323 4343 author = {Srihari Radhakrishnan}, 4324 4344 title = {High Performance Web Servers: A Study In Concurrent Programming Models}, 4325 school = {School of Computer Sc ., University of Waterloo},4345 school = {School of Computer Science, University of Waterloo}, 4326 4346 year = 2019, 4327 address = {Waterloo, Ontario, Canada , N2L 3G1},4347 address = {Waterloo, Ontario, Canada}, 4328 4348 note = {\url{https://hdl.handle.net/10012/14706}}, 4329 4349 } … … 4529 4549 author = {Richard C. Bilson}, 4530 4550 title = {Implementing Overloading and Polymorphism in \textsf{C}$\mathbf{\forall}$}, 4531 school = { School of Computer Science,University of Waterloo},4551 school = {University of Waterloo}, 4532 4552 year = 2003, 4533 address = {Waterloo, Ontario, Canada , N2L 3G1},4553 address = {Waterloo, Ontario, Canada}, 4534 4554 note = {\url{http://plg.uwaterloo.ca/theses/BilsonThesis.pdf}}, 4535 4555 } … … 4572 4592 year = 2018, 4573 4593 month = sep, 4574 address = {Waterloo, Ontario, Canada , N2L 3G1},4594 address = {Waterloo, Ontario, Canada}, 4575 4595 note = {\url{https://uwspace.uwaterloo.ca/handle/10012/13935}}, 4576 4596 } … … 5109 5129 school = {University of Waterloo}, 5110 5130 year = 1990, 5111 address = {Waterloo, Ontario, Canada , N2L 3G1}5131 address = {Waterloo, Ontario, Canada} 5112 5132 } 5113 5133 … … 5531 5551 title = {$\mu${S}ystem Annotated Reference Manual, Version 4.4.3}, 5532 5552 institution = {Department of Computer Science, University of Waterloo}, 5533 address = {Waterloo, Ontario, Canada , N2L 3G1},5553 address = {Waterloo, Ontario, Canada}, 5534 5554 month = sep, 5535 5555 year = 1994, … … 6273 6293 contributer = {pabuhr@plg}, 6274 6294 key = {OCaml}, 6275 title = {The {OC}aml system, release 5.1},6276 address = {Rust Project Developers},6277 year = 202 3,6278 note = {\url{https://v2.ocaml.org/manual /}},6295 author = {Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy and Jérôme Vouillon}, 6296 title = {The {OC}aml system, release 5.4}, 6297 year = 2025, 6298 note = {\url{https://v2.ocaml.org/manual}}, 6279 6299 } 6280 6300 … … 7733 7753 school = {School of Computer Science, University of Waterloo}, 7734 7754 year = 2017, 7735 address = {Waterloo, Ontario, Canada , N2L 3G1},7755 address = {Waterloo, Ontario, Canada}, 7736 7756 note = {\url{https://hdl.handle.net/10012/11830}}, 7737 7757 } … … 7819 7839 contributer = {pabuhr@plg}, 7820 7840 key = {Rust}, 7821 title = { {R}ust Programming Language},7822 address = {Rust ProjectDevelopers},7841 title = {The {R}ust Reference}, 7842 address = {Rust Developers}, 7823 7843 year = 2015, 7824 note = {\url{https://doc.rust-lang.org/ reference.html}},7844 note = {\url{https://doc.rust-lang.org/stable/reference}}, 7825 7845 } 7826 7846 … … 7875 7895 month = jun, 7876 7896 pages = {35-46}, 7897 } 7898 7899 @inproceedings{Kashyap17, 7900 contributer = {pabuhr@plg}, 7901 author = {Sanidhya Kashyap and Changwoo Min and Taesoo Kim}, 7902 title = {Scalable {NUMA-aware} Blocking Synchronization Primitives}, 7903 booktitle = {2017 USENIX Annual Tech. Conf.}, 7904 address = {Santa Clara, CA}, 7905 pages = {603-615}, 7906 publisher = {USENIX Assoc.}, 7907 year = 2017, 7908 month = jul, 7877 7909 } 7878 7910 … … 8321 8353 contributer = {pabuhr@plg}, 8322 8354 author = {Michael D. Tiemann}, 8323 title = {Solving the RPC problem in GNU{C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}}},8355 title = {Solving the {RPC} problem in {GNU} {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}}}, 8324 8356 booktitle = {Proceedings of the USENIX {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}} Conference}, 8325 8357 organization= {USENIX Association}, … … 8333 8365 keywords = {Polymorphic C}, 8334 8366 contributor = {a3moss@uwaterloo.ca}, 8335 title = {A sound polymorphic type system for a dialect of {C}},8367 title = {A Sound Polymorphic Type System for a Dialect of {C}}, 8336 8368 author = {Smith, Geoffrey and Volpano, Dennis}, 8337 8369 journal = {Science of computer programming}, … … 8543 8575 school = {Department of Computer Science, University of Waterloo}, 8544 8576 year = 1989, 8545 address = {Waterloo, Ontario, Canada , N2L 3G1},8577 address = {Waterloo, Ontario, Canada}, 8546 8578 } 8547 8579 … … 8784 8816 volume = 40, 8785 8817 number = 6, 8786 month = jun,8818 optmonth = jun, 8787 8819 year = 2005, 8788 8820 pages = {261-268}, … … 8909 8941 } 8910 8942 8943 @misc{Tractor, 8944 keywords = {Rust, C conversion}, 8945 contributer = {pabuhr@plg}, 8946 key = {Tractor}, 8947 title = {TRACTOR: Translating All C to Rust}, 8948 author = {Dan Wallach}, 8949 note = {DARPA}, 8950 howpublished= {\url{https://www.darpa.mil/research/programs/translating-all-c-to-rust}}, 8951 year = 2024, 8952 } 8953 8911 8954 @misc{Miller19, 8912 8955 keywords = {memory management, errors, unsafe}, 8913 8956 contributer = {pabuhr@plg}, 8914 title = {Trends, challenges, and strategic shifts in the software vulnerability mitigation landscape},8957 title = {Trends, Challenges, and Strategic Shifts in the Software Vulnerability Mitigation Landscape}, 8915 8958 author = {Matt Miller}, 8916 8959 month = feb, … … 8926 8969 school = {Department of Computer Science, University of Waterloo}, 8927 8970 year = 1989, 8928 address = {Waterloo, Ontario, Canada , N2L 3G1},8971 address = {Waterloo, Ontario, Canada}, 8929 8972 } 8930 8973 … … 9087 9130 title = {Type Resolution in \textsf{C}$\mathbf{\forall}$}, 9088 9131 school = {School of Computer Science, University of Waterloo}, 9089 address = {Waterloo, Ontario, Canada , N2L 3G1},9132 address = {Waterloo, Ontario, Canada}, 9090 9133 publisher = {UWSpace}, 9091 9134 year = {2025}, -
doc/proposals/autogen.md
r8f448e0 r5e0b6657 100 100 The main reason to manually remove functions is to enforce a behaviour based interface for a type, as opposed to a data based one. To enforce that new interface, this would have to interact with visibility. 101 101 102 ### Automatic Remove Hides Everything 103 As soon as you declare a custom constructor, _all_ autogenerated constructors become inaccessible. Often, this behaviour is good, and it agrees with C++. But the desire dual to "manually remove" exists: "manually keep." Furthermore, there is a use case for invoking an automatically provided constructor as a helper, when implementing a custom constructor. 104 105 struct S { 106 int i; 107 int & j; 108 }; 109 void ?{}( S & s, int & w ) { 110 // Unique best alternative includes deleted identifier in: 111 s{ 3, w }; 112 // intended meaning / workaround: 113 // s.i = 3; &s.j = &w; 114 } 115 116 This use case should be considered also, along with visibility. A private helper constructor should be usable in the implementation of a public value-add constructor. The private helper being an autogen is one such arrangement. 117 118 Users should have the option to adopt the idiom: All constructors funnel into the most private, all-member constructor. 119 120 ### Removed Functions Linger 121 Even if a function is made CFA-uncallable, it still shows in the emitted C code (`cfa -CFA`). An uncallable function shows identically to a callable function, with no indication of, "This declaration has been deleted," or, "Here is a redaction of X." This quirk reduces the utility of inspecting -CFA to answer, "What constructors would be available to me?" or, "What's the net effect of the constructor declarations and deletions that I've given?" 122 102 123 ## Other Problems & Requested Features 103 124 -
doc/theses/fangren_yu_MMath/test.adb
r8f448e0 r5e0b6657 6 6 Function Random return Float is begin return 3.5; end; 7 7 Function Random return Unbounded_String is begin return To_Unbounded_String( "abc" ); end; 8 8 9 9 Procedure Print( V : Integer ) is begin Put_Line( Integer'Image(V) ); end; 10 10 Procedure Print( V : Float ) is begin Put_Line( Float'Image(V) ); end; 11 11 Procedure Print( V : Unbounded_String ) is begin Put_Line( Ada.Strings.Unbounded.To_String(V) ); end; 12 12 13 13 Function Func( V : Integer ) return Integer is begin return V; end; 14 14 Function Func( V : Float ) return Float is begin return V; end; 15 15 Function Func( V : Unbounded_String ) return Unbounded_String is begin return V; end; 16 16 Function Func( V1 : Integer; V2 : Float ) return Float is begin return Float(V1) + V2; end; 17 18 subtype Int is Integer;17 18 subtype Int is Integer; 19 19 J : Int; 20 20 Function "-"( L, R : Int ) return Int is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion 21 22 -- duplicate body for "-" declared at line 2023 -- subtype SInt is Integer range -10 .. 10;24 -- Function "-"( L, R : SInt ) return SInt is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion25 21 22 -- duplicate body for "-" declared at line 20 23 -- subtype SInt is Integer range -10 .. 10; 24 -- Function "-"( L, R : SInt ) return SInt is begin Put_Line( "X" ); return Integer(L) + (-Integer(R)); end; -- prevent infinite recusion 25 26 26 i : Integer; 27 27 f : Float; 28 28 s : Unbounded_String; 29 29 30 30 Type Complex is 31 record32 Re, Im : Float;33 end record;31 record 32 Re, Im : Float; 33 end record; 34 34 c : Complex := (Re => 1.0, Im => 1.0); 35 Procedure Grind (X : Complex) is begin Put_Line( "Grind1" ); end;36 Procedure Grind (X : Unbounded_String) is begin Put_Line( "Grind2" ); end;37 35 Procedure Grind (X : Complex) is begin Put_Line( "Grind1" ); end; 36 Procedure Grind (X : Unbounded_String) is begin Put_Line( "Grind2" ); end; 37 38 38 generic 39 type T is private;40 with function "+"( X, Y: T ) return T;39 type T is private; 40 with function "+"( X, Y: T ) return T; 41 41 function twice( X : T ) return T; 42 42 43 43 function twice( X: T ) return T is 44 44 begin 45 Put_Line( "XXX" ); return X + X;-- The formal operator "*".45 Put_Line( "XXX" ); return X + X; -- The formal operator "*". 46 46 end twice; 47 47 48 48 function Int_Twice is new Twice( Integer, "+" => "+" ); 49 49 function float_Twice is new Twice( float, "+" => "+" ); 50 51 -- generic units cannot be overloaded52 -- generic53 --type T is private;54 --with function "+"( X, Y: T ) return T;55 -- function twice( X : T; Y : T ) return T;56 57 -- function twice( X: T; Y : T ) return T is58 -- begin59 -- Put_Line( "XXX" ); return X + X;-- The formal operator "*".60 -- end twice;50 51 -- generic units cannot be overloaded 52 -- generic 53 -- type T is private; 54 -- with function "+"( X, Y: T ) return T; 55 -- function twice( X : T; Y : T ) return T; 56 57 -- function twice( X: T; Y : T ) return T is 58 -- begin 59 -- Put_Line( "XXX" ); return X + X; -- The formal operator "*". 60 -- end twice; 61 61 begin 62 I := 3;63 I := 7 - 3;64 Print( i );65 F := 3.8;66 I := 7 - 2;67 Print( i );68 J := 7 - 3;69 Print( j );70 62 I := 3; 63 I := 7 - 3; 64 Print( i ); 65 F := 3.8; 66 I := 7 - 2; 67 Print( i ); 68 J := 7 - 3; 69 Print( j ); 70 71 71 i := Random; 72 Print( i );72 Print( i ); 73 73 f := Random; 74 Print( f );74 Print( f ); 75 75 s := Random; 76 Print( s );77 78 Print( Func( V => 7 ) );79 Print( Func( 7.5 ) );80 Print( Func( To_Unbounded_String( "abc" ) ) );81 Print( Func( 3, 3.5 ) );82 --Print( Func( 3, 3 ) );83 76 Print( s ); 77 78 Print( Func( V => 7 ) ); 79 Print( Func( 7.5 ) ); 80 Print( Func( To_Unbounded_String( "abc" ) ) ); 81 Print( Func( 3, 3.5 ) ); 82 -- Print( Func( 3, 3 ) ); 83 84 84 Grind( X => (Re => 1.0, Im => 1.0) ); 85 85 Grind( c ); 86 86 Grind( To_Unbounded_String( "abc" ) ); 87 87 88 88 i := Int_Twice( 2 ); 89 89 Put_Line( Integer'Image(i) ); 90 90 f := float_Twice( 2.5 ); 91 Print( f );91 Print( f ); 92 92 end test; 93 93 -
doc/theses/mike_brooks_MMath/intro.tex
r8f448e0 r5e0b6657 2 2 3 3 All modern programming languages provide three high-level containers (collections): array, linked-list, and string. 4 Often array is part of the programming language, while linked-list is built from (recursive) pointer types, and stringfrom a combination of array and linked-list.4 Often array is part of the programming language, while linked-lists are built from (recursive) pointer types, and strings from a combination of array and linked-list. 5 5 For all three types, languages and/or their libraries supply varying degrees of high-level mechanisms for manipulating these objects at the bulk and component level, such as copying, slicing, extracting, and iterating among elements. 6 6 7 7 Unfortunately, these three aspects of C cause a significant number of memory errors~\cite{Oorschot23}. 8 Estimates suggest 50\%~\cite{Mendio24} of total reported open-source vulnerabilities occurring in C result from errors using these facilities (memory errors). 8 9 For operating system and browser vendors, who heavily use systems languages, 60\%--70\% of reported software vulnerabilities involved memory errors~\cite{Kehrer23}. 9 10 For Microsoft, 70\% of vulnerabilities addressed via security updates between 2006--2018 are memory safety issues~\cite[slide 10]{Miller19}. 10 11 In a study of software exploits in the U.S. National Vulnerability Database over 2013--2017, the top reported vulnerability is (memory) buffer errors, among 19 vulnerability categories~\cite{Cifuentes19}. 11 Therefore, hardening these three C types goes a long way to make the majority of C programs safer .12 Therefore, hardening these three C types goes a long way to make the majority of C programs safer and eliminating major hacker attack-vectors. 12 13 13 14 This work looks at extending these three foundational container types in the programming language \CFA, which is a new dialect of the C programming language. … … 26 27 The array size can be static, dynamic but fixed after creation, or dynamic and variable after creation. 27 28 For static and dynamic-fixed, an array can be stack allocated, while dynamic-variable requires the heap. 28 Because array layout has contiguous components, subscripting is a computation (some form of pointer arithmetic).29 Because array layout has contiguous components, subscripting is a computation, \ie some form of pointer arithmetic. 29 30 30 31 C provides a simple array type as a language feature. 31 However, it adopts the controversial languageposition of treating pointer and array as duals, leading to multiple problems.32 However, it adopts the controversial position of treating pointer and array as duals, leading to multiple problems. 32 33 33 34 … … 36 37 A linked-list provides a homogeneous container often with $O(log N)$ or $O(N)$ access to elements using successor and predecessor operations that normally involve pointer chasing. 37 38 Subscripting by value (rather than position or location as for array) is sometimes available, \eg hash table. 38 Linked types are normally dynamically sized by adding and removing nodes using link fields internal or external to theelements (nodes).39 If a programming language allows pointers to stack storage, linked-list nodes can be allocated on the stack and connected with stack addresses (pointers);39 Linked types are dynamically sized by adding and removing nodes using link fields internal or external to the list elements (nodes). 40 If a programming language allows pointers to stack storage, linked-list nodes can be allocated on the stack and connected with stack addresses; 40 41 otherwise, elements are heap allocated with internal or external link fields. 41 42 … … 47 48 hash search table consisting of a key (string) with associated data (@<search.h>@) 48 49 \end{itemize} 49 Because these libraries are simple, awkward to use, and unsafe, C programmers commonly build bespoke linked data-structures.50 Because these container libraries can be restrictive, awkward to use, and unsafe, C programmers often build bespoke linked data-structures, which further increases the potential for memory errors. 50 51 51 52 … … 54 55 A string provides a dynamic array of homogeneous elements, where the elements are (often) some form of human-readable characters. 55 56 What differentiates a string from other types in that many of its operations work on groups of elements for scanning and changing, \eg @index@ and @substr@. 56 While subscripting individual elements is usually available, working at the individualcharacter level is considered poor practise, \ie underutilizing the powerful string operations.57 While subscripting individual elements is usually available, working at the character level is considered poor practise, \ie underutilizing the powerful string operations. 57 58 Therefore, the cost of a string operation is usually less important than the power of the operation to accomplish complex text manipulation, \eg search, analysing, composing, and decomposing string text. 58 59 The dynamic nature of a string means storage is normally heap allocated but often implicitly managed, even in unmanaged languages. 59 In somecases, string management is separate from heap management, \ie strings roll their own heap.60 In many cases, string management is separate from heap management, \ie strings roll their own heap. 60 61 61 62 The C string type is just a character array and requires user storage-management to handle varying size. 62 The character array uses the convention of marking its (variable) array length by placing the 0-valued control character at the end (null-terminated). 63 C adopts a terminating sentinel character, @'\0'@, to mark the end of a variable-length character-array versus a preceding length field. 64 Hence, the sentinel character is excluded from a string and determining the string length is an $O(N)$ operation. 63 65 The C standard library includes a number of high-level operations for working with this representation. 64 Most of these operations are awkward and error prone.66 Most of these operations are awkward to use and error prone. 65 67 66 68 … … 80 82 \begin{enumerate}[leftmargin=*] 81 83 \item 82 The se three aspects of C are difficult to understand, teach, and get right because they are correspondinglylow level.84 The three primary container types in C are difficult to understand, teach, and get right because they are too low level. 83 85 Providing higher-level, feature-rich versions of these containers in \CFA is a major component of the primary goal. 86 The result is a simplify programming experience, which increases productivity and maintainability. 84 87 \item 85 These three aspects of C cause the greatest safety issues because there are few or no safe guards when a programmer misunderstands or misuses these features~\cite{Elliott18, Blache19, Ruef19, Oorschot23}. 86 Estimates suggest 50\%~\cite{Mendio24} of total reported open-source vulnerabilities occurring in C result from errors using these facilities (memory errors), providing the major hacker attack-vectors. 88 The new container types must be as correct and safe to use as those in other modern programming languages, which has been shown to a primary concern of industry, government, and military~\cite{ONCD}. 89 Prior approaches focus on out-of-bound array accesses using a model-based approach (ASCET) in embedded systems (\eg cars)~\cite{Blache19}, and general and null-terminated string arrays using a \CC template syntax (Checked C)~\cite{Elliott18,Ruef19}. 90 Both White House~\cite{WhiteHouse24} and DARPA~\cite{DARPA24} recently released a recommendation to \emph{move away} from C and \CC, because of cybersecurity threats exploiting vulnerabilities in these languages. 91 Fixing these vulnerabilities negates this need, allowing C and its ecosystem to continue into the future. 87 92 \end{enumerate} 88 Both White House~\cite{WhiteHouse24} and DARPA~\cite{DARPA24} recently released a recommendation to move away from C and \CC, because of cybersecurity threats exploiting vulnerabilities in these older languages.89 Hardening these three types goes a long way to make the majority of C programs safer.90 93 91 92 While multiple new languages purport to be systems languages replacing C, the reality is that rewriting massive C code-bases is impractical and a non-starter if the new runtime uses garage collection. 94 While new languages, \eg Go, Rust, Swift, purport to be systems languages replacing C, the reality is that rewriting massive C code-bases is impractical and a non-starter if the runtime uses garbage collection. 95 Even assuming automated conversion of C programs to other safe languages, who will maintain this massive new code-base? 93 96 Furthermore, new languages must still interact with the underlying C operating system through fragile, type-unsafe, interlanguage-communication. 94 Switching to \CC is equally impractical as its complex and interdependent type-system (\eg objects, overloading, inheritance, templates) means idiomatic \CC code is difficult to use from C, and C programmers must expend significant effort learning new \CC. 95 Hence, rewriting and retraining costs for these languages can be prohibitive for companies with a large C software-base (Google, Apple, Microsoft, Amazon, AMD, Nvidia). 97 Switching to \CC is equally impractical as its complex and interdependent type-system (\eg objects, overloading, inheritance, templates) means idiomatic \CC code is difficult to use from C, and C programmers must expend significant effort learning new \CC features and idioms. 98 Finally, projects claiming to be modern C replacements (Cyclone~\cite{Grossman06}, Polymorphic C~\cite{Smith98}, GObject~\cite{GObject}) do not retain C backwards compatibility in syntax, programing model, or semantic compatibility; 99 these languages are equivalent to switching to a different programming language. 100 Hence, rewriting and retraining costs for other languages are prohibitive when companies have a large C software-base (Google, Apple, Microsoft, Amazon, AMD, Nvidia). 96 101 97 102 … … 100 105 Like many established programming languages, C has a standards committee and multiple ANSI/\-ISO language manuals~\cite{C99,C11,C18,C23}. 101 106 However, most programming languages are only partially explained by their standard's manual(s). 102 When it comes to explaining how C works, the definitive source is the @gcc@ compiler, which is mimicked by other C compilers, such as Clang~\cite{clang}. 103 Often other C compilers \emph{must} mimic @gcc@ because a large part of the C library (runtime) system (@glibc@ on Linux) contains @gcc@ features. 107 When it comes to explaining how C works, the definitive source is the @gcc@ compiler, which is mimicked by other C compilers, such as Clang~\cite{clang}, because a large part of the C library (runtime) system (@glibc@ on Linux) contains @gcc@ features. 104 108 Some key aspects of C need to be explained and understood by quoting from the language reference manual. 105 109 However, to illustrate actual program semantics, this thesis constructs multiple small programs whose behaviour exercises a particular point and then confirms the behaviour by running the program using multiple @gcc@ compilers. 106 110 These example programs show 107 \begin{itemize} 111 \begin{itemize}[itemsep=0pt] 108 112 \item if the compiler accepts or rejects certain syntax, 109 113 \item prints output to buttress a behavioural claim, … … 111 115 \end{itemize} 112 116 These programs are tested across @gcc@ versions 8--14 and clang versions 10--14 running on ARM, AMD, and Intel architectures. 113 Any discovered anomalies among compilers, versions, or architectures isdiscussed.117 Any discovered anomalies among compilers, versions, or architectures are discussed. 114 118 In general, it is never clear whether the \emph{truth} lies in the C standard or the compiler(s), which may be true for other programming languages. 115 119 … … 118 122 119 123 Overall, this work has produced significant syntactic and semantic improvements to C's arrays, linked-lists and string types. 120 As well, a strong plan for general iteration has been sketched out.124 % As well, a strong plan for general iteration has been sketched out. 121 125 The following are the detailed contributions, where performance and safety were always the motivating factors. 122 126 123 127 \subsection{Array} 124 128 125 Th is work's array improvements are:129 The improvements to C arrays are: 126 130 \begin{enumerate}[leftmargin=*] 127 131 \item 128 Introduce a small number of subtle changes to the typing rules for the C array, while still achieving significant backwards compatibility 132 Introduce a small number of subtle changes to the typing rules for the C array, while still achieving significant backwards compatibility. 129 133 \item 130 134 Create a new polymorphic mechanism in the \CFA @forall@ clause to specify array dimension values, similar to a fixed-typed parameter in a \CC \lstinline[language=C++]{template}. -
doc/theses/mike_brooks_MMath/uw-ethesis-frontpgs.tex
r8f448e0 r5e0b6657 129 129 \begin{center}\textbf{Abstract}\end{center} 130 130 131 \CFA strives to fix mistakes in C, chief among them, safety. 132 This thesis presents a significant step forward in \CFA's goal to remove unsafe pointer operations. 133 The thesis presents improvements to the \CFA language design, both syntax and semantics, to support advanced container features. 134 These features are implemented across the \CFA compiler, libraries, and runtime system. 135 The results maintain another \CFA goal of remaining 99\% backwards compatible with C. 136 This thesis leverages preexisting work within the compiler's type and runtime systems generated by prior students working on the \CFA project. 137 131 138 All modern programming languages provide three high-level containers (collections): array, linked-list, and string. 132 Often array is part of the programming language, while linked-list is built from (recursive) pointer types, and stringfrom a combination of array and linked-list.139 Often array is part of the programming language, while linked-lists are built from (recursive) pointer types, and strings from a combination of array and linked-list. 133 140 For all three types, languages and/or their libraries supply varying degrees of high-level mechanisms for manipulating these objects at the bulk and component level, such as copying, slicing, extracting, and iterating among elements. 134 Unfortunately, these three aspects of C cause 60\%--70\% of the reported software vulnerabilities involv edmemory errors, and 70\%--80\% of hacker attack-vectors target these types.141 Unfortunately, these three aspects of C cause 60\%--70\% of the reported software vulnerabilities involving memory errors, and 70\%--80\% of hacker attack-vectors target these types. 135 142 Therefore, hardening these three C types goes a long way to make the majority of C programs safer. 136 143 137 This work looks at extending these three foundational container types in the programming language \CFA, which is a new dialect of the C programming language. 138 The thesis describes improvements made to the \CFA language design, both syntax and semantics, to support the container features, and the source code created within the \CFA compiler, libraries, and runtime system to implement these features. 139 This work leverages preexisting work within the compiler's type and runtime systems generated by prior students working on the \CFA project. 140 141 Overall, this work has produced significant syntactic and semantic improvements to C's container types. 142 \begin{enumerate}[leftmargin=*] 143 \item 144 Introduce a small number of subtle changes to the typing rules for the C array, while still achieving significant backwards compatibility. 145 \item 146 Create a new polymorphic mechanism in the \CFA @forall@ clause to specify array dimension values, similar to a fixed-typed parameter in a \CC \lstinline[language=C++]{template}. 147 The new array type, enabled by prior features, defines an array with guaranteed runtime bound checks (often optimizer-removable) and implicit (guaranteed accurate) inter-function length communication. 148 \item 149 Create a new polymorphic list type and its runtime library following the established design pattern of intrusive link-fields for performance reasons, especially in concurrent programs. 150 \item 151 Create a new string type and runtime library comparable to the \CC @string@ type, including analogous coexistence with raw-character pointers, enabling programs to work with strings by value, without incurring excessive copying. 152 Substrings are supported, including the ability for overlapping ranges to share edits transparently. 153 \end{enumerate} 154 The thesis includes a performance evaluation that shows the new \CFA containers perform comparably with their C counterparts in many programming cases. 144 Specifically, an array utility is provided that tracks length internally, relieving the user of managing explicit length parameters and stopping buffer-overrun errors. 145 This feature requires augmenting the \CFA type system, making array length available at compile and runtime. 146 A linked-list utility is provided, which obviates many explicit recursive pointers by catering directly to system-programming uses (intrusive lists) for which a library solution is often dismissed. 147 Finally, a string utility is provided with implicit memory management of text in a specialized heap, relieving error-prone buffer management, including overrun, and providing a copy-on-write speed boost. 148 For all three utilities, performance is argued to be on-par with, and occasionally surpassing relevant comparators. 149 With the array, this case is made by showing complete erasure down to a naked C array, modulo runtime bound checks, which are removable more often than with Java-style length management. 150 With the linked list and string, empirical measures are compared with relevant libraries. 151 These utilities offer a system programmer workable alternatives to hand-rolling several common causes of system vulnerabilities, thereby improving \CFA's position as a safety-forward system-programming alternative. 155 152 156 153 \cleardoublepage -
doc/uC++toCFA/uC++toCFA.tex
r8f448e0 r5e0b6657 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon Sep 8 18:10:30202514 %% Update Count : 6 53413 %% Last Modified On : Mon Nov 17 11:14:48 2025 14 %% Update Count : 6677 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 345 345 346 346 \begin{cquote} 347 \setlength{\tabcolsep}{5pt} 347 348 \begin{tabular}{@{}l|ll@{}} 348 349 \begin{uC++} 349 350 350 351 351 void main() {352 void Coroutine::main() { 352 353 try { 353 354 _Enable { … … 357 358 catch( E & ) { ... } 358 359 } 360 void Coroutine::mem() { resume(); } 359 361 \end{uC++} 360 362 & … … 362 364 #define resumePoll( coroutine ) resume( coroutine ); poll() 363 365 #define suspendPoll suspend; poll() 364 void main( ) {366 void main( Coroutine & cor ) { 365 367 try { 366 368 enable_ehm(); … … 370 372 catch( E & ) { ... } 371 373 } 374 void mem( Coroutine & cor ) { resumePoll(); } 372 375 \end{cfa} 373 376 \end{tabular} … … 429 432 \end{tabular} 430 433 \end{cquote} 434 435 436 \section{Time} 437 438 \begin{cquote} 439 \setlength{\tabcolsep}{5pt} 440 \begin{tabular}{@{}l|l@{}} 441 \begin{uC++} 442 443 uTime start = uClock::currTime(); 444 ... 445 cout << "duration " << uClock::currTime() - start 446 << " sec." << endl; 447 \end{uC++} 448 & 449 \begin{cfa} 450 #include <clock.hfa> 451 Time start = timeHiRes(); // time with nanoseconds 452 ... 453 sout | "duration " | timeHiRes() - start | " sec."; 454 455 \end{cfa} 456 \end{tabular} 457 \end{cquote} 458 459 460 \section{Constructor / Destructor} 461 462 A constructor/destructor must have its structure type as the first parameter and be a reference. 463 \begin{cquote} 464 \begin{tabular}{@{}l|l@{}} 465 \begin{uC++} 466 467 struct S { 468 int i, j; 469 @S@() { i = j = 3; } 470 @S@( int i, int j ) { S::i = i; S::j = j; } 471 @S@( const S & s ) { *this = s; } 472 @~S@() {} 473 }; 474 S s0, s1 = { 1, 2 }; 475 476 S * s2 = new S{ 1, 2 }; delete s2; 477 s2 = new S{ 1, 2 }; delete s2; 478 S & s3 = *new S{ 1, 2 }; delete &s3; 479 s3 = *new S{ 1, 2 }; delete &s3; 480 \end{uC++} 481 & 482 \begin{cfa} 483 #include <stdlib.hfa> // new (malloc) 484 struct S { int i, j; }; 485 486 void @?{}@( @S & s@ ) { s.i = s.j = 3; } $\C[3in]{// default}$ 487 void @?{}@( @S & s@, int i, int j ) { s.i = i; s.j = j; } $\C{// initializer}$ 488 void @?{}@( @S & s@, const S rhs ) { ?{}( s, rhs.i, rhs.j ); } $\C{// copy}$ 489 void @^?{}@( @S & s@ ) { s.i = 0; s.j = 0; } $\C{// destructor}\CRT$ 490 491 S s0, s1 = { 1, 2 }; 492 // bug, cannot use 0/1 (zero_t/one_t) with "new" 493 S * s2 = new( 0@n@, 2 ); /* suffix n => (natural int) */ delete( s2 ); 494 s2 = new( 1@n@, 2 ); delete( s2 ); 495 S & s3 = *new( 2, 2 ); delete( &s3 ); 496 &s3 = &*new( 3, 2 ); delete( &s3 ); 497 \end{cfa} 498 \end{tabular} 499 \end{cquote} 500 501 502 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} 503 504 \CFA is NOT an object-oriented programming-language, so there is no receiver (\lstinline[language=c++]{this}) or nested structure routines. 505 The equivalent of a \emph{member} routine has an explicit structure parameter in any parameter position (often the first). 506 \begin{cquote} 507 \begin{tabular}{@{}l|l@{}} 508 \begin{uC++} 509 struct S { 510 int i = 0; // cheat, implicit default constructor 511 int setter( int j ) { int t = i; i = j; return t; } 512 int getter() { return i; } 513 }; 514 S s; 515 @s.@setter( 3 ); // object calls 516 int k = @s.@getter(); 517 \end{uC++} 518 & 519 \begin{cfa} 520 struct S { int i; }; 521 void ?{}( S & s ) { s.i = 0; } // explicit default constructor 522 int setter( @S & s,@ int j ) @with( s )@ { int t = i; i = j; return t; } 523 int getter( @S & s@ ) @with( s )@ { return i; } 524 525 S s; 526 setter( @s,@ 3 ); // normal calls 527 int k = getter( @s@ ); 528 \end{cfa} 529 \end{tabular} 530 \end{cquote} 531 Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause. 532 \begin{cfa} 533 struct S { int i; int j; double m; }; // field i has same type in structures S and T 534 struct T { int i; int k; int m; }; 535 void foo( S s, T t ) @with( s, t )@ { // open structure scope s and t in parallel 536 j + k; $\C[1.6in]{// unambiguous, s.j + t.k}$ 537 m = 5.0; $\C{// unambiguous, s.m = 5.0}$ 538 m = 1; $\C{// unambiguous, t.m = 1}$ 539 int a = m; $\C{// unambiguous, a = t.m}$ 540 double b = m; $\C{// unambiguous, b = s.m}$ 541 int c = s.i + t.i; $\C{// unambiguous with qualification}$ 542 (double)m; $\C{// unambiguous with cast s.m}\CRT$ 543 } 544 \end{cfa} 545 \noindent 546 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA. 431 547 432 548 … … 474 590 475 591 592 \enlargethispage{1000pt} 476 593 \section{\texorpdfstring{\lstinline{uArray}}{uArray}} 477 594 … … 525 642 \end{cquote} 526 643 527 528 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} 529 530 \CFA is NOT an object-oriented programming-language, so there is no receiver (\lstinline[language=c++]{this}) or nested structure routines. 531 The equivalent of a \emph{member} routine has an explicit structure parameter in any parameter position (often the first). 532 \begin{cquote} 533 \begin{tabular}{@{}l|l@{}} 644 \newpage 645 646 647 \section{Doubly-Linked Intrusive List} 648 649 \begin{cquote} 650 \setlength{\tabcolsep}{10pt} 651 \begin{tabular}{@{}l|l@{}} 652 \begin{uC++} 653 #include <iostream> 654 using namespace std; 655 struct Node : @public uSeqable@ { 656 int i; 657 Node( int i ) : i( i ) {} 658 }; 659 660 661 int main() { 662 @uSequence<Node> dlist;@ 663 Node n1{ 1 }, n2{ 2 }, n3{ 3 }; 664 dlist.addTail( &n1 ); 665 dlist.addHead( &n2 ); // out of order 666 dlist.insertAft( &n1, &n3 ); // insertBef 667 for ( Node * it = dlist.head(); it; it = dlist.succ( it ) ) { 668 cout << it->i << endl; 669 } 670 dlist.remove( &n3 ); // shorten list 671 dlist.dropTail(); // dropHead 672 Node * it; 673 for ( uSeqIter<Node> seqit(dlist); // uSeqIterRev 674 seqit >> it; ) { 675 cout << it->i << endl; 676 } 677 } 678 \end{uC++} 679 & 680 \begin{cfa} 681 #include <fstream.hfa> 682 #include <list.hfa> 683 struct Node { 684 @inline dlink( Node );@ 685 int i; 686 }; 687 @P9_EMBEDDED( Node, dlink( Node ) );@ // magic 688 void ?{}( Node & node, int i ) { node.i = i; } 689 int main() { 690 @dlist( Node ) dlist;@ 691 Node n1{ 1 }, n2{ 2 }, n3{ 3 }; 692 insert_last( dlist, n1 ); 693 insert_first( dlist, n2 ); // out of order 694 insert_after( n1, n3 ); // insert_before 695 for ( Node & it = first( dlist ); ⁢ &it = &next( it ) ) { 696 sout | it.i; 697 } 698 remove( n3 ); // shorten list 699 remove_last( dlist ); // remove_first 700 701 FOREACH( dlist, it ) { // FOREACH_REV 702 703 sout | it.i; 704 } 705 } 706 \end{cfa} 707 \end{tabular} 708 \end{cquote} 709 710 711 \section{RAII Dynamic Allocation} 712 713 \begin{cquote} 714 \begin{tabular}{@{}l|ll@{}} 534 715 \begin{uC++} 535 716 struct S { 536 int i = 0; // cheat, implicit default constructor 537 int setter( int j ) { int t = i; i = j; return t; } 538 int getter() { return i; } 539 }; 540 S s; 541 @s.@setter( 3 ); // object calls 542 int k = @s.@getter(); 543 \end{uC++} 544 & 545 \begin{cfa} 546 struct S { int i; }; 547 void ?{}( S & s ) { s.i = 0; } // explicit default constructor 548 int setter( @S & s,@ int j ) @with( s )@ { int t = i; i = j; return t; } 549 int getter( @S & s@ ) @with( s )@ { return i; } 550 551 S s; 552 setter( @s,@ 3 ); // normal calls 553 int k = getter( @s@ ); 554 \end{cfa} 555 \end{tabular} 556 \end{cquote} 557 Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause. 558 \begin{cfa} 559 struct S { int i; int j; double m; }; // field i has same type in structures S and T 560 struct T { int i; int k; int m; }; 561 void foo( S s, T t ) @with( s, t )@ { // open structure scope s and t in parallel 562 j + k; $\C[1.6in]{// unambiguous, s.j + t.k}$ 563 m = 5.0; $\C{// unambiguous, s.m = 5.0}$ 564 m = 1; $\C{// unambiguous, t.m = 1}$ 565 int a = m; $\C{// unambiguous, a = t.m}$ 566 double b = m; $\C{// unambiguous, b = s.m}$ 567 int c = s.i + t.i; $\C{// unambiguous with qualification}$ 568 (double)m; $\C{// unambiguous with cast s.m}\CRT$ 569 } 570 \end{cfa} 571 \noindent 572 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA. 573 574 575 \section{Constructor / Destructor} 576 577 A constructor/destructor must have its structure type as the first parameter and be a reference. 578 \begin{cquote} 579 \begin{tabular}{@{}l|l@{}} 580 \begin{uC++} 581 582 struct S { 583 int i, j; 584 @S@() { i = j = 3; } 585 @S@( int i, int j ) { S::i = i; S::j = j; } 586 @S@( const S & s ) { *this = s; } 587 @~S@() {} 588 }; 589 S s0; 590 S s1 = { 1, 2 }; 591 592 S * s2 = new S{ 1, 2 }; 593 delete s2; 594 s2 = new S{ 1, 2 }; 595 delete s2; 596 S & s3 = *new S{ 1, 2 }; 597 delete &s3; 598 s3 = *new S{ 1, 2 }; 599 delete &s3; 600 \end{uC++} 601 & 602 \begin{cfa} 603 #include <stdlib.hfa> // new (malloc) 604 struct S { int i, j; }; 605 606 void @?{}@( @S & s@ ) { s.i = s.j = 3; } $\C[3in]{// default}$ 607 void @?{}@( @S & s@, int i, int j ) { s.i = i; s.j = j; } $\C{// initializer}$ 608 void @?{}@( @S & s@, const S rhs ) { ?{}( s, rhs.i, rhs.j ); } $\C{// copy}$ 609 void @^?{}@( @S & s@ ) { s.i = 0; s.j = 0; } $\C{// destructor}\CRT$ 610 611 S s0; 612 S s1 = { 1, 2 }; 613 // bug, cannot use 0/1 (zero_t/one_t) with "new" 614 S * s2 = new( 0@n@, 2 ); // suffix n => (natural int) 615 delete( s2 ); 616 s2 = new( 1@n@, 2 ); 617 delete( s2 ); 618 S & s3 = *new( 2, 2 ); 619 delete( &s3 ); 620 &s3 = &*new( 3, 2 ); 621 delete( &s3 ); 717 ... S() { ... } ~S() { ... } // ctor / dtor 718 }; 719 S * s = new S; delete s; 720 S * sa = new S[10]; delete [] sa; 721 \end{uC++} 722 & 723 \begin{cfa} 724 #include <stdlib.hfa> 725 struct S { ... }; 726 void ?{}( S & ) { ... } void ^?{}( S & ) { ... } // ctor / dtor 727 S * s = new(); delete( s ); 728 S * sa = anew( 10 ); adelete( sa ); 622 729 \end{cfa} 623 730 \end{tabular} … … 660 767 } 661 768 \end{cfa} 662 \\663 \multicolumn{2}{@{}l@{}}{\lstinline{C c;}}664 769 \end{tabular} 665 770 \end{cquote} … … 708 813 709 814 \begin{cquote} 815 \setlength{\tabcolsep}{10pt} 710 816 \begin{tabular}{@{}l|ll@{}} 711 817 \begin{uC++} … … 738 844 } 739 845 \end{cfa} 740 \end{tabular} 741 \begin{tabular}{@{}l|ll@{}} 846 \\ 742 847 \begin{uC++} 743 848 _Actor Hello { ${\color{red}\LstCommentStyle{// : public uActor}}$ … … 829 934 830 935 uOwnerLock m; 831 uCondLock s;936 uCondLock c; 832 937 m.acquire(); 833 if ( ! s.empty() ) s.wait( m );938 if ( ! c.empty() ) c.wait( m ); 834 939 else { 835 940 m.release(); … … 841 946 #include <locks.hfa> 842 947 owner_lock m; 843 cond_lock( owner_lock ) s; // generic type on mutex lock948 cond_lock( owner_lock ) c; // generic type on mutex lock 844 949 lock( m ); 845 if ( ! empty( s ) ) wait( s, m );950 if ( ! empty( c ) ) wait( c, m ); 846 951 else { 847 952 unlock( m ); … … 852 957 \end{cquote} 853 958 959 \begin{cquote} 960 \begin{tabular}{@{}l|ll@{}} 961 \begin{uC++} 962 963 uSemaphore m, c; 964 m.P(); 965 if ( ! c.empty() ) c.P( m ); 966 else { 967 m.V(); 968 } 969 \end{uC++} 970 & 971 \begin{cfa} 972 #include <locks.hfa> 973 semaphore m, c; 974 P( m ); 975 if ( ! empty( c ) ) P( c, m ); 976 else { 977 V( m ); 978 } 979 \end{cfa} 980 \end{tabular} 981 \end{cquote} 982 983 984 \enlargethispage{1000pt} 854 985 855 986 \section{Barrier} … … 888 1019 #include <mutex_stmt.hfa> 889 1020 struct Barrier { 890 @ barrier b;@ // containment1021 @inline barrier;@ 891 1022 int total; 892 1023 893 1024 }; 894 void ?{}( Barrier & B, unsigned int group ) with(B) {895 @ ?{}( b, group );@ // initialize barrier1025 void ?{}( Barrier & b, unsigned int group ) with( b ) { 1026 @(b){ group };@ // initialize barrier 896 1027 total = 0; 897 1028 } 898 unsigned int block( Barrier & B, int subtotal ) with(B) {899 void @last@( ) { sout | total; } // called by Gth arriving thread1029 unsigned int block( Barrier & b, int subtotal ) with( b ) { 1030 void @last@(...) { sout | total; } // called by Gth arriving thread 900 1031 @mutex( b )@ { // use barrier's mutual exclusion 901 1032 total += subtotal; … … 909 1040 \end{cquote} 910 1041 1042 \newpage 911 1043 912 1044 \enlargethispage{1000pt} … … 916 1048 Internal Scheduling 917 1049 \begin{cquote} 1050 \setlength{\tabcolsep}{5pt} 918 1051 \begin{tabular}{@{}l|ll@{}} 919 1052 \begin{uC++} … … 979 1112 \end{cquote} 980 1113 981 \ newpage1114 \bigskip 982 1115 \noindent 983 1116 External Scheduling 984 1117 \begin{cquote} 1118 \setlength{\tabcolsep}{5pt} 985 1119 \begin{tabular}{@{}l|ll@{}} 986 1120 \begin{uC++} … … 1039 1173 1040 1174 1041 \input{uC++toCFA.ind} 1175 \newpage 1176 1177 \section{Futures (reference counting)} 1178 1179 1180 {\lstset{tabsize=3} 1181 \setlength{\tabcolsep}{5pt} 1182 \begin{tabular}{@{}l|ll@{}} 1183 \begin{uC++} 1184 #include <uFuture.h> 1185 @Future_ISM@<int> fi; 1186 @Future_ISM@<double> fd; 1187 struct Msg { int i, j; }; @Future_ISM@<Msg> fm; 1188 struct Stop {}; @Future_ISM@<Stop> fs; 1189 struct Cont {}; @Future_ISM@<Cont> fc; 1190 1191 _Task Worker { 1192 void main() { 1193 1194 for ( ;; ) { 1195 _Select( fi ) { cout << fi() << endl; fi.reset(); } 1196 and _Select( fd ) { cout << fd() << endl; fd.reset(); } 1197 and _Select( fm ) { 1198 cout << fm().i << " " << fm().j << endl; fm.reset(); 1199 } or _Select( fs ) { cout << "stop" << endl; break; } 1200 fc.delivery( (Cont){} ); // synchronize 1201 } 1202 } 1203 1204 }; 1205 int main() { 1206 Worker worker; 1207 for ( int i = 0; i < 10; i += 1 ) { 1208 fi( i ); fd( i + 2.5 ); fm( (Msg){ i, 2 } ); // fulfil 1209 fc(); fc.reset(); // synchronize 1210 } 1211 fs( (Stop){} ); 1212 } // wait for worker to terminate 1213 \end{uC++} 1214 & 1215 \begin{cfa} 1216 #include <future.hfa> 1217 @future_rc@(int) fi; 1218 @future_rc@(double) fd; 1219 struct Msg { int i, j; }; @future_rc@(Msg) fm; 1220 struct Stop {}; @future_rc@(Stop) fs; 1221 struct Cont {}; @future_rc@(Cont) fc; 1222 ExceptionDecl( Break ); 1223 thread Worker {}; 1224 void main( Worker & ) { 1225 try { 1226 for () { 1227 waituntil( fi ) { sout | fi(); reset( fi ); } 1228 and waituntil( fd ) { sout | fd(); reset( fd ); } 1229 and waituntil( fm ) { sout | fm().i | fm().j; reset( fm ); } 1230 or waituntil( fs ) { sout | "stop"; 1231 throw ExceptionInst( Break ); 1232 } 1233 fc( (Cont){} ); // synchronize 1234 } 1235 } catch( Break * ) {} 1236 } 1237 int main() { 1238 Worker worker; 1239 for ( i; 10 ) { 1240 fi( i ); fd( i + 2.5 ); fm( (Msg){ i, 2 } ); // fulfil 1241 fc(); reset( fc ); // synchronize 1242 } 1243 fs( (Stop){} ); 1244 } // wait for worker to terminate 1245 \end{cfa} 1246 \end{tabular} 1247 }% 1248 1249 %\input{uC++toCFA.ind} 1042 1250 1043 1251 % \bibliographystyle{plain}
Note:
See TracChangeset
for help on using the changeset viewer.