Changeset 64eeb06 for libcfa/src
- Timestamp:
- Jul 2, 2024, 2:27:57 PM (6 months ago)
- Branches:
- master
- Children:
- 72abc90a
- Parents:
- 011c29e
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r011c29e r64eeb06 4 4 #pragma GCC visibility push(default) 5 5 6 forall( ostype & | basic_ostream(ostype), E, V | CfaEnum(E, V) ) { 7 ostype & ?|?( ostype& os, E e ) { 6 forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) ) 7 istype & ?|?( istype & is, E & e ) { 8 if ( eof( is ) ) throwResume ExceptionInst( missing_data ); 9 char val[256]; 10 int args = fmt( is, "%255s", val ); 11 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 12 for ( s; E ) { 13 if ( val == label( s ) ) { e = s; break; } 14 } else { 15 fprintf( stderr, "invalid enumeration constant\n" ); 16 abort(); // cannot use abort stream 17 } // for 18 return is; 19 } 20 21 forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) { 22 ostype & ?|?( ostype & os, E e ) { 8 23 return os | label( e ); 9 24 } … … 11 26 } 12 27 13 forall( ostype & | basic_ostream(ostype), E | CfaEnum(E, quasi_void) ) 14 ostype & ?|?( ostype & os, E e ) { 15 return os | label( e ); 28 forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) { 29 ostype & ?|?( ostype & os, E e ) { 30 return os | label( e ); 31 } 32 OSTYPE_VOID_IMPL( E ) 16 33 } 17 34 18 forall( E, V | CfaEnum( E, V) ) { // relational operators19 int ?==?( E l, E r) { return posn(l) == posn(r); }20 int ?!=?( E l, E r) { return posn(l) != posn(r); }21 int ?<?( E l, E r) { return posn(l) < posn(r); }22 int ?<=?( E l, E r) { return posn(l) <= posn(r); }23 int ?>?( E l, E r) { return posn(l) > posn(r); }24 int ?>=?( E l, E r) { return posn(l) >= posn(r); }35 forall( E, V | CfaEnum( E, V ) ) { // relational operators 36 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } 37 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); } 38 int ?<?( E l, E r ) { return posn( l ) < posn( r ); } 39 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); } 40 int ?>?( E l, E r ) { return posn( l ) > posn( r ); } 41 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); } 25 42 26 E ++?( E& l) {27 l = succ( l);43 E ++?( E & l ) { 44 l = succ( l ); 28 45 return l; 29 46 } 30 47 31 E ?++( E& l) {48 E ?++( E & l ) { 32 49 E ret = l; 33 l = succ( l);50 l = succ( l ); 34 51 return ret; 35 52 } 36 53 37 E --?( E& l) {38 l = pred( l);54 E --?( E & l ) { 55 l = pred( l ); 39 56 return l; 40 57 } 41 58 42 E ?--( E& l) {59 E ?--( E & l ) { 43 60 E ret = l; 44 l = pred( l);61 l = pred( l ); 45 62 return ret; 46 63 } -
libcfa/src/enum.hfa
r011c29e r64eeb06 8 8 }; 9 9 10 forall( E | Bounded( E) ) trait Serial {10 forall( E | Bounded( E ) ) trait Serial { 11 11 unsigned fromInstance( E e ); 12 12 E fromInt( unsigned i ); … … 16 16 17 17 // Design one 18 forall( E, V | Serial( E) ) trait CfaEnum {18 forall( E, V | Serial( E ) ) trait CfaEnum { 19 19 char * label( E e ); 20 20 unsigned int posn( E e ); … … 24 24 // I/O 25 25 26 forall( ostype & | basic_ostream(ostype), E, V | CfaEnum(E, V) ) { 26 forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) ) 27 istype & ?|?( istype &, E ); 28 29 forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) { 27 30 ostype & ?|?( ostype &, E ); 28 31 OSTYPE_VOID( E ); 29 32 } 30 33 31 forall( ostype & | basic_ostream(ostype), E | CfaEnum(E, quasi_void) ) 32 ostype & ?|?( ostype &, E ); 34 forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) { 35 ostype & ?|?( ostype &, E ); 36 OSTYPE_VOID( E ); 37 } 33 38 34 39 // Design two <- should go for this if we have change the cost model 35 // forall( E | Serial(E)) trait CfaEnum {36 // char * label( E e);37 // unsigned int posn( E e);40 // forall( E | Serial( E ) ) trait CfaEnum { 41 // char * label( E e ); 42 // unsigned int posn( E e ); 38 43 // }; 39 44 40 // forall( E, V| CfaEnum(E)) trait TypedEnum {41 // V value( E e);45 // forall( E, V| CfaEnum( E)) trait TypedEnum { 46 // V value( E e); 42 47 // }; 43 48 44 forall( E, V | CfaEnum( E, V) ) { // relational operators45 int ?==?( E, E);46 int ?!=?( E, E);47 int ?<?( E, E);48 int ?<=?( E, E);49 int ?>?( E, E);50 int ?>=?( E, E);49 forall( E, V | CfaEnum( E, V ) ) { // relational operators 50 int ?==?( E, E ); 51 int ?!=?( E, E ); 52 int ?<?( E, E ); 53 int ?<=?( E, E ); 54 int ?>?( E, E ); 55 int ?>=?( E, E ); 51 56 52 int ++?( E&);53 int ?++( E&);54 int --?( E&);55 int ?--( E&);57 int ++?( E &); 58 int ?++( E &); 59 int --?( E &); 60 int ?--( E &); 56 61 }
Note: See TracChangeset
for help on using the changeset viewer.