From b02c241a0178ce74b3b7e5bd6276a1e2a3d520c3 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 11:37:07 -0700 Subject: [PATCH 1/8] Add short explanation to transpiler.ml --- src/passes/6-transpiler/transpiler.ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/passes/6-transpiler/transpiler.ml b/src/passes/6-transpiler/transpiler.ml index 0cef7b26b..a7ddc8c31 100644 --- a/src/passes/6-transpiler/transpiler.ml +++ b/src/passes/6-transpiler/transpiler.ml @@ -1,3 +1,7 @@ +(* The Transpiler is a function that takes as input the Typed AST, and outputs expressions in a language that is basically a Michelson based on with named variables and first-class-environments. + +For more info, see back-end.md: https://gitlab.com/ligolang/ligo/blob/dev/gitlab-pages/docs/contributors/big-picture/back-end.md *) + open! Trace open Helpers From e3c581ff02143d77eb0ea1dd64c852f0eeb13908 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 11:47:09 -0700 Subject: [PATCH 2/8] Fix typo in transpiler.ml explanation --- src/passes/6-transpiler/transpiler.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passes/6-transpiler/transpiler.ml b/src/passes/6-transpiler/transpiler.ml index a7ddc8c31..5886ab542 100644 --- a/src/passes/6-transpiler/transpiler.ml +++ b/src/passes/6-transpiler/transpiler.ml @@ -1,4 +1,4 @@ -(* The Transpiler is a function that takes as input the Typed AST, and outputs expressions in a language that is basically a Michelson based on with named variables and first-class-environments. +(* The Transpiler is a function that takes as input the Typed AST, and outputs expressions in a language that is basically a Michelson with named variables and first-class-environments. For more info, see back-end.md: https://gitlab.com/ligolang/ligo/blob/dev/gitlab-pages/docs/contributors/big-picture/back-end.md *) From 51e6c441f2515d92080f054978ac3cb25005ad3c Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 13:32:43 -0700 Subject: [PATCH 3/8] Add documentation for pascaligo parser interface as .mli --- src/passes/1-parser/pascaligo.mli | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/passes/1-parser/pascaligo.mli diff --git a/src/passes/1-parser/pascaligo.mli b/src/passes/1-parser/pascaligo.mli new file mode 100644 index 000000000..e82d6ab35 --- /dev/null +++ b/src/passes/1-parser/pascaligo.mli @@ -0,0 +1,21 @@ +(* This file provides an interface to the PascaLIGO parser. *) + +open Trace + +module Parser = Parser_pascaligo.Parser +module AST = Parser_pascaligo.AST +module ParserLog = Parser_pascaligo.ParserLog +module LexToken = Parser_pascaligo.LexToken + + +(** Open a PascaLIGO filename given by string and convert into an abstract syntax tree. *) +val parse_file : string -> (AST.t result) + +(** Convert a given string into a PascaLIGO abstract syntax tree *) +val parse_string : string -> AST.t result + +(** Parse a given string as a PascaLIGO expression and return an expression AST. + +This is intended to be used for interactive interpreters, or other scenarios +where you would want to parse a PascaLIGO expression outside of a contract. *) +val parse_expression : string -> AST.expr result From 211d5ea37fc4a0a34bd23f7263845ec778b4a5d3 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 13:42:33 -0700 Subject: [PATCH 4/8] Add explanation of AST relationship to Parser.mly to AST.mli --- src/passes/1-parser/pascaligo/AST.mli | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 15e7e9883..5999f8ceb 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -135,8 +135,15 @@ type 'a braces = { rbrace : rbrace } -(* The Abstract Syntax Tree *) +(** The Abstract Syntax Tree +The AST mirrors the contents of Parser.mly, which defines a tree of parsing +productions that are used to make a syntax tree from a given program input. + +This file defines the concrete AST for PascaLIGO, which is used to associate +regions of the source code text with the contents of the syntax tree. + +*) type t = { decl : declaration nseq; eof : eof From 30d25ee24770ea09bd74d1dfabad060f0ea99ed9 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 13:59:53 -0700 Subject: [PATCH 5/8] Convert top comment in LexToken.mli to ocamldoc comment --- src/passes/1-parser/pascaligo/LexToken.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passes/1-parser/pascaligo/LexToken.mli b/src/passes/1-parser/pascaligo/LexToken.mli index f98c7576c..0b645293b 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mli +++ b/src/passes/1-parser/pascaligo/LexToken.mli @@ -1,4 +1,4 @@ -(* This signature defines the lexical tokens for LIGO +(** This signature defines the lexical tokens for LIGO _Tokens_ are the abstract units which are used by the parser to build the abstract syntax tree (AST), in other words, the stream of From c2489fd310f38b5b876b5b7e4aa25aae82791549 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 14:07:12 -0700 Subject: [PATCH 6/8] ocamldoc-ify Markup.mli --- src/passes/1-parser/shared/Markup.mli | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/passes/1-parser/shared/Markup.mli b/src/passes/1-parser/shared/Markup.mli index 2522b52a9..6b31c0647 100644 --- a/src/passes/1-parser/shared/Markup.mli +++ b/src/passes/1-parser/shared/Markup.mli @@ -1,12 +1,11 @@ -(* This module defines the sorts of markup recognised by the LIGO +(** This module defines the sorts of markup recognised by the LIGO lexer *) module Region = Simple_utils.Region -(* A lexeme is piece of concrete syntax belonging to a token. In +(** A lexeme is piece of concrete syntax belonging to a token. In algebraic terms, a token is also a piece of abstract lexical syntax. Lexical units emcompass both markup and lexemes. *) - type lexeme = string type t = @@ -19,7 +18,7 @@ type t = type markup = t -(* Pretty-printing of markup +(** Pretty-printing of markup The difference between [to_lexeme] and [to_string] is that the former builds the corresponding concrete syntax (the lexeme), From fcfbbcb9c15ef9d8272d5f7af40a130caf1848fa Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 3 Oct 2019 15:32:16 -0700 Subject: [PATCH 7/8] Delete dead code and add .mli docs to simplify/pascaligo.ml --- src/passes/2-simplify/pascaligo.ml | 32 ----------------------------- src/passes/2-simplify/pascaligo.mli | 14 +++++++++++++ 2 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 src/passes/2-simplify/pascaligo.mli diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 31e739f36..1d5f1b89b 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -8,7 +8,6 @@ open Combinators let nseq_to_list (hd, tl) = hd :: tl let npseq_to_list (hd, tl) = hd :: (List.map snd tl) -let npseq_to_nelist (hd, tl) = hd, (List.map snd tl) let pseq_to_list = function | None -> [] | Some lst -> npseq_to_list lst @@ -36,16 +35,6 @@ module Errors = struct ] in error ~data title message - let bad_bytes loc str = - let title () = "bad bytes string" in - let message () = - Format.asprintf "bytes string contained non-hexadecimal chars" in - let data = [ - ("location", fun () -> Format.asprintf "%a" Location.pp loc) ; - ("bytes", fun () -> str) ; - ] in - error ~data title message - let unsupported_proc_decl decl = let title () = "procedure declarations" in let message () = @@ -88,17 +77,6 @@ module Errors = struct ] in error ~data title message - let unsupported_arith_op expr = - let title () = "arithmetic expressions" in - let message () = - Format.asprintf "this arithmetic operator is not supported yet" in - let expr_loc = Raw.expr_to_region expr in - let data = [ - ("expr_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ expr_loc) - ] in - error ~data title message - let unsupported_string_catenation expr = let title () = "string expressions" in let message () = @@ -110,16 +88,6 @@ module Errors = struct ] in error ~data title message - let unsupported_proc_calls call = - let title () = "procedure calls" in - let message () = - Format.asprintf "procedure calls are not supported yet" in - let data = [ - ("call_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ call.Region.region) - ] in - error ~data title message - let unsupported_for_loops region = let title () = "bounded iterators" in let message () = diff --git a/src/passes/2-simplify/pascaligo.mli b/src/passes/2-simplify/pascaligo.mli new file mode 100644 index 000000000..ebce134d6 --- /dev/null +++ b/src/passes/2-simplify/pascaligo.mli @@ -0,0 +1,14 @@ +(** Converts PascaLIGO programs to the Simplified Abstract Syntax Tree. *) + +open Ast_simplified + +module Raw = Parser.Pascaligo.AST +module SMap = Map.String + +(** Convert a concrete PascaLIGO expression AST to the simplified expression AST + used by the compiler. *) +val simpl_expression : Raw.expr -> expression Trace.result + +(** Convert a concrete PascaLIGO program AST to the simplified program AST used + by the compiler. *) +val simpl_program : Raw.ast -> program Trace.result From 0207d1f88f5cb529b9d12d25225d4f3df8b743e9 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 4 Oct 2019 15:33:50 -0700 Subject: [PATCH 8/8] Add .mli for SAST pretty printer with minimal comments --- src/stages/ast_simplified/PP.mli | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/stages/ast_simplified/PP.mli diff --git a/src/stages/ast_simplified/PP.mli b/src/stages/ast_simplified/PP.mli new file mode 100644 index 000000000..798fe18fa --- /dev/null +++ b/src/stages/ast_simplified/PP.mli @@ -0,0 +1,33 @@ +(** Pretty printer for the Simplified Abstract Syntax Tree *) + +open Types + +val type_expression : Format.formatter -> type_expression -> unit + +val literal : Format.formatter -> literal -> unit + +val expression : Format.formatter -> expression -> unit + +val option_type_name : Format.formatter -> string * type_expression option -> unit + +val assoc_expression : Format.formatter -> (expr * expr) -> unit + +val access : Format.formatter -> access -> unit + +val access_path : Format.formatter -> access_path -> unit + +val type_annotation : Format.formatter -> type_expression option -> unit + +val single_record_patch : Format.formatter -> string * expr -> unit + +val single_tuple_patch : Format.formatter -> int * expr -> unit + +(* Shows the type expected for the matched value *) +val matching_type : Format.formatter -> 'a matching -> unit + +val matching_variant_case_type : Format.formatter -> (string * string) * 'a -> unit + +val declaration : Format.formatter -> declaration -> unit + +(** Pretty print a full program AST *) +val program : Format.formatter -> program -> unit