Changeset 5189888 for src/examples


Ignore:
Timestamp:
Nov 20, 2015, 4:44:27 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, string, with_gc
Children:
7e23d0a, bdf1954
Parents:
66a2a61 (diff), 839ccbb (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 /u/cforall/software/cfa/cfa-cc

Conflicts:

src/SymTab/Validate.cc

Location:
src/examples
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/examples/Makefile.am

    r66a2a61 r5189888  
    1111## Created On       : Sun May 31 09:08:15 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Thu Jun  4 23:13:10 2015
    14 ## Update Count     : 22
     13## Last Modified On : Fri Nov 20 16:03:46 2015
     14## Update Count     : 24
    1515###############################################################################
    1616
     
    1919CC = @CFA_BINDIR@/cfa
    2020
    21 noinst_PROGRAMS = fstream_test vector_test
    22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c
     21noinst_PROGRAMS = fstream_test vector_test # build but do not install
     22fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c
    2323vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c
  • src/examples/Makefile.in

    r66a2a61 r5189888  
    4949PROGRAMS = $(noinst_PROGRAMS)
    5050am_fstream_test_OBJECTS = iostream.$(OBJEXT) fstream.$(OBJEXT) \
    51         fstream_test.$(OBJEXT)
     51        fstream_test.$(OBJEXT) iterator.$(OBJEXT)
    5252fstream_test_OBJECTS = $(am_fstream_test_OBJECTS)
    5353fstream_test_LDADD = $(LDADD)
     
    176176top_builddir = @top_builddir@
    177177top_srcdir = @top_srcdir@
    178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c
     178fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c
    179179vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c
    180180all: all-am
  • src/examples/fstream.c

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:12:33 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Nov 19 22:43:31 2015
     13// Update Count     : 4
    1414//
    1515
     
    3030                fwrite( data, size, 1, os->file );
    3131                os->fail = ferror( os->file );
    32         }
     32        } // if
    3333        return os;
    34 }
     34} // write
    3535
    3636int fail( ofstream *os ) {
    3737        return os->fail;
    38 }
     38} // fail
    3939
    4040static ofstream *make_ofstream() {
     
    4242        new_stream->fail = 0;
    4343        return new_stream;
    44 }
     44} // make_ofstream
    4545
    4646ofstream *ofstream_stdout() {
     
    4848        stdout_stream->file = stdout;
    4949        return stdout_stream;
    50 }
     50} // ofstream_stdout
    5151
    5252ofstream *ofstream_stderr() {
     
    5454        stderr_stream->file = stderr;
    5555        return stderr_stream;
    56 }
     56} // ofstream_stderr
    5757
    5858ofstream *ofstream_fromfile( const char *name ) {
  • src/examples/hello.c

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:14:58 2015
    13 // Update Count     : 1
     12// Last Modified On : Fri Nov 20 16:02:50 2015
     13// Update Count     : 3
    1414//
    1515
     
    2828// Local Variables: //
    2929// tab-width: 4 //
    30 // compile-command: "cfa hello.c fstream.o iostream.o" //
     30// compile-command: "cfa hello.c fstream.o iostream.o iterator.o" //
    3131// End: //
  • src/examples/iostream.c

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:18:13 2015
    13 // Update Count     : 2
     12// Last Modified On : Fri Nov 20 13:19:19 2015
     13// Update Count     : 9
    1414//
    1515
     
    1717extern "C" {
    1818#include <stdio.h>
    19 //#include <string.h>
    20 //#include <ctype.h>
    21         typedef long unsigned int size_t;
    22         size_t strlen(const char *s);
     19#include <string.h>                                                                             // strlen
    2320}
    2421
     
    2623ostype * ?<<?( ostype *os, char c ) {
    2724        return write( os, &c, 1 );
    28 }
     25} // ?<<?
    2926
    3027forall( dtype ostype | ostream( ostype ) )
    3128ostype * ?<<?( ostype *os, int i ) {
    32         char buffer[20];      // larger than the largest integer
     29        char buffer[32];                                                                        // larger than the largest integer
    3330        sprintf( buffer, "%d", i );
    3431        return write( os, buffer, strlen( buffer ) );
    35 }
     32} // ?<<?
    3633
    3734forall( dtype ostype | ostream( ostype ) )
    3835ostype * ?<<?( ostype *os, double d ) {
    39         char buffer[32];      // larger than the largest double
     36        char buffer[32];                                                                        // larger than the largest double
    4037        sprintf( buffer, "%g", d );
    4138        return write( os, buffer, strlen( buffer ) );
    42 }
     39} // ?<<?
    4340
    4441forall( dtype ostype | ostream( ostype ) )
    4542ostype * ?<<?( ostype *os, const char *cp ) {
    4643        return write( os, cp, strlen( cp ) );
    47 }
     44} // ?<<?
     45
     46forall( dtype ostype | ostream( ostype ) )
     47ostype * ?<<?( ostype *os, const void *p ) {
     48        char buffer[32];                                                                        // larger than the largest pointer
     49        sprintf( buffer, "%p", p );
     50        return write( os, buffer, strlen( buffer ) );
     51} // ?<<?
     52
     53forall( type elt_type | writeable( elt_type ),
     54                type iterator_type | iterator( iterator_type, elt_type ),
     55                dtype os_type | ostream( os_type ) )
     56void write( iterator_type begin, iterator_type end, os_type *os ) {
     57        void print( elt_type i ) {
     58                os << i << ' ';
     59        }
     60        for_each( begin, end, print );
     61} // ?<<?
     62
     63forall( type elt_type | writeable( elt_type ),
     64                type iterator_type | iterator( iterator_type, elt_type ),
     65                dtype os_type | ostream( os_type ) )
     66void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     67        void print( elt_type i ) {
     68                os << i << ' ';
     69        }
     70        for_each_reverse( begin, end, print );
     71} // ?<<?
     72
    4873
    4974forall( dtype istype | istream( istype ) )
    5075istype * ?>>?( istype *is, char *cp ) {
    5176        return read( is, cp, 1 );
    52 }
     77} // ?>>?
    5378
    5479forall( dtype istype | istream( istype ) )
     
    7297        unread( is, cur );
    7398        return is;
    74 }
     99} // ?>>?
    75100
    76101// Local Variables: //
  • src/examples/iostream.h

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:18:46 2015
    13 // Update Count     : 1
     12// Last Modified On : Thu Nov 19 17:56:51 2015
     13// Update Count     : 5
    1414//
    1515
    1616#ifndef IOSTREAM_H
    1717#define IOSTREAM_H
     18
     19#include "iterator.h"
    1820
    1921typedef unsigned long streamsize_type;
     
    3436forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
    3537forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
     38forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
     39
     40// writes the range [begin, end) to the given stream
     41forall( type elt_type | writeable( elt_type ),
     42                type iterator_type | iterator( iterator_type, elt_type ),
     43                dtype os_type | ostream( os_type ) )
     44void write( iterator_type begin, iterator_type end, os_type *os );
     45
     46forall( type elt_type | writeable( elt_type ),
     47                type iterator_type | iterator( iterator_type, elt_type ),
     48                dtype os_type | ostream( os_type ) )
     49void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    3650
    3751
  • src/examples/iterator.c

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:41:41 2015
    13 // Update Count     : 3
     12// Last Modified On : Thu Nov 19 17:54:37 2015
     13// Update Count     : 24
    1414//
    1515
    1616#include "iterator.h"
    1717
    18 /// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
    19 /// void
    20 /// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) )
    21 /// {
    22 ///   iterator_type i;
    23 ///   for ( i = begin; i != end; ++i ) {
    24 ///      func( *i );
    25 ///   }
    26 /// }
    27 
    28 forall( type elt_type | writeable( elt_type ),
    29                 type iterator_type | iterator( iterator_type, elt_type ),
    30                 dtype os_type | ostream( os_type ) )
    31 void write_all( iterator_type begin, iterator_type end, os_type *os ) {
    32         iterator_type i;
    33         for ( i = begin; i != end; ++i ) {
    34                 os << *i << ' ';
     18forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     19void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     20        for ( iterator_type i = begin; i != end; ++i ) {
     21                func( *i );
    3522        }
    3623}
    3724
    38 forall( type elt_type | writeable( elt_type ),
    39                 type iterator_type | iterator( iterator_type, elt_type ),
    40                 dtype os_type | ostream( os_type ) )
    41 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    42         iterator_type i; // "= end;" does not work
    43         i = end;
    44         do {
     25forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     26void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     27        for ( iterator_type i = end; i != begin; ) {
    4528                --i;
    46                 os << *i << ' ';
    47         } while ( i != begin );
     29                func( *i );
     30        }
    4831}
    4932
  • src/examples/iterator.h

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:41:57 2015
    13 // Update Count     : 3
     12// Last Modified On : Thu Nov 19 17:58:28 2015
     13// Update Count     : 6
    1414//
    1515
    1616#ifndef ITERATOR_H
    1717#define ITERATOR_H
    18 
    19 #include "iostream.h"
    2018
    2119// An iterator can be used to traverse a data structure.
     
    3432};
    3533
    36 context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
     34context iterator_for( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
    3735//      [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
    3836        iterator_type begin( collection_type );
     
    4341void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    4442
    45 // writes the range [begin, end) to the given stream
    46 forall( type elt_type | writeable( elt_type ),
    47                 type iterator_type | iterator( iterator_type, elt_type ),
    48                 dtype os_type | ostream( os_type ) )
    49 void write_all( iterator_type begin, iterator_type end, os_type *os );
    50 
    51 forall( type elt_type | writeable( elt_type ),
    52                 type iterator_type | iterator( iterator_type, elt_type ),
    53                 dtype os_type | ostream( os_type ) )
    54 void write_reverse( iterator_type begin, iterator_type end, os_type *os );
     43forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     44void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    5545
    5646#endif // ITERATOR_H
  • src/examples/vector_test.c

    r66a2a61 r5189888  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:42:55 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Nov 19 17:54:34 2015
     13// Update Count     : 9
    1414//
    1515
     
    2929        sout << "enter N elements and C-d on a separate line:\n";
    3030        for ( ;; ) {
    31         sin >> &num;
     31                sin >> &num;
    3232          if ( fail( sin ) || eof( sin ) ) break;
    33         append( &vec, num );
     33                append( &vec, num );
    3434        }
    3535        // write out the numbers
    3636
    3737        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 ) {
    41         sout << vec[ index ] << " ";
    42         }
     38        write( begin( vec ), end( vec ), sout );
    4339        sout << "\n";
    44 #if 1
     40
    4541        sout << "Array elements reversed:\n";
    4642        write_reverse( begin( vec ), end( vec ), sout );
    4743        sout << "\n";
    48 #endif
    4944}
    50 
    51 // ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o
    5245
    5346// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.