Changes between Version 8 and Version 9 of PIL
- Timestamp:
- 10/04/24 13:35:48 (20 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PIL
v8 v9 2 2 3 3 == Basic Properties 4 *PIL programs are target of translators from C, Fortran, MPI/OpenMP/etc. They can also be written by humans.5 *PIL should be a high-level language like CIVL-C.6 *PIL programs can be easily translated to PFG.7 *PIL must also have a totally well-defined semantics and syntax.8 *PIL programs can have nested funtion definitions.9 *PIL programs can use preprocessor directives like in C10 *There are no automatic conversions. All must be done by explicit casts.11 *`$input`/`$output` variables in global scope (like CIVL-C)12 *Identifiers are like in C, e.g., `x`, `f10`, ...13 *Keywords, functions, etc. not in C start with `$` (like CIVL-C)14 *Libraries: similar to C, `#include <stdlib.h>`, but these name PIL libraries and there are additional PIL libraries15 *PIL programs can be divided into multiple files (translation units)16 *One TU can refer to a variable, function, type, in another TU.17 *the variable just needs to be declared somewhere in the TU18 *the function just needs a prototype somewhere in the TU19 *the use of "static" in a variable decl or function def makes it private to that TU (so two can have same name)20 *no need for "extern"21 *at most one of the TUs declaring the variable can have an initializer22 *at most one of the TUs can have a definition for a function23 *Program order:24 *a program is a sequence of variable, function, and type definitions.25 *the order is totally irrelevant.26 *a variable can be used anywhere it is in scope27 *a function can be called anywhere it is in scope4 1. PIL programs are target of translators from C, Fortran, MPI/OpenMP/etc. They can also be written by humans. 5 1. PIL should be a high-level language like CIVL-C. 6 1. PIL programs can be easily translated to PFG. 7 1. PIL must also have a totally well-defined semantics and syntax. 8 1. PIL programs can have nested funtion definitions. 9 1. PIL programs can use preprocessor directives like in C 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 15 1. PIL programs can be divided into multiple files (translation units) 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 28 28 29 29 == Types … … 75 75 Procedure definitions can be nested. It is an error to call a procedure `f` when `f` is not in scope. (This is similar to Gnu C.) In other words, if the call takes place in dyscope d, then the definition of `f` must be in d's static scope, or in the parent of d's static scope, or its parent, etc. 76 76 77 A procedure definition can be templated:78 {{{79 <T1,T2,...> <procedure def>80 }}}81 This defines one procedure for each assignment of types to the Ti.82 83 77 There is a second way to specify a procedure, using a lambda expression, which is described below. 84 78 … … 96 90 }}} 97 91 where `expr` is a side-effect-free expression of type `R` and can refer to any variables in scope. 92 93 === Misc. 94 95 Both procedure and logic function definitions can be templated, e.g., 96 {{{ 97 <T1,T2> int f($map<T1,T2> f, T1 x) { ... } 98 <T1,T2> $logic int g($map<T1,T2> f, T1 x) { ... } 99 }}} 100 This defines one procedure for each assignment of types to the `Ti`. 101 102 Both kinds of functions can be declared without providing definitions, indicating that the definition can be found in a different translation unit: 103 {{{ 104 int f(int x); 105 $logic int g(int x); 106 }}} 98 107 99 108 === Lambda expressions … … 115 124 The type of this expression is `R(T1, ..., Tn)`. The resulting value of this is type is a procedure which can be called or assigned to a variable, etc., just like any other procedure value. 116 125 117 Note that the definition can only use the specified variables. Evaluating this expression yields a closure, which is a pair consisting of a dyscope and the body of the procedure. The dyscope has variables `vj`, which are initialized by evaluating the `initj` when the lambda expression is evaluated. The body of the procedure may read and write to the `vj`. That dyscope will live as long as the procedure is around. Hence a function may return a closure and that closure may still be called at any time, anywhere in the program, regardless of whether the original lambda expression is in scope. 126 Note that the definition can only use the specified variables. Evaluating this expression yields a closure, which is a pair consisting of a dyscope and the body of the procedure. The dyscope has variables `vj`, which are initialized by evaluating the `initj` when the lambda expression is evaluated. The body of the procedure may read and write to the `vj`. That dyscope has no parent and will live as long as the procedure is around. Hence a function may return a closure and that closure may still be called at any time, anywhere in the program, regardless of whether the original lambda expression is in scope. 127 128 When a procedure closure is called, a new dyscope is created whose parent dyscope is the dyscope of the closure. In the new dyscope, the formal parameters are assigned the actual values and procedure is executed in that scope. When it returns, the new dyscope is removed. 118 129 119 130 A lambda expression that specifies a logic function has the form
