From 1cdb8d8f6c328037b8f1b9446a497e0e94861f19 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Wed, 17 Jan 2024 09:16:47 -0600 Subject: Start of discocaml. --- .gitignore | 1 + discocaml/default.nix | 10 ++++++++++ discocaml/dune | 7 +++++++ discocaml/dune-project | 6 ++++++ discocaml/main.ml | 27 +++++++++++++++++++++++++++ flake.nix | 13 ++++++++++--- 6 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 discocaml/default.nix create mode 100644 discocaml/dune create mode 100644 discocaml/dune-project create mode 100644 discocaml/main.ml diff --git a/.gitignore b/.gitignore index 4c39c23..3476910 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ result result-* # Non-Nix outputs +_build/ target/ # Configuration and state files diff --git a/discocaml/default.nix b/discocaml/default.nix new file mode 100644 index 0000000..0045cdf --- /dev/null +++ b/discocaml/default.nix @@ -0,0 +1,10 @@ +{ buildDunePackage, ocaml-compiler-libs, ppx_deriving, ppx_import, ppxlib }: + +buildDunePackage { + pname = "discocaml"; + version = "0.1.0"; + minimalOcamlVersion = "5.1"; + src = ./.; + nativeBuildInputs = [ ]; + buildInputs = [ ppx_deriving ppx_import ppxlib ]; +} diff --git a/discocaml/dune b/discocaml/dune new file mode 100644 index 0000000..02fcc09 --- /dev/null +++ b/discocaml/dune @@ -0,0 +1,7 @@ +(executable + (libraries compiler-libs.common) + (name main) + (package discocaml) + (preprocess + (staged_pps ppx_import ppx_deriving.show)) + (public_name discocaml)) diff --git a/discocaml/dune-project b/discocaml/dune-project new file mode 100644 index 0000000..bd6504b --- /dev/null +++ b/discocaml/dune-project @@ -0,0 +1,6 @@ +(lang dune 3.8) + +(package + (name discocaml) + (synopsis "Some tools for interacting with OCaml with a Discord bot") + (depends)) diff --git a/discocaml/main.ml b/discocaml/main.ml new file mode 100644 index 0000000..2cc97b5 --- /dev/null +++ b/discocaml/main.ml @@ -0,0 +1,27 @@ +(* +type position = [%import: Lexing.position] [@@deriving show] + +type location = [%import: (Location.t[@with Lexing.position := position])] +[@@deriving show] + +type constant = [%import: Parsetree.constant] [@@deriving show] +type expression_desc = [%import: Parsetree.expression_desc] [@@deriving show] +type expression = [%import: Parsetree.expression] [@@deriving show] + +type structure_item_desc = [%import: Parsetree.structure_item_desc] +[@@deriving show] + +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 + +let () = + parse ~path:"main.ml" "let () = print_endline ((\"Hello, world!\") )" + |> List.iter (Pprintast.toplevel_phrase Format.std_formatter) diff --git a/flake.nix b/flake.nix index 15c47ca..aeb0b59 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,7 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + ocamlPkgs = pkgs.ocaml-ng.ocamlPackages_5_1; toolchain = fenix.packages.${system}.stable.withComponents [ "cargo" "rustc" @@ -20,16 +21,22 @@ in rec { devShells.default = pkgs.mkShell { inputsFrom = builtins.attrValues packages; - nativeBuildInputs = [ pkgs.cargo-watch pkgs.sqlite pkgs.sqlx-cli ]; + nativeBuildInputs = + [ pkgs.cargo-watch ocamlPkgs.ocaml-lsp pkgs.sqlite pkgs.sqlx-cli ]; }; - packages.default = - let toml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + packages = { + default = packages.lambo; + + discocaml = ocamlPkgs.callPackage ./discocaml { }; + + lambo = let toml = builtins.fromTOML (builtins.readFile ./Cargo.toml); in rust.buildRustPackage { pname = toml.package.name; version = toml.package.version; src = ./.; cargoLock.lockFile = ./Cargo.lock; }; + }; }); } -- cgit v1.2.3