Changeset 9f7285e


Ignore:
Timestamp:
Dec 8, 2024, 9:02:49 AM (10 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
bc999b7
Parents:
6503ef4
Message:

formatting, temporarily remove quasi_void

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    r6503ef4 r9f7285e  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov  8 17:07:15 2024
    13 // Update Count     : 144
     12// Last Modified On : Sun Dec  8 09:01:23 2024
     13// Update Count     : 149
    1414//
    1515
    1616#define __cforall_builtins__
    1717
    18 // type that wraps a pointer and a destructor-like function - used in generating implicit destructor calls for struct members in user-defined functions
    19 // Note: needs to occur early, because it is used to generate destructor calls during code generation
    20 forall(T &)
     18// Type that wraps a pointer and a destructor-like function - used in generating implicit destructor calls for struct
     19// members in user-defined functions. Note: needs to occur early, because it is used to generate destructor calls during
     20// code generation
     21forall( T &)
    2122struct __Destructor {
    2223        T * object;
    23         void (*dtor)(T *);
    24 };
    25 
    26 // defined destructor in the case that non-generated code wants to use __Destructor
    27 forall(T &)
    28 static inline void ^?{}(__Destructor(T) & x) {
    29         if (x.object && x.dtor) {
    30                 x.dtor(x.object);
    31         }
    32 }
    33 
    34 // easy interface into __Destructor's destructor for easy codegen purposes
     24        void (*dtor)( T * );
     25};
     26
     27// Defined destructor in the case that non-generated code wants to use __Destructor.
     28forall( T &)
     29static inline void ^?{}( __Destructor(T) & x ) {
     30        if ( x.object && x.dtor ) {
     31                x.dtor( x.object );
     32        }
     33}
     34
     35// Easy interface into __Destructor's destructor for easy codegen purposes.
    3536extern "C" {
    36         forall(T &)
    37         static inline void __destroy_Destructor(__Destructor(T) * dtor) {
     37        forall( T &)
     38        static inline void __destroy_Destructor( __Destructor(T) * dtor ) {
    3839                ^(*dtor){};
    3940        }
     
    4748#include "../src/exception.h"
    4849
    49 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
    50 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    51 
    52 forall(T &)
    53 static inline T & identity(T & i) {
     50void exit( int status, const char fmt[], ... ) __attribute__ (( format( printf, 2, 3 ), __nothrow__, __leaf__, __noreturn__ ));
     51void abort( const char fmt[], ... ) __attribute__ (( format( printf, 1, 2 ), __nothrow__, __leaf__, __noreturn__ ));
     52
     53forall( T &)
     54static inline T & identity( T & i ) {
    5455        return i;
    5556}
     
    6061};
    6162
    62 static inline void  ?{}(generator$ & this) { ((int&)this) = 0; }
    63 static inline void ^?{}(generator$ &) {}
     63static inline void  ?{}( generator$ & this ) { ((int&)this) = 0; }
     64static inline void ^?{}( generator$ &) {}
    6465
    6566forall( T & )
    6667trait is_generator {
    67       void main(T & this);
    68       generator$ * get_generator(T & this);
    69 };
    70 
    71 forall(T & | is_generator(T))
    72 static inline T & resume(T & gen) {
    73         main(gen);
     68      void main( T & this );
     69      generator$ * get_generator( T & this );
     70};
     71
     72forall( T & | is_generator( T ) )
     73static inline T & resume( T & gen ) {
     74        main( gen );
    7475        return gen;
    7576}
     
    7778// implicit increment, decrement if += defined, and implicit not if != defined
    7879
    79 // C11 reference manual Section 6.5.16 (page101): "An assignment expression has the value of the left operand after the
     80// C11 reference manual Section 6.5.16 (page 101): "An assignment expression has the value of the left operand after the
    8081// assignment, but is not an lvalue." Hence, return a value not a reference.
    8182static inline {
     
    110111// forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); T ?+=?( T &, T ); T ?-=?( T &, T ); int ?<?( T, T ); } )
    111112// static inline T __for_control_index_constraints__( T t ) { return t; }
     113
    112114
    113115// exponentiation operator implementation
     
    122124} // extern "C"
    123125
    124 static inline {
     126static inline {                                                                                 // wrappers
    125127        float ?\?( float x, float y ) { return powf( x, y ); }
    126128        double ?\?( double x, double y ) { return pow( x, y ); }
    127129        long double ?\?( long double x, long double y ) { return powl( x, y ); }
    128         float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }
     130        float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf( x, y ); }
    129131        double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }
    130132        long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
     
    154156} // distribution
    155157
    156 struct quasi_void {};
    157 static inline void ?{}(quasi_void &) {}
    158 static inline void ?{}(quasi_void &, quasi_void) {}
    159 static inline void ^?{}(quasi_void &) {}
    160 static inline quasi_void ?=?(quasi_void &, quasi_void & _src) { return _src; }
     158// struct quasi_void {};
     159// static inline void ?{}( quasi_void &) {}
     160// static inline void ?{}( quasi_void &, quasi_void ) {}
     161// static inline void ^?{}( quasi_void &) {}
     162// static inline quasi_void ?=?( quasi_void &, quasi_void & _src ) { return _src; }
     163
     164
     165// enumeration implementation
    161166
    162167forall( E ) trait Bounded {
    163         E lowerBound(void);
    164         E upperBound(void);
     168        E lowerBound( void );
     169        E upperBound( void );
    165170};
    166171
     
    204209                if ( fromInstance( e ) >= fromInstance( upper ) )
    205210                        abort( "call to succ() exceeds enumeration upper bound of %d.", fromInstance( upper ) );
    206                 return succ_unsafe(e);
     211                return succ_unsafe( e );
    207212        }
    208213
    209214        E pred( E e ) {
    210215                E lower = lowerBound();
    211                 if ( fromInstance( e ) <= fromInstance(lower ) )
     216                if ( fromInstance( e ) <= fromInstance( lower ) )
    212217                        abort( "call to pred() exceeds enumeration lower bound of %d.", fromInstance( lower ) );
    213218                return pred_unsafe( e );
     
    223228
    224229static inline
    225 forall( E | CfaEnum(E) | Serial(E) ) {
     230forall( E | CfaEnum( E ) | Serial( E ) ) {
    226231        int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators
    227232        int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
     
    232237
    233238        E ++?( E & l ) {                                                                        // increment operators
    234                 int pos = posn(l);
    235                 l = fromInt_unsafe(pos+1);
     239                int pos = posn( l );
     240                l = fromInt_unsafe( pos + 1 );
    236241                return l;
    237242        }
    238243
    239244        E --?( E & l ) {
    240                 int pos = posn(l);
    241                 l = fromInt_unsafe(pos-1);
     245                int pos = posn( l );
     246                l = fromInt_unsafe( pos - 1 );
    242247                return l;
    243248        }
    244249
    245250        E ?+=? ( E & l, one_t ) {
    246                 int pos = posn(l);
    247                 l = fromInt_unsafe(pos+1);
     251                int pos = posn( l );
     252                l = fromInt_unsafe( pos + 1 );
    248253                return l;
    249254        }
    250255
    251256        E ?-=? ( E & l, one_t ) {
    252                 int pos = posn(l);
    253                 l = fromInt_unsafe(pos-1);
     257                int pos = posn( l );
     258                l = fromInt_unsafe( pos - 1 );
    254259                return l;
    255260        }
    256261
    257262        E ?+=? ( E & l, int i ) {
    258                 int pos = posn(l);
    259                 l = fromInt_unsafe(pos+i);
     263                int pos = posn( l );
     264                l = fromInt_unsafe( pos + i );
    260265                return l;
    261266        }
    262267
    263268        E ?-=? ( E & l, int i ) {
    264                 int pos = posn(l);
    265                 l = fromInt_unsafe(pos-i);
     269                int pos = posn( l );
     270                l = fromInt_unsafe( pos - i );
    266271                return l;
    267272        }
    268273
    269274        E ?++( E & l ) {
    270                 int pos = posn(l);
    271                 l = fromInt_unsafe(pos+1);
    272                 return fromInt_unsafe(pos);
     275                int pos = posn( l );
     276                l = fromInt_unsafe( pos + 1 );
     277                return fromInt_unsafe( pos );
    273278        }
    274279
    275280        E ?--( E & l ) {
    276                 int pos = posn(l);
    277                 l = fromInt_unsafe(pos-1);
    278                 return fromInt_unsafe(pos);
     281                int pos = posn( l );
     282                l = fromInt_unsafe( pos - 1 );
     283                return fromInt_unsafe( pos );
    279284        }
    280285}
Note: See TracChangeset for help on using the changeset viewer.