Changeset 1581

Show
Ignore:
Timestamp:
08/18/08 08:40:54 (3 months ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Some bitwise operations with integer literals of 16 or 8 bits produce invalid compilation errors.
reported-by:hopscc

Location:
cobra/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1577 r1581  
    101101 
    102102* Fixed: Using `ref` on a variable that experienced an error causes an internal exception. 
     103 
     104* Fixed: Some bitwise operations with integer literals of 16 or 8 bits produce invalid compilation errors. 
  • cobra/trunk/Source/Expr.cobra

    r1577 r1581  
    242242                """ 
    243243                type = .type 
    244                 cast = _contextType and type.isDynamic 
     244                cast = false 
     245                if _contextType 
     246                        if type.isDynamic 
     247                                cast = true 
     248                        else if type inherits IntType 
     249                                if type.size < 32, cast = true 
    245250                if cast 
    246251                        if parens, sw.write('(') 
     
    27622767 
    27632768        get asSharp as String is override 
    2764                 return _value.toString 
     2769                s = '' 
     2770                if (info = .token.info) inherits int 
     2771                        branch info 
     2772                                on - 8, s = 'System.SByte' 
     2773                                on + 8, s = 'System.Byte' 
     2774                                on -16, s = 'System.Int16' 
     2775                                on +16, s = 'System.UInt16' 
     2776                                on -32, s = '' 
     2777                                on +32, s = 'U' 
     2778                                on -64, s = 'L' 
     2779                                on +64, s = 'UL' 
     2780                                else, throw FallThroughException(info) 
     2781                if s.length <= 2 
     2782                        return _value.toString + s 
     2783                else 
     2784                        return '([s])[_value.toString]' 
    27652785 
    27662786 
  • cobra/trunk/Tests/100-basics/920-hex-lit.cobra

    r1537 r1581  
    137137                        assert b.getType is Byte 
    138138                                 
    139                         # These dont compile for some reason - same with non hex vals 
    140                         #b = 255u8 
    141                         #b = b & 0x1fu8 
    142                         ## OR 
    143                         ##b = b & 31u8 
    144                         #assert b == 0x1fu8 
    145                         #b = 255u8 
    146                         #b1 = 0x1fu8 
    147                         #b = b & b1 
    148                         #print b 
     139                        b = 255u8 
     140                        b = b & 0x1fu8 
     141                        assert b == 0x1fu8 
     142 
     143                        b = 255u8 
     144                        b = b & 31u8 
     145                        assert b == 0x1fu8 
     146 
     147                        b = 255u8 
     148                        b1 = 0x1fu8 
     149                        b = b & b1 
     150                        assert b == 0x1fu8 
    149151         
    150152                        c = 0x0_u8 
     
    152154                        assert c == 0x1e_u8 
    153155                                 
    154                         # Neither do these 
    155                         #c = 0x0_u8 
    156                         #c = c | 0x0_u8 
    157                         #assert c == 0x1e_u8 
    158                         # 
    159                         #c = 0x0_u8 
    160                         #c1 = 0x0_u8 
    161                         #c = c | c1 
    162                         #assert c == 0x1e_u8 
    163                                  
     156                        c = 0x0_u8 
     157                        c = c | 0x1e_u8 
     158                        assert c == 0x1e_u8 
     159 
     160                        c = 0x0_u8 
     161                        c1 = 0x1e_u8 
     162                        c = c | c1 
     163                        assert c == 0x1e_u8 
     164         
    164165                def main is shared 
    165166                        .lit