Gardening.

This commit is contained in:
Christian Rinderknecht 2019-10-07 16:33:34 +02:00
parent 0c7bfbdecd
commit ff9584c7b7
12 changed files with 268 additions and 270 deletions

View File

@ -1 +1 @@
--explain --external-tokens Token --base Parser ParToken.mly --explain --external-tokens LexToken --base Parser ParToken.mly

View File

@ -4,18 +4,17 @@ $HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml $HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml
$HOME/git/ligo/src/parser/shared/Lexer.mli ../shared/Lexer.mli
$HOME/git/ligo/src/parser/shared/Lexer.mll ../shared/Lexer.mll
$HOME/git/ligo/src/parser/shared/Error.mli ../shared/Error.mli
$HOME/git/ligo/src/parser/shared/EvalOpt.ml ../shared/EvalOpt.ml
$HOME/git/ligo/src/parser/shared/EvalOpt.mli ../shared/EvalOpt.mli
$HOME/git/ligo/src/parser/shared/FQueue.ml ../shared/FQueue.ml
$HOME/git/ligo/src/parser/shared/FQueue.mli ../shared/FQueue.mli
$HOME/git/ligo/src/parser/shared/LexerLog.mli ../shared/LexerLog.mli
$HOME/git/ligo/src/parser/shared/LexerLog.ml ../shared/LexerLog.ml
$HOME/git/ligo/src/parser/shared/Markup.ml ../shared/Markup.ml
$HOME/git/ligo/src/parser/shared/Markup.mli ../shared/Markup.mli
$HOME/git/ligo/src/parser/shared/Utils.mli ../shared/Utils.mli
$HOME/git/ligo/src/parser/shared/Utils.ml ../shared/Utils.ml
$HOME/git/ligo/src/parser/shared/Version.ml
Stubs/Simple_utils.ml Stubs/Simple_utils.ml

View File

@ -6,7 +6,7 @@ let () = Printexc.record_backtrace true
(* Running the lexer on the source *) (* Running the lexer on the source *)
let options = EvalOpt.read "Ligodity" ".mligo" let options = EvalOpt.read "CameLIGO" ".mligo"
open EvalOpt open EvalOpt

View File

@ -800,7 +800,6 @@ projection:
} }
} }
| module_name DOT field_name DOT nsepseq(selection,DOT) { | module_name DOT field_name DOT nsepseq(selection,DOT) {
let open Region in
let module_name = $1 in let module_name = $1 in
let field_name = $3 in let field_name = $3 in
let value = module_name.value ^ "." ^ field_name.value in let value = module_name.value ^ "." ^ field_name.value in

View File

@ -1,3 +1,5 @@
[@@@warning "-42"]
open AST open AST
open! Region open! Region
@ -351,7 +353,6 @@ and print_fun_expr {value; _} =
print_expr body print_expr body
and print_conditional {value; _} = and print_conditional {value; _} =
let open Region in
let {kwd_if; test; kwd_then; ifso; kwd_else; ifnot} = value let {kwd_if; test; kwd_then; ifso; kwd_else; ifnot} = value
in print_token ghost "("; in print_token ghost "(";
print_token kwd_if "if"; print_token kwd_if "if";

View File

@ -6,7 +6,7 @@ let () = Printexc.record_backtrace true
(* Reading the command-line options *) (* Reading the command-line options *)
let options = EvalOpt.read "Ligodity" ".mligo" let options = EvalOpt.read "CameLIGO" ".mligo"
open EvalOpt open EvalOpt

View File

@ -4,17 +4,17 @@ $HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml $HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml $HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml
$HOME/git/ligo/src/parser/shared/Lexer.mli ../shared/Lexer.mli
$HOME/git/ligo/src/parser/shared/Lexer.mll ../shared/Lexer.mll
$HOME/git/ligo/src/parser/shared/Error.mli ../shared/Error.mli
$HOME/git/ligo/src/parser/shared/EvalOpt.ml ../shared/EvalOpt.ml
$HOME/git/ligo/src/parser/shared/EvalOpt.mli ../shared/EvalOpt.mli
$HOME/git/ligo/src/parser/shared/FQueue.ml ../shared/FQueue.ml
$HOME/git/ligo/src/parser/shared/FQueue.mli ../shared/FQueue.mli
$HOME/git/ligo/src/parser/shared/LexerLog.mli ../shared/LexerLog.mli
$HOME/git/ligo/src/parser/shared/LexerLog.ml ../shared/LexerLog.ml
$HOME/git/ligo/src/parser/shared/Markup.ml ../shared/Markup.ml
$HOME/git/ligo/src/parser/shared/Markup.mli ../shared/Markup.mli
$HOME/git/ligo/src/parser/shared/Utils.mli ../shared/Utils.mli
$HOME/git/ligo/src/parser/shared/Utils.ml ../shared/Utils.ml
Stubs/Simple_utils.ml Stubs/Simple_utils.ml

View File

@ -119,9 +119,9 @@ use the non-operation `skip`.
end end
end with f end with f
Like Pascal, PascaLIGO offers procedures, as well as functions. The <!-- Like Pascal, PascaLIGO offers procedures, as well as functions. The -->
difference follows the divide between expressions and instructions: <!-- difference follows the divide between expressions and instructions: -->
function calls are expressions, procedure calls are instructions. <!-- function calls are expressions, procedure calls are instructions. -->
In order for a function to be a candidate to be an entrypoint to the In order for a function to be a candidate to be an entrypoint to the
contract, it needs to return a specific type: `list (operation) * contract, it needs to return a specific type: `list (operation) *
@ -554,7 +554,7 @@ given the declarations (in verbose style)
then the value of `r.f` is `4`. then the value of `r.f` is `4`.
### Predefined functions, procedures and instructions ### Predefined functions instructions
Beyond a few operators, PascaLIGO features some predefined values and Beyond a few operators, PascaLIGO features some predefined values and
functions. functions.
@ -590,54 +590,54 @@ string: if `offset + length` is greater than the length of `string`,
the result is `None`, otherwise `Some (substring)`. See section the result is `None`, otherwise `Some (substring)`. See section
"Options". "Options".
#### Lists <!-- #### Lists -->
PascaLIGO offers two kinds of iterators on lists. <!-- PascaLIGO offers two kinds of iterators on lists. -->
The first applies a given function to all the items of a given list, <!-- The first applies a given function to all the items of a given list, -->
each call returning the predefined value `Unit`. If the function name <!-- each call returning the predefined value `Unit`. If the function name -->
is `f` and the list is `l`, this is expressed as <!-- is `f` and the list is `l`, this is expressed as -->
list_iter (l, f); <!-- list_iter (l, f); -->
Note: `list_iter` is a predefined _procedure_. Procedures are <!-- Note: `list_iter` is a predefined _procedure_. Procedures are -->
functions that return `Unit` and whose calls are instructions, not <!-- functions that return `Unit` and whose calls are instructions, not -->
expressions. The same holds for the iterated function `f` here. See <!-- expressions. The same holds for the iterated function `f` here. See -->
section "Declarations/Procedures". <!-- section "Declarations/Procedures". -->
For an iterator like `list_iter` to be useful, it needs to be able to <!-- For an iterator like `list_iter` to be useful, it needs to be able to -->
perform a side effect, which user-defined procedures and functions <!-- perform a side effect, which user-defined procedures and functions -->
cannot do. Like so: <!-- cannot do. Like so: -->
function iter (const delta : int; const l : list (int)) : int is <!-- function iter (const delta : int; const l : list (int)) : int is -->
var acc : int := 0 <!-- var acc : int := 0 -->
procedure aggregate (const i : int) is <!-- procedure aggregate (const i : int) is -->
begin <!-- begin -->
acc := acc + i <!-- acc := acc + i -->
end <!-- end -->
begin <!-- begin -->
aggregate (delta); // Has no effect on acc <!-- aggregate (delta); // Has no effect on acc -->
list_iter (l, aggregate) // Has an effect on acc <!-- list_iter (l, aggregate) // Has an effect on acc -->
end with acc <!-- end with acc -->
The other predefined iterator on lists is `list_map`. It is useful <!-- The other predefined iterator on lists is `list_map`. It is useful -->
when we need to apply a function to all the items of a list and gather <!-- when we need to apply a function to all the items of a list and gather -->
them into another list, in the same order as the original items. (In <!-- them into another list, in the same order as the original items. (In -->
mathematical terms, `list_map` builds the list of the images through <!-- mathematical terms, `list_map` builds the list of the images through -->
the function.) For instance, the function `iter` <!-- the function.) For instance, the function `iter` -->
function iter (const l : list (int)) : list (int) is <!-- function iter (const l : list (int)) : list (int) is -->
function incr (const i : int) : int is <!-- function incr (const i : int) : int is -->
begin <!-- begin -->
skip <!-- skip -->
end with i+1 <!-- end with i+1 -->
begin <!-- begin -->
skip <!-- skip -->
end with list_map (l, incr) <!-- end with list_map (l, incr) -->
will take a list of integers as a parameter and return a list with the <!-- will take a list of integers as a parameter and return a list with the -->
integers all incremented, e.g., `iter (list [1;2;3])` evaluates in <!-- integers all incremented, e.g., `iter (list [1;2;3])` evaluates in -->
`list [2;3;4]`. <!-- `list [2;3;4]`. -->
#### Sets #### Sets
@ -709,18 +709,13 @@ functions to update sets.
has value `3`. has value `3`.
- Complete iteration on sets is performed by loops. See section
- The iterator `set_iter` is similar to `list_iter`: it takes a set "Loops".
and a procedure (or function returning `Unit`) and applies it in
turn to all the elements of the set.
- Another form of complete iteration on sets is performed by
loops. See section "Loops".
#### Maps #### Maps
Currently, maps have less support than sets. PascaLIGO offers the Currently, maps have less support than sets. PascaLIGO offers the
following functions and procedures on maps: following functions on maps:
- Adding bindings to a map is only possible if the map is mutable, - Adding bindings to a map is only possible if the map is mutable,
that is, if it was declared with the annotation `var`, like so, in that is, if it was declared with the annotation `var`, like so, in
@ -768,19 +763,8 @@ following functions and procedures on maps:
where `sender` is a key and `backers` is a map. If the key is where `sender` is a key and `backers` is a map. If the key is
absent in the map, this instruction is a non-operation. absent in the map, this instruction is a non-operation.
- The iterator `map_iter` is similar to `list_iter`: it takes a set - Complete iteration on maps is performed by loops. See section
and a procedure (or function returning `Unit`) and applies it in "Loops".
turn to all the bindings of the map. The type of the iterated
procedure/function is expected to be `key * value -> unit`.
- The iterator `map_map` is similar to `list_map`: it takes a map
and a function and builds a new map by applying the function to
all the bindings. In particular, this means that the expected
return type of the iterated function must be the type of the
values in the map.
- Another form of complete iteration on maps is performed by
loops. See section "Loops".
#### Failures #### Failures
@ -800,17 +784,17 @@ can chose.
## Declarations ## Declarations
There are several kinds of declarations: types, mutable variables, There are several kinds of declarations: types, mutable variables,
constants, functions, procedures, fields. Depending on the syntactic constants, functions, fields. Depending on the syntactic context, only
context, only some of those declarations will be allowed. Declarations some of those declarations will be allowed. Declarations may be
may be separated by a semicolon. (Because each declaration starts with a separated by a semicolon. (Because each declaration starts with a
keyword they can be parsed without separators.) keyword they can be parsed without separators.)
### Types ### Types
Type declarations are found only at top-level, that is, outside any Type declarations are found only at top-level, that is, outside any
function or procedure. They associate a type name to a type function. They associate a type name to a type expression. The general
expression. The general syntax is syntax is
type some_type_name is some_type_expression type some_type_name is some_type_expression
@ -959,27 +943,39 @@ is valid and changes the value of the mutable variable `counter` to be
`3n`. This is the semantics found in all imperative languages. `3n`. This is the semantics found in all imperative languages.
IMPORTANT: Mutable variables cannot be declared at top-level, but only IMPORTANT: Mutable variables cannot be declared at top-level, but only
in the scope of function and procedure bodies. This is to avoid global in the scope of function bodies. This is to avoid global side effects
side effects that hide the control flow and makes static analysis that hide the control flow and makes static analysis extremely
extremely difficult. difficult.
### Functions ### Functions
Function declarations can occur both at top-level and inside functions Function declarations can occur both at top-level and inside
and procedures (in the tradition of Pascal). We saw an example functions, in the tradition of Pascal. For example,
earlier:
function iter (const l : list (int)) : list (int) is function incr_list (const l : list (int)) : list (int) is
function incr (const i : int) : int is function incr_int (const i : int) : int is
begin begin
skip skip
end with i+1 end with i+1
const item : int = 0
begin begin
skip var temp : list (int) := nil;
end with list_map (l, incr) for item in l
begin
temp := incr_int (item) # temp
end;
var new_l : list (int) := nil;
for item in temp
begin
new_l := item # new_l
end
end with new_l
Here, the function `incr` is declared inside the declaration of the Here, the function `incr_int` is declared inside the declaration of
function `iter`. The general shape of a function declaration is the function `incr_list`, which take a list of integers and a list
containing the same integers plus one.
The general shape of a function declaration is
function my_name ( ... (* parameters here *)) : return_type is function my_name ( ... (* parameters here *)) : return_type is
... // local declarations here ... // local declarations here
@ -1042,7 +1038,7 @@ copies. Let us copy an example seen above:
function iter (const delta : int; const l : list (int)) : int is function iter (const delta : int; const l : list (int)) : int is
var acc : int := 0 var acc : int := 0
procedure aggregate (const i : int) is function aggregate (const i : int) : unit is
begin begin
acc := acc + i // acc is part of the copied environment acc := acc + i // acc is part of the copied environment
end end
@ -1058,41 +1054,41 @@ value in return.
IMPORTANT: _Functions cannot be recursive in PascaLIGO_, that is why IMPORTANT: _Functions cannot be recursive in PascaLIGO_, that is why
loops or iterators are needed. loops or iterators are needed.
### Procedures <!-- ### Procedures -->
WARNING: Procedures are not implemented in the current version of LIGO, they <!-- WARNING: Procedures are not implemented in the current version of LIGO, they -->
will appear in a future version with these semantics but cannot currently be <!-- will appear in a future version with these semantics but cannot currently be -->
used. <!-- used. -->
Procedures are a special kind of functions that return `Unit`. They <!-- Procedures are a special kind of functions that return `Unit`. They -->
are declared as follows: <!-- are declared as follows: -->
procedure my_name ( ... (* parameters here *)) is <!-- procedure my_name ( ... (* parameters here *)) is -->
... // local declarations here <!-- ... // local declarations here -->
begin <!-- begin -->
... // instructions here <!-- ... // instructions here -->
end <!-- end -->
Since function calls (see section "Functions") leave the environment <!-- Since function calls (see section "Functions") leave the environment -->
invariant, one may wonder what use there is to procedures. As we have <!-- invariant, one may wonder what use there is to procedures. As we have -->
seen in the section about "Lists" and their iterators, the exception <!-- seen in the section about "Lists" and their iterators, the exception -->
to this rule are predefined iterators, like `list_iter`. They actually <!-- to this rule are predefined iterators, like `list_iter`. They actually -->
allow the iterated function to perform side effects. Here is the <!-- allow the iterated function to perform side effects. Here is the -->
example again: <!-- example again: -->
function iter (const delta : int; const l : list (int)) : int is <!-- function iter (const delta : int; const l : list (int)) : int is -->
var acc : int := 0 <!-- var acc : int := 0 -->
procedure aggregate (const i : int) is <!-- procedure aggregate (const i : int) is -->
begin <!-- begin -->
acc := acc + i <!-- acc := acc + i -->
end <!-- end -->
begin <!-- begin -->
aggregate (delta); // Has no effect on acc <!-- aggregate (delta); // Has no effect on acc -->
list_iter (l, aggregate) // Has an effect on acc <!-- list_iter (l, aggregate) // Has an effect on acc -->
end with acc <!-- end with acc -->
(For the keen reader, this is because the iterated function is inlined <!-- (For the keen reader, this is because the iterated function is inlined -->
by the compiler.) <!-- by the compiler.) -->
## Instructions ## Instructions
@ -1154,7 +1150,7 @@ To iterate on a set `s`, we would write, for instance,
... // instructions ... // instructions
end end
where `e` is bound in turn in increasing orde to each element of the where `e` is bound in turn in increasing order to each element of the
set `s`. For example, given the declarations set `s`. For example, given the declarations
const s : set (int) = set 3; 1; 2 end const s : set (int) = set 3; 1; 2 end
@ -1329,7 +1325,7 @@ PascaLIGO has an explicit keyword for the non-operation: `skip`. Using
- The `for` loop is not supported yet. - The `for` loop is not supported yet.
- Procedures are not supported yet. <!-- - Procedures are not supported yet. -->
- Nested code blocks are not supported yet. - Nested code blocks are not supported yet.

View File

@ -6,7 +6,7 @@ let () = Printexc.record_backtrace true
(* Reading the command-line options *) (* Reading the command-line options *)
let options = EvalOpt.read "Pascaligo" ".ligo" let options = EvalOpt.read "PascaLIGO" ".ligo"
open EvalOpt open EvalOpt

View File

@ -8,7 +8,7 @@ let () = Printexc.record_backtrace true
(* Reading the command-line options *) (* Reading the command-line options *)
let options = EvalOpt.read () let options = EvalOpt.read "PascaLIGO" ".ligo"
open EvalOpt open EvalOpt

View File

@ -47,6 +47,9 @@ type options = {
cmd : command cmd : command
} }
(* Parsing the command-line options on stdin *) (* Parsing the command-line options on stdin. The first parameter is
the name of the concrete syntax, e.g., "pascaligo", and the second
is the file extension, e.g., ".ligo".
*)
val read : string -> string -> options val read : string -> string -> options