Changeset ae7f1e0 for src/examples


Ignore:
Timestamp:
Feb 24, 2016, 10:38:01 AM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
61a4875
Parents:
c44e622 (diff), b502055 (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' into gc_noraii

Location:
src/examples
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • src/examples/abs.c

    rc44e622 rae7f1e0  
    1010// Created On       : Thu Jan 28 18:26:16 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:58 2016
    13 // Update Count     : 43
     12// Last Modified On : Wed Feb 17 09:32:04 2016
     13// Update Count     : 44
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    21 
    2220        char ch = -65;
    2321        sout | "char\t\t\t"                                     | ch     | "\tabs " | abs( ch ) | endl;
  • src/examples/alloc.c

    rc44e622 rae7f1e0  
    1111// Created On       : Wed Feb  3 07:56:22 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Feb  3 16:32:04 2016
    14 // Update Count     : 38
     13// Last Modified On : Wed Feb 17 11:43:23 2016
     14// Update Count     : 40
    1515//
    1616
     
    2727
    2828int main( void ) {
    29     ofstream * sout = ofstream_stdout();
    30 
    3129    size_t size = 10;
    3230    int * p;
     
    10098    free( x );
    10199#endif
    102     free( sout );
    103100}
    104101
  • src/examples/fstream_test.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:11:33 2016
    13 // Update Count     : 42
     12// Last Modified On : Wed Feb 17 11:45:43 2016
     13// Update Count     : 43
    1414//
    1515
     
    1717
    1818int main( void ) {
    19         ofstream *sout = ofstream_stdout();
    20         ifstream *sin = ifstream_stdin();
    2119        int nombre;
    2220        sout | "Entrez un nombre, s'il vous plaît:\n";
  • src/examples/hello.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:11:49 2016
    13 // Update Count     : 7
     12// Last Modified On : Wed Feb 17 12:11:45 2016
     13// Update Count     : 8
    1414//
    1515
     
    1717
    1818int main() {
    19         ofstream *sout = ofstream_stdout();
    20         ifstream *sin = ifstream_stdin();
    2119        sout | "Bonjour au monde!\n";
    2220}
  • src/examples/identity.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:11:58 2016
    13 // Update Count     : 8
     12// Last Modified On : Wed Feb 17 12:17:32 2016
     13// Update Count     : 10
    1414//
    1515
     
    2222
    2323int main() {
    24         ofstream *sout = ofstream_stdout();
    2524        sout | "char\t\t\t"                                     | identity( 'z' ) | endl;
    2625        sout | "signed int\t\t"                         | identity( 4 ) | endl;
     
    3029        sout | "signed long long int\t"         | identity( 4ll ) | endl;
    3130        sout | "unsigned long long int\t"       | identity( 4ull ) | endl;
    32         sout | "float\t\t\t"                            | identity( 4.0f ) | endl;
    33         sout | "double\t\t\t"                           | identity( 4.0 ) | endl;
    34         sout | "long double\t\t"                        | identity( 4.0l ) | endl;
     31        sout | "float\t\t\t"                            | identity( 4.1f ) | endl;
     32        sout | "double\t\t\t"                           | identity( 4.1 ) | endl;
     33        sout | "long double\t\t"                        | identity( 4.1l ) | endl;
    3534}
    3635
  • src/examples/minmax.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:49 2016
    13 // Update Count     : 46
     12// Last Modified On : Wed Feb 17 12:17:53 2016
     13// Update Count     : 47
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    2120        // char does not have less or greater than.
    2221        int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; }
  • src/examples/quad.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:13:48 2016
    13 // Update Count     : 5
     12// Last Modified On : Wed Feb 17 12:19:24 2016
     13// Update Count     : 6
    1414//
    1515
     
    2727
    2828int main() {
    29         ofstream *sout = ofstream_stdout();
    3029        int N = 2;
    3130        sout | "result of quad of " | N | " is " | quad( N ) | endl;
  • src/examples/quoted_keyword.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:13:58 2016
    13 // Update Count     : 8
     12// Last Modified On : Wed Feb 17 12:19:45 2016
     13// Update Count     : 9
    1414//
    1515
     
    2828
    2929int main() {
    30         ofstream *sout = ofstream_stdout();
    3130        sout | `catch` + st.`type` + st.`struct` + `throw` | endl;
    3231}
  • src/examples/random.c

    rc44e622 rae7f1e0  
    77
    88int main() {
    9         ofstream *sout = ofstream_stdout();
    10 
    119        randseed( getpid() );                                                           // set random seed
    1210
  • src/examples/square.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:14:16 2016
    13 // Update Count     : 25
     12// Last Modified On : Wed Feb 17 12:21:58 2016
     13// Update Count     : 26
    1414//
    1515
     
    2323int main() {
    2424#if 0
    25         ofstream *sout = ofstream_stdout();
    2625        sout | "result of squaring 9 is " | endl;
    2726
  • src/examples/sum.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  5 16:47:44 2016
    13 // Update Count     : 139
     12// Last Modified On : Tue Feb 16 23:49:31 2016
     13// Update Count     : 189
    1414//
    1515
     
    3333
    3434// Required to satisfy sumable as char does not have addition.
    35 // const char 0;
    36 // char ?+?( char op1, char op2 ) { return (int)op1 + op2; } // cast forces integer addition or recursion
    37 // char ++?( char *op ) { *op += 1; return *op; }
    38 // char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
     35const char 0;
     36char ?+?( char t1, char t2 ) { return (int)t1 + t2; }   // cast forces integer addition, otherwise recursion
     37char ?+=?( char *t1, char t2 ) { *t1 = *t1 + t2; return *t1; }
     38char ++?( char *t ) { *t += 1; return *t; }
     39char ?++( char *t ) { char temp = *t; *t += 1; return temp; }
    3940
    4041int main( void ) {
    4142        const int low = 5, High = 15, size = High - low;
    42         ofstream *sout = ofstream_stdout();
    43 #if 0
    4443
    45         char s = 0, a[size];
    46         char v = low;
     44        char s = 0, a[size], v = low;
    4745        for ( int i = 0; i < size; i += 1, v += 1 ) {
    4846                s += v;
    4947                a[i] = v;
    50         }
     48        } // for
    5149        sout | "sum from " | low | " to " | High | " is "
    5250                 | (int)sum( size, a ) | ", check " | (int)s | endl;
    5351
    54         int s = 0, a[size];
    55         int v = low;
     52        int s = 0, a[size], v = low;
    5653        for ( int i = 0; i < size; i += 1, v += 1 ) {
    5754                s += (int)v;
    5855                a[i] = (int)v;
    59         }
     56        } // for
    6057        sout | "sum from " | low | " to " | High | " is "
    6158                 | sum( size, (int *)a ) | ", check " | (int)s | endl;
    6259
    63         float s = 0.0, a[size];
    64         float v = low / 10.0;
     60        float s = 0.0, a[size], v = low / 10.0;
    6561        for ( int i = 0; i < size; i += 1, v += 0.1f ) {
    6662                s += (float)v;
    6763                a[i] = (float)v;
    68         }
     64        } // for
    6965        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    7066                 | sum( size, (float *)a ) | ", check " | (float)s | endl;
    71 #endif
    72         double s = 0, a[size];
    73         double v = low / 10.0;
    7467
     68        double s = 0, a[size], v = low / 10.0;
    7569        for ( int i = 0; i < size; i += 1, v += 0.1 ) {
    7670                s += (double)v;
    7771                a[i] = (double)v;
    78         }
     72        } // for
    7973        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    8074                 | sum( size, (double *)a ) | ", check " | (double)s | endl;
    8175
    82         // struct S { int i, j; } sarr[size];
    83         // struct S 0 = { 0, 0 };
    84         // struct S 1 = { 1, 1 };
    85         // S ?+?( S t1, S t2 ) { S s = { t1.i + t1.j, t2.i + t2.j }; return s; }
    86         // S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
    87         // S ++?( S *t ) { *t += 1; return *t; }
    88         // S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
    89         // sum( size, sarr );
     76        struct S { int i, j; } 0 = { 0, 0 }, 1 = { 1, 1 };
     77        S ?+?( S t1, S t2 ) { S s = { t1.i + t2.i, t1.j + t2.j }; return s; }
     78        S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
     79        S ++?( S *t ) { *t += 1; return *t; }
     80        S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
     81        ofstream * ?|?( ofstream * os, S v ) { return os | v.i | ' ' | v.j; }
     82
     83        S s = 0, a[size], v = { low, low };
     84        for ( int i = 0; i < size; i += 1, v += (S)1 ) {
     85                s += (S)v;
     86                a[i] = (S)v;
     87        } // for
     88        sout | "sum from " | low | " to " | High | " is "
     89                 | sum( size, (S *)a ) | ", check " | (S)s | endl;
    9090} // main
    9191
  • src/examples/swap.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:04 2016
    13 // Update Count     : 63
     12// Last Modified On : Wed Feb 17 12:22:12 2016
     13// Update Count     : 64
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    21 
    2220        char c1 = 'a', c2 = 'b';
    2321        sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap ";
  • src/examples/twice.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:14:44 2016
    13 // Update Count     : 12
     12// Last Modified On : Wed Feb 17 12:23:25 2016
     13// Update Count     : 13
    1414//
    1515
     
    2727        char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
    2828
    29         ofstream *sout = ofstream_stdout();
    3029        sout | twice( 'a' ) | ' ' | twice( 1 ) | ' ' | twice( 3.2 ) | endl;
    3130}
  • src/examples/vector_test.c

    rc44e622 rae7f1e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:14:52 2016
    13 // Update Count     : 17
     12// Last Modified On : Wed Feb 17 12:23:55 2016
     13// Update Count     : 18
    1414//
    1515
     
    2020
    2121int main( void ) {
    22         ofstream *sout = ofstream_stdout();
    23         ifstream *sin = ifstream_stdin();
    2422        vector_int vec = vector_int_allocate();
    2523
Note: See TracChangeset for help on using the changeset viewer.