Ignore:
Timestamp:
Oct 29, 2024, 12:50:56 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
b699a61
Parents:
63cf80e (diff), d0296db6 (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/theses/mike_brooks_MMath/programs
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa

    r63cf80e r7ef4438  
    22#include <stdlib.hfa>
    33#include <array.hfa>
    4 #include <locale.h>                                                     // setlocale
     4#include <string.hfa>
    55
    66
     
    88
    99
    10 forall( [C], [S] ) $\C{// Class size, Students in class}$
     10forall( [C], [S] ) $\C{// num courses, num students}$
    1111struct School {
    12         @array( int, C )@ classIds; $\C{// nested VLAs}$
    13         @array( int, S )@ studentIds;
    14         @array( int, C, S )@ preferences; $\C{// multidimensional}$
     12        @array@( string, C ) course_codes; $\C{// nested VLAs}$
     13        @array@( string, S ) student_ids;
     14        @array@( int, C, S ) preferences; $\C{// multidimensional}$
    1515};
    16 
    17 
    18 
    19 // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)
    20 
    21 forall( [C], [S] )
    22 void ?{}( School( C, S ) & this ) {}
    23 
    24 forall( [C], [S] )
    25         void ^?{}( School( C, S ) & this ) {}
    2616
    2717
     
    3929
    4030forall( [C], [S] )
    41 void 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;
     31int getPref( @School( C, S ) & school@, int is, int pref ) {
     32    for ( ic; C ) {
     33        int curPref = @school.preferences@[ic][is];   $\C{// offset calculation implicit}$
     34                if ( curPref == pref ) return ic;
     35        }
     36    assert( false );
    4537}
    4638
     
    5648
    5749
     50int main() {
     51        int nc, ns;
     52        sin | nc | " courses,";
     53        sin | ns | " students";
     54        @School( nc, ns ) school;@
     55        // ... elided: read data into school
    5856
    5957
    60 int 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;
     58
     59
     60        {       string sv;
     61        int iv;
     62        // headers' row
     63        sin | "\nc\\s";
     64        for ( is ; ns ) {
     65            // column label
     66            sin | sv;
     67            school.student_ids[is] = sv;
     68        }
     69        // body rows
     70        for ( ic ; nc ) {
     71            // row label
     72            sin | sv;
     73            school.course_codes[ic] = sv;
     74            for ( is ; ns ) {
     75                // matrix item
     76                sin | iv;
     77                school.preferences[ic][is] = iv;
     78            }
     79        }
     80    }
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90        for ( is; ns ) {
     91                sout | school.student_ids[is] | ": " | nonl;
     92                for ( pref; 1 ~= nc ) {
     93            int ic = getPref(school, is, pref);
     94            sout | school.course_codes[ ic ] | nonl;
    7795                }
    7896                sout | nl;
     
    8199
    82100
    83 
    84 /*
    85 $\$$ cat school1
    86 2 2
    87 0 0 1
    88 1 0 7
    89 0 1 12
    90 1 1 13
    91 $\$$ a.out < school1
    92 student 0 1 7
    93 student 1 12 13
    94 
    95 $\$$ cat school2
    96 3 3
    97 0 0 1
    98 1 0 7
    99 2 0 8
    100 0 1 12
    101 1 1 13
    102 2 1 14
    103 0 2 26
    104 1 2 27
    105 2 2 28
    106 $\$$ a.out < school2
    107 student 0 1 7 8
    108 student 1 12 13 14
    109 student 2 26 27 28
    110 */
    111 
    112101// Local Variables: //
    113102// compile-command: "sed -f sedcmd hello-accordion.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" //
  • TabularUnified doc/theses/mike_brooks_MMath/programs/hello-array.cfa

    r63cf80e r7ef4438  
    4949*/
    5050
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64#ifdef SHOWERR1
     65
    5166void fred() {
     67
     68
     69
     70        array( float, @10@ ) x;
     71        array( float, @20@ ) y;
     72        f( x, x );              $\C[0.5in]{// ok}$
     73        f( y, y );              $\C{// ok}$
     74        f( x, y );              $\C{// error}\CRT$
     75
     76
     77
     78
     79}
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90forall( [M], [N] )
     91void bad( array(float, M) &x,
     92                array(float, N) &y ) {
     93        f( x, x );              $\C[0.5in]{// ok}$
     94        f( y, y );              $\C{// ok}$
     95
     96        f( x, y );              $\C{// error}\CRT$
     97}
     98
     99#endif
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110forall( [M], [N] )
     111void bad_fixed( array( float, M ) & x,
     112                array( float, N ) & y ) {
     113        f( x, x );              $\C[0.5in]{// ok}$
     114        f( y, y );              $\C{// ok}$
     115        if ( M == N )
     116                f( x, @(array( float, M ) &)@y ); $\C{// ok}$
     117}
     118
     119
     120
     121
     122
     123
     124void fred_ok_only() {
    52125        array( float, @10@ ) x;
    53126        array( float, @20@ ) y;
     
    57130}
    58131
    59 #ifdef SHOWERR1
    60 forall( [M], [N] )
    61 void bad( array(float, M) &x, array(float, N) &y ) {
    62         f( x, x );              $\C[1.5in]{// ok}$
    63         f( y, y );              $\C{// ok}$
    64         f( x, y );              $\C{// error}\CRT$
    65 }
    66 #endif
    67 
    68 
    69132
    70133forall( [M], [N] )
    71 void bad_fixed( array( float, M ) & x, array( float, N ) & y ) {
    72         if ( M == N )
    73                 f( x, @(array( float, M ) &)@y ); $\C{// cast y to matching type}$
     134void bad_ok_only( array(float, M) &x,
     135                array(float, N) &y ) {
     136        f( x, x );
     137        f( y, y );
     138
     139//      f( x, y );
    74140}
     141
    75142
    76143// Local Variables: //
  • TabularUnified doc/theses/mike_brooks_MMath/programs/school1

    r63cf80e r7ef4438  
    1 2 2
    2 0 0 1
    3 1 0 7
    4 0 1 12
    5 1 1 13
     13 courses, 2 students
     2c\s     90111111 90222222
     3ENGL101        3        2
     4PHYS101        1        3
     5CHEM101        2        1
  • TabularUnified doc/theses/mike_brooks_MMath/programs/school2

    r63cf80e r7ef4438  
    1 3 3
    2 0 0 1
    3 1 0 7
    4 2 0 8
    5 0 1 12
    6 1 1 13
    7 2 1 14
    8 0 2 26
    9 1 2 27
    10 2 2 28
     15 courses, 3 students
     2c\s     90111111 90222222 90333333
     3ENGL101        3        2        3
     4PHYS101        1        3        4
     5CHEM101        2        1        5
     6PHIL101        4        5        2
     7MATH499        5        4        1
Note: See TracChangeset for help on using the changeset viewer.