Changes between Version 26 and Version 27 of IR
- Timestamp:
- 11/22/15 21:22:29 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR
v26 v27 93 93 A type name is a syntactic element that names a type, together with possibly more information that makes the type "complete". All of the names listed above are type names, such as `int[]`, but so is `int[n*m]`. This is the same as in C. 94 94 95 The expression `$typeof(T)`, where `T` is a type name, returns a value of type `$type` representing the type `T`. 95 The expression `$typefrom(T)`, where `T` is a type name, returns a value of type `$type` representing the type `T`. 96 97 The expression `$typeof(e)`, where `e` is an expression, returns the type of `e`, a value of type `$type`. 96 98 97 99 The expression `$initval(d)` takes a `$type` value `d` and returns the initial value for an object of type `d`. … … 110 112 // statements (leaving out the chooses and whens for brevity) 111 113 n=10; 112 _S=$type of(struct S { int a[n]; };114 _S=$typefrom(struct S { int a[n]; }; 113 115 x1=$initval(_S); 114 116 n=20; … … 156 158 == Expressions == 157 159 158 In the following list of expressions, `e`, `e0`, `e1`, etc., are expressions. `T` is a type name. 160 In the following list of expressions, `e`, `e0`, `e1`, etc., are expressions. `T` is a type name. `t` is an expression of type `$type`. 159 161 160 162 * literals … … 172 174 * `NULL` : value of type `void*` 173 175 * variables 174 * `$typeof(T)` : an expression of type `$type` 175 * `sizeof(T)` : the size of the type named `T` 176 * `$initval(e)`, where `e` is an expression of type `$type` 176 * `$typefrom(T)` : an expression of type `$type`, the type represented by the type name `T` 177 * `$typeof(e)` : expression of type `$type`, the type of the expression `e` 178 * `$sizeof(t)` : the size of that type. Note that the C `sizeof(expr)` can be translated as `$sizeof($typeof(expr))`. The C `sizeof(T)` can be translated as `$sizeof($typefrom(T))`. 179 * `$initval(t)` : initial value of type `t` 177 180 * `$defined(e)` 178 * `e1+e2` : addition 181 * `e1+e2` : addition. One of the following must hold: 182 * `e1` and `e2` have the same numeric type. Note that there are no "automatic conversions" as there are in C. If the original expressions have different types, explicit casts must be inserted. 183 * `e1` has pointer type and `e2` has an integer type. (Alternatively, we could define a separate function `$pointer_add(p,n)`.) 179 184 * `e1-e2` : subtraction 180 185 * `e1*e2` : multiplication 181 186 * `e1/e2` : division 187 * If both are integer types, the result is integer division. Otherwise it is real division. Need to define what happens for negative integers. 182 188 * `e1%e2` : modulus 183 * `e1[e2]` : array index189 * `e1[e2]` : array subscript expression. Note that `e1` must have array type, not pointer type. (This is different from C.) If `e1` has pointer type, use `*(e1+e2)` instead. 184 190 * `*e` : pointer dereference 185 191 * `&e` : address-of 186 192 * `!e` : logical not 187 193 * `-e` : negative 188 * `(T)e` : cast expression 194 * `$cast(e,t)` : casts `e` to a value of type `t` 195 * need to list all of the legal casts and what they mean exactly 189 196 * cast of integer to array-of-boolean, and vice-versa? 190 197 * `e1==e2`, `e1!=e2` … … 201 208 202 209 210 Pointers: unlike C, there is no "array-pointer pun". If an array `a` needs to be converted to a pointer, you must use `&a[0]`. 211 203 212 == The Primitive Statements == 204 213 … … 210 219 * Wait: `$wait(e);` 211 220 * **Wailtall?** 212 * Malloc: `e=(T)$malloc(e1,e2);` **??** 213 * Free: `free(e);` 221 * Allocation 222 * `e=$allocate(h,t,e);`, where 223 * `h` as type `$heap` 224 * `t` has type `$type` 225 * `e` has integer type. 226 * Allocates `e` objects of type `t` on heap `h` 227 * Free: `free(p);` 214 228 * Noop: `;` 215 229 * **Is there a need to add annotations for "true" or "false" branch, etc.?** … … 244 258 245 259 == Libraries == 246
