Skip to content

Commit

Permalink
bucklescript to melange
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri committed Oct 23, 2023
1 parent 2550857 commit af5df80
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 211 deletions.
10 changes: 5 additions & 5 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
/atd/ @mjambon
/atdcat/ @mjambon

# OCaml and Bucklescript support
# OCaml and Melange support
/atdgen-runtime/ @rgrinberg @mjambon
/atdgen/ @rgrinberg @mjambon

# Bucklescript-specific files
obuckle_* @rgrinberg
bucklescript/ @rgrinberg
*_bs* @rgrinberg
# Melange-specific files
omelange_* @rgrinberg @jchavarri
melange/ @rgrinberg @jchavarri
*_mel* @rgrinberg @jchavarri

# Java support
# /atdj/ YOUR_NAME_HERE
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Contributing to a specific subproject

Each subproject has its own README:

* [atdgen](atdgen): targets OCaml, Bucklescript
* [atdgen](atdgen): targets OCaml, Melange
* [atdj](atdj): targets Java
* [atdpy](atdpy): targets Python
* [atds](atds): targets Scala
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and type-safe serializers, deserializers and validators.
Target programming languages currently supported:
* DLang: [atdd](atdd)
* Java: [atdj](atdj)
* OCaml, Bucklescript: [atdgen](atdgen)
* OCaml, Melange: [atdgen](atdgen)
* Python: [atdpy](atdpy)
* Scala: [atds](atds)
* TypeScript: [atdts](atdts)
Expand Down
4 changes: 2 additions & 2 deletions atdgen-codec-runtime.opam
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Runtime for atdgen generated bucklescript converters"
synopsis: "Runtime for atdgen generated Melange converters"
description: """
This library contains the types that are used by atdgen's
bucklescript backend"""
Melange backend"""
maintainer: [
"Louis Roché <louis@louisroche.net>"
"Martin Jambon <martin@mjambon.com>"
Expand Down
26 changes: 13 additions & 13 deletions atdgen/bin/ag_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type mode =
| Biniou (* -biniou (deprecated) *)
| Json (* -json (deprecated) *)
| Validate (* -validate (deprecated) *)
| Bucklescript (* -bs (bucklescript) *)
| Melange (* -mel (melange) *)

let parse_ocaml_version () =
let re = Re.Str.regexp "^\\([0-9]+\\)\\.\\([0-9]+\\)" in
Expand Down Expand Up @@ -123,12 +123,12 @@ let main () =
containing OCaml serializers and deserializers for the JSON
data format from the specifications in example.atd.";

"-bs", Arg.Unit (fun () -> set_once "output type" mode Bucklescript),
"-mel", Arg.Unit (fun () -> set_once "output type" mode Melange),
"
Produce files example_bs.mli and example_bs.ml
Produce files example_mel.mli and example_mel.ml
containing OCaml serializers and deserializers for the JSON
data format from the specifications in example.atd using
bucklescript's json api.";
Melange's JSON api.";


"-v", Arg.Unit (fun () -> set_once "output type" mode V),
Expand Down Expand Up @@ -287,7 +287,7 @@ Generate OCaml code offering:
* record-creating functions supporting default fields (-v)
* user-specified data validators (-v)
Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-mel) example.atd" Sys.argv.(0) in
Arg.parse options (fun file -> files := file :: !files) msg;

if (!std_json
Expand All @@ -305,7 +305,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
Some x -> x
| None ->
match mode with
T | B | J | Bucklescript -> false
T | B | J | Melange -> false
| V -> true
| Biniou | Json | Validate -> true
| Dep | List -> true (* don't care *)
Expand All @@ -317,7 +317,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
| T
| B | Biniou
| V | Validate
| Bucklescript
| Melange
| Dep | List -> false (* don't care *)
in

Expand Down Expand Up @@ -351,7 +351,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
| B -> base ^ "_b"
| J -> base ^ "_j"
| V -> base ^ "_v"
| Bucklescript -> base ^ "_bs"
| Melange -> base ^ "_mel"
| Dep
| List
| Biniou
Expand All @@ -363,7 +363,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
match base_prefix with
None ->
(match mode with
B | J | V | Bucklescript -> Some "T"
B | J | V | Melange -> Some "T"
| Biniou | Validate
| T | Dep | List
| Json -> None
Expand All @@ -373,7 +373,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
Some _ as x -> x
| None ->
(match mode with
B | J | V | Bucklescript ->
B | J | V | Melange ->
Some (String.capitalize_ascii (Filename.basename base) ^ "_t")
| T | Json | Dep | List | Validate
| Biniou -> None
Expand All @@ -387,7 +387,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
match mode with
Dep -> print_deps (get_base_prefix ())
| List -> print_file_list (get_base_prefix ())
| Bucklescript
| Melange
| T | B | J | V | Biniou | Json | Validate ->

let opens = List.rev !opens in
Expand All @@ -404,8 +404,8 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list|-bs) example.atd" Sys.argv.(0) in
~preprocess_input: !j_preprocess_input
| V | Validate ->
Ov_emit.make_ocaml_files
| Bucklescript ->
Obuckle_emit.make_ocaml_files
| Melange ->
Omelange_emit.make_ocaml_files
| Dep | List -> assert false
in
let with_default default = function None -> default | Some x -> x in
Expand Down
10 changes: 5 additions & 5 deletions atdgen/src/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ module Repr = struct
| Def of atd_ocaml_def
end

type target = Default | Biniou | Json | Validate | Bucklescript
type target = Default | Biniou | Json | Validate | Melange

let all_targets = [ Default; Biniou; Json; Validate; Bucklescript ]
let all_targets = [ Default; Biniou; Json; Validate; Melange ]

let ocaml_int_of_string s : atd_ocaml_int option =
match s with
Expand Down Expand Up @@ -134,7 +134,7 @@ let path_of_target (target : target) =
| Default -> [ "ocaml" ]
| Biniou -> [ "ocaml_biniou"; "ocaml" ]
| Json -> [ "ocaml_json"; "ocaml" ]
| Bucklescript -> ["ocaml_bs"; "ocaml"]
| Melange -> ["ocaml_mel"; "ocaml"]
| Validate -> [ "ocaml_validate"; "ocaml" ]

(*
Expand Down Expand Up @@ -178,7 +178,7 @@ let annot_schema_of_target (target : target) : Atd.Annot.schema =
| Default -> []
| Biniou -> Biniou.annot_schema_biniou
| Json -> Json.annot_schema_json
| Bucklescript -> Json.annot_schema_json
| Melange -> Json.annot_schema_json
| Validate -> []
in
ocaml_sections @ other_section
Expand Down Expand Up @@ -364,7 +364,7 @@ let get_ocaml_module target an =
| Default -> type_module
| Biniou -> s ^ "_b"
| Json -> s ^ "_j"
| Bucklescript -> s ^ "_bs"
| Melange -> s ^ "_mel"
| Validate -> s ^ "_v"
in
(type_module, main_module))
Expand Down
2 changes: 1 addition & 1 deletion atdgen/src/ocaml.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type atd_ocaml_sum = Classic | Poly
type atd_ocaml_record = Record | Object
type atd_ocaml_int = Int | Char | Int32 | Int64 | Float
type atd_ocaml_list = List | Array
type target = Default | Biniou | Json | Validate | Bucklescript
type target = Default | Biniou | Json | Validate | Melange

type atd_ocaml_wrap = {
ocaml_wrap_t : string;
Expand Down
4 changes: 2 additions & 2 deletions atdgen/src/oj_mapping.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ and mapping_of_field ocaml_field_prefix = function
let defs_of_atd_modules l ~(target : Ocaml.target)=
(match target with
| Json
| Bucklescript -> ()
| t -> invalid_arg "target must be json or bucklescript");
| Melange -> ()
| t -> invalid_arg "target must be json or melange");
List.map (fun (is_rec, l) ->
( is_rec
, List.map (function Atd.Ast.Type atd ->
Expand Down
20 changes: 10 additions & 10 deletions atdgen/src/obuckle_emit.ml → atdgen/src/omelange_emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ type param =
-> (Ocaml.Repr.t, Json.json_repr) Mapping.mapping;
}

let target : Ocaml.target = Bucklescript
let target : Ocaml.target = Melange
let annot_schema = Ocaml.annot_schema_of_target target

let open_enum_not_supported () =
failwith "open_enum is not supported in bucklescript mode"
failwith "open_enum is not supported in melange mode"

let runtime_module = "Atdgen_codec_runtime"

Expand Down Expand Up @@ -57,7 +57,7 @@ let destruct_sum (x : Oj_mapping.t) =
| _ -> Error.error (loc_of_mapping x) "Cannot destruct unknown type"


let make_ocaml_bs_intf ~with_create buf deref defs =
let make_ocaml_mel_intf ~with_create buf deref defs =
List.concat_map snd defs
|> List.filter Ox_emit.include_intf
|> List.iter (fun (x : (_, _) Mapping.def) ->
Expand Down Expand Up @@ -323,7 +323,7 @@ let get_left_reader_name p name param =
let args = List.map (fun s -> Mapping.Tvar (Atd.Ast.dummy_loc, s)) param in
get_reader_name p (Mapping.Name (Atd.Ast.dummy_loc, name, args, None, None))
let make_ocaml_bs_reader p ~original_types is_rec let1 _let2
let make_ocaml_mel_reader p ~original_types is_rec let1 _let2
(def : (_, _) Mapping.def) =
let x = Option.value_exn def.def_value in
let name = def.def_name in
Expand Down Expand Up @@ -593,7 +593,7 @@ and make_sum_writer ?type_annot (p : param)
; Block cases
; Line ")"]
let make_ocaml_bs_writer p ~original_types is_rec let1 _let2
let make_ocaml_mel_writer p ~original_types is_rec let1 _let2
(def : (_, _) Mapping.def) =
let x = Option.value_exn def.def_value in
let name = def.def_name in
Expand All @@ -618,7 +618,7 @@ let make_ocaml_bs_writer p ~original_types is_rec let1 _let2
Line (sprintf ")%s" extra_args);
]
let make_ocaml_bs_impl
let make_ocaml_mel_impl
~with_create
~original_types
buf deref defs =
Expand All @@ -631,12 +631,12 @@ let make_ocaml_bs_impl
let writers =
List.map_first (fun ~is_first def ->
let let1, let2 = Ox_emit.get_let ~is_rec ~is_first in
make_ocaml_bs_writer p ~original_types is_rec let1 let2 def
make_ocaml_mel_writer p ~original_types is_rec let1 let2 def
) l in
let readers =
List.map_first (fun ~is_first def ->
let let1, let2 = Ox_emit.get_let ~is_rec ~is_first in
make_ocaml_bs_reader p ~original_types is_rec let1 let2 def
make_ocaml_mel_reader p ~original_types is_rec let1 let2 def
) l
in
List.flatten (writers @ readers))
Expand All @@ -659,7 +659,7 @@ let make_ml
if with_typedefs && with_fundefs then
bprintf buf "\n";
if with_fundefs then
make_ocaml_bs_impl ~with_create ~original_types buf deref defs;
make_ocaml_mel_impl ~with_create ~original_types buf deref defs;
Buffer.contents buf
let make_mli
Expand All @@ -678,7 +678,7 @@ let make_mli
if with_typedefs && with_fundefs then
bprintf buf "\n";
if with_fundefs then
make_ocaml_bs_intf ~with_create buf deref defs;
make_ocaml_mel_intf ~with_create buf deref defs;
Buffer.contents buf
let make_ocaml_files
Expand Down
File renamed without changes.
51 changes: 0 additions & 51 deletions atdgen/test/bucklescript/dune

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions atdgen/test/melange/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(rule
(targets melangespec_mel.ml melangespec_mel.mli)
(deps melangespec.atd)
(action (run atdgen %{deps} -mel)))

(rule
(targets melangespec_t.ml melangespec_t.mli)
(deps melangespec.atd)
(action (run atdgen %{deps} -t)))

(rule
(targets melangespec_j.ml melangespec_j.mli)
(deps melangespec.atd)
(action (run atdgen %{deps} -j -j-std)))

(library
(name melangespec_types)
(wrapped false)
(libraries atdgen-codec-runtime)
(modules melangespec_t a_t a_mel))

(library
(name melangespec_mel)
(wrapped false)
(libraries atdgen-codec-runtime melangespec_types)
(modules melangespec_mel))

(executable
(name melangespec_roundtrip)
(modules melangespec_roundtrip melangespec_j a_j)
(libraries melangespec_types melangespec_mel atdgen-runtime atdgen-codec-runtime biniou yojson))

(rule
(alias runtest)
(package atdgen)
(action (diff melangespec_mel.expected.ml melangespec_mel.ml)))

(rule
(alias runtest)
(package atdgen)
(action (diff melangespec_mel.expected.mli melangespec_mel.mli)))

(rule
(alias runtest)
(package atdgen)
(action (diff melangespec_j.expected.ml melangespec_j.ml)))

(rule
(alias runtest)
(package atdgen)
(action (run ./melangespec_roundtrip.exe)))
File renamed without changes.
Loading

0 comments on commit af5df80

Please sign in to comment.