From df84763eb2ff857c94200cbe719fd1e24987021d Mon Sep 17 00:00:00 2001 From: Galfour Date: Sat, 13 Apr 2019 13:26:13 +0000 Subject: [PATCH] basic bin --- src/ligo/bin/cli.ml | 25 ++++++++++++++++++++++++- src/ligo/bin/dune | 1 + src/ligo/ligo.ml | 20 ++++++++++++++++++++ src/ligo/ligo.opam | 1 - src/ligo/multifix/lex/generator.ml | 6 +++--- src/ligo/test/multifix_tests.ml | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/ligo/bin/cli.ml b/src/ligo/bin/cli.ml index 306831a00..145efa795 100644 --- a/src/ligo/bin/cli.ml +++ b/src/ligo/bin/cli.ml @@ -1 +1,24 @@ -let () = () +open Trace + +let () = + let l = Array.length Sys.argv in + if l < 2 + then raise (Failure "Pass a command") ; + Format.printf "Toto %d\n%!" (Array.length Sys.argv) ; + let command = Sys.argv.(1) in + let _ = + match command with + | "compile" -> ( + let%bind () = + if l <> 4 + then simple_fail "Bad number of argument to compile" + else ok () in + let source = Sys.argv.(2) in + let entry_point = Sys.argv.(3) in + let%bind michelson = Ligo.compile_file source entry_point in + Format.printf "%a" Micheline.Michelson.pp michelson ; + ok () + ) + | _ -> simple_fail "Bad command" + in + () diff --git a/src/ligo/bin/dune b/src/ligo/bin/dune index 1bc76350d..cde43dc40 100644 --- a/src/ligo/bin/dune +++ b/src/ligo/bin/dune @@ -3,6 +3,7 @@ (public_name ligo) (libraries tezos-utils + ligo ) (package ligo) (preprocess diff --git a/src/ligo/ligo.ml b/src/ligo/ligo.ml index 6d15a9ed8..c699fb0f7 100644 --- a/src/ligo/ligo.ml +++ b/src/ligo/ligo.ml @@ -128,6 +128,8 @@ let transpile_value let untranspile_value (v : Mini_c.value) (e:AST_Typed.type_value) : AST_Typed.annotated_expression result = Transpiler.untranspile v e +let compile : Mini_c.program -> string -> Mini_c.Compiler.compiled_program result = Mini_c.Compiler.translate_program + let type_file ?(debug_simplify = false) ?(debug_typed = false) (path:string) : AST_Typed.program result = let%bind raw = parse_file path in @@ -194,3 +196,21 @@ let easy_run_main (path:string) (input:string) : AST_Typed.annotated_expression let%bind simpl_expr = simplify_expr raw_expr in let%bind typed_expr = type_expression simpl_expr in easy_run_main_typed typed typed_expr + +let compile_file (source: string) (entry_point:string) : Micheline.Michelson.t result = + let%bind raw = + trace (simple_error "parsing") @@ + parse_file source in + let%bind simplified = + trace (simple_error "simplifying") @@ + simplify raw in + let%bind typed = + trace (simple_error "typing") @@ + type_ simplified in + let%bind mini_c = + trace (simple_error "transpiling") @@ + transpile typed in + let%bind {body = michelson} = + trace (simple_error "compiling") @@ + compile mini_c entry_point in + ok michelson diff --git a/src/ligo/ligo.opam b/src/ligo/ligo.opam index 459ced958..bf16e3e7f 100644 --- a/src/ligo/ligo.opam +++ b/src/ligo/ligo.opam @@ -12,7 +12,6 @@ depends: [ "menhir" "ppx_let" "tezos-utils" - "meta-michelson" ] build: [ [ "dune" "build" "-p" name "-j" jobs ] diff --git a/src/ligo/multifix/lex/generator.ml b/src/ligo/multifix/lex/generator.ml index eb52583fd..45104c0c2 100644 --- a/src/ligo/multifix/lex/generator.ml +++ b/src/ligo/multifix/lex/generator.ml @@ -126,9 +126,9 @@ let tokens = [ keyword "then" ; keyword "else" ; keyword "list" ; - keyword "block" ; - keyword "for" ; - keyword "const" ; + (* keyword "block" ; + * keyword "for" ; + * keyword "const" ; *) keyword "fun" ; keyword "match" ; keyword "with" ; diff --git a/src/ligo/test/multifix_tests.ml b/src/ligo/test/multifix_tests.ml index b079c6a59..f3236a246 100644 --- a/src/ligo/test/multifix_tests.ml +++ b/src/ligo/test/multifix_tests.ml @@ -20,6 +20,6 @@ let integration () : unit result = let main = "Multifix", [ test "basic" basic ; - test "simplfiy" simplify ; + test "simplify" simplify ; test "integration" integration ; ]