Changes between Version 91 and Version 92 of IR2


Ignore:
Timestamp:
05/12/21 16:15:48 (5 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR2

    v91 v92  
    253253  * `p-q` (pointer subtraction): `$subtractable(p,q)`
    254254  * `(T)e` (cast): `$castable(e, T)`
    255   * `*p`: `$valid(p)`
     255  * `*p`: `$valid(p)` --- this means it is safe to write to `*p`.  (It may not be safe to read `*p` because the object pointed to by p may not yet have been initialized.)
    256256* The result of an unsafe operation is unspecified, but will result in some value of the appropriate type.
    257 * Explanation of `$defined`: a bit is associated to each object.  We say an object is "defined" if the bit is true, else it is undefined.  An object is initially undefined.  It becomes defined by assignment.
    258 Memory locations are created by declaring variables and allocation.   Every variable initially holds an undefined value.   Memory locations become defined by assigning to them defined values.
    259   * Question: should an assignment of an undefined value to a variable make that variable defined, or not?
    260   * Constants are defined values.  This includes integer and real constants, and `NULL`.
    261   * An operation returns a defined value if all inputs are defined and the inputs are acceptable for the specific operation.
    262   * It is arguable about whether we should make division by 0, out of bound array indexes, etc., undefined values.  They could be defined.
    263   * Once an array is allocated with `$new_array`, the array itself is still undefined and all elements are undefined.  However `$defined($length(a))` will return `$true`.
    264   * Once an object is heap allocated with `p=$alloc(...)`, `p` becomes defined, but `*p`, `*(p+1)`, ..., are all undefined as they hold uninitialized data.
    265   * A pointer that points to the location one past the last element of an array or object is defined, but not valid.  The same holds for `NULL`.
    266   * If a pointer points to an object on the heap and that object is freed, the pointer becomes undefined.  Similarly, if it points into an object that goes out of scope, the pointer becomes undefined.
    267   * If an object is heap allocated then a pointer `p` into that object will be defined, but `*p` will be undefined (as the memory location pointed to by `p` has uninitialized data), but `$valid(p)` will return `$true`, indicating it is safe to write to that location.
     257* Explanation of `$defined`:
     258  * A bit is associated to each object.  We say an object is "defined" if the bit is true, else it is undefined.
     259  * An object is initially undefined.  It becomes defined by assignment.
     260  * Objects of pointer type are special in that they can change from defined to undefined.  This happens when the object into which they point is deallocated or goes out of scope.
     261  * An object of array type becomes defined when assigned a `$new_array`.  However, its elements are undefined.
     262  * An object of array type also becomes defined when assigned a `$new` value.  In that case, the elements are also defined.
     263  * A pointer becomes defined when assigned the result of an `$alloc`.   Each element in the newly allocated object is undefined.
     264  * 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).
     265
    268266
    269267=== Allowed Casts ===