Changeset 1717

Show
Ignore:
Timestamp:
11/01/08 01:50:15 (2 months ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Assigning values less than zero to variables of type int8 and int16 gives a false compilation error.
ticket:45

Location:
cobra/trunk
Files:
4 modified

Legend:

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

    r1710 r1717  
    178178 
    179179* Fixed: A `for` statement iterating over a Hashtable doesn't infer the enumerator type correctly (DictionaryEntry). ticket:54 
     180 
     181* Fixed: Assigning values less than zero to variables of type int8 and int16 gives a false compilation error. ticket:45 
  • cobra/trunk/Source/BinaryOpExpr.cobra

    r1706 r1717  
    213213 
    214214        def _bindImp 
    215                 left = _left 
    216                 right = _right 
    217215                try 
    218216                        base._bindImp 
     
    220218                        # for a type inference situation, create a var of type passthrough for the left hand side 
    221219                        # to prevent superfluous errors in subsequent statements 
     220                        left = _left 
    222221                        if left inherits IdentifierExpr 
    223222                                if left.definition is nil 
     
    229228                                _type = .compiler.passThroughType 
    230229                        throw 
     230                left = _left 
     231                right = _right 
    231232                assert right.type 
    232233                if left inherits IdentifierExpr 
  • cobra/trunk/Source/Expr.cobra

    r1709 r1717  
    20682068        def _bindImp is override 
    20692069                base._bindImp 
    2070                 _expr.bindImp 
    2071                 if _type is nil 
    2072                         _type = _expr.type 
    2073                 branch _op 
    2074                         on 'MINUS' 
    2075                                 _type = _expr.type 
    2076                         on 'PLUS' 
    2077                                 _type = _expr.type 
    2078                         on 'TILDE' 
    2079                                 _type = _expr.type 
     2070                op = .op 
     2071                expr = _expr 
     2072                expr.bindImp 
     2073                if _type is nil, _type = _expr.type 
     2074                branch op 
     2075                        on 'MINUS', _type = expr.type 
     2076                        on 'PLUS',  _type = expr.type 
     2077                        on 'TILDE', _type = expr.type 
    20802078                        on 'NOT' 
    2081                                 if _expr.type is not .compiler.boolType 
    2082                                         _expr = TruthExpr(_expr, this).bindAll to TruthExpr 
     2079                                if expr.type is not .compiler.boolType 
     2080                                        _expr = TruthExpr(expr, this).bindAll to TruthExpr 
    20832081                                        _type = .compiler.boolType 
    20842082                        else 
    2085                                 throw FallThroughException(_op) 
     2083                                throw FallThroughException(op) 
     2084 
     2085                if op in ['MINUS', 'PLUS']  # TODO: 'TILDE' for ints? 
     2086                        if expr inherits AtomicLiteral 
     2087                                if expr.isNumeric 
     2088                                        token = expr.token.copy 
     2089                                        branch op 
     2090                                                on 'PLUS',  pass 
     2091                                                on 'MINUS', token.value = -(token.value to dynamic) 
     2092                                                else, throw FallThroughException(op) 
     2093                                        nodeType = expr.getType 
     2094                                        expr = nodeType(token).bindAll to Expr 
     2095                                        _transformTo(expr) 
    20862096 
    20872097        def toCobraSource as String is override 
    20882098                branch _op 
    20892099                        on 'MINUS', op = '-' 
    2090                         on 'PLUS', op = '+' 
     2100                        on 'PLUS',  op = '+' 
    20912101                        on 'TILDE', op = '~' 
    2092                         on 'NOT', op = 'not ' 
    2093                         else: throw FallThroughException(_op) 
     2102                        on 'NOT',   op = 'not ' 
     2103                        else, throw FallThroughException(_op) 
    20942104                return op + _expr.toCobraSource 
    20952105 
     
    21162126                base.init(token) 
    21172127                _text = token.text 
     2128 
     2129        get isNumeric as bool 
     2130                """ 
     2131                Returns true if the literal is numeric such that + and - could apply to it. 
     2132                The default implementation returns false. 
     2133                """ 
     2134                return false 
    21182135 
    21192136        def bindImp as dynamic is override 
     
    21822199                _value = token.value to decimal 
    21832200 
     2201        get isNumeric as bool is override 
     2202                return true 
     2203 
    21842204        def _bindImp is override 
    21852205                base._bindImp 
     
    21982218                _value = token.value to decimal 
    21992219 
     2220        get isNumeric as bool is override 
     2221                return true 
     2222 
     2223        get value from var 
     2224 
    22002225        def _bindImp is override 
    22012226                base._bindImp 
     
    22142239                _value = token.value to float 
    22152240 
     2241        get isNumeric as bool is override 
     2242                return true 
     2243 
    22162244        def _bindImp is override 
    22172245                base._bindImp 
     
    22332261                base.init(token) 
    22342262                _value = value 
     2263 
     2264        get isNumeric as bool is override 
     2265                return true 
    22352266 
    22362267        get value from var 
  • cobra/trunk/Tests/110-basics-two/110-int-types.cobra

    r1490 r1717  
    5353                d as uint64 = 0 
    5454                e as uint   = 0 
     55                a = 1 
     56                b = 2 
     57                c = 3 
     58                d = 4 
     59                e = 5 
    5560                CobraCore.noOp(a, b, c, d, e) 
    5661 
    5762        def testIntLits2 
    58                 a as uint8  = 1 
    59                 b as uint16 = 2 
    60                 c as uint32 = 3 
    61                 d as uint64 = 4 
    62                 e as uint   = 0 
     63                a as int8  = 0 
     64                b as int16 = 0 
     65                c as int32 = 0 
     66                d as int64 = 0 
     67                e as int   = 0 
     68                a = 1 
     69                b = 2 
     70                c = 3 
     71                d = 4 
     72                e = 5 
     73                a = -1 
     74                b = -1 
     75                c = -1 
     76                d = -1 
     77                e = -1 
    6378                CobraCore.noOp(a, b, c, d, e) 
    6479 
     
    8196                assert i8b.getType == SByte 
    8297         
    83                 i16=3345 to int16 
    84                 i16a=3345i16 
    85                 i16b=3345_i16 
     98                i16 = 3345 to int16 
     99                i16a = 3345i16 
     100                i16b = 3345_i16 
    86101                assert i16.getType == Int16 
    87102                assert i16a.getType == Int16 
     
    91106                assert l.getType == Int64 
    92107                ##l0 = 23233L 
    93                 la= 327652 to int64 
     108                la = 327652 to int64 
    94109                assert la.getType == Int64 
    95                 la0= 327652_i64 
     110                la0 = 327652_i64 
    96111                assert la0.getType == Int64 
    97                 la1= 327652i64 
     112                la1 = 327652i64 
    98113                assert la1.getType == Int64 
    99114         
     
    102117                assert u.getType == UInt32 
    103118         
    104                 u8 =254 to uint8 
     119                u8 = 254 to uint8 
    105120                assert u8.getType == Byte 
    106                 u8a= 155u8 
     121                u8a = 155u8 
    107122                assert u8a.getType == Byte 
    108123                u8b = 240_u8 
     
    122137                assert u1.getType == UInt32 
    123138                ##u2 = 655U 
    124                 ul= 32761 to uint64 
     139                ul = 32761 to uint64 
    125140                assert ul.getType == UInt64 
    126                 ##ul1= 32761UL 
    127                 ula= 32761_u64 
     141                ##ul1 = 32761UL 
     142                ula = 32761_u64 
    128143                assert ula.getType == UInt64 
    129                 ulb= 32761u64 
     144                ulb = 32761u64 
    130145                assert ulb.getType == UInt64