Changeset 86bd7c1f


Ignore:
Timestamp:
May 27, 2015, 8:33:19 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, string, with_gc
Children:
00cc023
Parents:
52ac3b4
Message:

licencing: eighth groups of files

Location:
src/examples
Files:
40 edited

Legend:

Unmodified
Added
Removed
  • src/examples/abstype.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa-cpp -nx Abstype.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// abstype.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:10:01 2015
     13// Update Count     : 4
     14//
    215
    316type T | { T x( T ); };
    417
    518T y( T t ) {
    6     T t_instance;
    7     return x( t );
     19        T t_instance;
     20        return x( t );
    821}
    922
     
    1629
    1730U x( U u ) {
    18     U u_instance = u;
    19     (*u)++;
    20     return u;
     31        U u_instance = u;
     32        (*u)++;
     33        return u;
    2134}
    2235
    2336int *break_abstraction( U u ) {
    24     return u;
     37        return u;
    2538}
     39
     40// Local Variables: //
     41// tab-width: 4 //
     42// compile-command: "cfa abstype.c" //
     43// End: //
  • src/examples/array.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa -c -o array.o array.c"
    2 // "cfa -CFA array.c > array_out.c"
    3 // "gcc32 array_out.c ../LibCfa/libcfa.a"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// array.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:10:13 2015
     13// Update Count     : 2
     14//
    415
    516#include "array.h"
     
    1627forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
    1728elt_type * begin( array_type array ) {
    18     return &array[ 0 ];
     29        return &array[ 0 ];
    1930}
    2031
     
    2233forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
    2334elt_type * end( array_type array ) {
    24     return &array[ last( array ) ] + 1;
     35        return &array[ last( array ) ] + 1;
    2536}
     37
     38// Local Variables: //
     39// tab-width: 4 //
     40// compile-command: "cfa array.c" //
     41// End: //
  • src/examples/array.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// array.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:10:32 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef ARRAY_H
    217#define ARRAY_H
     
    722// element has index 0.
    823context array( type array_type, type elt_type ) {
    9     lvalue elt_type ?[?]( array_type, int );
     24        lvalue elt_type ?[?]( array_type, int );
    1025};
    1126
    1227// A bounded array is an array that carries its maximum index with it.
    1328context bounded_array( type array_type, type elt_type | array( array_type, elt_type ) ) {
    14     int last( array_type );
     29        int last( array_type );
    1530};
    1631
     
    3247
    3348#endif // ARRAY_H
     49
     50// Local Variables: //
     51// tab-width: 4 //
     52// compile-command: "cfa array.c" //
     53// End: //
  • src/examples/assert.c

    r52ac3b4 r86bd7c1f  
    1 // "./cfa-cpp -c rodolfo2.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// assert.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:10:43 2015
     13// Update Count     : 2
     14//
    215
    3 extern "C" {
    4     #include <assert.h>
     16void f() {
     17        (1) ? (void)(0) : (void)(0);
    518}
    619
    7 int a = 7;
    8 
    9 void f() {
    10     int b;
    11     b = a;
    12     int a = 8;
    13     assert( b == 7 );
    14 }
     20// Local Variables: //
     21// tab-width: 4 //
     22// compile-command: "cfa assert.c" //
     23// End: //
  • src/examples/constants.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// constants.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:11:03 2015
     13// Update Count     : 3
     14//
     15
    116int foo() {
    2     1_234_Ul;
    3     -0_177;
    4     0x_ff_FF_ff_FF;
    5     +9_223_372_036_854_775_807;
    6     12.123_333_E_27;
    7     0X_1.ff_ff_ff_ff_ff_fff_P_1023;
    8     '\0';
    9     '\1_2_3';
    10     L_'\x_ff_ee';
    11     L"a_bc\u_00_40xyz\xff_AA";
    12     "a_bc\\
     17        1_234_Ul;
     18        -0_177;
     19        0x_ff_FF_ff_FF;
     20        +9_223_372_036_854_775_807;
     21        12.123_333_E_27;
     22        0X_1.ff_ff_ff_ff_ff_fff_P_1023;
     23        '\0';
     24        '\1_2_3';
     25        L_'\x_ff_ee';
     26        L"a_bc\u_00_40xyz\xff_AA";
     27        "a_bc\\
    1328  u_00_40xyz";
    1429}
    1530
    1631// Local Variables: //
    17 // compile-command: "../../bin/cfa -std=c99 constants.c" //
     32// tab-width: 4 //
     33// compile-command: "cfa constants.c" //
    1834// End: //
  • src/examples/control_structures.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// control_structures.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:07:42 2015
     13// Update Count     : 1
     14//
     15
    116int main() {
    217        L1: {
    3                 L2: switch ( 3_333_333 ) {  // underscores in constant
    4                         case 1,2,3:     // 4~8, 4...8 not working
     18                L2: switch ( 3_333_333 ) {                                              // underscores in constant
     19                        case 1,2,3:                                                                     // 4~8, 4...8 not working
    520                                L3: for ( ;; ) {
    621                                        L4: for ( ;; ) {
    7                                                 break L1;   // labelled break
     22                                                break L1;                                               // labelled break
    823                                                break L2;
    924                                                break L3;
    1025                                                break L4;
    1126
    12                                                 // continue L1; // labelled continue - should be an error
    13                                                 // continue L2; // should be an error
     27                                                //continue L1;                                  // labelled continue - should be an error
     28                                                //continue L2;                                  // should be an error
    1429                                                continue L3;
    1530                                                continue L4;
     
    4560
    4661// Local Variables: //
    47 // compile-command: "../../bin/cfa control_structures.c" //
     62// tab-width: 4 //
     63// compile-command: "cfa control_structures.c" //
    4864// End: //
  • src/examples/ctxts.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// ctxts.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:11:19 2015
     13// Update Count     : 2
     14//
     15
    116context has_f( type T ) {
    2     T f( T );
     17        T f( T );
    318};
    419
    520context has_g( type U | has_f( U ) ) {
    6     U g( U );
     21        U g( U );
    722};
    823
    924forall( type V | has_g( V ) ) void h( V );
     25
     26// Local Variables: //
     27// tab-width: 4 //
     28// compile-command: "cfa ctxts.c" //
     29// End: //
  • src/examples/esskaykay.c

    r52ac3b4 r86bd7c1f  
    1 // "./cfa-cpp -cn esskaykay.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// esskaykay.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:11:45 2015
     13// Update Count     : 2
     14//
    215
    316// forall (type A, type B, type C) C ess (C (*f) (A,B), B (*g) (A), A x) { return f(x,g(x)); }
     
    1023
    1124forall (type A) A esskaykay (A x) { ess (kay, kay, x); }
     25
     26// Local Variables: //
     27// tab-width: 4 //
     28// compile-command: "cfa esskaykay.c" //
     29// End: //
  • src/examples/forward.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// forward.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:11:57 2015
     13// Update Count     : 2
     14//
     15
    116forall(type T) lvalue T *?( T* );
    217int ?=?( int*, int );
     
    621
    722void f() {
    8     *x;
     23        *x;
    924}
    1025
    1126// Local Variables: //
    12 // compile-command: "../../bin/cfa forward.c" //
     27// tab-width: 4 //
     28// compile-command: "cfa forward.c" //
    1329// End: //
  • src/examples/fstream.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// fstream.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:12:33 2015
     13// Update Count     : 2
     14//
     15
    116#include "fstream.h"
    217
     
    722
    823struct ofstream {
    9     FILE *file;
    10     int fail;
     24        FILE *file;
     25        int fail;
    1126};
    1227
    1328ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
    14     if ( ! os->fail ) {
    15         fwrite( data, size, 1, os->file );
    16         os->fail = ferror( os->file );
    17     }
    18     return os;
     29        if ( ! os->fail ) {
     30                fwrite( data, size, 1, os->file );
     31                os->fail = ferror( os->file );
     32        }
     33        return os;
    1934}
    2035
    2136int fail( ofstream *os ) {
    22     return os->fail;
     37        return os->fail;
    2338}
    2439
    2540static ofstream *make_ofstream() {
    26     ofstream *new_stream = malloc( sizeof( ofstream ) );
    27     new_stream->fail = 0;
    28     return new_stream;
     41        ofstream *new_stream = malloc( sizeof( ofstream ) );
     42        new_stream->fail = 0;
     43        return new_stream;
    2944}
    3045
    3146ofstream *ofstream_stdout() {
    32     ofstream *stdout_stream = make_ofstream();
    33     stdout_stream->file = stdout;
    34     return stdout_stream;
     47        ofstream *stdout_stream = make_ofstream();
     48        stdout_stream->file = stdout;
     49        return stdout_stream;
    3550}
    3651
    3752ofstream *ofstream_stderr() {
    38     ofstream *stderr_stream = make_ofstream();
    39     stderr_stream->file = stderr;
    40     return stderr_stream;
     53        ofstream *stderr_stream = make_ofstream();
     54        stderr_stream->file = stderr;
     55        return stderr_stream;
    4156}
    4257
    4358ofstream *ofstream_fromfile( const char *name ) {
    44     ofstream *file_stream = make_ofstream();
    45     file_stream->file = fopen( name, "w" );
    46     file_stream->fail = file_stream->file == 0;
    47     return file_stream;
     59        ofstream *file_stream = make_ofstream();
     60        file_stream->file = fopen( name, "w" );
     61        file_stream->fail = file_stream->file == 0;
     62        return file_stream;
    4863}
    4964
    5065void ofstream_close( ofstream *os ) {
    51     if ( os->file != stdout && os->file != stderr ) {
    52         os->fail = fclose( os->file );
    53     }
    54     free( os );
     66        if ( os->file != stdout && os->file != stderr ) {
     67                os->fail = fclose( os->file );
     68        }
     69        free( os );
    5570}
    5671
    5772struct ifstream {
    58     FILE *file;
    59     int fail;
    60     int eof;
     73        FILE *file;
     74        int fail;
     75        int eof;
    6176};
    6277
    6378ifstream *read( ifstream *is, char *data, streamsize_type size ) {
    64     if ( ! is->fail && ! is->eof ) {
    65         fread( data, size, 1, is->file );
    66         is->fail = ferror( is->file );
    67         is->eof = feof( is->file );
    68     }
    69     return is;
     79        if ( ! is->fail && ! is->eof ) {
     80                fread( data, size, 1, is->file );
     81                is->fail = ferror( is->file );
     82                is->eof = feof( is->file );
     83        }
     84        return is;
    7085}
    7186 
    7287ifstream *unread( ifstream *is, char c ) {
    73     if ( ! is->fail ) {
    74         if ( ! EOF == ungetc( c, is->file ) ) {
    75             is->fail = 1;
     88        if ( ! is->fail ) {
     89                if ( ! EOF == ungetc( c, is->file ) ) {
     90                        is->fail = 1;
     91                }
    7692        }
    77     }
    78     return is;
     93        return is;
    7994}
    8095
    8196int fail( ifstream *is ) {
    82     return is->fail;
     97        return is->fail;
    8398}
    8499
    85100int eof( ifstream *is ) {
    86     return is->eof;
     101        return is->eof;
    87102}
    88103
    89104static ifstream *make_ifstream() {
    90     ifstream *new_stream = malloc( sizeof( ifstream ) );
    91     new_stream->fail = 0;
    92     new_stream->eof = 0;
    93     return new_stream;
     105        ifstream *new_stream = malloc( sizeof( ifstream ) );
     106        new_stream->fail = 0;
     107        new_stream->eof = 0;
     108        return new_stream;
    94109}
    95110
    96111ifstream *ifstream_stdin() {
    97     ifstream *stdin_stream = make_ifstream();
    98     stdin_stream->file = stdin;
    99     return stdin_stream;
     112        ifstream *stdin_stream = make_ifstream();
     113        stdin_stream->file = stdin;
     114        return stdin_stream;
    100115}
    101116
    102117ifstream *ifstream_fromfile( const char *name ) {
    103     ifstream *file_stream = make_ifstream();
    104     file_stream->file = fopen( name, "r" );
    105     file_stream->fail = file_stream->file == 0;
    106     return file_stream;
     118        ifstream *file_stream = make_ifstream();
     119        file_stream->file = fopen( name, "r" );
     120        file_stream->fail = file_stream->file == 0;
     121        return file_stream;
    107122}
     123
     124// Local Variables: //
     125// tab-width: 4 //
     126// compile-command: "cfa fstream.c" //
     127// End: //
  • src/examples/fstream.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// fstream.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:13:08 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef __FSTREAM_H__
    217#define __FSTREAM_H__
     
    2742
    2843#endif // __FSTREAM_H__
     44
     45// Local Variables: //
     46// tab-width: 4 //
     47// compile-command: "cfa fstream.c" //
     48// End: //
  • src/examples/fstream_test.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// fstream_test.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:13:43 2015
     13// Update Count     : 2
     14//
     15
    116#include "fstream.h"
    217
    318int main() {
    4     ofstream *sout = ofstream_stdout();
    5     ifstream *sin = ifstream_stdin();
    6     int nombre;
    7     sout << "Appuyez un nombre, s'il vous plâit:\n";
    8     sin >> &nombre;
    9     sout << "Vous avez appuyé: " << nombre << "\n";
     19        ofstream *sout = ofstream_stdout();
     20        ifstream *sin = ifstream_stdin();
     21        int nombre;
     22        sout << "Appuyez un nombre, s'il vous plâit:\n";
     23        sin >> &nombre;
     24        sout << "Vous avez appuyé: " << nombre << "\n";
    1025}
     26
     27// Local Variables: //
     28// tab-width: 4 //
     29// compile-command: "cfa fstream_test.c" //
     30// End: //
  • src/examples/fwrite.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// fwrite.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:14:12 2015
     13// Update Count     : 1
     14//
     15
    116extern "C" {
    2     #include <stdio.h>
     17        #include <stdio.h>
    318}
    419
    520int main() {
    6     fwrite( "test\n", 5, 1, stdout );
     21        fwrite( "test\n", 5, 1, stdout );
    722}
     23
     24// Local Variables: //
     25// tab-width: 4 //
     26// compile-command: "cfa fwrite.c" //
     27// End: //
  • src/examples/hello.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// hello.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:14:58 2015
     13// Update Count     : 1
     14//
     15
    116#include "fstream.h"
    217
    318int main() {
    4     ofstream *sout = ofstream_stdout();
    5     ifstream *sin = ifstream_stdin();
    6     sout << "Bonjour au monde!\n";
    7     sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
    8     int i, j, k;
    9     sin >> &i >> &j >> &k;
    10     sout << "i:" << i << " j:" << j << " k:" << k << "\n";
     19        ofstream *sout = ofstream_stdout();
     20        ifstream *sin = ifstream_stdin();
     21        sout << "Bonjour au monde!\n";
     22        sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
     23        int i, j, k;
     24        sin >> &i >> &j >> &k;
     25        sout << "i:" << i << " j:" << j << " k:" << k << "\n";
    1126}
    1227
    1328// Local Variables: //
    14 // compile-command: "../../bin/cfa hello.c fstream.o iostream.o" //
     29// tab-width: 4 //
     30// compile-command: "cfa hello.c fstream.o iostream.o" //
    1531// End: //
  • src/examples/huge.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// huge.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:15:34 2015
     13// Update Count     : 1
     14//
     15
    116int huge( int n, forall( type T ) T (*f)( T ) ) {
    2     if ( n <= 0 )
    3         return f( 0 );
    4     else
    5         return huge( n - 1, f( f ) );
     17        if ( n <= 0 )
     18                return f( 0 );
     19        else
     20                return huge( n - 1, f( f ) );
    621}
     22
     23// Local Variables: //
     24// tab-width: 4 //
     25// compile-command: "cfa huge.c" //
     26// End: //
  • src/examples/identity.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// identity.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:16:30 2015
     13// Update Count     : 2
     14//
     15
    116#include "fstream.h"
    217
    318forall( type T )
    419T identity( T t ) {
    5     return t;
     20        return t;
    621}
    722
    823int main() {
    9     ofstream *sout = ofstream_stdout();
    10     char c = 'a';
    11     c = identity( c );
    12     sout << c << ' ' << identity( c ) << '\n';
    13     int i = 5;
    14     i = identity( i );
    15     sout << i << ' ' << identity( i ) << '\n';
    16     double d = 3.2;
    17     d = identity( d );
    18     sout << d << ' ' << identity( d ) << '\n';
     24        ofstream *sout = ofstream_stdout();
     25        char c = 'a';
     26        c = identity( c );
     27        sout << c << ' ' << identity( c ) << '\n';
     28        int i = 5;
     29        i = identity( i );
     30        sout << i << ' ' << identity( i ) << '\n';
     31        double d = 3.2;
     32        d = identity( d );
     33        sout << d << ' ' << identity( d ) << '\n';
    1934}
    2035
    2136// Local Variables: //
    22 // compile-command: "../../bin/cfa identity.c fstream.o iostream.o" //
     37// tab-width: 4 //
     38// compile-command: "cfa identity.c fstream.o iostream.o" //
    2339// End: //
  • src/examples/includes.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// includes.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:17:04 2015
     13// Update Count     : 1
     14//
     15
    116#if 1
    217//#include <aio.h>              // FAILS -- includes locale.h
     
    3853
    3954// Local Variables: //
    40 // compile-command: "../../bin/cfa includes.c" //
     55// tab-width: 4 //
     56// compile-command: "cfa includes.c" //
    4157// End: //
  • src/examples/index.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// index.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:17:31 2015
     13// Update Count     : 1
     14//
     15
    116context index( type T ) {
    2     T ?+?( T, T );
    3     T ?-?( T, T );
    4     const T 0, 1;
     17        T ?+?( T, T );
     18        T ?-?( T, T );
     19        const T 0, 1;
    520};
     21
     22// Local Variables: //
     23// tab-width: 4 //
     24// compile-command: "cfa index.c" //
     25// End: //
  • src/examples/iostream.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa -c -o iostream.o iostream.c"
    2 // "cfa -v -E iostream.c > iostream_out.c"
    3 // "cfa -CFA iostream.c > iostream_out.c"
    4 // "cfa iostream_out.c"
    5 // "gcc32 iostream_out.c LibCfa/libcfa.a"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// iostream.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:18:13 2015
     13// Update Count     : 2
     14//
    615
    716#include "iostream.h"
     
    1019//#include <string.h>
    1120//#include <ctype.h>
    12 typedef long unsigned int size_t;
    13 size_t strlen(const char *s);
     21        typedef long unsigned int size_t;
     22        size_t strlen(const char *s);
    1423}
    1524
    1625forall( dtype ostype | ostream( ostype ) )
    1726ostype * ?<<?( ostype *os, char c ) {
    18     return write( os, &c, 1 );
     27        return write( os, &c, 1 );
    1928}
    2029
    2130forall( dtype ostype | ostream( ostype ) )
    2231ostype * ?<<?( ostype *os, int i ) {
    23     char buffer[20];      // larger than the largest integer
    24     sprintf( buffer, "%d", i );
    25     return write( os, buffer, strlen( buffer ) );
     32        char buffer[20];      // larger than the largest integer
     33        sprintf( buffer, "%d", i );
     34        return write( os, buffer, strlen( buffer ) );
    2635}
    2736
    2837forall( dtype ostype | ostream( ostype ) )
    2938ostype * ?<<?( ostype *os, double d ) {
    30     char buffer[32];      // larger than the largest double
    31     sprintf( buffer, "%g", d );
    32     return write( os, buffer, strlen( buffer ) );
     39        char buffer[32];      // larger than the largest double
     40        sprintf( buffer, "%g", d );
     41        return write( os, buffer, strlen( buffer ) );
    3342}
    3443
    3544forall( dtype ostype | ostream( ostype ) )
    3645ostype * ?<<?( ostype *os, const char *cp ) {
    37     return write( os, cp, strlen( cp ) );
     46        return write( os, cp, strlen( cp ) );
    3847}
    3948
    4049forall( dtype istype | istream( istype ) )
    4150istype * ?>>?( istype *is, char *cp ) {
    42     return read( is, cp, 1 );
     51        return read( is, cp, 1 );
    4352}
    4453
    4554forall( dtype istype | istream( istype ) )
    4655istype * ?>>?( istype *is, int *ip ) {
    47     char cur;
     56        char cur;
    4857 
    49     // skip some whitespace
    50     do {
    51         is >> &cur;
    52         if ( fail( is ) || eof( is ) ) return is;
    53     } while ( !( cur >= '0' && cur <= '9' ) );
     58        // skip some whitespace
     59        do {
     60                is >> &cur;
     61                if ( fail( is ) || eof( is ) ) return is;
     62        } while ( !( cur >= '0' && cur <= '9' ) );
    5463 
    55     // accumulate digits
    56     *ip = 0;
    57     while ( cur >= '0' && cur <= '9' ) {
    58         *ip = *ip * 10 + ( cur - '0' );
    59         is >> &cur;
    60         if ( fail( is ) || eof( is ) ) return is;
    61     }
     64        // accumulate digits
     65        *ip = 0;
     66        while ( cur >= '0' && cur <= '9' ) {
     67                *ip = *ip * 10 + ( cur - '0' );
     68                is >> &cur;
     69                if ( fail( is ) || eof( is ) ) return is;
     70        }
    6271 
    63     unread( is, cur );
    64     return is;
     72        unread( is, cur );
     73        return is;
    6574}
     75
     76// Local Variables: //
     77// tab-width: 4 //
     78// compile-command: "cfa iostream.c" //
     79// End: //
  • src/examples/iostream.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// iostream.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:18:46 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef IOSTREAM_H
    217#define IOSTREAM_H
     
    520
    621context ostream( dtype ostype ) {
    7     ostype *write( ostype *, const char *, streamsize_type );
    8     int fail( ostype * );
     22        ostype *write( ostype *, const char *, streamsize_type );
     23        int fail( ostype * );
    924};
    1025
    1126context writeable( type T ) {
    12     forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
     27        forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
    1328};
    1429
     
    2237
    2338context istream( dtype istype ) {
    24     istype *read( istype *, char *, streamsize_type );
    25     istype *unread( istype *, char );
    26     int fail( istype * );
    27     int eof( istype * );
     39        istype *read( istype *, char *, streamsize_type );
     40        istype *unread( istype *, char );
     41        int fail( istype * );
     42        int eof( istype * );
    2843};
    2944
    3045context readable( type T ) {
    31     forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
     46        forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
    3247};
    3348
     
    3954
    4055#endif // IOSTREAM_H
     56
     57// Local Variables: //
     58// tab-width: 4 //
     59// compile-command: "cfa iostream.c" //
     60// End: //
  • src/examples/it_out.c

    r52ac3b4 r86bd7c1f  
    1 # 1 "iterator.c"
    2 # 1 "<built-in>"
    3 # 1 "<command line>"
    4 # 1 "iterator.c"
    5 # 1 "iterator.h" 1
    6 
    7 
    8 
    9 # 1 "iostream.h" 1
    10 
    11 
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// it_out.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:41:23 2015
     13// Update Count     : 4
     14//
    1215
    1316typedef unsigned long streamsize_type;
    1417
    15 
    16 
    17 context ostream( dtype os_type )
    18 {
    19 
    20     os_type *write( os_type *, const char *, streamsize_type );
    21 
    22 
    23     int fail( os_type * );
     18context ostream( dtype os_type ) {
     19        os_type *write( os_type *, const char *, streamsize_type );
     20        int fail( os_type * );
    2421};
    2522
    26 
    27 
    28 
    29 context writeable( type T )
    30 {
    31     forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, T );
     23context writeable( type T ) {
     24        forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, T );
    3225};
    33 
    34 
    3526
    3627forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, char );
     
    3829forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );
    3930
    40 
    41 
    42 
    43 context istream( dtype is_type )
    44 {
    45 
    46     is_type *read( is_type *, char *, streamsize_type );
    47 
    48 
    49     is_type *unread( is_type *, char );
    50 
    51 
    52     int fail( is_type * );
    53 
    54 
    55     int eof( is_type * );
     31context istream( dtype is_type ) {
     32        is_type *read( is_type *, char *, streamsize_type );
     33        is_type *unread( is_type *, char );
     34        int fail( is_type * );
     35        int eof( is_type * );
    5636};
    5737
    58 
    59 
    60 
    61 context readable( type T )
    62 {
    63     forall( dtype is_type | istream( is_type ) ) is_type * ?<<?( is_type *, T );
     38context readable( type T ) {
     39        forall( dtype is_type | istream( is_type ) ) is_type * ?<<?( is_type *, T );
    6440};
    65 
    66 
    6741
    6842forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, char* );
    6943forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, int* );
    70 # 5 "iterator.h" 2
    7144
     45context iterator( type iterator_type, type elt_type ) {
     46        iterator_type ?++( iterator_type* );
     47        iterator_type ++?( iterator_type* );
     48        int ?==?( iterator_type, iterator_type );
     49        int ?!=?( iterator_type, iterator_type );
    7250
    73 context iterator( type iterator_type, type elt_type )
    74 {
    75 
    76     iterator_type ?++( iterator_type* );
    77     iterator_type ++?( iterator_type* );
    78 
    79 
    80     int ?==?( iterator_type, iterator_type );
    81     int ?!=?( iterator_type, iterator_type );
    82 
    83 
    84     lvalue elt_type *?( iterator_type );
     51        lvalue elt_type *?( iterator_type );
    8552};
    8653
    87 
     54forall( type elt_type | writeable( elt_type ),
     55                type iterator_type | iterator( iterator_type, elt_type ),
     56                dtype os_type | ostream( os_type ) )
     57void write_all( iterator_type begin, iterator_type end, os_type *os );
    8858
    8959forall( type elt_type | writeable( elt_type ),
    90         type iterator_type | iterator( iterator_type, elt_type ),
    91         dtype os_type | ostream( os_type ) )
    92 void write_all( iterator_type begin, iterator_type end, os_type *os );
    93 # 2 "iterator.c" 2
     60                type iterator_type | iterator( iterator_type, elt_type ),
     61                dtype os_type | ostream( os_type ) )
     62void write_all( elt_type begin, iterator_type end, os_type *os ) {
     63        os << begin;
     64}
    9465
    95 forall( type elt_type | writeable( elt_type ),
    96         type iterator_type | iterator( iterator_type, elt_type ),
    97         dtype os_type | ostream( os_type ) )
    98 void
    99 write_all( elt_type begin, iterator_type end, os_type *os )
    100 {
    101     os << begin;
    102 }
     66// Local Variables: //
     67// tab-width: 4 //
     68// compile-command: "cfa it_out.c" //
     69// End: //
  • src/examples/iterator.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa iterator.c"
    2 // "cfa -CFA iterator.c > iterator_out.c"
    3 // "gcc31 iterator_out.c ../LibCfa/libcfa.a"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// iterator.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:41:41 2015
     13// Update Count     : 3
     14//
    415
    516#include "iterator.h"
     
    1122///   iterator_type i;
    1223///   for ( i = begin; i != end; ++i ) {
    13 ///    func( *i );
     24///      func( *i );
    1425///   }
    1526/// }
    1627
    1728forall( type elt_type | writeable( elt_type ),
    18         type iterator_type | iterator( iterator_type, elt_type ),
    19         dtype os_type | ostream( os_type ) )
     29                type iterator_type | iterator( iterator_type, elt_type ),
     30                dtype os_type | ostream( os_type ) )
    2031void write_all( iterator_type begin, iterator_type end, os_type *os ) {
    21     iterator_type i;
    22     for ( i = begin; i != end; ++i ) {
    23         os << *i << ' ';
    24     }
     32        iterator_type i;
     33        for ( i = begin; i != end; ++i ) {
     34                os << *i << ' ';
     35        }
    2536}
    2637
    2738forall( type elt_type | writeable( elt_type ),
    28         type iterator_type | iterator( iterator_type, elt_type ),
    29         dtype os_type | ostream( os_type ) )
     39                type iterator_type | iterator( iterator_type, elt_type ),
     40                dtype os_type | ostream( os_type ) )
    3041void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    31     iterator_type i; // "= end;" does not work
    32     i = end;
    33     do {
    34         --i;
    35         os << *i << ' ';
    36     } while ( i != begin );
     42        iterator_type i; // "= end;" does not work
     43        i = end;
     44        do {
     45                --i;
     46                os << *i << ' ';
     47        } while ( i != begin );
    3748}
     49
     50// Local Variables: //
     51// tab-width: 4 //
     52// compile-command: "cfa iterator.c" //
     53// End: //
  • src/examples/iterator.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// iterator.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:41:57 2015
     13// Update Count     : 3
     14//
     15
    116#ifndef ITERATOR_H
    217#define ITERATOR_H
     
    621// An iterator can be used to traverse a data structure.
    722context iterator( type iterator_type, type elt_type ) {
    8     // point to the next element
    9 //    iterator_type ?++( iterator_type * );
    10     iterator_type ++?( iterator_type * );
    11     iterator_type --?( iterator_type * );
     23        // point to the next element
     24//      iterator_type ?++( iterator_type * );
     25        iterator_type ++?( iterator_type * );
     26        iterator_type --?( iterator_type * );
    1227
    13     // can be tested for equality with other iterators
    14     int ?==?( iterator_type, iterator_type );
    15     int ?!=?( iterator_type, iterator_type );
     28        // can be tested for equality with other iterators
     29        int ?==?( iterator_type, iterator_type );
     30        int ?!=?( iterator_type, iterator_type );
    1631
    17     // dereference to get the pointed-at element
    18     lvalue elt_type *?( iterator_type );
     32        // dereference to get the pointed-at element
     33        lvalue elt_type *?( iterator_type );
    1934};
    2035
    2136context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
    22 //    [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
    23     iterator_type begin( collection_type );
    24     iterator_type end( collection_type );
     37//      [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
     38        iterator_type begin( collection_type );
     39        iterator_type end( collection_type );
    2540};
    2641
     
    3045// writes the range [begin, end) to the given stream
    3146forall( type elt_type | writeable( elt_type ),
    32         type iterator_type | iterator( iterator_type, elt_type ),
    33         dtype os_type | ostream( os_type ) )
     47                type iterator_type | iterator( iterator_type, elt_type ),
     48                dtype os_type | ostream( os_type ) )
    3449void write_all( iterator_type begin, iterator_type end, os_type *os );
    3550
    3651forall( type elt_type | writeable( elt_type ),
    37         type iterator_type | iterator( iterator_type, elt_type ),
    38         dtype os_type | ostream( os_type ) )
     52                type iterator_type | iterator( iterator_type, elt_type ),
     53                dtype os_type | ostream( os_type ) )
    3954void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    4055
    4156#endif // ITERATOR_H
     57
     58// Local Variables: //
     59// tab-width: 4 //
     60// compile-command: "cfa iterator.c" //
     61// End: //
  • src/examples/min.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// min.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:23:19 2015
     13// Update Count     : 2
     14//
     15
    116extern "C" {
    2     int printf( const char *, ... );
     17        int printf( const char *, ... );
    318//#include <stdio.h>
    419}
     
    621forall( type T | { int ?<?( T, T ); } )
    722T min( const T t1, const T t2 ) {
    8     return t1 < t2 ? t1 : t2;
     23        return t1 < t2 ? t1 : t2;
    924}
    1025
    1126int main() {
    12     char c;
    13 //    c = min( 'z', 'a' );
    14 //    printf( "minimum %d\n", c );
    15     int i;
    16     i = min( 4, 3 );
    17     printf( "minimum %d\n", min( 4, 3 ) );
    18     float f;
    19     f = min( 4.0, 3.1 );
    20     printf( "minimum %g\n", f );
    21     double d;
    22     d = min( 4.0, 3.2 );
    23     printf( "minimum %g\n", d );
     27        char c;
     28//      c = min( 'z', 'a' );
     29//      printf( "minimum %d\n", c );
     30        int i;
     31        i = min( 4, 3 );
     32        printf( "minimum %d\n", min( 4, 3 ) );
     33        float f;
     34        f = min( 4.0, 3.1 );
     35        printf( "minimum %g\n", f );
     36        double d;
     37        d = min( 4.0, 3.2 );
     38        printf( "minimum %g\n", d );
    2439}
    2540
    2641// Local Variables: //
    27 // compile-command: "../../bin/cfa min.c" //
     42// tab-width: 4 //
     43// compile-command: "cfa min.c" //
    2844// End: //
  • src/examples/new.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// new.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:23:55 2015
     13// Update Count     : 1
     14//
     15
    116forall( type T )
    217void f( T *t ) {
    3     t--;
    4     *t;
    5     ++t;
    6     t += 2;
    7     t + 2;
    8     --t;
    9     t -= 2;
    10     t - 4;
    11     t[7];
    12     7[t];
     18        t--;
     19        *t;
     20        ++t;
     21        t += 2;
     22        t + 2;
     23        --t;
     24        t -= 2;
     25        t - 4;
     26        t[7];
     27        7[t];
    1328}
     29
     30// Local Variables: //
     31// tab-width: 4 //
     32// compile-command: "cfa new.c" //
     33// End: //
  • src/examples/prolog.c

    r52ac3b4 r86bd7c1f  
    1 // "./cfa prolog.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// prolog.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:25:52 2015
     13// Update Count     : 1
     14//
    215
    316extern "C" { extern int printf( const char *fmt, ... ); }
     
    1326
    1427context ArithmeticType( type T ) {
    15     void is_arithmetic( T );
     28        void is_arithmetic( T );
    1629};
    1730
    1831context IntegralType( type T | ArithmeticType( T ) ) {
    19     void is_integer( T );
     32        void is_integer( T );
    2033};
    2134
    2235forall( type T | IntegralType( T ) | { void printResult( T ); } )
    2336void hornclause( T param ) {
    24     printResult( param );
     37        printResult( param );
    2538}
    2639
    2740int main() {
    28     int x;
    29     double x;
    30     char * x;
    31     hornclause( x );
     41        int x;
     42        double x;
     43        char * x;
     44        hornclause( x );
    3245}
     46
     47// Local Variables: //
     48// tab-width: 4 //
     49// compile-command: "cfa prolog.c" //
     50// End: //
  • src/examples/quad.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// quad.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:26:36 2015
     13// Update Count     : 2
     14//
     15
    116extern "C" {
    2     #include <stdio.h>
     17#include <stdio.h>
    318}
    419
    520forall( type T | { T ?*?( T, T ); } )
    621T square( T t ) {
    7     return t * t;
     22        return t * t;
    823}
    924
    1025forall( type U | { U square( U ); } )
    1126U quad( U u ) {
    12     return square( square( u ) );
     27        return square( square( u ) );
    1328}
    1429
    1530int main() {
    16     int N = 2;
    17     printf( "result of quad of %d is %d\n", N, quad( N ) );
     31        int N = 2;
     32        printf( "result of quad of %d is %d\n", N, quad( N ) );
    1833}
    1934
    2035// Local Variables: //
    21 // compile-command: "../../bin/cfa quad.c" //
     36// tab-width: 4 //
     37// compile-command: "cfa quad.c" //
    2238// End: //
  • src/examples/quoted_keyword.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// quoted_keyword.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:27:26 2015
     13// Update Count     : 2
     14//
     15
    116// test quoted keyword usage
    217int `catch`;
    318
    419struct {
    5     int `type`;
    6     int `struct`;
     20        int `type`;
     21        int `struct`;
    722} st;
    823
     
    1126
    1227int foo() {
    13     int w = `catch` + st.`type` + st.`struct` + `throw`;
     28        int w = `catch` + st.`type` + st.`struct` + `throw`;
    1429}
    1530
     
    1732
    1833// Local Variables: //
    19 // compile-command: "../../bin/cfa quoted_keyword.c" //
     34// tab-width: 4 //
     35// compile-command: "cfa quoted_keyword.c" //
    2036// End: //
  • src/examples/s.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// s.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:42:39 2015
     13// Update Count     : 2
     14//
     15
    116//int ?!=?( int, int );
    217
    318void f() {
    4 //    int a;
    5 //    a ? 4 : 5;
    6     1 ? 4 : 5;
    7     0 ? 4 : 5;
     19//      int a;
     20//      a ? 4 : 5;
     21        1 ? 4 : 5;
     22        0 ? 4 : 5;
    823}
     24
     25// Local Variables: //
     26// tab-width: 4 //
     27// compile-command: "cfa s.c" //
     28// End: //
  • src/examples/simple.c

    r52ac3b4 r86bd7c1f  
    1 // './cfa square.c'
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// simple.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:30:27 2015
     13// Update Count     : 3
     14//
    215
    316extern "C" {
    4     int printf( const char *fmt, ... );
     17        int printf( const char *fmt, ... );
    518}
    619
    720context has_star( type T ) {
    8     T ?*?( T, T );
     21        T ?*?( T, T );
    922};
    1023
    1124int ?*?( int, int );
    12 int ?=?( int*, int );
     25int ?=?( int *, int );
    1326
    1427forall( type T | has_star( T ) )
    1528T square( T t ) {
    16     return t * t;
     29        return t * t;
    1730}
    1831
    1932int main() {
    20     printf( "result of square of 5 is %d\n", square( 5 ) );
     33        printf( "result of square of 5 is %d\n", square( 5 ) );
    2134}
     35
     36// Local Variables: //
     37// tab-width: 4 //
     38// compile-command: "cfa simple.c" //
     39// End: //
  • src/examples/simplePoly.c

    r52ac3b4 r86bd7c1f  
    1 // './cfa-cpp -nc < simplePoly.c'
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// simplePoly.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:31:17 2015
     13// Update Count     : 2
     14//
    215
    316forall( type T, type U | { T f( T, U ); } )
    4 T q( T t, U u )
    5 {
    6     return f( t, u );
     17T q( T t, U u ) {
     18        return f( t, u );
    719//  return t;
    820}
     
    1123
    1224void g( void ) {
    13     int y;
    14     double x;
     25        int y;
     26        double x;
    1527//  if ( y )
    16     q( 3, &x );
     28        q( 3, &x );
    1729}
     30
     31// Local Variables: //
     32// tab-width: 4 //
     33// compile-command: "cfa simplePoly.c" //
     34// End: //
  • src/examples/simpler.c

    r52ac3b4 r86bd7c1f  
    1 // "./cfa-cpp -c simpler.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// simpler.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:31:48 2015
     13// Update Count     : 1
     14//
    215
    316forall( type T ) T id( T, T );
    417
    518int main() {
    6     id( 0, 7 );
     19        id( 0, 7 );
    720}
     21
     22// Local Variables: //
     23// tab-width: 4 //
     24// compile-command: "cfa simpler.c" //
     25// End: //
  • src/examples/specialize.c

    r52ac3b4 r86bd7c1f  
    1 // "./cfa specialize.c"
    2 // "./cfa -g simple.c"
    3 // "./cfa -CFA simple.c > simple_out.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// specialize.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:32:26 2015
     13// Update Count     : 2
     14//
    415
    516/// void f( const int * );
     
    2536
    2637extern "C" {
    27   int printf( const char*, ... );
     38        int printf( const char*, ... );
    2839}
    2940
    3041forall( type T ) T f( T t )
    3142{
    32   printf( "in f; sizeof T is %d\n", sizeof( T ) );
    33   return t;
     43        printf( "in f; sizeof T is %d\n", sizeof( T ) );
     44        return t;
    3445}
    3546
    3647void g( int (*p)(int) )
    3748{
    38   printf( "g: f(7) returned %d\n", f(7) );
     49        printf( "g: f(7) returned %d\n", f(7) );
    3950}
    4051
    4152int main() {
    42   g( f );
     53        g( f );
    4354}
     55
     56// Local Variables: //
     57// tab-width: 4 //
     58// compile-command: "cfa specialize.c" //
     59// End: //
  • src/examples/square.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// square.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:43:34 2015
     13// Update Count     : 2
     14//
     15
    116extern "C" {
    217#include <stdio.h>
    318}
    419
    5 forall( type T | { T ?*?( T, T ); })
     20forall( type T | { T ?*?( T, T ); } )
    621T square( T t ) {
    7     return t * t;
     22        return t * t;
    823}
    924
     25//char ?*?( char a1, char a2 ) {
     26//      return (char)( (int)a1 * (int)a2 );
     27//}
     28
    1029int main() {
    11     printf( "result of square of 5 is %d\n", square( 5 ) );
    12     printf( "result of square of 5 is %f\n", square( 5.0 ) );
     30        char c = 5;
     31        short int s = 5;
     32        int i = 5;
     33        float f = 5.0;
     34        double d = 5.0;
     35//      printf( "result of square of 5 is %d\n", (char)square( c ) );
     36        printf( "result of square of 5 is %d\n", square( s ) );
     37        printf( "result of square of 5 is %d\n", square( i ) );
     38        printf( "result of square of 5 is %f\n", square( f ) );
     39        printf( "result of square of 5 is %f\n", square( d ) );
    1340}
     41
     42// Local Variables: //
     43// tab-width: 4 //
     44// compile-command: "cfa square.c" //
     45// End: //
  • src/examples/sum.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// sum.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:43:46 2015
     13// Update Count     : 4
     14//
     15
    116extern "C" {
    2     int printf( const char *, ... );
     17        int printf( const char *, ... );
    318}
    419
    520context sumable( type T ) {
    6     const T 0;
    7     T ?+?( T, T );
    8     T ?++( T * );
    9     T ?+=?( T *, T );
     21        const T 0;
     22        T ?+?( T, T );
     23        T ?++( T * );
     24        T ?+=?( T *, T );
    1025};
    1126
    1227forall( type T | sumable( T ) )
    1328T sum( int n, T a[] ) {
    14     T total;                            // instantiate T, select 0
    15     total = 0;
    16     for ( int i = 0; i < n; i += 1 )
    17         total = total + a[i];           // select +
    18     return total;
     29        T total;                                                                                        // instantiate T, select 0
     30        total = 0;
     31        for ( int i = 0; i < n; i += 1 )
     32                total = total + a[i];                                                   // select +
     33        return total;
    1934}
    2035
     
    2742
    2843int main() {
    29     const int size = 10, low = 0, High = 10;
    30     int si = 0, ai[10]; // size
    31     int i;
    32     for ( i = low; i < High; i += 1 ) {
    33         si += i;
    34         ai[i] = i;
    35     }
    36     printf( "sum from %d to %d is %d, check %d\n",
    37             low, High, sum( size, ai ), si );
     44        const int size = 10, low = 0, High = 10;
     45        int si = 0, ai[10]; // size
     46        int i;
     47        for ( i = low; i < High; i += 1 ) {
     48                si += i;
     49                ai[i] = i;
     50        }
     51        printf( "sum from %d to %d is %d, check %d\n",
     52                        low, High, sum( size, ai ), si );
    3853
    39 //    char ci[10];
    40 //    char c = sum( size, ci );
    41 //    float fi[10];
    42 //    float f = sum( size, fi );
     54//      char ci[10];
     55//      char c = sum( size, ci );
     56//      float fi[10];
     57//      float f = sum( size, fi );
    4358
    44     double sd = 0.0, ad[10]; // size
    45     for ( i = low; i < High; i += 1 ) {
    46         double d = i / (double)size;
    47         sd += d;
    48         ad[i] = d;
    49     }
    50     printf( "sum from %g to %g is %g, check %g\n",
    51             low / (double)size, High / (double)size, sum( size, ad ), sd );
     59        double sd = 0.0, ad[10];                                                        // size
     60        for ( i = low; i < High; i += 1 ) {
     61                double d = i / (double)size;
     62                sd += d;
     63                ad[i] = d;
     64        }
     65        printf( "sum from %g to %g is %g, check %g\n",
     66                        low / (double)size, High / (double)size, sum( size, ad ), sd );
    5267}
    5368
    5469// Local Variables: //
    55 // compile-command: "../../bin/cfa sum.c" //
     70// tab-width: 4 //
     71// compile-command: "cfa sum.c" //
    5672// End: //
  • src/examples/swap.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// swap.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:34:47 2015
     13// Update Count     : 1
     14//
     15
    116extern "C" {
    2     int printf( const char *, ... );
     17        int printf( const char *, ... );
    318}
    419
    520forall( type T )
    621void swap( T *left, T *right ) {
    7     T temp = *left;
    8     *left = *right;
    9     *right = temp;
     22        T temp = *left;
     23        *left = *right;
     24        *right = temp;
    1025}
    1126
    1227int main() {
    13     int x = 1, y = 2;
    14     printf( "%d %d\n", x, y );
    15     swap( &x, &y );
    16     printf( "%d %d\n", x, y );
     28        int x = 1, y = 2;
     29        printf( "%d %d\n", x, y );
     30        swap( &x, &y );
     31        printf( "%d %d\n", x, y );
    1732}
    1833
    1934// Local Variables: //
    20 // compile-command: "../../bin/cfa swap.c" //
     35// tab-width: 4 //
     36// compile-command: "cfa swap.c" //
    2137// End: //
  • src/examples/twice.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// twice.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:37:23 2015
     13// Update Count     : 1
     14//
     15
    116#include "fstream.h"
    217
    318forall( type T | { T ?+?( T, T ); T ?++( T * ); [T] ?+=?( T *, T ); } )
    419T twice( const T t ) {
    5     return t + t;
     20        return t + t;
    621}
    722
    823int main() {
    9     ofstream *sout = ofstream_stdout();
    10     sout << twice( 1 ) << ' ' << twice( 3.2 ) << '\n';
     24        ofstream *sout = ofstream_stdout();
     25        sout << twice( 1 ) << ' ' << twice( 3.2 ) << '\n';
    1126}
    1227
    1328// Local Variables: //
    14 // compile-command: "../../bin/cfa twice.c fstream.o iostream.o" //
     29// tab-width: 4 //
     30// compile-command: "cfa twice.c fstream.o iostream.o" //
    1531// End: //
  • src/examples/vector_int.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa vector_int.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// vector_int.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:38:05 2015
     13// Update Count     : 3
     14//
    215
    316#include "vector_int.h"
     
    1023
    1124vector_int vector_int_allocate() {
    12     return vector_int_allocate( DEFAULT_CAPACITY );
     25        return vector_int_allocate( DEFAULT_CAPACITY );
    1326}
    1427
    1528vector_int vector_int_allocate( int reserve ) {
    16     vector_int new_vector;
    17     new_vector.last = -1;
    18     new_vector.capacity = reserve;
    19     new_vector.data = malloc( sizeof( int ) * reserve );
    20     return new_vector;
     29        vector_int new_vector;
     30        new_vector.last = -1;
     31        new_vector.capacity = reserve;
     32        new_vector.data = malloc( sizeof( int ) * reserve );
     33        return new_vector;
    2134}
    2235
    2336void vector_int_deallocate( vector_int vec ) {
    24     free( vec.data );
     37        free( vec.data );
    2538}
    2639
    2740void reserve( vector_int *vec, int reserve ) {
    28     if ( reserve > vec->capacity ) {
    29         vec->data = realloc( vec->data, sizeof( int ) * reserve );
    30         vec->capacity = reserve;
    31     }
     41        if ( reserve > vec->capacity ) {
     42                vec->data = realloc( vec->data, sizeof( int ) * reserve );
     43                vec->capacity = reserve;
     44        }
    3245}
    3346
    3447void append( vector_int *vec, int element ) {
    35     vec->last++;
    36     if ( vec->last == vec->capacity ) {
    37         vec->capacity *= 2;
    38         vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
    39     }
    40     vec->data[ vec->last ] = element;
     48        vec->last++;
     49        if ( vec->last == vec->capacity ) {
     50                vec->capacity *= 2;
     51                vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
     52        }
     53        vec->data[ vec->last ] = element;
    4154}
    4255
     
    4457
    4558lvalue int ?[?]( vector_int vec, int index ) {
    46     return vec.data[ index ];
     59        return vec.data[ index ];
    4760}
    4861
    4962int last( vector_int vec ) {
    50     return vec.last;
     63        return vec.last;
    5164}
    5265
     66
     67// Local Variables: //
     68// tab-width: 4 //
     69// compile-command: "cfa vector_int.c" //
     70// End: //
  • src/examples/vector_int.h

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// vector_int.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:39:05 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef VECTOR_INT_H
    217#define VECTOR_INT_H
     
    520
    621typedef struct vector_int {
    7     int last;                                           // last used index
    8     int capacity;                                       // last possible index before reallocation
    9     int *data;                                          // array
     22        int last;                                                                                       // last used index
     23        int capacity;                                                                           // last possible index before reallocation
     24        int *data;                                                                                      // array
    1025} vector_int;
    1126
    12 vector_int vector_int_allocate();                       // allocate vector with default capacity
    13 vector_int vector_int_allocate( int reserve );          // allocate vector with specified capacity
    14 void vector_int_deallocate( vector_int );               // deallocate vector's storage
     27vector_int vector_int_allocate();                                               // allocate vector with default capacity
     28vector_int vector_int_allocate( int reserve );                  // allocate vector with specified capacity
     29void vector_int_deallocate( vector_int );                               // deallocate vector's storage
    1530
    16 void reserve( vector_int *vec, int reserve );           // reserve more capacity
    17 void append( vector_int *vec, int element );            // add element to end of vector, resizing as necessary
     31void reserve( vector_int *vec, int reserve );                   // reserve more capacity
     32void append( vector_int *vec, int element );                    // add element to end of vector, resizing as necessary
    1833
    1934// implement bounded_array
    2035
    21 lvalue int ?[?]( vector_int vec, int index );           // access to arbitrary element (does not resize)
    22 int last( vector_int vec );                             // return last element
     36lvalue int ?[?]( vector_int vec, int index );                   // access to arbitrary element (does not resize)
     37int last( vector_int vec );                                                             // return last element
    2338
    2439#endif // VECTOR_INT_H
     40
     41// Local Variables: //
     42// tab-width: 4 //
     43// compile-command: "cfa vector_int.c" //
     44// End: //
  • src/examples/vector_test.c

    r52ac3b4 r86bd7c1f  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// vector_test.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:42:55 2015
     13// Update Count     : 2
     14//
     15
    116#include "fstream.h"
    217#include "vector_int.h"
     
    520
    621int main() {
    7     ofstream *sout = ofstream_stdout();
    8     ifstream *sin = ifstream_stdin();
    9     vector_int vec = vector_int_allocate();
     22        ofstream *sout = ofstream_stdout();
     23        ifstream *sin = ifstream_stdin();
     24        vector_int vec = vector_int_allocate();
    1025
    11     // read in numbers until EOF or error
    12     int num;
     26        // read in numbers until EOF or error
     27        int num;
    1328
    14     sout << "enter N elements and C-d on a separate line:\n";
    15     for ( ;; ) {
     29        sout << "enter N elements and C-d on a separate line:\n";
     30        for ( ;; ) {
    1631        sin >> &num;
    17       if ( fail( sin ) || eof( sin ) ) break;
     32          if ( fail( sin ) || eof( sin ) ) break;
    1833        append( &vec, num );
    19     }
    20     // write out the numbers
     34        }
     35        // write out the numbers
    2136
    22     sout << "Array elements:\n";
    23 //    write_all( begin( vec ), end( vec ), sout );
    24 //    sout << "\n";
    25     for ( int index = 0; index <= last( vec ); index += 1 ) {
     37        sout << "Array elements:\n";
     38//      write_all( begin( vec ), end( vec ), sout );
     39//      sout << "\n";
     40        for ( int index = 0; index <= last( vec ); index += 1 ) {
    2641        sout << vec[ index ] << " ";
    27     }
    28     sout << "\n";
     42        }
     43        sout << "\n";
    2944#if 1
    30     sout << "Array elements reversed:\n";
    31     write_reverse( begin( vec ), end( vec ), sout );
    32     sout << "\n";
     45        sout << "Array elements reversed:\n";
     46        write_reverse( begin( vec ), end( vec ), sout );
     47        sout << "\n";
    3348#endif
    3449}
    3550
    3651// ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o
     52
     53// Local Variables: //
     54// tab-width: 4 //
     55// compile-command: "cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o" //
     56// End: //
Note: See TracChangeset for help on using the changeset viewer.