Changes between Version 98 and Version 99 of IR2
- Timestamp:
- 05/14/21 10:35:15 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR2
v98 v99 17 17 18 18 1. **Do variables have default initial values?** 19 * Every variable holds a value of its type, always. However the initial values of variables is unspecified. Therefore a correct CIVL-IR program should explicitly initialize every variable before it is used. Moreover, there is a defined bit associated to each variable, and it is initially false, indicating that the variable is "undefined". It becomes defined when it is assigned.Details are below.19 * No. Every variable 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. 20 20 1. **How do you initialize a variable?** 21 * By assigning a value to it. For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n`.21 * In the declaration. For example `n=$new($int);` will assign `n` an arbitrary integer, while `n=0;` will assign the integer `0` to `n`. 22 22 1. **How is an array allocated?** 23 * An array variable `a` is declared with a decl such as `T a[] ;`, and then a statement such as `a=$new_array(n, T);` will assign to `a` a new array value for an array of length `n` of elements of type `T` in which all entries are undefined. (Alternatively, `a=$new(T[n])` will create an array of arbitrary defined values.) For heap-allocation, a pointer is declared with a decl such as `T * p;`, and a heap variable is also declared somewhere with a decl such as `$heap heap;` and then a statement such as`p = $alloc(&heap, n, T);` will add a new object to the heap and return a pointer to the first element. An `$alloc`-ed object can be deallocated with `$free(p);`.23 * An array variable `a` is declared with a decl such as `T a[] = $new_array(n, T);` which assigns to `a` a new array value for an array of length `n` of elements of type `T` in which all entries are undefined. (Alternatively, `T a[] = $new(T[n])` will create an array of arbitrary defined values.) For heap-allocation, `T * p = $undef;` followed by the statement `p = $alloc(&heap, n, T);` will add a new object to the heap and return a pointer to the first element. An `$alloc`-ed object can be deallocated with `$free(p);`. 24 24 1. **Is there an "array-pointer pun", as in C?** 25 25 * No, if you want a pointer to element 0 of an array, you have to explicitly write something like `&a[0]`. … … 51 51 ';' 52 52 ; 53 decl: type-param-list? qualifier* type-specifier declarator contract-clause* ';' ; 54 function-definition: type-param-list? qualifier* type-specifier declarator contract-clause* block ; 55 qualifier: 53 decl: function-decl | object-decl ; 54 function-decl: type-param-list? function-qualifier* type-specifier declarator contract-clause* ';' ; 55 object-decl: type-specifier declarator '=' initializer ';' ; 56 function-definition: type-param-list? function-qualifier* type-specifier declarator contract-clause* block ; 57 function-qualifier: 56 58 '$abstract_f' /* abstract function; only for function decls */ 57 59 | '$pure_f' /* function is a mathematical function of its parameters */ … … 169 171 | lvalue '=' expr ';' /* assignment */ 170 172 | (lvalue '=')? expr type-args? '(' expression-list? ')' ';' /* function call */ 171 | (lvalue '=')?'$spawn' expr type-args? '(' expression-list? ')' ';' /* process creation */173 | lvalue '=' '$spawn' expr type-args? '(' expression-list? ')' ';' /* process creation */ 172 174 | '$wait' expr ';' /* wait until p terminates */ 173 175 | 'return' expr? ';' /* return from function call */ 174 | (lvalue '=')? '$alloc' '(' expr ',' expr ',' type-name ')' ';' /* heap allocation */175 | '$free' expr ';' /* frees something that was $alloc-ed */176 | (lvalue '=')? '$new_array' '(' expr ',' type-name ')' ';' /* allocation of array of undefined values*/177 176 | '$atomic_enter' ';' /* enter atomic region */ 178 177 | '$atomic_exit' ';' /* exit atomic region */ … … 227 226 | expr type-args? '(' expression-list? ')' /* application of abstract function (and perhaps other functions?) */ 228 227 | '$new' '(' type-name ')' /* returns a new arbitrary value of the given type */ 228 | '$new_array' '(' expr ',' type-name ')' /* allocation of array of undefined values*/ 229 229 | '$forall' '(' decl expr? ')' expr /* universal quantification */ 230 230 | '$exists' '(' decl expr? ')' expr /* existential quantification */ … … 239 239 expr-pair-list: expr-pair (',' expr-pair)* ; 240 240 expr-pair: '{' expr ',' expr '}' ; 241 241 initializer: expr | '$undef' ; 242 242 }}} 243 243 … … 300 300 301 301 {{{ 302 $system void $exit(void); 303 $system $bool $terminated($proc p); 304 $system int $choose_int($int n); // how is this different than $new($int)? 302 <T> $system alloc($heap * h, $int n); // heap allocation of n elements of type T 303 $system $free($void * p); // frees something that was $alloc-ed 304 $system void $exit(); // terminate process immediately 305 $system $bool $terminated($proc p); // has the process terminated? 306 $system int $choose_int($int n); // nondeterministic choice of int in 0..n-1 305 307 306 308 }}}
