Changes in / [c588acb:cc077f4]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/enum.cfa

    rc588acb rcc077f4  
    66
    77forall( E | Serial( E ) ) {
    8         E fromInt( unsigned i ) {
     8        E fromInt( int i ) {
    99                E upper = upperBound();
    1010                E lower = lowerBound();
  • libcfa/src/enum.hfa

    rc588acb rcc077f4  
    99
    1010forall( E | Bounded( E ) ) trait Serial {
    11         unsigned fromInstance( E e );
    12         E fromInt_unsafe( unsigned i );
     11        int fromInstance( E e );
     12        E fromInt_unsafe( int i );
    1313        E succ_unsafe( E e );
    1414        E pred_unsafe( E e );
     
    1616
    1717forall( E | Serial( E ) ) {
    18         E fromInt( unsigned i );
     18        E fromInt( int i );
    1919        E succ( E e );
    2020        E pred( E e );
     
    3636forall( E ) trait CfaEnum {
    3737        const char * label( E e );
    38         unsigned int posn( E e );
     38        int posn( E e );
    3939};
    4040
     
    6363
    6464        E ++?( E & l ) {                                                                        // increment operators
    65                 l = succ( l );
     65                int pos = posn(l);
     66                l = fromInt_unsafe(pos+1);
     67                return l;
     68        }
     69
     70        E --?( E & l ) {
     71                int pos = posn(l);
     72                l = fromInt_unsafe(pos-1);
    6673                return l;
    6774        }
    6875
    6976        E ?+=? ( E & l, one_t ) {
    70                 l = succ(l);
     77                int pos = posn(l);
     78                l = fromInt_unsafe(pos+1);
    7179                return l;
    7280        }
    73        
     81
    7482        E ?-=? ( E & l, one_t ) {
    75                 l = pred(l);
     83                int pos = posn(l);
     84                l = fromInt_unsafe(pos-1);
    7685                return l;
    7786        }
    7887
    7988        E ?+=? ( E & l, int i ) {
    80                 int pos = posn(l) + i;
    81                 return fromInt(pos);
     89                int pos = posn(l);
     90                l = fromInt_unsafe(pos+i);
     91                return l;
    8292        }
    8393
    8494        E ?-=? ( E & l, int i ) {
    85                 int pos = posn(l) - i;
    86                 return fromInt(pos);
    87         }
    88        
    89         E ?++( E & l ) {
    90                 E ret = l;
    91                 l = succ( l );
    92                 return ret;
    93         }
    94 
    95         E --?( E & l ) {
    96                 l = pred( l );
     95                int pos = posn(l);
     96                l = fromInt_unsafe(pos-i);
    9797                return l;
    9898        }
    9999
     100        E ?++( E & l ) {
     101                int pos = posn(l);
     102                l = fromInt_unsafe(pos+1);
     103                return fromInt_unsafe(pos);
     104        }
     105
    100106        E ?--( E & l ) {
    101                 E ret = l;
    102                 l = pred( l );
    103                 return ret;
     107                int pos = posn(l);
     108                l = fromInt_unsafe(pos-1);
     109                return fromInt_unsafe(pos);
    104110        }
    105111}
  • src/ControlStruct/TranslateEnumRange.cpp

    rc588acb rcc077f4  
    5151    // it wraps around and become unsigned max
    5252    ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
    53         "?<=?",
     53        stmt->is_inc? "?<=?": "?>=?",
    5454        {   new ast::NameExpr( location, indexName ),
    55             ast::UntypedExpr::createCall( location, "upperBound", {} )  });
     55            stmt->is_inc?
     56                ast::UntypedExpr::createCall( location, "upperBound", {} ):
     57                ast::UntypedExpr::createCall( location, "lowerBound", {} )
     58        });
    5659    auto increment = ast::UntypedExpr::createCall( location,
    5760        stmt->is_inc? "succ_unsafe": "pred_unsafe",
  • src/Validate/ImplementEnumFunc.cpp

    rc588acb rcc077f4  
    2525                : decl(decl),
    2626                  functionNesting{functionNesting},
    27                 //   quasi_void_decl(new ast::StructDecl(decl->location,
    28                 //      "quasi_void", ast::AggregateDecl::Struct,
    29                 //      {}, ast::Linkage::AutoGen)),
    3027                  proto_linkage{ast::Linkage::Cforall} {}
    3128
     
    194191        {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    195192        {new ast::ObjectDecl(getLocation(), "_ret",
    196             new ast::BasicType(ast::BasicKind::UnsignedInt))});
     193            new ast::BasicType(ast::BasicKind::SignedInt))});
    197194}
    198195
     
    229226        return genProto(
    230227                "fromInt_unsafe",
    231                 {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::UnsignedInt))},
     228                {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::SignedInt))},
    232229                {new ast::ObjectDecl(getLocation(), "_ret", new ast::EnumInstType(decl))}
    233230        );
     
    238235                "fromInstance",
    239236                {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    240                 {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::UnsignedInt))}
     237                {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::SignedInt))}
    241238        );
    242239}
     
    285282                func->location,
    286283                new ast::VariableExpr(func->location, param),
    287                 new ast::BasicType(ast::BasicKind::UnsignedInt),
     284                new ast::BasicType(ast::BasicKind::SignedInt),
    288285                ast::GeneratedFlag::ExplicitCast
    289286        );
     
    383380                        func->location,
    384381                        new ast::VariableExpr( func->location, func->params.front() ),
    385                         new ast::BasicType( ast::BasicKind::UnsignedInt ),
     382                        new ast::BasicType( ast::BasicKind::SignedInt ),
    386383                        ast::GeneratedFlag::ExplicitCast
    387384                )});
     
    407404                func->location,
    408405                new ast::VariableExpr(func->location, func->params.front()),
    409                 new ast::BasicType( ast::BasicKind::UnsignedInt ),
     406                new ast::BasicType( ast::BasicKind::SignedInt ),
    410407                        ast::GeneratedFlag::ExplicitCast);
    411408        func->stmts = new ast::CompoundStmt(
  • tests/ctrl-flow/.expect/loopctrl.txt

    rc588acb rcc077f4  
    1191190 -2 -4 -6 -8
    1201200 1 2 3 4 5 6 7 8 9
     121A B C
     122A B C D
     123D B
    121124A B C D
    122125D C B A
  • tests/ctrl-flow/loopctrl.cfa

    rc588acb rcc077f4  
    8383
    8484        enum(int) E { A, B, C, D };
    85 //      for ( E e; A ~= C ) { sout | e; } sout | nl;
    86 //      for ( e; A ~= D ) { sout | e; } sout | nl;
    87 //      for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl;
     85        for ( E e; A ~= C ) { sout | e; } sout | nl;
     86        for ( e; A ~= D ) { sout | e; } sout | nl;
     87        for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl;
    8888        for ( e; E ) { sout | e; } sout | nl;
    8989        for ( e; -~= E ) { sout | e; } sout | nl;
Note: See TracChangeset for help on using the changeset viewer.