Changeset ee06e41b for tests/sum.cfa


Ignore:
Timestamp:
Feb 18, 2019, 1:04:30 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
d08beee
Parents:
ada4575
Message:

add char, signed char, unsigned char to basic types in prologue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/sum.cfa

    rada4575 ree06e41b  
    1111// Created On       : Wed May 27 17:56:53 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sat Feb  9 15:38:48 2019
    14 // Update Count     : 293
     13// Last Modified On : Sun Feb 17 22:54:16 2019
     14// Update Count     : 328
    1515//
    1616
     
    3434} // sum
    3535
    36 // Not in prelude.
    37 unsigned char ?+?( unsigned char t1, unsigned char t2 ) { return (int)t1 + t2; } // cast forces integer addition, otherwise recursion
    38 unsigned char ?+=?( unsigned char & t1, unsigned char t2 ) { t1 = t1 + t2; return t1; }
    39 unsigned char ++?( unsigned char & t ) { t += 1; return t; }
    40 unsigned char ?++( unsigned char & t ) { unsigned char temp = t; t += 1; return temp; }
    41 
    42 // Not in prelude.
    43 void ?{}( unsigned char & c, zero_t ) { c = 0; }
    44 void ?{}( int & i, zero_t ) { i = 0; }
    45 void ?{}( float & f, zero_t ) { f = 0.0; }
    46 void ?{}( double & d, zero_t ) { d = 0.0; }
    47 
    4836int main( void ) {
    4937        const int low = 5, High = 15, size = High - low;
    5038
    51         unsigned char s = 0, a[size], v = (char)low;
    52         for ( int i = 0; i < size; i += 1, v += 1 ) {
     39        signed char s = 0, a[size], v = (char)low;
     40        for ( int i = 0; i < size; i += 1, v += 1hh ) {
    5341                s += v;
    5442                a[i] = v;
    5543        } // for
    5644        sout | "sum from" | low | "to" | High | "is"
    57                  | sum( size, (unsigned char *)a ) | ", check" | (int)s;
     45                 | sum( size, (signed char *)a ) | ", check" | (int)s;
     46
     47        unsigned char s = 0, a[size], v = low;
     48        for ( int i = 0; i < size; i += 1, v += 1hhu ) {
     49                s += (unsigned char)v;
     50                a[i] = (unsigned char)v;
     51        } // for
     52        sout | "sum from" | low | "to" | High | "is"
     53                 | sum( size, (unsigned char *)a ) | ", check" | (unsigned char)s;
     54
     55        short int s = 0, a[size], v = low;
     56        for ( int i = 0; i < size; i += 1, v += 1h ) {
     57                s += (short int)v;
     58                a[i] = (short int)v;
     59        } // for
     60        sout | "sum from" | low | "to" | High | "is"
     61                 | sum( size, (short int *)a ) | ", check" | (short int)s;
    5862
    5963        int s = 0, a[size], v = low;
Note: See TracChangeset for help on using the changeset viewer.