ADT
        ast-experimental
      
      
        
          | 
            Last change
 on this file since 878cfcc was             8d76f2b, checked in by Michael Brooks <mlbrooks@…>, 4 years ago           | 
        
        
          | 
             
Adding runtime bound checking for array subscripts and showing the optimizer removing them. 
 
Adding draft thesis content on dependent types and bound checks. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            971 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include <array.hfa>
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #ifndef DIMSVERSION
 | 
|---|
| 4 | #define DIMSVERSION 1
 | 
|---|
| 5 | #endif
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #if DIMSVERSION == 1
 | 
|---|
| 8 | 
 | 
|---|
| 9 | forall( [N] )
 | 
|---|
| 10 | size_t foo( array( size_t, N ) & a ) {
 | 
|---|
| 11 |     size_t retval = 0;
 | 
|---|
| 12 |     for( i; N ) {
 | 
|---|
| 13 |         retval += a[i];
 | 
|---|
| 14 |     }
 | 
|---|
| 15 |     return retval;
 | 
|---|
| 16 | }
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #elif DIMSVERSION == 2 
 | 
|---|
| 19 | 
 | 
|---|
| 20 | forall( [N], [M] )
 | 
|---|
| 21 | size_t foo( array( size_t, N, M ) & a ) {
 | 
|---|
| 22 |     size_t retval = 0;
 | 
|---|
| 23 |     for( i; N ) for( j; M ) {
 | 
|---|
| 24 |         retval += a[i][j];
 | 
|---|
| 25 |     }
 | 
|---|
| 26 |     return retval;
 | 
|---|
| 27 | }
 | 
|---|
| 28 | 
 | 
|---|
| 29 | #elif DIMSVERSION == 3
 | 
|---|
| 30 | 
 | 
|---|
| 31 | forall( [N] )
 | 
|---|
| 32 | size_t foo( array( size_t, N ) & a, array( size_t, N ) & b ) {
 | 
|---|
| 33 |     size_t retval = 0;
 | 
|---|
| 34 |     for( i; N ) {
 | 
|---|
| 35 |         retval += a[i] - b[i];
 | 
|---|
| 36 |     }
 | 
|---|
| 37 |     return retval;
 | 
|---|
| 38 | }
 | 
|---|
| 39 | 
 | 
|---|
| 40 | #elif DIMSVERSION == 4
 | 
|---|
| 41 | 
 | 
|---|
| 42 | forall( [M], [N], [P] )
 | 
|---|
| 43 | void foo   ( array(size_t, M, P) & src1,
 | 
|---|
| 44 |              array(size_t, P, N) & src2, 
 | 
|---|
| 45 |              array(size_t, M, N) & tgt ) {
 | 
|---|
| 46 |     for (i; M) for (j; N) {
 | 
|---|
| 47 |         tgt[i][j] = 0;
 | 
|---|
| 48 |         for (k; P)
 | 
|---|
| 49 |             tgt[i][j] += src1[i][k] * src2[k][j];
 | 
|---|
| 50 |     }
 | 
|---|
| 51 | }
 | 
|---|
| 52 | 
 | 
|---|
| 53 | #else
 | 
|---|
| 54 | #error Bad Version 
 | 
|---|
| 55 | #endif
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.