Changes between Version 108 and Version 109 of IR2
- Timestamp:
- 05/20/21 13:17:14 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR2
v108 v109 17 17 18 18 1. **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. 20 20 1. **How do you initialize a variable?** 21 21 * 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`. … … 62 62 | '$atomic_f' /* function invocations take place atomically */ 63 63 ; 64 object-decl: type-specifier declarator '=' initializer';' ;64 object-decl: type-specifier declarator ('=' expr)? ';' ; 65 65 function-definition: type-param-list? function-qualifier* type-specifier declarator contract-clause* block ; 66 66 block: '{' typedef* decl* function-definition* statement* '}' ; … … 249 249 expr-pair-list: expr-pair (',' expr-pair)* ; 250 250 expr-pair: '{' expr ',' expr '}' ; 251 initializer: expr | '$undef' ;252 251 }}} 253 252 … … 280 279 Create a symbolic constant named `UNDEF` for each type T. These can be created on-the-fly, as they are needed. 281 280 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.)281 A 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.) 283 282 284 283 For 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. 285 284 286 285 `$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.289 286 290 287 Evaluation of `$defined(expr)` returns `!FORALL UNDEF:T . expr == UNDEF`, where `T` is the type of `expr`.
