aboutsummaryrefslogtreecommitdiff
path: root/discocaml
diff options
context:
space:
mode:
Diffstat (limited to 'discocaml')
-rw-r--r--discocaml/default.nix6
-rw-r--r--discocaml/dune6
-rw-r--r--discocaml/main.ml27
3 files changed, 30 insertions, 9 deletions
diff --git a/discocaml/default.nix b/discocaml/default.nix
index 0045cdf..392c146 100644
--- a/discocaml/default.nix
+++ b/discocaml/default.nix
@@ -1,10 +1,10 @@
-{ buildDunePackage, ocaml-compiler-libs, ppx_deriving, ppx_import, ppxlib }:
+{ buildDunePackage, yojson, ocaml-compiler-libs, ppx_deriving
+, ppx_deriving_yojson, ppx_import, ppxlib }:
buildDunePackage {
pname = "discocaml";
version = "0.1.0";
minimalOcamlVersion = "5.1";
src = ./.;
- nativeBuildInputs = [ ];
- buildInputs = [ ppx_deriving ppx_import ppxlib ];
+ buildInputs = [ ppx_deriving ppx_deriving_yojson ppx_import ppxlib yojson ];
}
diff --git a/discocaml/dune b/discocaml/dune
index 02fcc09..695d78f 100644
--- a/discocaml/dune
+++ b/discocaml/dune
@@ -1,7 +1,9 @@
(executable
- (libraries compiler-libs.common)
+ (flags
+ (:standard -cclib -static -cclib -lm))
+ (libraries compiler-libs.common yojson)
(name main)
(package discocaml)
(preprocess
- (staged_pps ppx_import ppx_deriving.show))
+ (staged_pps ppx_import ppx_deriving.show ppx_deriving_yojson))
(public_name discocaml))
diff --git a/discocaml/main.ml b/discocaml/main.ml
index 2cc97b5..d9895f1 100644
--- a/discocaml/main.ml
+++ b/discocaml/main.ml
@@ -1,3 +1,14 @@
+type command = [ `Roundtrip ]
+
+let command_of_yojson = function
+ | `String "Roundtrip" -> Ok `Roundtrip
+ | _ -> Error "invalid command"
+
+type request = { expr : string; command : command }
+[@@deriving of_yojson { exn = true }]
+
+type response = [ `Error of string ] [@@deriving to_yojson { exn = true }]
+
(*
type position = [%import: Lexing.position] [@@deriving show]
@@ -14,14 +25,22 @@ type structure_item_desc = [%import: Parsetree.structure_item_desc]
type structure_item = [%import: Parsetree.structure_item] [@@deriving show]
type structure = [%import: Parsetree.structure] [@@deriving show]
type toplevel_phrase = [%import: Parsetree.toplevel_phrase] [@@deriving show]
-*)
let parse ~path (src : string) =
let buf = Lexing.from_string src in
buf.lex_start_p <- { buf.lex_start_p with pos_fname = path };
buf.lex_curr_p <- { buf.lex_curr_p with pos_fname = path };
- Parse.use_file buf
+ Parse.expression buf
+
+let () =
+ parse ~path:"main.ml" " print_endline ((\"Hello, world!\") )"
+ |> Format.fprintf Format.std_formatter "\n%a\n" Pprintast.expression
+*)
+
+let handle_request { expr; command } : response =
+ match command with `Roundtrip -> `Error ("TODO: " ^ expr)
let () =
- parse ~path:"main.ml" "let () = print_endline ((\"Hello, world!\") )"
- |> List.iter (Pprintast.toplevel_phrase Format.std_formatter)
+ Yojson.Safe.from_channel stdin
+ |> request_of_yojson_exn |> handle_request |> response_to_yojson
+ |> Yojson.Safe.to_channel stdout