Changeset 42dcae7


Ignore:
Timestamp:
Nov 25, 2014, 9:16:10 AM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
3848e0e
Parents:
d11f789
Message:

re-inserted remove and reorder hoisted aggregate, fixed example programs

Location:
translator
Files:
4 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • translator/SymTab/Validate.cc

    rd11f789 r42dcae7  
    221221        if ( inStruct ) {
    222222            // Add elements in stack order corresponding to nesting structure.
    223             declsToAdd.push_back( aggregateDecl );
     223            declsToAdd.push_front( aggregateDecl );
    224224            Visitor::visit( aggregateDecl );
    225225        } else {
  • translator/examples/forward.c

    rd11f789 r42dcae7  
    1 // "./cfa-cpp -nc forward.c"
    2 
    31forall(type T) lvalue T *?( T* );
    42int ?=?( int*, int );
     
    108    *x;
    119}
     10
     11// Local Variables: //
     12// compile-command: "../../bin/cfa forward.c" //
     13// End: //
  • translator/examples/fstream.c

    rd11f789 r42dcae7  
    1 // "cfa -E fstream.c > fstream_out.c"
    2 // "cfa -c -o fstream.o fstream.c"
    3 
    41#include "fstream.h"
    52
     
    1411};
    1512
    16 ofstream * write( ofstream *os, const char *data, streamsize_type size ) {
    17     if( !os->fail ) {
     13ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
     14    if ( ! os->fail ) {
    1815        fwrite( data, size, 1, os->file );
    1916        os->fail = ferror( os->file );
     
    2623}
    2724
    28 static ofstream * make_ofstream() {
     25static ofstream *make_ofstream() {
    2926    ofstream *new_stream = malloc( sizeof( ofstream ) );
    3027    new_stream->fail = 0;
     
    3229}
    3330
    34 ofstream * ofstream_stdout() {
     31ofstream *ofstream_stdout() {
    3532    ofstream *stdout_stream = make_ofstream();
    3633    stdout_stream->file = stdout;
     
    3835}
    3936
    40 ofstream * ofstream_stderr() {
     37ofstream *ofstream_stderr() {
    4138    ofstream *stderr_stream = make_ofstream();
    4239    stderr_stream->file = stderr;
     
    4441}
    4542
    46 ofstream * ofstream_fromfile( const char *name ) {
     43ofstream *ofstream_fromfile( const char *name ) {
    4744    ofstream *file_stream = make_ofstream();
    4845    file_stream->file = fopen( name, "w" );
     
    5249
    5350void ofstream_close( ofstream *os ) {
    54     if( os->file != stdout && os->file != stderr ) {
     51    if ( os->file != stdout && os->file != stderr ) {
    5552        os->fail = fclose( os->file );
    5653    }
     
    6461};
    6562
    66 ifstream * read( ifstream *is, char *data, streamsize_type size ) {
    67     if( !is->fail && !is->eof ) {
     63ifstream *read( ifstream *is, char *data, streamsize_type size ) {
     64    if ( ! is->fail && ! is->eof ) {
    6865        fread( data, size, 1, is->file );
    6966        is->fail = ferror( is->file );
     
    7471 
    7572ifstream *unread( ifstream *is, char c ) {
    76     if( !is->fail ) {
    77         if( EOF == ungetc( c, is->file ) ) {
     73    if ( ! is->fail ) {
     74        if ( ! EOF == ungetc( c, is->file ) ) {
    7875            is->fail = 1;
    7976        }
     
    9087}
    9188
    92 static ifstream * make_ifstream() {
     89static ifstream *make_ifstream() {
    9390    ifstream *new_stream = malloc( sizeof( ifstream ) );
    9491    new_stream->fail = 0;
     
    9794}
    9895
    99 ifstream * ifstream_stdin() {
     96ifstream *ifstream_stdin() {
    10097    ifstream *stdin_stream = make_ifstream();
    10198    stdin_stream->file = stdin;
     
    103100}
    104101
    105 ifstream * ifstream_fromfile( const char *name ) {
     102ifstream *ifstream_fromfile( const char *name ) {
    106103    ifstream *file_stream = make_ifstream();
    107104    file_stream->file = fopen( name, "r" );
  • translator/examples/fstream.h

    rd11f789 r42dcae7  
    1 #ifndef FSTREAM_H
    2 #define FSTREAM_H
     1#ifndef __FSTREAM_H__
     2#define __FSTREAM_H__
    33
    44#include "iostream.h"
     
    2626ifstream *ifstream_fromfile( const char *name );
    2727
    28 #endif // FSTREAM_H
     28#endif // __FSTREAM_H__
  • translator/examples/fstream_test.c

    rd11f789 r42dcae7  
    1 // "cfa -c -o fstream_test.o fstream_test.c"
    2 // "cfa -CFA fstream_test.c > fstream_test_out.c"
    3 // "gcc31 -c fstream_test_out.c"
    4 
    51#include "fstream.h"
    62
  • translator/examples/fwrite.c

    rd11f789 r42dcae7  
    1 // "cfa -CFA fwrite.c > fwrite.i"
    2 // "cfa fwrite.i"
    3 
    41extern "C" {
    5 #include <stdio.h>
     2    #include <stdio.h>
    63}
    74
  • translator/examples/identity.c

    rd11f789 r42dcae7  
    1 extern "C" {
    2     int printf( const char *fmt, ... );
    3 }
     1#include "fstream.h"
    42
    53forall( type T )
     
    97
    108int main() {
    11     printf( "result of identity of 5 is %d\n", identity( 5 ) );
    12     return 0;
     9    ofstream *sout = ofstream_stdout();
     10    char c = 'a';
     11    sout << c << ' ' << identity( c ) << '\n';
     12    int i = 5;
     13    sout << i << ' ' << identity( i ) << '\n';
     14    double d = 3.2;
     15    sout << d << ' ' << identity( d ) << '\n';
    1316}
     17
     18// Local Variables: //
     19// compile-command: "../../bin/cfa identity.c fstream.o iostream.o" //
     20// End: //
  • translator/examples/min.c

    rd11f789 r42dcae7  
    1 // "./cfa min.c"
    2 // "./cfa -CFA min.c > min_out.c"
    3 // "gcc32 -g min_out.c LibCfa/libcfa.a"
    4 
    51extern "C" {
    62    int printf( const char *, ... );
    73}
    84
    9 forall( type T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } )
     5forall( type T | { int ?<?( T, T ); } )
    106T min( T t1, T t2 ) {
    117    return t1 < t2 ? t1 : t2;
     
    139
    1410int main() {
     11//    char c;
     12//    c = min( 'a', 'z' );
     13//    printf( "minimum %d\n", c );
     14    int i;
     15    i = min( 4, 3 );
     16    printf( "minimum %d\n", min( 4, 3 ) );
    1517    float f;
    16     f = min( 4.0, 3.0 );
    17     printf( "result is %f\n", f );
     18    f = min( 4.0, 3.1 );
     19    printf( "minimum %g\n", f );
     20    double d;
     21    d = min( 4.0, 3.2 );
     22    printf( "minimum %g\n", d );
    1823}
     24
     25// Local Variables: //
     26// compile-command: "../../bin/cfa min.c" //
     27// End: //
  • translator/examples/quad.c

    rd11f789 r42dcae7  
    11extern "C" {
    2 #include <stdio.h>
     2    #include <stdio.h>
    33}
    44
     
    1717    printf( "result of quad of %d is %d\n", N, quad( N ) );
    1818}
     19
     20// Local Variables: //
     21// compile-command: "../../bin/cfa quad.c" //
     22// End: //
  • translator/examples/sum.c

    rd11f789 r42dcae7  
    1 // "./cfa -g sum.c"
    2 // "./cfa -CFA sum.c > sum_out.c"
    3 // "gcc32 -g sum_out.c LibCfa/libcfa.a"
    4 
    51extern "C" {
    62    int printf( const char *, ... );
     
    95context sumable( type T ) {
    106    const T 0;
    11     T ?+?(T, T);
    12     T ?++(T*);
    13     [T] ?+=?(T*,T);
     7    T ?+?( T, T );
     8    T ?++( T * );
     9    [T] ?+=?( T *, T );
    1410};
    1511
    1612forall( type T | sumable( T ) )
    1713T sum( int n, T a[] ) {
    18     T total = 0;
    19     int i;
    20     for ( i = 0; i < n; i += 1 )
    21         total = total + a[i];
     14    T total = 0;                        // instantiate T, select 0
     15    for ( int i = 0; i < n; i += 1 )
     16        total = total + a[i];           // select +
    2217    return total;
    2318}
    2419
    2520int main() {
    26     int a[10];
    27     for ( int i = 0; i < 10; ++i ) {
    28         a[i] = i;
     21    const int size = 10, low = 0, High = 10;
     22    int si, ai[10]; // size
     23    int i;
     24    for ( i = low; i < High; i += 1 ) {
     25        si += i;
     26        ai[i] = i;
    2927    }
    30     printf( "the sum is %d\n", sum( 10, a ) );
     28    printf( "sum from %d to %d is %d, check %d\n",
     29            low, High, sum( size, ai ), si );
     30    double sd, ad[10]; // size
     31    for ( i = low; i < High; i += 1 ) {
     32        double d = i / (double)size;
     33        sd += d;
     34        ad[i] = d;
     35    }
     36    printf( "sum from %g to %g is %g, check %g\n",
     37            low / (double)size, High / (double)size, sum( size, ad ), sd );
    3138}
     39
     40// Local Variables: //
     41// compile-command: "../../bin/cfa sum.c" //
     42// End: //
Note: See TracChangeset for help on using the changeset viewer.