| 10 | | 1. There are no automatic conversions. All must be done by explicit casts. |
| 11 | | 1. `$input`/`$output` variables in global scope (like CIVL-C) |
| 12 | | 1. Identifiers are like in C, e.g., `x`, `f10`, ... |
| 13 | | 1. Keywords, functions, etc. not in C start with `$` (like CIVL-C) |
| 14 | | 1. Libraries: similar to C, `#include <stdlib.h>`, but these name PIL libraries and there are additional PIL libraries |
| | 11 | 1. There are no automatic conversions. There is no "array-pointer pun". All conversions must be done by explicit casts or other expressions. To convert an array `a` to a pointer to element 0 of `a`, write `&a[0]`. |
| | 12 | 1. PIL supports `$input`/`$output` variables in global scope (like CIVL-C) |
| | 13 | 1. PIL identifiers are the same as C's, e.g., `x`, `f10`, ... |
| | 14 | 1. Keywords, built-in or library functions, constants, and types not in C start with `$` (like CIVL-C) |
| | 15 | 1. PIL supports libraries: similar to C, `#include <stdlib.h>`, but these name PIL libraries and there are additional standard PIL libraries not in the C standard library |
| | 16 | 1. Program order: |
| | 17 | 1. A program is a set of variable, function, and type definitions. |
| | 18 | 1. The order is totally irrelevant. |
| | 19 | 1. A variable can be used anywhere it is in scope. |
| | 20 | 1. A function can be called anywhere it is in scope. |
| 16 | | 1. One TU can refer to a variable, function, type, in another TU. |
| 17 | | 1. the variable just needs to be declared somewhere in the TU |
| 18 | | 1. the function just needs a prototype somewhere in the TU |
| 19 | | 1. the use of "static" in a variable decl or function def makes it private to that TU (so two can have same name) |
| 20 | | 1. no need for "extern" |
| 21 | | 1. at most one of the TUs declaring the variable can have an initializer |
| 22 | | 1. at most one of the TUs can have a definition for a function |
| 23 | | 1. Program order: |
| 24 | | 1. a program is a sequence of variable, function, and type definitions. |
| 25 | | 1. the order is totally irrelevant. |
| 26 | | 1. a variable can be used anywhere it is in scope |
| 27 | | 1. a function can be called anywhere it is in scope |
| | 22 | 1. One TU can refer to a variable, function, or type, in another TU. |
| | 23 | 1. The variable just needs to be declared somewhere in the TU. |
| | 24 | 1. The function just needs a prototype somewhere in the TU. |
| | 25 | 1. The use of `static` in a variable declaration or function definition makes it private to that TU (so two can have same name), as in C. |
| | 26 | 1. There is no need for `extern` so this is not in PIL. |
| | 27 | 1. At most one of the TUs declaring the variable can have an initializer. |
| | 28 | 1. At most one of the TUs can have a definition for a function. |
| 30 | | - '''type names''' are used for all declarations (no C declarators). Examples: |
| 31 | | * `$int[]`: array of integer |
| 32 | | * `$int*`: pointer to integer |
| 33 | | * `$int*[]`: array of pointer to integer |
| 34 | | * `$int[]*`: pointer to array of integer |
| 35 | | * `$int*[]($real)`: function from Real to array of pointer to integer |
| | 31 | - '''type names''' are used for all declarations. There are no C declarators. Examples: |
| | 32 | * `$int[] a`: declares `a` to be an array of integer |
| | 33 | * `$int* p`: pointer to integer |
| | 34 | * `$int*[] b`: array of pointer to integer |
| | 35 | * `$int[]* q`: pointer to array of integer |
| | 36 | * `$int*[]($real) f`: function from Real to array of pointer to integer |
| 37 | | - what are the limits of these types? to be decided |
| 38 | | - `$int`, `$real` (mathematical types) |
| 39 | | - `struct`: as in C |
| 40 | | - `union`: as in C |
| 41 | | - `T[]`: sequence of `T`. Note: no "T[n]". sequences can be assigned, returned, passed as arguments, etc. |
| 42 | | - `$set<T>` : finite set of `T`, ops to add, contains, remove, size, ... |
| 43 | | - `$map<T1,T2>` : finite map from `T1` to `T2`, ops to put, get, containsKey, ... |
| 44 | | - `$fun<T1,T2>` : "logic functions": deterministic, total, side-effect free functions from `T1` to `T2` |
| 45 | | - `$tuple<T,...>` : tuples of specified type (similar to struct) |
| 46 | | - `$rel<T,...>` : relations of specified type (set of tuples) |
| | 38 | * `$int`: the set of integers |
| | 39 | * `$real`: the set of Reals |
| | 40 | * `fint[lo,hi]`: set of integers between `lo` and `hi`, inclusive. `lo` and `hi` are constant expressions so are known at compile time. |
| | 41 | * `uint[hi]`: nonnegative integers less than the constant expression`hi`. Arithmetic is performed modulo `hi` (like C's unsigned integer types). |
| | 42 | * `$float<p,emax>`: the set of IEEE binary floating point numbers with precision `p` and emax `emax`. These are also constant expressions. |
| 48 | | - what can be pointed to: var, array element, struct element, union member, ... |
| 49 | | - Type definitions: `typedef typename ID;` |
| | 44 | - `struct TAG { T1 f1; ... Tn fn; }`: a C struct |
| | 45 | - `union`: similar |
| | 46 | - `T[]`: sequence of `T`. Note: there is no "T[n]". Sequences are first-class values: they can be assigned, returned, passed as arguments, etc. |
| | 47 | - `R(T1, ..., Tn)`: the type of a procedure which consumes values in `T1`, ..., `Tn` and returns a value in `R`. This is basically C's function type. |
| | 48 | - `$fun<T1,T2>` : "logic functions": deterministic, total, side-effect free functions from `T1` to `T2`. Note however the function may depend on the state (i.e., the state should be considered a hidden input). A `$pure` function is a function that does not depend on the state. |
| | 49 | - `$set<T>` : finite set of `T` |
| | 50 | - `$map<T1,T2>` : finite map from `T1` to `T2`. A map is a set of ordered pairs `(x,y)` with the property that if `(x,y)` and `(x,z)` are in the map, then `y`=`z`. |
| | 51 | - `$tuple<T,...>` : tuples of specified type. This is similar to `struct`, but is anonymous and the fields do not have names. |
| | 52 | - Type definitions have the form: `typedef typename ID;` |
| 65 | | The definition above defines a '''constant''' `f` of type '''`R(T1, ..., Tn)`'''. Procedures are first-class values. One may declare a variable of type `R(T1, ..., Tn)`, a procedure may return a value of that type, a procedure may consume a value of that type, a value of that type may be assigned to a variable, etc. Hence the procedure type is just like any other type, and procedure definitions define new constants of that type, just as `1` is a constant of type `$int`. Note this is different from C in that C uses function pointers; PIL dispenses with the need for function pointers. |
| | 68 | The definition above defines a '''constant''' `f` of type '''`R(T1, ..., Tn)`'''. Procedures are first-class values. One may declare a variable of type `R(T1, ..., Tn)`, a procedure may return a value of that type, a procedure may consume a value of that type, a value of that type may be assigned to a variable, etc. Hence the procedure type is just like any other type, and procedure definitions define new constants of that type, just as `1` is a constant of type `$int`. Note this is different from C in that C uses function pointers; PIL dispenses with the need for function pointers and just uses functions. |
| 86 | | Logic functions are a certain class of functions that have no side-effects, and are deterministic total functions of their arguments and the current state. A logic function has a type of the form `$fun<R,T1,...,Tn>`, logical functions which consume inputs of type `T1`, ..., `Tn` and return a value of type `R`. |
| | 89 | Logic functions are a certain class of functions that have no side-effects, and are deterministic total functions of their arguments and the current state. A logic function has a type of the form `$fun<R,T1,...,Tn>`, which signifies the set of logical functions which consume inputs of type `T1`, ..., `Tn` and return a value of type `R`. |
| 166 | | - `$logic _Bool $set_in(T x, $set<T> s);` // is x an element of s? |
| 167 | | - `$logic $set<T> $set_with($set<T> s, T x);` // s U {x} |
| 168 | | - `$logic $set<T> $set_without($set<T> s, T x);` // s - {x} |
| 169 | | - `$logic $set<T> $set_union($set<T> s1, $set<T> s2);` // s1 U s2 |
| 170 | | - `$logic $set<T> $set_difference($set<T> s1, $set<T> s2);` // s1-s2 |
| 171 | | - `$logic $set_intersection($set<T> s1, $set<T> s2);` // s1 \cap s2 |
| 172 | | - `$logic T[] $set_elements($set<T> s);` |
| 173 | | - `$logic _Bool $set_isSubsetOf($set<T> s1, $set<T> s2);` |
| 174 | | - `$logic $set<U> $set_map($set<T> s, $fun<T,U> f);` |
| | 169 | - `$pure $logic _Bool $set_in(T x, $set<T> s);` // is x an element of s? |
| | 170 | - `$pure $logic $set<T> $set_with($set<T> s, T x);` // s U {x} |
| | 171 | - `$pure $logic $set<T> $set_without($set<T> s, T x);` // s - {x} |
| | 172 | - `$pure $logic $set<T> $set_union($set<T> s1, $set<T> s2);` // s1 U s2 |
| | 173 | - `$pure $logic $set<T> $set_difference($set<T> s1, $set<T> s2);` // s1-s2 |
| | 174 | - `$pure $logic $set_intersection($set<T> s1, $set<T> s2);` // s1 \cap s2 |
| | 175 | - `$pure $logic T[] $set_elements($set<T> s);` |
| | 176 | - `$pure $logic _Bool $set_isSubsetOf($set<T> s1, $set<T> s2);` |
| | 177 | - `$pure $logic $set<U> $set_map($set<T> s, $fun<T,U> f);` |