Skip to content

Commit

Permalink
umm working?
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Sep 7, 2018
1 parent 4afa674 commit 59d50e1
Show file tree
Hide file tree
Showing 53 changed files with 619 additions and 22 deletions.
3 changes: 3 additions & 0 deletions belt/dune
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
(include_subdirs unqualified)

(library
(c_names stubs)
(name Belt))
12 changes: 12 additions & 0 deletions belt/stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>

CAMLprim value belt_makemutablelist(value a, value l) {
CAMLparam2(a, l);
CAMLlocal1(box);
box = caml_alloc_small(2, 0);
Field(box, 0) = a;
Field(box, 1) = l;
CAMLreturn(box);
}
31 changes: 15 additions & 16 deletions belt_ppx/Belt_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ let mapper =
let loc = e.pexp_loc in
begin match e.pexp_desc with
| Pexp_apply({pexp_desc=Pexp_ident {txt = Lident "|."; _}; _}, ["", obj_arg; "", fn]) ->
(* | Pexp_ident {txt = Lident "|."} -> *)
(*
a |. f
a |. f b c [@bs] --> f a b c [@bs]
*)
let new_obj_arg = self.expr self obj_arg in
begin match fn with
| {pexp_desc = Pexp_apply (fn, args); pexp_loc; _} ->
let fn = self.expr self fn in
let args = List.map (fun (lab,exp) -> lab, self.expr self exp ) args in
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", new_obj_arg) :: args);
pexp_attributes = [];
pexp_loc = pexp_loc}
| _ -> Exp.apply ~loc (self.expr self fn) ["", new_obj_arg]
end
let new_obj_arg = self.expr self obj_arg in
begin match fn with
| {pexp_desc = Pexp_apply (fn, args); pexp_loc; _} ->
let fn = self.expr self fn in
let args = List.map (fun (lab,exp) -> lab, self.expr self exp ) args in
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", new_obj_arg) :: args);
pexp_attributes = [];
pexp_loc = pexp_loc}
| {pexp_desc = Pexp_construct (lident, None); pexp_loc; _} ->
{ Parsetree.pexp_desc = Pexp_construct(lident, (Some new_obj_arg));
pexp_attributes = [];
pexp_loc = pexp_loc}
| _ -> Exp.apply ~loc (self.expr self fn) ["", new_obj_arg]
end
| _ -> Ast_mapper.default_mapper.expr self e
end
}

let () = Driver.register ~name:"ppx_lwt" ~args:[] Versions.ocaml_402 (fun _config _cookies -> mapper)
let () = Driver.register ~name:"ppx_belt" ~args:[] Versions.ocaml_402 (fun _config _cookies -> mapper)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions ppx/Ppx_Monads.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ the result of the whole thing to be unit, use `let%consume`.
*/

open Migrate_parsetree
open OCaml_402.Ast

/***
* https://ocsigen.org/lwt/dev/api/Ppx_lwt
* https://github.com/zepalmer/ocaml-monadic
Expand Down Expand Up @@ -148,7 +151,7 @@ This is intented for performing side-effects only -- `otherStuff`
must end up as type `unit`.
|};

let mapper = _argv =>
let mapper =
Parsetree.{
...Ast_mapper.default_mapper,
expr: (mapper, expr) =>
Expand Down Expand Up @@ -184,4 +187,4 @@ let mapper = _argv =>
}
};

let () = Ast_mapper.run_main(mapper);
let () = Driver.register(~name="ppx_monads", ~args=[], Versions.ocaml_402, (_config, _cookies) => mapper);
7 changes: 7 additions & 0 deletions ppx/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

(library
(name Ppx_monads)
(libraries compiler-libs ocaml-migrate-parsetree ppx_tools_versioned)
(preprocess (pps ppx_tools_versioned.metaquot_402))
(kind ppx_rewriter))

2 changes: 1 addition & 1 deletion src/analyze/Hover.re
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ let newHover = (~rootUri, ~file: SharedTypes.file, ~extra, ~getModule, ~markdown
}
};

Some(String.concat("\n\n", parts |. Belt_List.keepMap(x => x)))
Some(String.concat("\n\n", parts |. Belt.List.keepMap(x => x)))
} |? typeString)

}
Expand Down
6 changes: 3 additions & 3 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
(executable
(name Bin)
(public_name Bin)
(libraries compiler-libs Belt Vendor ocaml-migrate-parsetree ppx_tools_versioned)
(flags :standard -open Vendor)
(preprocess (pps Belt_ppx )))
(libraries compiler-libs.common Belt Vendor str)
(flags :standard -open Vendor -w -26)
(preprocess (pps Belt_ppx Ppx_monads)))
Loading

0 comments on commit 59d50e1

Please sign in to comment.