Changeset 1717
- Timestamp:
- 11/01/08 01:50:15 (2 months ago)
- Location:
- cobra/trunk
- Files:
-
- 4 modified
-
Developer/IntermediateReleaseNotes.text (modified) (1 diff)
-
Source/BinaryOpExpr.cobra (modified) (3 diffs)
-
Source/Expr.cobra (modified) (6 diffs)
-
Tests/110-basics-two/110-int-types.cobra (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Developer/IntermediateReleaseNotes.text
r1710 r1717 178 178 179 179 * 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 213 213 214 214 def _bindImp 215 left = _left216 right = _right217 215 try 218 216 base._bindImp … … 220 218 # for a type inference situation, create a var of type passthrough for the left hand side 221 219 # to prevent superfluous errors in subsequent statements 220 left = _left 222 221 if left inherits IdentifierExpr 223 222 if left.definition is nil … … 229 228 _type = .compiler.passThroughType 230 229 throw 230 left = _left 231 right = _right 231 232 assert right.type 232 233 if left inherits IdentifierExpr -
cobra/trunk/Source/Expr.cobra
r1709 r1717 2068 2068 def _bindImp is override 2069 2069 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 2080 2078 on 'NOT' 2081 if _expr.type is not .compiler.boolType2082 _expr = TruthExpr( _expr, this).bindAll to TruthExpr2079 if expr.type is not .compiler.boolType 2080 _expr = TruthExpr(expr, this).bindAll to TruthExpr 2083 2081 _type = .compiler.boolType 2084 2082 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) 2086 2096 2087 2097 def toCobraSource as String is override 2088 2098 branch _op 2089 2099 on 'MINUS', op = '-' 2090 on 'PLUS', op = '+'2100 on 'PLUS', op = '+' 2091 2101 on 'TILDE', op = '~' 2092 on 'NOT', op = 'not '2093 else :throw FallThroughException(_op)2102 on 'NOT', op = 'not ' 2103 else, throw FallThroughException(_op) 2094 2104 return op + _expr.toCobraSource 2095 2105 … … 2116 2126 base.init(token) 2117 2127 _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 2118 2135 2119 2136 def bindImp as dynamic is override … … 2182 2199 _value = token.value to decimal 2183 2200 2201 get isNumeric as bool is override 2202 return true 2203 2184 2204 def _bindImp is override 2185 2205 base._bindImp … … 2198 2218 _value = token.value to decimal 2199 2219 2220 get isNumeric as bool is override 2221 return true 2222 2223 get value from var 2224 2200 2225 def _bindImp is override 2201 2226 base._bindImp … … 2214 2239 _value = token.value to float 2215 2240 2241 get isNumeric as bool is override 2242 return true 2243 2216 2244 def _bindImp is override 2217 2245 base._bindImp … … 2233 2261 base.init(token) 2234 2262 _value = value 2263 2264 get isNumeric as bool is override 2265 return true 2235 2266 2236 2267 get value from var -
cobra/trunk/Tests/110-basics-two/110-int-types.cobra
r1490 r1717 53 53 d as uint64 = 0 54 54 e as uint = 0 55 a = 1 56 b = 2 57 c = 3 58 d = 4 59 e = 5 55 60 CobraCore.noOp(a, b, c, d, e) 56 61 57 62 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 63 78 CobraCore.noOp(a, b, c, d, e) 64 79 … … 81 96 assert i8b.getType == SByte 82 97 83 i16 =3345 to int1684 i16a =3345i1685 i16b =3345_i1698 i16 = 3345 to int16 99 i16a = 3345i16 100 i16b = 3345_i16 86 101 assert i16.getType == Int16 87 102 assert i16a.getType == Int16 … … 91 106 assert l.getType == Int64 92 107 ##l0 = 23233L 93 la = 327652 to int64108 la = 327652 to int64 94 109 assert la.getType == Int64 95 la0 = 327652_i64110 la0 = 327652_i64 96 111 assert la0.getType == Int64 97 la1 = 327652i64112 la1 = 327652i64 98 113 assert la1.getType == Int64 99 114 … … 102 117 assert u.getType == UInt32 103 118 104 u8 = 254 to uint8119 u8 = 254 to uint8 105 120 assert u8.getType == Byte 106 u8a = 155u8121 u8a = 155u8 107 122 assert u8a.getType == Byte 108 123 u8b = 240_u8 … … 122 137 assert u1.getType == UInt32 123 138 ##u2 = 655U 124 ul = 32761 to uint64139 ul = 32761 to uint64 125 140 assert ul.getType == UInt64 126 ##ul1 = 32761UL127 ula = 32761_u64141 ##ul1 = 32761UL 142 ula = 32761_u64 128 143 assert ula.getType == UInt64 129 ulb = 32761u64144 ulb = 32761u64 130 145 assert ulb.getType == UInt64
