Merge branch 'master' of gitlab.com:gabriel.alfour/tezos

This commit is contained in:
Galfour 2019-04-15 17:42:15 +00:00
commit 49c44f9721
16 changed files with 49 additions and 33 deletions

View File

@ -1,24 +1,24 @@
type file_location = { (* type file_location = { *)
filename : string ; (* filename : string ; *)
start_line : int ; (* start_line : int ; *)
start_column : int ; (* start_column : int ; *)
end_line : int ; (* end_line : int ; *)
end_column : int ; (* end_column : int ; *)
} (* } *)
type virtual_location = string type virtual_location = string
type t = type t =
| File of file_location | File of Region.t (* file_location *)
| Virtual of virtual_location | Virtual of virtual_location
let make (start_pos:Lexing.position) (end_pos:Lexing.position) : t = let make (start_pos:Lexing.position) (end_pos:Lexing.position) : t =
let filename = start_pos.pos_fname in (* TODO: give correct unicode offsets (the random number is here so
let start_line = start_pos.pos_lnum in that searching for wrong souce locations appearing in messages
let end_line = end_pos.pos_lnum in will quickly lead here *)
let start_column = start_pos.pos_cnum - start_pos.pos_bol in File (Region.make
let end_column = end_pos.pos_cnum - end_pos.pos_bol in ~start:(Pos.make ~byte:start_pos ~point_num:(-1897000) ~point_bol:(-1897000))
File { filename ; start_line ; start_column ; end_line ; end_column } ~stop:(Pos.make ~byte:end_pos ~point_num:(-1897000) ~point_bol:(-1897000)))
let virtual_location s = Virtual s let virtual_location s = Virtual s
let dummy = virtual_location "dummy" let dummy = virtual_location "dummy"

View File

@ -21,3 +21,5 @@ module Map = X_map
module Dictionary = Dictionary module Dictionary = Dictionary
module Environment = Environment module Environment = Environment
module Tree = Tree module Tree = Tree
module Region = Region
module Pos = Pos

View File

@ -6,7 +6,7 @@ type type_name = string
type 'a name_map = 'a SMap.t type 'a name_map = 'a SMap.t
type 'a type_name_map = 'a SMap.t type 'a type_name_map = 'a SMap.t
type program = declaration list type program = declaration Location.wrap list
and declaration = and declaration =
| Declaration_type of named_type_expression | Declaration_type of named_type_expression
@ -214,7 +214,7 @@ module PP = struct
fprintf ppf "const %s = %a" name annotated_expression ae fprintf ppf "const %s = %a" name annotated_expression ae
let program ppf (p:program) = let program ppf (p:program) =
fprintf ppf "@[<v>%a@]" (list_sep declaration (tag "@;")) p fprintf ppf "@[<v>%a@]" (list_sep declaration (tag "@;")) (List.map Location.unwrap p)
end end
module Rename = struct module Rename = struct

View File

@ -8,7 +8,7 @@ type type_name = string
type 'a name_map = 'a SMap.t type 'a name_map = 'a SMap.t
type 'a type_name_map = 'a SMap.t type 'a type_name_map = 'a SMap.t
type program = declaration list type program = declaration Location.wrap list
and declaration = and declaration =
| Declaration_constant of named_expression | Declaration_constant of named_expression
@ -136,7 +136,7 @@ let get_entry (p:program) (entry : string) : annotated_expression result =
in in
let%bind result = let%bind result =
trace_option (simple_error "no entry point with given name") @@ trace_option (simple_error "no entry point with given name") @@
Tezos_utils.List.find_map aux p in Tezos_utils.List.find_map aux (List.map Location.unwrap p) in
ok result ok result
let get_functional_entry (p:program) (entry : string) : (lambda * type_value) result = let get_functional_entry (p:program) (entry : string) : (lambda * type_value) result =
@ -245,7 +245,7 @@ module PP = struct
fprintf ppf "const %s = %a" name annotated_expression ae fprintf ppf "const %s = %a" name annotated_expression ae
let program ppf (p:program) = let program ppf (p:program) =
fprintf ppf "@[<v>%a@]" (list_sep declaration (tag "@;")) p fprintf ppf "@[<v>%a@]" (list_sep declaration (tag "@;")) (List.map Location.unwrap p)
end end

View File

@ -21,6 +21,9 @@
aliased to [token]. aliased to [token].
*) *)
module Region = Tezos_utils.Region
module Pos = Tezos_utils.Pos
type lexeme = string type lexeme = string
(* TOKENS *) (* TOKENS *)

View File

@ -9,6 +9,8 @@ type lexeme = string
let sprintf = Printf.sprintf let sprintf = Printf.sprintf
module Region = Tezos_utils.Region
module Pos = Tezos_utils.Pos
module SMap = Utils.String.Map module SMap = Utils.String.Map
module SSet = Utils.String.Set module SSet = Utils.String.Set

View File

@ -1,3 +1,5 @@
module Region = Tezos_utils.Region
type lexeme = string type lexeme = string
type t = type t =

View File

@ -1,6 +1,8 @@
(* This module defines the sorts of markup recognised by the LIGO (* This module defines the sorts of markup recognised by the LIGO
lexer *) lexer *)
module Region = Tezos_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 algebraic terms, a token is also a piece of abstract lexical
syntax. Lexical units emcompass both markup and lexemes. *) syntax. Lexical units emcompass both markup and lexemes. *)

View File

@ -292,19 +292,20 @@ and simpl_param : Raw.param_decl -> named_type_expression result = fun t ->
let%bind type_expression = simpl_type_expression c.param_type in let%bind type_expression = simpl_type_expression c.param_type in
ok { type_name ; type_expression } ok { type_name ; type_expression }
and simpl_declaration : Raw.declaration -> declaration result = fun t -> and simpl_declaration : Raw.declaration -> declaration Location.wrap result = fun t ->
let open! Raw in let open! Raw in
let loc : 'a . 'a Raw.reg -> _ -> _ = fun x v -> Location.wrap ~loc:(File x.region) v in
match t with match t with
| TypeDecl x -> | TypeDecl x ->
let {name;type_expr} : Raw.type_decl = x.value in let {name;type_expr} : Raw.type_decl = x.value in
let%bind type_expression = simpl_type_expression type_expr in let%bind type_expression = simpl_type_expression type_expr in
ok @@ Declaration_type {type_name=name.value;type_expression} ok @@ loc x @@ Declaration_type {type_name=name.value;type_expression}
| ConstDecl x -> | ConstDecl x ->
let {name;const_type;init} = x.value in let {name;const_type;init} = x.value in
let%bind expression = simpl_expression init in let%bind expression = simpl_expression init in
let%bind t = simpl_type_expression const_type in let%bind t = simpl_type_expression const_type in
let type_annotation = Some t in let type_annotation = Some t in
ok @@ Declaration_constant {name=name.value;annotated_expression={expression with type_annotation}} ok @@ loc x @@ Declaration_constant {name=name.value;annotated_expression={expression with type_annotation}}
| LambdaDecl (FunDecl x) -> | LambdaDecl (FunDecl x) ->
let {name;param;ret_type;local_decls;block;return} : fun_decl = x.value in let {name;param;ret_type;local_decls;block;return} : fun_decl = x.value in
(match npseq_to_list param.value.inside with (match npseq_to_list param.value.inside with
@ -329,7 +330,7 @@ and simpl_declaration : Raw.declaration -> declaration result = fun t ->
let type_annotation = Some (T_function (input_type, output_type)) in let type_annotation = Some (T_function (input_type, output_type)) in
Declaration_constant {name;annotated_expression = {expression;type_annotation}} Declaration_constant {name;annotated_expression = {expression;type_annotation}}
in in
ok decl ok @@ loc x @@ decl
) )
| lst -> ( | lst -> (
let%bind params = bind_map_list simpl_param lst in let%bind params = bind_map_list simpl_param lst in
@ -371,7 +372,7 @@ and simpl_declaration : Raw.declaration -> declaration result = fun t ->
let type_annotation = Some (T_function (input_type, output_type)) in let type_annotation = Some (T_function (input_type, output_type)) in
Declaration_constant {name = name.value;annotated_expression = {expression;type_annotation}} Declaration_constant {name = name.value;annotated_expression = {expression;type_annotation}}
in in
ok decl ok @@ loc x @@ decl
) )
) )
| LambdaDecl (ProcDecl _) -> simple_fail "no proc declaration yet" | LambdaDecl (ProcDecl _) -> simple_fail "no proc declaration yet"

View File

@ -196,7 +196,7 @@ let statement : I.statement -> O.declaration result = fun s ->
ok @@ O.Declaration_type {type_name = unwrap n ; type_expression = unwrap te'} ok @@ O.Declaration_type {type_name = unwrap n ; type_expression = unwrap te'}
let program : I.program -> O.program result = fun (Program lst) -> let program : I.program -> O.program result = fun (Program lst) ->
bind_map_list (apply Location.unwrap >| bind_map_location statement) lst bind_map_list (bind_map_location statement) lst
let main : I.entry_point -> O.program Location.wrap result = let main : I.entry_point -> O.program Location.wrap result =
bind_map_location program bind_map_location program

View File

@ -5,6 +5,9 @@ open Combinators
module AST = Ast_typed module AST = Ast_typed
open AST.Combinators open AST.Combinators
let temp_unwrap_loc = Location.unwrap
let temp_unwrap_loc_list = List.map Location.unwrap
let list_of_map m = List.rev @@ Map.String.fold (fun _ v prev -> v :: prev) m [] let list_of_map m = List.rev @@ Map.String.fold (fun _ v prev -> v :: prev) m []
let kv_list_of_map m = List.rev @@ Map.String.fold (fun k v prev -> (k, v) :: prev) m [] let kv_list_of_map m = List.rev @@ Map.String.fold (fun k v prev -> (k, v) :: prev) m []
let map_of_kv_list lst = let map_of_kv_list lst =
@ -364,7 +367,7 @@ let translate_program (lst:AST.program) : program result =
let%bind ((_, env') as cur') = translate_declaration env cur in let%bind ((_, env') as cur') = translate_declaration env cur in
ok (cur' :: tl, env'.post_environment) ok (cur' :: tl, env'.post_environment)
in in
let%bind (statements, _) = List.fold_left aux (ok ([], Environment.empty)) lst in let%bind (statements, _) = List.fold_left aux (ok ([], Environment.empty)) (temp_unwrap_loc_list lst) in
ok statements ok statements
let translate_main (l:AST.lambda) (t:AST.type_value) : anon_function result = let translate_main (l:AST.lambda) (t:AST.type_value) : anon_function result =
@ -391,7 +394,7 @@ let translate_entry (lst:AST.program) (name:string) : anon_function result =
match lst with match lst with
| [] -> None | [] -> None
| hd :: tl -> ( | hd :: tl -> (
let AST.Declaration_constant an = hd in let AST.Declaration_constant an = temp_unwrap_loc hd in
if an.name = name if an.name = name
then ( then (
match an.annotated_expression.expression with match an.annotated_expression.expression with

View File

@ -96,13 +96,14 @@ module Errors = struct
end end
open Errors open Errors
let rec type_program (p:I.program) : O.program result = let rec type_program (p:I.program) : O.program result =
let aux (e, acc:(environment * O.declaration list)) (d:I.declaration) = let aux (e, acc:(environment * O.declaration Location.wrap list)) (d:I.declaration Location.wrap) =
let%bind (e', d') = type_declaration e d in let%bind ed' = (bind_map_location (type_declaration e)) d in
let loc : 'a . 'a Location.wrap -> _ -> _ = fun x v -> Location.wrap ~loc:x.location v in
let (e', d') = Location.unwrap ed' in
match d' with match d' with
| None -> ok (e', acc) | None -> ok (e', acc)
| Some d' -> ok (e', d' :: acc) | Some d' -> ok (e', loc ed' d' :: acc)
in in
let%bind (_, lst) = let%bind (_, lst) =
trace (fun () -> program_error p ()) @@ trace (fun () -> program_error p ()) @@