Changes in libcfa/prelude/builtins.c [eae8b37:108b2c7]
- File:
-
- 1 edited
-
libcfa/prelude/builtins.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/builtins.c
reae8b37 r108b2c7 160 160 static inline quasi_void ?=?(quasi_void &, quasi_void & _src) { return _src; } 161 161 162 forall( E ) trait Bounded {163 E lowerBound(void);164 E upperBound(void);165 };166 167 forall( E | Bounded( E ) ) trait Serial {168 int fromInstance( E e );169 E fromInt_unsafe( int i );170 E succ_unsafe( E e );171 E pred_unsafe( E e );172 };173 174 static inline forall( E | Serial( E ) ) {175 E fromInt( int i );176 E succ( E e );177 E pred( E e );178 int Countof( E );179 }180 181 forall( E ) trait CfaEnum {182 const char * label( E e );183 int posn( E e );184 };185 186 forall( E, V | CfaEnum( E ) ) trait TypedEnum {187 V value( E e );188 };189 190 static inline {191 forall( E | Serial( E ) ) {192 E fromInt( int i ) {193 E upper = upperBound();194 E lower = lowerBound();195 // It is okay to overflow as overflow will be theoretically caught by the other bound196 if ( i < fromInstance( lower ) || i > fromInstance( upper ) )197 abort( "call to fromInt has index %d outside of enumeration range %d-%d.",198 i, fromInstance( lower ), fromInstance( upper ) );199 return fromInt_unsafe( i );200 }201 202 E succ( E e ) {203 E upper = upperBound();204 if ( fromInstance( e ) >= fromInstance( upper ) )205 abort( "call to succ() exceeds enumeration upper bound of %d.", fromInstance( upper ) );206 return succ_unsafe(e);207 }208 209 E pred( E e ) {210 E lower = lowerBound();211 if ( fromInstance( e ) <= fromInstance(lower ) )212 abort( "call to pred() exceeds enumeration lower bound of %d.", fromInstance( lower ) );213 return pred_unsafe( e );214 }215 216 int Countof( E ) {217 E upper = upperBound();218 E lower = lowerBound();219 return fromInstance( upper ) + fromInstance( lower ) + 1;220 }221 }222 }223 224 static inline225 forall( E | CfaEnum(E) | Serial(E) ) {226 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators227 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }228 int ?<?( E l, E r ) { return posn( l ) < posn( r ); }229 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); }230 int ?>?( E l, E r ) { return posn( l ) > posn( r ); }231 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); }232 233 E ++?( E & l ) { // increment operators234 int pos = posn(l);235 l = fromInt_unsafe(pos+1);236 return l;237 }238 239 E --?( E & l ) {240 int pos = posn(l);241 l = fromInt_unsafe(pos-1);242 return l;243 }244 245 E ?+=? ( E & l, one_t ) {246 int pos = posn(l);247 l = fromInt_unsafe(pos+1);248 return l;249 }250 251 E ?-=? ( E & l, one_t ) {252 int pos = posn(l);253 l = fromInt_unsafe(pos-1);254 return l;255 }256 257 E ?+=? ( E & l, int i ) {258 int pos = posn(l);259 l = fromInt_unsafe(pos+i);260 return l;261 }262 263 E ?-=? ( E & l, int i ) {264 int pos = posn(l);265 l = fromInt_unsafe(pos-i);266 return l;267 }268 269 E ?++( E & l ) {270 int pos = posn(l);271 l = fromInt_unsafe(pos+1);272 return fromInt_unsafe(pos);273 }274 275 E ?--( E & l ) {276 int pos = posn(l);277 l = fromInt_unsafe(pos-1);278 return fromInt_unsafe(pos);279 }280 }281 282 162 // Local Variables: // 283 163 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.