Changes in / [fc276f3:4175659]
- Files:
-
- 2 added
- 27 edited
-
libcfa/prelude/builtins.c (modified) (1 diff)
-
libcfa/src/Makefile.am (modified) (1 diff)
-
libcfa/src/enum.cfa (added)
-
libcfa/src/enum.hfa (added)
-
libcfa/src/iostream.cfa (modified) (1 diff)
-
libcfa/src/iostream.hfa (modified) (1 diff)
-
libcfa/src/rational.cfa (modified) (3 diffs)
-
libcfa/src/rational.hfa (modified) (1 diff)
-
src/AST/Decl.hpp (modified) (1 diff)
-
src/AST/Expr.cpp (modified) (1 diff)
-
src/Parser/TypeData.cpp (modified) (1 diff)
-
tests/.expect/KRfunctions.arm64.txt (modified) (1 diff)
-
tests/.expect/KRfunctions.x64.txt (modified) (1 diff)
-
tests/.expect/declarationSpecifier.arm64.txt (modified) (1 diff)
-
tests/.expect/declarationSpecifier.x64.txt (modified) (1 diff)
-
tests/.expect/declarationSpecifier.x86.txt (modified) (1 diff)
-
tests/.expect/extension.x64.txt (modified) (1 diff)
-
tests/.expect/extension.x86.txt (modified) (1 diff)
-
tests/.expect/gccExtensions.arm64.txt (modified) (1 diff)
-
tests/.expect/gccExtensions.x64.txt (modified) (1 diff)
-
tests/ctrl-flow/loopctrl.cfa (modified) (1 diff)
-
tests/enum_tests/.expect/position.txt (modified) (1 diff)
-
tests/enum_tests/anonymous.cfa (modified) (1 diff)
-
tests/enum_tests/enumInlineValue.cfa (modified) (1 diff)
-
tests/enum_tests/input.cfa (modified) (1 diff)
-
tests/enum_tests/planet.cfa (modified) (1 diff)
-
tests/enum_tests/position.cfa (modified) (1 diff)
-
tests/enum_tests/typedIntEnum.cfa (modified) (1 diff)
-
tests/enum_tests/voidEnum.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/builtins.c
rfc276f3 r4175659 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 // -
libcfa/src/Makefile.am
rfc276f3 r4175659 85 85 parseconfig.hfa \ 86 86 rational.hfa \ 87 enum.hfa \ 87 88 stdlib.hfa \ 88 89 strstream.hfa \ -
libcfa/src/iostream.cfa
rfc276f3 r4175659 1202 1202 1203 1203 1204 forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial( E ) )1205 istype & ?|?( istype & is, E & e ) {1206 // fprintf( stderr, "here0\n" );1207 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );1208 1209 // Match longest input enumerator string to enumerator labels, where enumerator names are unique.1210 1211 int N = countof( E ), lnths[N], fred = 0;1212 // printf( "N %d\n", N );1213 int r = 0;1214 // for ( s; E : r; 0~@ ) {1215 for ( s; E ) { // scan string rows gathering lengths1216 lnths[r] = strlen( label( s ) );1217 if ( lnths[r] > fred ) fred = lnths[r];1218 // fprintf( stderr, "%s %d %d\n", label( s ), lnths[r], fred );1219 r += 1;1220 } // for1221 1222 int mcol = -1; // last match column1223 char ch, curr = '\0', prev = '\0';1224 1225 fmt( is, " " ); // skip optional whitespace1226 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );1227 1228 for ( c; fred ) { // scan columns of the label matix (some columns missing)1229 int args = fmt( is, "%c", &ch ); // read character1230 // fprintf( stderr, "fmt args: %d eof: %d\n", args, eof(is) );1231 if ( eof( is ) ) {1232 // fprintf( stderr, "Eof1\n" );1233 if ( c == 0 ) return is; // no characters read ?1234 clear( is ); // => read something => reset EOF => detect again on next read1235 // fprintf( stderr, "Eof2\n" );1236 break;1237 } // if1238 if ( args != 1 ) throwResume ExceptionInst( missing_data ); // may be unnecessary since reading single character1239 1240 // printf( "read '%c'\n", ch );1241 for ( r; N ) { // scan enumeration strings for matching character in current column1242 // printf( "%d %d %d\n", c, r, lnths[r] );1243 if ( c < lnths[r] ) { // string long enough for this column check ?1244 char match = label( fromInt( r ) )[c]; // optimization1245 // printf( "%c '%c'\n", match, ch );1246 // Stop on first match, could be other matches.1247 if ( (match == ch) && (c == 0 || curr == label( fromInt( r ) )[c - 1]) ) {1248 // printf( "match %d %d %d '%c' '%c' '%c' '%c' 'c'\n", c, r, lnths[r], match, ch, prev, label( fromInt( r ) )[c - 1] );1249 mcol = c; // matching column1250 prev = curr; // last matching character1251 curr = ch; // current matching character1252 break;1253 } // if1254 } // if1255 } else {1256 // fprintf( stderr, "finished mcol: %d ch: '%c' curr: '%c' prev: '%c'\n", mcol, ch, curr, prev );1257 ungetc( ch, is ); // push back last unmatching character1258 if ( mcol == -1 ) throwResume ExceptionInst( missing_data ); // no matching character in first column1259 break;1260 } // for1261 // printf( "\n" );1262 // } else {1263 // fprintf( stderr, "finished2 %d\n", mcol );1264 } // for1265 1266 for ( c; N ) { // scan enumeration strings of length "mcol" for match1267 if ( mcol == lnths[c] - 1 ) {1268 char match = label( fromInt( c ) )[mcol]; // optimization1269 // printf( "finished1 mcol: %d c: %d lnth: %d match: '%c' curr: '%c' prev: '%c'\n", mcol, c, lnths[c], match, curr, prev );1270 if ( (match == curr) && (mcol == 0 || prev == label( fromInt( c ) )[mcol - 1]) ) {1271 e = fromInt( c );1272 break;1273 } // if1274 } // if1275 } else {1276 // fprintf( stderr, "finished3 %d\n", mcol );1277 throwResume ExceptionInst( missing_data ); // no match in this column1278 } // for1279 return is;1280 }1281 1282 forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {1283 ostype & ?|?( ostype & os, E e ) {1284 return os | label( e );1285 }1286 OSTYPE_VOID_IMPL( os, E )1287 }1288 1289 1204 // Local Variables: // 1290 1205 // tab-width: 4 // -
libcfa/src/iostream.hfa
rfc276f3 r4175659 507 507 } // distribution 508 508 509 forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial(E) )510 istype & ?|?( istype &, E & );511 512 forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {513 ostype & ?|?( ostype &, E );514 OSTYPE_VOID( E );515 }516 517 509 // Local Variables: // 518 510 // tab-width: 4 // -
libcfa/src/rational.cfa
rfc276f3 r4175659 21 21 22 22 // Arithmetic, Relational 23 forall( T | Simple(T) ) { 23 24 forall( T | arithmetic( T ) ) { 24 25 // helper routines 26 25 27 // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce 26 28 // rationals. alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm … … 42 44 return gcd( abs( n ), d ); // simplify 43 45 } // simplify 44 } 45 46 forall( T | arithmetic( T ) ) { 46 47 47 // constructors 48 48 … … 197 197 198 198 forall( T ) { 199 forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | Simple(T) )199 forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | arithmetic( T ) ) 200 200 istype & ?|?( istype & is, rational(T) & r ) { 201 201 is | r.numerator | r.denominator; -
libcfa/src/rational.hfa
rfc276f3 r4175659 78 78 79 79 // I/O 80 forall(T | multiplicative(T) | equality(T))81 trait Simple {82 int ?<?( T, T );83 };84 80 85 81 forall( T ) { 86 forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | Simple(T) )82 forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | arithmetic( T ) ) 87 83 istype & ?|?( istype &, rational(T) & ); 88 84 -
src/AST/Decl.hpp
rfc276f3 r4175659 74 74 bool isTypeFixed = false; 75 75 bool isHidden = false; 76 bool isMember = false;77 76 78 77 DeclWithType( const CodeLocation& loc, const std::string& name, Storage::Classes storage, -
src/AST/Expr.cpp
rfc276f3 r4175659 123 123 bool VariableExpr::get_lvalue() const { 124 124 // It isn't always an lvalue, but it is never an rvalue. 125 if(dynamic_cast<const ast::EnumInstType *>(var->get_type())) return !var->isMember;126 125 return true; 127 126 } -
src/Parser/TypeData.cpp
rfc276f3 r4175659 1481 1481 ast::ObjectDecl * object = strict_dynamic_cast<ast::ObjectDecl *>( member ); 1482 1482 object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide; 1483 object->isMember = true;1484 1483 if ( ret->isOpaque() && cur->has_enumeratorValue() ) { 1485 1484 SemanticError( td->location, "Opague cannot have an explicit initializer value." ); -
tests/.expect/KRfunctions.arm64.txt
rfc276f3 r4175659 104 104 signed int _X1bi_2; 105 105 { 106 signed int *(*_tmp_cp_ret 8)(signed int __param_0, signed int __param_1);107 ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret 8=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret8)));106 signed int *(*_tmp_cp_ret0)(signed int __param_0, signed int __param_1); 107 ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret0=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret0))); 108 108 } 109 109 -
tests/.expect/KRfunctions.x64.txt
rfc276f3 r4175659 104 104 signed int _X1bi_2; 105 105 { 106 signed int *(*_tmp_cp_ret 8)(signed int __param_0, signed int __param_1);107 ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret 8=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret8)));106 signed int *(*_tmp_cp_ret0)(signed int __param_0, signed int __param_1); 107 ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret0=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret0))); 108 108 } 109 109 -
tests/.expect/declarationSpecifier.arm64.txt
rfc276f3 r4175659 1059 1059 } 1060 1060 1061 signed int _tmp_cp_ret 8;1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret 8=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret8);1061 signed int _tmp_cp_ret0; 1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0); 1063 1063 if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) { 1064 1064 { -
tests/.expect/declarationSpecifier.x64.txt
rfc276f3 r4175659 1059 1059 } 1060 1060 1061 signed int _tmp_cp_ret 8;1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret 8=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret8);1061 signed int _tmp_cp_ret0; 1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0); 1063 1063 if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) { 1064 1064 { -
tests/.expect/declarationSpecifier.x86.txt
rfc276f3 r4175659 1059 1059 } 1060 1060 1061 signed int _tmp_cp_ret 8;1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret 8=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret8);1061 signed int _tmp_cp_ret0; 1062 signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0); 1063 1063 if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) { 1064 1064 { -
tests/.expect/extension.x64.txt
rfc276f3 r4175659 457 457 458 458 { 459 signed int _tmp_cp_ret 8;460 ((void)(((void)(_tmp_cp_ret 8=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret8));459 signed int _tmp_cp_ret0; 460 ((void)(((void)(_tmp_cp_ret0=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret0)); 461 461 } 462 462 -
tests/.expect/extension.x86.txt
rfc276f3 r4175659 457 457 458 458 { 459 signed int _tmp_cp_ret 8;460 ((void)(((void)(_tmp_cp_ret 8=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret8));459 signed int _tmp_cp_ret0; 460 ((void)(((void)(_tmp_cp_ret0=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret0)); 461 461 } 462 462 -
tests/.expect/gccExtensions.arm64.txt
rfc276f3 r4175659 339 339 } 340 340 341 signed int _tmp_cp_ret 8;342 signed int _X3reti_2 = (((void)(_tmp_cp_ret 8=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret8);341 signed int _tmp_cp_ret0; 342 signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0); 343 343 if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) { 344 344 { -
tests/.expect/gccExtensions.x64.txt
rfc276f3 r4175659 339 339 } 340 340 341 signed int _tmp_cp_ret 8;342 signed int _X3reti_2 = (((void)(_tmp_cp_ret 8=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret8);341 signed int _tmp_cp_ret0; 342 signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0); 343 343 if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) { 344 344 { -
tests/ctrl-flow/loopctrl.cfa
rfc276f3 r4175659 15 15 16 16 #include <fstream.hfa> 17 #include <enum.hfa> 17 18 18 19 void fred() { -
tests/enum_tests/.expect/position.txt
rfc276f3 r4175659 1 Enumeration Constant<Blue>:: value: blue, position: 2, label: Blue, default output: Blue2 Runtime Value<fishy>:: value: green, position: 1, label: Green, default output: Green3 Runtime Value<C2>:: value: green, position: 1, label: Green, default output: Green1 Compile Time: blue value: blue, position: 2, label: Blue, default return value: blue 2 Runtime: fishy value: green, position: 1, label: Green, default return value: green 3 Runtime: C2 value: green, position: 1, label: Green, default return value: green 4 4 ao is red 5 5 ko is green -
tests/enum_tests/anonymous.cfa
rfc276f3 r4175659 3 3 4 4 int main() { 5 sout | value(nthreads);5 sout | nthreads; 6 6 } 7 7 -
tests/enum_tests/enumInlineValue.cfa
rfc276f3 r4175659 1 1 #include <fstream.hfa> 2 #include <enum.hfa> 2 3 3 4 enum(int) A !{ -
tests/enum_tests/input.cfa
rfc276f3 r4175659 1 1 #include <fstream.hfa> 2 #include <enum.hfa> 2 3 3 4 int main() { -
tests/enum_tests/planet.cfa
rfc276f3 r4175659 1 1 #include <fstream.hfa> 2 2 #include <stdlib.hfa> 3 #include <enum.hfa> 3 4 4 5 struct MR { double mass, radius; }; -
tests/enum_tests/position.cfa
rfc276f3 r4175659 17 17 Colour c2 = fishy; 18 18 19 sout | " Enumeration Constant<Blue>:: value: " | value(Colour.Blue) | ", position: " | posn(Colour.Blue) | ", label: " | label(Colour.Blue) | ", default output: " | Colour.Blue;20 sout | "Runtime Value<fishy>:: value: " | value(fishy) | ", position: " | posn(fishy) | ", label: " | label(fishy) | ", default output: " | fishy;21 sout | "Runtime Value<C2>:: value: " | value(c2) | ", position: " | posn(c2) | ", label: " | label(c2) | ", default output: " | c2;19 sout | "Compile Time: blue value: " | value(Colour.Blue) | ", position: " | posn(Colour.Blue) | ", label: " | label(Colour.Blue) | ", default return value: " | Colour.Blue; 20 sout | "Runtime: fishy value: " | value(fishy) | ", position: " | posn(fishy) | ", label: " | label(fishy) | ", default return value: " | fishy; 21 sout | "Runtime: C2 value: " | value(c2) | ", position: " | posn(c2) | ", label: " | label(c2) | ", default return value: " | c2; 22 22 Colour.Red; 23 23 char * ao = Colour.Red; -
tests/enum_tests/typedIntEnum.cfa
rfc276f3 r4175659 12 12 13 13 int main() { 14 sout | "0=" | value(zero);15 sout | "1=" | value(one);16 sout | "1000=" | value(thousand);17 sout | "1001=" | value(thousand_one);18 sout | "2000=" | value(two_thousand);19 sout | "2001=" | value(two_thousand_one);20 sout | "2002=" | value(two_thousand_two);14 sout | "0=" | zero; 15 sout | "1=" | one; 16 sout | "1000=" | thousand; 17 sout | "1001=" | thousand_one; 18 sout | "2000=" | two_thousand; 19 sout | "2001=" | two_thousand_one; 20 sout | "2002=" | two_thousand_two; 21 21 return 0; 22 22 } -
tests/enum_tests/voidEnum.cfa
rfc276f3 r4175659 1 1 #include <fstream.hfa> 2 #include <enum.hfa> 2 3 3 4 enum() E { A, B, C };
Note:
See TracChangeset
for help on using the changeset viewer.