Changes between Version 108 and Version 109 of IR2


Ignore:
Timestamp:
05/20/21 13:17:14 (5 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR2

    v108 v109  
    1717
    18181. **Do variables have default initial values?**
    19   * No.  Every object variable must must be explicitly initialized.  However, `$undef` can be used as the initializer, indicating that the variable is undefined.  Even in this case, the variable has some unspecified value of its type.   Details are below.
     19  * An object variable may or may not include an explicit initializer.   If it does not include an initializer, the variable is "undefined".  Even in this case, the variable has some unspecified value of its type.   Details are below.
    20201. **How do you initialize a variable?**
    2121  * In the declaration.   For example `$int n=$new($int);` will assign `n` an arbitrary integer, while `$int n=0;` will assign the integer `0` to `n`.
     
    6262  | '$atomic_f'  /* function invocations take place atomically */
    6363  ;
    64 object-decl: type-specifier declarator '=' initializer ';' ;
     64object-decl: type-specifier declarator ('=' expr)? ';' ;
    6565function-definition: type-param-list? function-qualifier* type-specifier declarator contract-clause* block ;
    6666block: '{' typedef* decl* function-definition* statement* '}' ;
     
    249249expr-pair-list: expr-pair (',' expr-pair)* ;
    250250expr-pair: '{' expr ',' expr '}' ;
    251 initializer: expr | '$undef' ;
    252251}}}
    253252
     
    280279Create a symbolic constant named `UNDEF` for each type T.   These can be created on-the-fly, as they are needed.
    281280
    282 A variable initialized with `$undef` is initialized to the `UNDEF` of its type.   The exception is a struct, which may be initialized to a concrete struct in which each field is `UNDEF`.   (Either way will work, but the latter will probably be more effective.)
     281A variable without initializer is initialized to the `UNDEF` of its type.   The exception is a struct, which may be initialized to a concrete struct in which each field is `UNDEF`.   (Either way will work, but the latter will probably be more effective.)
    283282
    284283For a complete type T, the "undef-initializer" for T is defined as follows: if T is not an array type, the undef-initializer is defined exactly as above: either the symbolic constant `UNDEF` or a concrete struct of `UNDEF`s.   If T is the complete array type S[n], the undef-initializer is the array-lambda expression with length n and defining expression the undef-initializer for S. 
    285284
    286285`$new_array(n,T)` returns the undef-initializer for T[n].
    287 
    288 `$alloc(h,n,T)` creates a new object in the heap h with value the undef-initializer for T[n], and returns a pointer to element 0 of that object.
    289286
    290287Evaluation of `$defined(expr)` returns `!FORALL UNDEF:T . expr == UNDEF`, where `T` is the type of `expr`.