Changes between Version 26 and Version 27 of IR


Ignore:
Timestamp:
11/22/15 21:22:29 (10 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR

    v26 v27  
    9393A 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.
    9494
    95 The expression `$typeof(T)`, where `T` is a type name, returns a value of type `$type` representing the type `T`.
     95The expression `$typefrom(T)`, where `T` is a type name, returns a value of type `$type` representing the type `T`.
     96
     97The expression `$typeof(e)`, where `e` is an expression, returns the type of `e`, a value of type `$type`.
    9698
    9799The expression `$initval(d)` takes a `$type` value `d` and returns the initial value for an object of type `d`.
     
    110112// statements (leaving out the chooses and whens for brevity)
    111113n=10;
    112 _S=$typeof(struct S { int a[n]; };
     114_S=$typefrom(struct S { int a[n]; };
    113115x1=$initval(_S);
    114116n=20;
     
    156158== Expressions ==
    157159
    158 In the following list of expressions, `e`, `e0`, `e1`, etc., are expressions.  `T` is a type name.
     160In the following list of expressions, `e`, `e0`, `e1`, etc., are expressions.  `T` is a type name. `t` is an expression of type `$type`.
    159161
    160162* literals
     
    172174 * `NULL` : value of type `void*`
    173175* 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`
    177180* `$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)`.)
    179184* `e1-e2` : subtraction
    180185* `e1*e2` : multiplication
    181186* `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.
    182188* `e1%e2` : modulus
    183 * `e1[e2]` : array index
     189* `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. 
    184190* `*e` : pointer dereference
    185191* `&e` : address-of
    186192* `!e` : logical not
    187193* `-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
    189196 * cast of integer to array-of-boolean, and vice-versa?
    190197* `e1==e2`, `e1!=e2`
     
    201208
    202209
     210Pointers: 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
    203212== The Primitive Statements ==
    204213
     
    210219* Wait: `$wait(e);`
    211220* **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);`
    214228* Noop: `;`
    215229 * **Is there a need to add annotations for "true" or "false" branch, etc.?**
     
    244258
    245259== Libraries ==
    246