Added traces for system and command errors. Added handling of #include.
This commit is contained in:
parent
ee190174fe
commit
206a3dbd35
1
src/ligo/contracts/included.ligo
Normal file
1
src/ligo/contracts/included.ligo
Normal file
@ -0,0 +1 @@
|
|||||||
|
const foo : int = 144
|
3
src/ligo/contracts/includer.ligo
Normal file
3
src/ligo/contracts/includer.ligo
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "included.ligo"
|
||||||
|
|
||||||
|
const bar : int = foo
|
@ -153,6 +153,18 @@ let specific_try handler f =
|
|||||||
ok @@ f ()
|
ok @@ f ()
|
||||||
) with exn -> fail (handler exn)
|
) with exn -> fail (handler exn)
|
||||||
|
|
||||||
|
let sys_try f =
|
||||||
|
let handler = function
|
||||||
|
| Sys_error str -> error "Sys_error" str
|
||||||
|
| exn -> raise exn
|
||||||
|
in
|
||||||
|
specific_try handler f
|
||||||
|
|
||||||
|
let sys_command command =
|
||||||
|
sys_try (fun () -> Sys.command command) >>? function
|
||||||
|
| 0 -> ok ()
|
||||||
|
| n -> fail (error "Nonzero return code" (string_of_int n))
|
||||||
|
|
||||||
let sequence f lst =
|
let sequence f lst =
|
||||||
let rec aux acc = function
|
let rec aux acc = function
|
||||||
| hd :: tl -> (
|
| hd :: tl -> (
|
||||||
|
@ -98,21 +98,3 @@ let () =
|
|||||||
let () = close_all () in
|
let () = close_all () in
|
||||||
print_error ~offsets EvalOpt.mode error
|
print_error ~offsets EvalOpt.mode error
|
||||||
| Sys_error msg -> Utils.highlight msg
|
| Sys_error msg -> Utils.highlight msg
|
||||||
|
|
||||||
(*
|
|
||||||
(* Temporary: force dune to build AST2.ml *)
|
|
||||||
let () =
|
|
||||||
let open AST2 in
|
|
||||||
let _ = s_ast in
|
|
||||||
()
|
|
||||||
|
|
||||||
(*
|
|
||||||
(* Temporary: force dune to build AST2.ml *)
|
|
||||||
let () =
|
|
||||||
if false then
|
|
||||||
let _ = Typecheck2.annotate in
|
|
||||||
()
|
|
||||||
else
|
|
||||||
()
|
|
||||||
*)
|
|
||||||
*)
|
|
||||||
|
@ -10,10 +10,20 @@ module Typer = Typer
|
|||||||
module Transpiler = Transpiler
|
module Transpiler = Transpiler
|
||||||
|
|
||||||
open Ligo_helpers.Trace
|
open Ligo_helpers.Trace
|
||||||
|
|
||||||
let parse_file (source: string) : AST_Raw.t result =
|
let parse_file (source: string) : AST_Raw.t result =
|
||||||
|
let pp_input =
|
||||||
|
let prefix = Filename.(source |> basename |> remove_extension)
|
||||||
|
and suffix = ".pp.ligo"
|
||||||
|
in prefix ^ suffix in
|
||||||
|
|
||||||
|
let cpp_cmd = Printf.sprintf "cpp -traditional-cpp %s -o %s"
|
||||||
|
source pp_input in
|
||||||
|
let%bind () = sys_command cpp_cmd in
|
||||||
|
|
||||||
let%bind channel =
|
let%bind channel =
|
||||||
generic_try (simple_error "error opening file") @@
|
generic_try (simple_error "error opening file") @@
|
||||||
(fun () -> open_in source) in
|
(fun () -> open_in pp_input) in
|
||||||
let lexbuf = Lexing.from_channel channel in
|
let lexbuf = Lexing.from_channel channel in
|
||||||
let module Lexer = Lexer.Make(LexToken) in
|
let module Lexer = Lexer.Make(LexToken) in
|
||||||
let Lexer.{read ; close} =
|
let Lexer.{read ; close} =
|
||||||
|
@ -76,6 +76,14 @@ let unit_expression () : unit result =
|
|||||||
get_a_unit result in
|
get_a_unit result in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
|
let include_ () : unit result =
|
||||||
|
let%bind program = type_file "./contracts/includer.ligo" in
|
||||||
|
let%bind result = easy_evaluate_typed "bar" program in
|
||||||
|
let%bind n =
|
||||||
|
trace (simple_error "Include failed") @@
|
||||||
|
AST_Typed.Combinators.get_a_int result in
|
||||||
|
Assert.assert_equal_int 144 n
|
||||||
|
|
||||||
let record_ez_int names n =
|
let record_ez_int names n =
|
||||||
let open AST_Typed.Combinators in
|
let open AST_Typed.Combinators in
|
||||||
ez_e_a_record @@ List.map (fun x -> x, e_a_int n) names
|
ez_e_a_record @@ List.map (fun x -> x, e_a_int n) names
|
||||||
@ -337,4 +345,5 @@ let main = "Integration (End to End)", [
|
|||||||
test "declarations" declarations ;
|
test "declarations" declarations ;
|
||||||
test "quote declaration" quote_declaration ;
|
test "quote declaration" quote_declaration ;
|
||||||
test "quote declarations" quote_declarations ;
|
test "quote declarations" quote_declarations ;
|
||||||
|
test "#include directives" include_ ;
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user