Changeset 52f85e0 for src


Ignore:
Timestamp:
Feb 10, 2016, 3:57:00 PM (8 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:
6ba0659, cce7872
Parents:
bd85400
Message:

syslib updates and examples, formatting, make double 0 work

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cc

    rbd85400 r52f85e0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 06:57:43 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Oct 05 14:48:45 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  2 15:34:36 2016
     13// Update Count     : 7
    1414//
    1515
     
    6969                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    7070                if ( destAsPointer && basicType->isInteger() ) {
    71                         cost = Cost( 1, 0, 0 );
     71                        //cost = Cost( 1, 0, 0 );
     72                        cost = Cost::infinity;
    7273                } else {
    7374                        ConversionCost::visit( basicType );
     
    8788                                        cost = Cost( 0, 0, 1 );
    8889                                } else if ( castResult < 0 ) {
    89                                         cost = Cost( 1, 0, 0 );
     90                                        cost = Cost::infinity;
     91                                        //cost = Cost( 1, 0, 0 );
    9092                                } // if
    9193                        } // if
    9294                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    9395                        if ( destAsBasic->isInteger() ) {
    94                                 cost = Cost( 1, 0, 0 );
     96                                //cost = Cost( 1, 0, 0 );
     97                                cost = Cost::infinity;
    9598                        } // if
    9699                }
  • src/ResolvExpr/Resolver.cc

    rbd85400 r52f85e0  
    1010// Created On       : Sun May 17 12:17:01 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 24 17:33:54 2015
    13 // Update Count     : 178
     12// Last Modified On : Tue Feb  9 21:57:52 2016
     13// Update Count     : 179
    1414//
    1515
     
    322322                                                                                                BasicType::SignedInt);
    323323                                } else {
    324                                         DeclarationWithType * decl = lookupId(n);
     324                                        DeclarationWithType * decl = lookupId( n );
    325325                                        initContext = decl->get_type();
    326326                                }
     
    344344                                        if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) {
    345345                                                if ( isCharType( pt->get_base() ) ) {
    346                                                         // strip cast if we're initializing a char[] with a char *, e.g.
    347                                                         // char x[] = "hello";
     346                                                        // strip cast if we're initializing a char[] with a char *, e.g.  char x[] = "hello";
    348347                                                        CastExpr *ce = dynamic_cast< CastExpr * >( newExpr );
    349348                                                        singleInit->set_value( ce->get_arg() );
  • src/examples/sum.c

    rbd85400 r52f85e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  5 16:47:44 2016
    13 // Update Count     : 139
     12// Last Modified On : Sat Feb  6 11:57:42 2016
     13// Update Count     : 182
    1414//
    1515
     
    3333
    3434// Required to satisfy sumable as char does not have addition.
    35 // const char 0;
    36 // char ?+?( char op1, char op2 ) { return (int)op1 + op2; } // cast forces integer addition or recursion
    37 // char ++?( char *op ) { *op += 1; return *op; }
    38 // char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
     35const char 0;
     36char ?+?( char t1, char t2 ) { return (int)t1 + t2; }   // cast forces integer addition, otherwise recursion
     37char ?+=?( char *t1, char t2 ) { *t1 = *t1 + t2; return *t1; }
     38char ++?( char *t ) { *t += 1; return *t; }
     39char ?++( char *t ) { char temp = *t; *t += 1; return temp; }
    3940
    4041int main( void ) {
    4142        const int low = 5, High = 15, size = High - low;
    4243        ofstream *sout = ofstream_stdout();
    43 #if 0
    4444
    45         char s = 0, a[size];
    46         char v = low;
     45        char s = 0, a[size], v = low;
    4746        for ( int i = 0; i < size; i += 1, v += 1 ) {
    4847                s += v;
    4948                a[i] = v;
    50         }
     49        } // for
    5150        sout | "sum from " | low | " to " | High | " is "
    5251                 | (int)sum( size, a ) | ", check " | (int)s | endl;
    5352
    54         int s = 0, a[size];
    55         int v = low;
     53        int s = 0, a[size], v = low;
    5654        for ( int i = 0; i < size; i += 1, v += 1 ) {
    5755                s += (int)v;
    5856                a[i] = (int)v;
    59         }
     57        } // for
    6058        sout | "sum from " | low | " to " | High | " is "
    6159                 | sum( size, (int *)a ) | ", check " | (int)s | endl;
    6260
    63         float s = 0.0, a[size];
    64         float v = low / 10.0;
     61        float s = 0.0, a[size], v = low / 10.0;
    6562        for ( int i = 0; i < size; i += 1, v += 0.1f ) {
    6663                s += (float)v;
    6764                a[i] = (float)v;
    68         }
     65        } // for
    6966        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    7067                 | sum( size, (float *)a ) | ", check " | (float)s | endl;
    71 #endif
    72         double s = 0, a[size];
    73         double v = low / 10.0;
    7468
     69        double s = 0, a[size], v = low / 10.0;
    7570        for ( int i = 0; i < size; i += 1, v += 0.1 ) {
    7671                s += (double)v;
    7772                a[i] = (double)v;
    78         }
     73        } // for
    7974        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    8075                 | sum( size, (double *)a ) | ", check " | (double)s | endl;
    8176
    82         // struct S { int i, j; } sarr[size];
    83         // struct S 0 = { 0, 0 };
    84         // struct S 1 = { 1, 1 };
    85         // S ?+?( S t1, S t2 ) { S s = { t1.i + t1.j, t2.i + t2.j }; return s; }
    86         // S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
    87         // S ++?( S *t ) { *t += 1; return *t; }
    88         // S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
    89         // sum( size, sarr );
     77        struct S { int i, j; } 0 = { 0, 0 }, 1 = { 1, 1 };
     78        S ?+?( S t1, S t2 ) { S s = { t1.i + t2.i, t1.j + t2.j }; return s; }
     79        S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
     80        S ++?( S *t ) { *t += 1; return *t; }
     81        S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
     82        ofstream * ?|?( ofstream * os, S v ) { return os | v.i | ' ' | v.j; }
     83
     84        S s = 0, a[size], v = { low, low };
     85        for ( int i = 0; i < size; i += 1, v += (S)1 ) {
     86                s += (S)v;
     87                a[i] = (S)v;
     88        } // for
     89        sout | "sum from " | low | " to " | High | " is "
     90                 | sum( size, (S *)a ) | ", check " | (S)s | endl;
    9091} // main
    9192
  • src/libcfa/iostream.c

    rbd85400 r52f85e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  1 14:20:30 2016
    13 // Update Count     : 60
     12// Last Modified On : Wed Feb 10 15:48:46 2016
     13// Update Count     : 66
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <string.h>                                                                             // strlen
     21#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2122#include <complex.h>                                                                    // creal, cimag
    2223}
     
    7273ostype * ?|?( ostype *os, double d ) {
    7374        char buffer[32];
    74         return write( os, buffer, sprintf( buffer, "%g", d ) );
     75        return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) );
    7576} // ?|?
    7677
     
    7879ostype * ?|?( ostype *os, long double d ) {
    7980        char buffer[32];
    80         return write( os, buffer, sprintf( buffer, "%Lg", d ) );
     81        return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) );
    8182} // ?|?
    8283
  • src/libcfa/stdlib.c

    rbd85400 r52f85e0  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  5 15:41:24 2016
    13 // Update Count     : 128
     12// Last Modified On : Wed Feb 10 15:45:56 2016
     13// Update Count     : 140
    1414//
    1515
     
    2323#include <string.h>                                                                             // memset
    2424#include <malloc.h>                                                                             // malloc_usable_size
    25 #include <stdio.h>
    2625#include <math.h>                                                                               // fabsf, fabs, fabsl
    2726#include <complex.h>                                                                    // _Complex_I, cabsf, cabs, cabsl
     
    106105long int ato( const char * ptr ) {
    107106        long int li;
    108         if ( sscanf( ptr, "%ld", &li ) == EOF ) {};                     // check return code
     107        if ( sscanf( ptr, "%ld", &li ) == EOF ) {}                      // check return code
    109108        return li;
    110109}
    111110unsigned long int ato( const char * ptr ) {
    112111        unsigned long int uli;
    113         if ( sscanf( ptr, "%lu", &uli ) == EOF ) {};            // check return code
     112        if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}                     // check return code
    114113        return uli;
    115114}
    116115long long int ato( const char * ptr ) {
    117116        long long int lli;
    118         if ( sscanf( ptr, "%lld", &lli ) == EOF ) {};           // check return code
     117        if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}            // check return code
    119118        return lli;
    120119}
    121120unsigned long long int ato( const char * ptr ) {
    122121        unsigned long long int ulli;
    123         if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {};          // check return code
     122        if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}           // check return code
    124123        return ulli;
    125124}
    126125float ato( const char * ptr ) {
    127126        float f;
    128         if ( sscanf( ptr, "%f", &f ) == EOF ) {};                       // check return code
     127        if ( sscanf( ptr, "%f", &f ) == EOF ) {}                        // check return code
    129128        return f;
    130129}
    131130double ato( const char * ptr ) {
    132131        double d;
    133         if ( sscanf( ptr, "%lf", &d ) == EOF ) {};                      // check return code
     132        if ( sscanf( ptr, "%lf", &d ) == EOF ) {}                       // check return code
    134133        return d;
    135134}
    136135long double ato( const char * ptr ) {
    137136        long double ld;
    138         printf( "FRED " );
    139         if ( sscanf( ptr, "%.32Lf", &ld ) == EOF ) {};          // check return code
     137        if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}                      // check return code
    140138        return ld;
    141139}
    142140float _Complex ato( const char * ptr ) {
    143141        float re, im;
    144         if ( sscanf( ptr, "%g%g", &re, &im ) == EOF ) {};       // check return code
     142        if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}       // check return code
    145143        return re + im * _Complex_I;
    146144}
    147145double _Complex ato( const char * ptr ) {
    148146        double re, im;
    149         if ( sscanf( ptr, "%.16lg%.16lg", &re, &im ) == EOF ) {}; // check return code
     147        if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code
    150148        return re + im * _Complex_I;
    151149}
    152150long double _Complex ato( const char * ptr ) {
    153151        long double re, im;
    154         if ( sscanf( ptr, "%.32Lg%.32Lg", &re, &im ) == EOF ) {}; // check return code
     152        if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {}     // check return code
    155153        return re + im * _Complex_I;
    156154}       
Note: See TracChangeset for help on using the changeset viewer.