diff --git a/.gitmodules b/.gitmodules index 9e0292d..a187044 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,9 @@ path = ostap url = https://github.com/PLTools/ostap.git branch = old+dune + +[submodule "ppx_blob"] + path = ppx_blob + url = https://github.com/actionshrimp/ppx_blob.git + branch = fix-for-dune-3 + diff --git a/.ocamlformat-enable b/.ocamlformat-enable index ebc7cdb..15bb652 100644 --- a/.ocamlformat-enable +++ b/.ocamlformat-enable @@ -1 +1,2 @@ client.ml +L3/testL3.ml \ No newline at end of file diff --git a/L3/L3.ml b/L3/L3.ml index d433a33..ff0ec1a 100644 --- a/L3/L3.ml +++ b/L3/L3.ml @@ -451,19 +451,3 @@ let json_to_bytecode ~fk ~fk2 : Yojson.Safe.t -> SM.t = | _ -> fk2 "ожидался список" *) - - -let () = - let input = {| -let fix = { f x -> f ({ eta -> fix(f, eta) },x) } in -( let fac = { self n -> if n<=1 then 1 else n*self(n-1) fi } in - write(fix(fac, 4)) -) -|} in - match Parser.parse input with - | `Fail msg -> print_endline msg - | `Ok ast -> - match Program.eval [3] ast with - | rez -> Format.printf "%a\n%!" (Format.pp_print_list Format.pp_print_int) rez - | exception exc -> print_endline (Printexc.to_string exc) - diff --git a/L3/dune b/L3/dune index 3bcd626..3652aef 100644 --- a/L3/dune +++ b/L3/dune @@ -17,3 +17,20 @@ (preprocess (action (run %{project_root}/pp5+gt+plugins+ostap+dump.byte %{input-file})))) + +(library + (name testL3) + (modules testL3) + (libraries L3) + (inline_tests) + (flags + (:standard -rectypes)) + (preprocessor_deps + (file t01.l3) + (file t02.l3) + (file t03.l3) + (file t04.l3) + (file t05.l3) + (file t06.l3)) + (preprocess + (pps ppx_expect ppx_blob))) diff --git a/L3/testL3.ml b/L3/testL3.ml new file mode 100644 index 0000000..67cc3c4 --- /dev/null +++ b/L3/testL3.ml @@ -0,0 +1,50 @@ +open L3 + +let test input = + match Parser.parse input with + | `Fail msg -> print_endline msg + | `Ok ast -> ( + match Program.eval [ 3 ] ast with + | rez -> + Format.printf "%a\n%!" (Format.pp_print_list Format.pp_print_int) rez + | exception exc -> print_endline (Printexc.to_string exc)) + +let%expect_test " " = + test + {| +let fix = { f x -> f ({ eta -> fix(f, eta) },x) } in +( let fac = { self n -> if n<=1 then 1 else n*self(n-1) fi } in +write(fix(fac, 4)) +) +|}; + [%expect "L3.Program.Undefined(\"fix\")"] + +let%expect_test " " = + test [%blob "t01.l3"]; + [%expect " + 1 + 5"] + +let%expect_test " " = + test [%blob "t02.l3"]; + [%expect " + 543210 + 0"] + +let%expect_test " " = + test [%blob "t03.l3"]; + [%expect "120"] + +let%expect_test " " = + test [%blob "t04.l3"]; + [%expect "120"] + +let%expect_test " " = + test [%blob "t05.l3"]; + [%expect " + 1111 + 12"] + +let%expect_test " " = + test [%blob "t06.l3"]; + [%expect "120"] diff --git a/ppx_blob b/ppx_blob new file mode 160000 index 0000000..513d847 --- /dev/null +++ b/ppx_blob @@ -0,0 +1 @@ +Subproject commit 513d847e589e0638d90b83ac62467f5e65d9245f