bin
This commit is contained in:
parent
cc4138fc2c
commit
7ca28cb34a
@ -1,24 +1,34 @@
|
|||||||
open Trace
|
open Trace
|
||||||
|
|
||||||
let () =
|
let toplevel x =
|
||||||
|
match x with
|
||||||
|
| Trace.Ok () -> ()
|
||||||
|
| Errors ss ->
|
||||||
|
Format.printf "Errors: %a\n%!" errors_pp @@ List.map (fun f -> f()) ss
|
||||||
|
|
||||||
|
let main () =
|
||||||
let l = Array.length Sys.argv in
|
let l = Array.length Sys.argv in
|
||||||
if l < 2
|
let%bind () =
|
||||||
then raise (Failure "Pass a command") ;
|
if l < 2
|
||||||
Format.printf "Toto %d\n%!" (Array.length Sys.argv) ;
|
then simple_fail "Pass a command"
|
||||||
|
else ok () in
|
||||||
let command = Sys.argv.(1) in
|
let command = Sys.argv.(1) in
|
||||||
let _ =
|
(* Format.printf "Processing command %s (%d)\n" command l ; *)
|
||||||
match command with
|
match command with
|
||||||
| "compile" -> (
|
| "compile" -> (
|
||||||
let%bind () =
|
let%bind () =
|
||||||
if l <> 4
|
if l <> 4
|
||||||
then simple_fail "Bad number of argument to compile"
|
then simple_fail "Bad number of argument to compile"
|
||||||
else ok () in
|
else ok () in
|
||||||
let source = Sys.argv.(2) in
|
let source = Sys.argv.(2) in
|
||||||
let entry_point = Sys.argv.(3) in
|
let entry_point = Sys.argv.(3) in
|
||||||
let%bind michelson = Ligo.compile_file source entry_point in
|
(* Format.printf "Compiling %s from %s\n%!" entry_point source ; *)
|
||||||
Format.printf "%a" Micheline.Michelson.pp michelson ;
|
let%bind michelson =
|
||||||
ok ()
|
trace (simple_error "compile michelson") @@
|
||||||
)
|
Ligo.compile_file source entry_point in
|
||||||
|
Format.printf "Program : %a\n" Micheline.Michelson.pp michelson ;
|
||||||
|
ok ()
|
||||||
|
)
|
||||||
| _ -> simple_fail "Bad command"
|
| _ -> simple_fail "Bad command"
|
||||||
in
|
|
||||||
()
|
let () = toplevel @@ main ()
|
||||||
|
@ -2,3 +2,4 @@ module Parser = Parser
|
|||||||
module AST = AST
|
module AST = AST
|
||||||
module Lexer = Lexer
|
module Lexer = Lexer
|
||||||
module LexToken = LexToken
|
module LexToken = LexToken
|
||||||
|
module ParserLog = ParserLog
|
||||||
|
@ -59,7 +59,7 @@ let rec value ppf : value -> unit = function
|
|||||||
and value_assoc ppf : (value * value) -> unit = fun (a, b) ->
|
and value_assoc ppf : (value * value) -> unit = fun (a, b) ->
|
||||||
fprintf ppf "%a -> %a" value a value b
|
fprintf ppf "%a -> %a" value a value b
|
||||||
|
|
||||||
and expression ppf ((e, _, _):expression) = match e with
|
and expression' ppf (e:expression') = match e with
|
||||||
| E_variable v -> fprintf ppf "%s" v
|
| E_variable v -> fprintf ppf "%s" v
|
||||||
| E_application(a, b) -> fprintf ppf "(%a)@(%a)" expression a expression b
|
| E_application(a, b) -> fprintf ppf "(%a)@(%a)" expression a expression b
|
||||||
| E_constant(p, lst) -> fprintf ppf "%s %a" p (pp_print_list ~pp_sep:space_sep expression) lst
|
| E_constant(p, lst) -> fprintf ppf "%s %a" p (pp_print_list ~pp_sep:space_sep expression) lst
|
||||||
@ -69,8 +69,14 @@ and expression ppf ((e, _, _):expression) = match e with
|
|||||||
| E_make_none _ -> fprintf ppf "none"
|
| E_make_none _ -> fprintf ppf "none"
|
||||||
| E_Cond (c, a, b) -> fprintf ppf "%a ? %a : %a" expression c expression a expression b
|
| E_Cond (c, a, b) -> fprintf ppf "%a ? %a : %a" expression c expression a expression b
|
||||||
|
|
||||||
and function_ ppf ({binder ; input ; output ; body ; result}:anon_function_content) =
|
and expression ppf (e', _, _) = expression' ppf e'
|
||||||
fprintf ppf "fun (%s:%a) : %a %a return %a"
|
|
||||||
|
and function_ ppf ({binder ; input ; output ; body ; result ; capture_type}:anon_function_content) =
|
||||||
|
fprintf ppf "fun[%s] (%s:%a) : %a %a return %a"
|
||||||
|
(match capture_type with
|
||||||
|
| No_capture -> "quote"
|
||||||
|
| Shallow_capture _ -> "shallow"
|
||||||
|
| Deep_capture _ -> "deep")
|
||||||
binder
|
binder
|
||||||
type_ input
|
type_ input
|
||||||
type_ output
|
type_ output
|
||||||
|
@ -432,12 +432,20 @@ type compiled_program = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let translate_program (p:program) (entry:string) : compiled_program result =
|
let translate_program (p:program) (entry:string) : compiled_program result =
|
||||||
let is_main ((s, _):toplevel_statement) = match s with
|
let is_main ((s, _):toplevel_statement) =
|
||||||
| name , (E_function f, T_function (_, _), _) when f.capture_type = No_capture && name = entry -> Some f
|
match s with
|
||||||
| _ -> None in
|
| name , (E_function f, T_function (_, _), _)
|
||||||
|
when f.capture_type = No_capture && name = entry ->
|
||||||
|
Some f
|
||||||
|
| name , (E_literal (D_function {content ; capture = None}), T_function (_, _), _)
|
||||||
|
when name = entry ->
|
||||||
|
Some content
|
||||||
|
| _ -> None
|
||||||
|
in
|
||||||
let%bind main =
|
let%bind main =
|
||||||
trace_option (simple_error "no functional entry") @@
|
trace_option (simple_error "no functional entry") @@
|
||||||
Tezos_utils.List.find_map is_main p in
|
Tezos_utils.List.find_map is_main p
|
||||||
|
in
|
||||||
let {input;output} : anon_function_content = main in
|
let {input;output} : anon_function_content = main in
|
||||||
let%bind body = translate_function_body main in
|
let%bind body = translate_function_body main in
|
||||||
let%bind input = Compiler_type.Ty.type_ input in
|
let%bind input = Compiler_type.Ty.type_ input in
|
||||||
|
@ -401,7 +401,7 @@ and simpl_single_instruction : Raw.single_instr -> instruction result = fun t ->
|
|||||||
ok @@ I_assignment {name = name.value ; annotated_expression = value_expr}
|
ok @@ I_assignment {name = name.value ; annotated_expression = value_expr}
|
||||||
)
|
)
|
||||||
| Path path -> (
|
| Path path -> (
|
||||||
let err_content () = Format.asprintf "%a" (PP_helpers.printer Raw.print_path) path in
|
let err_content () = Format.asprintf "%a" (PP_helpers.printer Ligo_parser.ParserLog.print_path) path in
|
||||||
fail @@ (fun () -> error (thunk "no path assignments") err_content ())
|
fail @@ (fun () -> error (thunk "no path assignments") err_content ())
|
||||||
)
|
)
|
||||||
| MapPath v -> (
|
| MapPath v -> (
|
||||||
@ -432,7 +432,7 @@ and simpl_single_instruction : Raw.single_instr -> instruction result = fun t ->
|
|||||||
let%bind record = match r.path with
|
let%bind record = match r.path with
|
||||||
| Name v -> ok v.value
|
| Name v -> ok v.value
|
||||||
| path -> (
|
| path -> (
|
||||||
let err_content () = Format.asprintf "%a" (PP_helpers.printer Raw.print_path) path in
|
let err_content () = Format.asprintf "%a" (PP_helpers.printer Ligo_parser.ParserLog.print_path) path in
|
||||||
fail @@ (fun () -> error (thunk "no complex record patch yet") err_content ())
|
fail @@ (fun () -> error (thunk "no complex record patch yet") err_content ())
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
|
Loading…
Reference in New Issue
Block a user