Changes between Version 115 and Version 116 of IR2
- Timestamp:
- 06/04/21 08:41:56 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR2
v115 v116 166 166 * Arrays are mutable. As in C, the left hand size of an assignment may have the form `a[i]`, where `a` is an object of array type. Sequences are immutable. 167 167 * Elements of an array are addressable, i.e., one can form a pointer such as `&a[i]`. This is not possible with sequences, sets, maps, or relations---there is no way to have a pointer to any component of such a type. 168 * A function may neither consume nor return an object of array type. There is no such restriction for sequences.168 * A function may neither consume nor return an object of array type. [why?] There is no such restriction for sequences. 169 169 * The difference between the function type and map type: 170 * a function cannot return a function; nor can a function consume an argument of functional type 170 * a function cannot return a function; nor can a function consume an argument of functional type [why?] 171 171 * a function may return a pointer to a function and may consume an argument of type pointer to function... 172 172 * a function pointer is formed by `&f`, where `f` is the name of a function … … 185 185 }; 186 186 }}} 187 * A * pure type name* is one in which the optional length expression for an array type never occurs.188 * A * complete type name* is defined recursively as follows: a struct or union type is complete if and only if all the member types are complete; an array type is complete if and only if the element type is complete and the length is specified; all other types are complete.187 * A **pure type name** is one in which the optional length expression for an array type never occurs. Type arguments in angular brackets must be pure types. Declarations are pure types by the grammar. 188 * A **complete type name** is defined recursively as follows: a struct or union type is complete if and only if all the member types are complete; an array type is complete if and only if the element type is complete and the length is specified; all other types are complete. 189 189 190 190 … … 213 213 214 214 * For function calls and spawns, the first expression shall have a functional type. That function must be a system or defined function (not an abstract function). 215 * The first expression following `$alloc` has type `$heap*`. It is a pointer to the heap that will be modified by allocating the new memory. The second expression has type `$int` and is the number of elements being allocated. This is followed by the element type. The function returns a pointer to the first element of an array, similar to C's malloc. It is deallocated using function`$free`.216 215 217 216 … … 294 293 * A pointer becomes defined when assigned the result of an `$alloc`. Each element in the newly allocated object is undefined. 295 294 * Example: to determine whether it is safe to read `*(p+i)`, assert `$summable(p, i) && $valid(p+i) && $defined(*(p+i))`. You must check (1) you can sum `p` and `i`, (2) `p+i` points to an object of the base type, so dereference is safe, and (3) the object is defined (has been assigned a value). If you aren't sure `p` and `i` have been defined, you can add `$defined(p) && $defined(i)` to the assertion. It may be more efficient to use temporary variables and break this up into multiple assertions. 296 * `$fresh` and `$new` consume an argument of type `$type<T>` and return a value of type `T`. For `$new`, the argument must specify a complete type. 295 * `$fresh` and `$new` consume an argument of type `$type<T>` and return a value of type `T`. For `$new`, the argument must specify a complete type. Fresh accepts any type name. 296 297 297 298 298 === How to implement `$defined` using symbolic execution ===
