Changeset 960665c for doc


Ignore:
Timestamp:
Aug 20, 2024, 6:15:01 PM (16 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
ad47ec4
Parents:
d1f5054 (diff), df2e00f (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
doc
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    rd1f5054 r960665c  
    471471        E e;
    472472
    473         for () {
    474                 try {
    475                         @sin | e@;
    476                 } catch( missing_data * ) {
    477                         sout | "missing data";
    478                         continue; // try again
     473        try {
     474                for () {
     475                        try {
     476                                @sin | e@;
     477                        } catch( missing_data * ) {
     478                                sout | "missing data";
     479                                continue; // try again
     480                        }
     481                        sout | e | "= " | value( e );
    479482                }
    480           if ( eof( sin ) ) break;
    481                 sout | e | "= " | value( e );
    482         }
     483        } catch( end_of_file ) {}
    483484}
    484485\end{cfa}
  • doc/theses/mike_brooks_MMath/array.tex

    rd1f5054 r960665c  
    205205Orthogonally, the new @array@ type works with \CFA's generic types, providing argument safety and the associated implicit communication of array length.
    206206Specifically, \CFA allows aggregate types to be generalized with multiple type parameters, including parameterized element types and lengths.
    207 Doing so gives a refinement of C's ``flexible array member'' pattern, allowing nesting structures with array members anywhere within other structures.
     207Doing so gives a refinement of C's ``flexible array member'' pattern, allowing nesting structures with array members anywhere within the structures.
    208208\lstinput{10-15}{hello-accordion.cfa}
    209 This structure's layout has the starting offset of @municipalities@ varying in @NprovTerty@, and the offset of @total_pt@ and @total_mun@ varying in both generic parameters.
    210 For a function that operates on a @CanPop@ structure, the type system handles this variation transparently.
     209This structure's layout has the starting offset of @studentIds@ varying in generic parameter @C@, and the offset of @preferences@ varying in both generic parameters.
     210For a function that operates on a @School@ structure, the type system handles this memory layout transparently.
    211211\lstinput{40-45}{hello-accordion.cfa}
    212 \VRef[Figure]{f:checkHarness} shows the @CanPop@ harness and results with different array sizes, if the municipalities changed after a census.
     212\VRef[Figure]{f:checkHarness} shows the @School@ harness and results with different array sizes, where multidimensional arrays are discussed next.
    213213
    214214\begin{figure}
    215 \lstinput{60-68}{hello-accordion.cfa}
    216 \lstinput{70-75}{hello-accordion.cfa}
    217 \caption{\lstinline{check} Harness}
     215% super hack to get this to line up
     216\begin{tabular}{@{}ll@{\hspace{25pt}}l@{}}
     217\begin{tabular}{@{}p{3.25in}@{}}
     218\lstinput{60-66}{hello-accordion.cfa}
     219\vspace*{-3pt}
     220\lstinput{73-80}{hello-accordion.cfa}
     221\end{tabular}
     222&
     223\raisebox{0.32\totalheight}{%
     224\lstinput{85-93}{hello-accordion.cfa}
     225}%
     226&
     227\lstinput{95-109}{hello-accordion.cfa}
     228\end{tabular}
     229\caption{\lstinline{school} Harness and Output}
    218230\label{f:checkHarness}
    219231\end{figure}
     
    488500From there, @x[all]@ itself is simply a two-dimensional array, in the strict C sense, of these building blocks.
    489501An atom (like the bottommost value, @x[all][3][2]@), is the contained value (in the square box)
    490 and a lie about its size (the wedge above it, growing upward).
     502and a lie about its size (the left diagonal above it, growing upward).
    491503An array of these atoms (like the intermediate @x[all][3]@) is just a contiguous arrangement of them, done according to their size;
    492504call such an array a column.
    493505A column is almost ready to be arranged into a matrix;
    494506it is the \emph{contained value} of the next-level building block, but another lie about size is required.
    495 At first, an atom needs to be arranged as if it were bigger, but now a column needs to be arranged as if it is smaller (the wedge above it, shrinking upward).
     507At first, an atom needs to be arranged as if it were bigger, but now a column needs to be arranged as if it is smaller (the left diagonal above it, shrinking upward).
    496508These lying columns, arranged contiguously according to their size (as announced) form the matrix @x[all]@.
    497509Because @x[all]@ takes indices, first for the fine stride, then for the coarse stride, it achieves the requirement of representing the transpose of @x@.
     
    502514compared with where analogous rows appear when the row-level option is presented for @x@.
    503515
    504 \PAB{I don't understand this paragraph: These size lies create an appearance of overlap.
    505 For example, in \lstinline{x[all]}, the shaded band touches atoms 2.0, 2.1, 2.2, 2.3, 1.4, 1.5 and 1.6.
     516For example, in \lstinline{x[all]}, the shaded band touches atoms 2.0, 2.1, 2.2, 2.3, 1.4, 1.5 and 1.6 (left diagonal).
    506517But only the atom 2.3 is storing its value there.
    507 The rest are lying about (conflicting) claims on this location, but never exercising these alleged claims.}
     518The rest are lying about (conflicting) claims on this location, but never exercising these alleged claims.
    508519
    509520Lying is implemented as casting.
     
    511522This structure uses one type in its internal field declaration and offers a different type as the return of its subscript operator.
    512523The field within is a plain-C array of the fictional type, which is 7 floats long for @x[all][3][2]@ and 1 float long for @x[all][3]@.
    513 The subscript operator presents what is really inside, by casting to the type below the wedge of the lie.
     524The subscript operator presents what is really inside, by casting to the type below the left diagonal of the lie.
    514525
    515526%  Does x[all] have to lie too?  The picture currently glosses over how it it advertises a size of 7 floats.  I'm leaving that as an edge case benignly misrepresented in the picture.  Edge cases only have to be handled right in the code.
  • doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa

    rd1f5054 r960665c  
    88
    99
    10 forall( T, @[NprovTerty]@, @[Nmunicipalities]@ )
    11 struct CanPop {
    12         array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$
    13         array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$
    14         int total_pt, total_mun;
     10forall( [C], [S] ) $\C{// Class size, Students in class}$
     11struct School {
     12        @array( int, C )@ classIds; $\C{// nested VLAs}$
     13        @array( int, S )@ studentIds;
     14        @array( int, C, S )@ preferences; $\C{// multidimensional}$
    1515};
     16
    1617
    1718
    1819// TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)
    1920
    20 forall( T, [NprovTerty], [Nmunicipalities] )
    21         void ?{}( T &, CanPop( T, NprovTerty, Nmunicipalities ) & this ) {}
     21forall( [C], [S] )
     22void ?{}( School( C, S ) & this ) {}
    2223
    23 forall( T &, [NprovTerty], [Nmunicipalities] )
    24         void ^?{}( CanPop( T, NprovTerty, Nmunicipalities ) & this ) {}
     24forall( [C], [S] )
     25        void ^?{}( School( C, S ) & this ) {}
    2526
    2627
     
    3738
    3839
    39 
    40 forall( T, [NprovTerty], [Nmunicipalities] )
    41 void check( CanPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) {
    42         total_pt = total_mun = 0;
    43         for ( i; NprovTerty ) total_pt += provTerty[i];
    44         for ( i; Nmunicipalities ) total_mun += municipalities[i];
     40forall( [C], [S] )
     41void init( @School( C, S ) & classes@, int class, int student, int pref ) with( classes ) {
     42        classIds[class] = class; $\C{// handle dynamic offsets of fields within structure}$
     43        studentIds[student] = student;
     44        preferences[class][student] = pref;
    4545}
    4646
     
    5858
    5959
    60 int main( int argc, char * argv[] ) {
    61         const int npt = ato( argv[1] ), nmun = ato( argv[2] );
    62         @CanPop( int, npt, nmun ) pop;@
    63         // read in population numbers
    64         @check( pop );@
    65         sout | setlocale( LC_NUMERIC, getenv( "LANG" ) );
    66         sout | "Total province/territory:" | pop.total_pt;
    67         sout | "Total municipalities:" | pop.total_mun;
     60int main() {
     61        int classes, students;
     62        sin | classes | students;
     63        @School( classes, students ) school;@
     64        int class, student, preference;
     65        // read data into school calling init
     66        // for each student's class/preferences
     67        try {
     68                for ( ) {
     69                        sin | class | student | preference;
     70                        init( school, class, student, preference );
     71                }
     72        } catch( end_of_file * ) {}
     73        for ( s; students ) {
     74                sout | "student" | s | nonl;
     75                for ( c; classes ) {
     76                        sout | school.preferences[c][s] | nonl;
     77                }
     78                sout | nl;
     79        }
    6880}
     81
     82
     83
    6984/*
    70 $\$$ ./a.out  13  3573
    71 Total province/territory: 36,991,981
    72 Total municipalities: 36,991,981
    73 $\$$ ./a.out  13  3654
    74 Total province/territory: 36,991,981
    75 Total municipalities: 36,991,981
     85$\$$ cat school1
     862 2
     870 0 1
     881 0 7
     890 1 12
     901 1 13
     91$\$$ a.out < school1
     92student 0 1 7
     93student 1 12 13
     94
     95$\$$ cat school2
     963 3
     970 0 1
     981 0 7
     992 0 8
     1000 1 12
     1011 1 13
     1022 1 14
     1030 2 26
     1041 2 27
     1052 2 28
     106$\$$ a.out < school2
     107student 0 1 7 8
     108student 1 12 13 14
     109student 2 26 27 28
    76110*/
    77111
  • doc/theses/mike_brooks_MMath/string.tex

    rd1f5054 r960665c  
    11\chapter{String}
    22
    3 
    4 
    5 
    6 
    7 \subsection{Logical overlap}
     3This chapter presents my work on designing and building a modern string type in \CFA.
     4The discussion starts with examples of interesting string problems, followed by examples of how these issues are solved in my design.
     5
     6
     7\section{Logical overlap}
    88
    99\input{sharing-demo.tex}
     
    2020\subsection{RAII limitations}
    2121
    22 Earlier work on \CFA [to cite Schluntz] implemented the feature of constructors and destructors.  A constructor is a user-defined function that runs implicitly, when control passes an object's declaration, while a destructor runs at the exit of the declaration's lexical scope.  The feature allows programmers to assume that, whenever a runtime object of a certain type is accessible, the system called one of the programmer's constuctor functions on that object, and a matching destructor call will happen in the future.  The feature helps programmers know that their programs' invariants obtain.
    23 
    24 The purposes of such invariants go beyond ensuring authentic values for the bits inside the object.   These invariants can track occurrences of the managed objects in other data structures.  Reference counting is a typical application of the latter invariant type.  With a reference-counting smart pointer, the consturctor and destructor \emph{of the pointer type} track the lifecycles of occurrences of these pointers, by incrementing and decrementing a counter (ususally) on the referent object, that is, they maintain a that is state separate from the objects to whose lifecycles they are attached.  Both the \CC and \CFA RAII systems ares powerful enough to achive such reference counting.
    25 
    26 The \CC RAII system supports a more advanced application.  A lifecycle function has access to the object under managamanet, by location; constructors and destuctors receive a @this@ parameter providing its memory address.  A lifecycle-function implementation can then add its objects to a collection upon creation, and remove them at destruction.  A modulue that provides such objects, by using and encapsulating such a collection, can traverse the collection at relevant times, to keep the objects ``good.''  Then, if you are the user of such an module, declaring an object of its type means not only receiving an authentically ``good'' value at initialization, but receiving a subscription to a service that will keep the value ``good'' until you are done with it.
     22Earlier work on \CFA [to cite Schluntz] implemented the feature of constructors and destructors.  A constructor is a user-defined function that runs implicitly, when control passes an object's declaration, while a destructor runs at the exit of the declaration's lexical scope.  The feature allows programmers to assume that, whenever a runtime object of a certain type is accessible, the system called one of the programmer's constructor functions on that object, and a matching destructor call will happen in the future.  The feature helps programmers know that their programs' invariants obtain.
     23
     24The purposes of such invariants go beyond ensuring authentic values for the bits inside the object.   These invariants can track occurrences of the managed objects in other data structures.  Reference counting is a typical application of the latter invariant type.  With a reference-counting smart pointer, the constructor and destructor \emph{of the pointer type} track the life cycles of occurrences of these pointers, by incrementing and decrementing a counter (usually) on the referent object, that is, they maintain a that is state separate from the objects to whose life cycles they are attached.  Both the \CC and \CFA RAII systems ares powerful enough to achieve such reference counting.
     25
     26The \CC RAII system supports a more advanced application.  A life cycle function has access to the object under management, by location; constructors and destuctors receive a @this@ parameter providing its memory address.  A lifecycle-function implementation can then add its objects to a collection upon creation, and remove them at destruction.  A modulue that provides such objects, by using and encapsulating such a collection, can traverse the collection at relevant times, to keep the objects ``good.''  Then, if you are the user of such an module, declaring an object of its type means not only receiving an authentically ``good'' value at initialization, but receiving a subscription to a service that will keep the value ``good'' until you are done with it.
    2727
    2828In many cases, the relationship between memory location and lifecycle is simple.  But with stack-allocated objects being used as parameters and returns, there is a sender version in one stack frame and a receiver version in another.  \CC is able to treat those versions as distinct objects and guarantee a copy-constructor call for communicating the value from one to the other.  This ability has implications on the language's calling convention.  Consider an ordinary function @void f( Vehicle x )@, which receives an aggregate by value.  If the type @Vehicle@ has custom lifecycle functions, then a call to a user-provided copy constructor occurs, after the caller evaluates its argument expression, after the callee's stack frame exists, with room for its variable @x@ (which is the location that the copy-constructor must target), but before the user-provided body of @f@ begins executing.  \CC achieves this ordering by changing the function signature, in the compiled form, to pass-by-reference and having the callee invoke the copy constructor in its preamble.  On the other hand, if @Vehicle@ is a simple structure then the C calling convention is applied as the code originally appeared, that is, the callsite implementation code performs a bitwise copy from the caller's expression result, into the callee's x.
  • doc/user/user.tex

    rd1f5054 r960665c  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jul 26 06:56:11 2024
    14 %% Update Count     : 6955
     13%% Last Modified On : Thu Aug 15 22:23:30 2024
     14%% Update Count     : 6957
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    46564656\VRef[Figure]{f:CFACommand-LineProcessing} demonstrates the file operations by showing the idiomatic \CFA command-line processing and copying an input file to an output file.
    46574657Note, a stream variable may be copied because it is a reference to an underlying stream data-structures.
    4658 \Textbf{All I/O errors are handled as exceptions}, but end-of-file is not an exception as C programmers are use to explicitly checking for it.
     4658\Textbf{All unusual I/O cases are handled as exceptions, including end-of-file.}
    46594659
    46604660\begin{figure}
     
    46864686        in | nlOn;                                                              §\C{// turn on reading newline}§
    46874687        char ch;
    4688         for () {                                                                §\C{// read/write characters}§
    4689                 in | ch;
    4690           if ( eof( in ) ) break;                               §\C{// eof ?}§
    4691                 out | ch;
    4692         } // for
     4688        try {
     4689                for () {                                                        §\C{// read/write characters}§
     4690                        in | ch;
     4691                        out | ch;
     4692                } // for
     4693        } catch( end_of_file * ) {                              §\C{// end-of-file raised}§
     4694        } // try
    46934695} // main
    46944696\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.