Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create atdgen-www binary and runtime #2

Draft
wants to merge 7 commits into
base: ahrefs/atdgen-www-form-original
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atd.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ license: "MIT"
homepage: "https://github.com/ahrefs/atd"
bug-reports: "https://github.com/ahrefs/atd/issues"
depends: [
"ocaml" {>= "4.02"}
"ocaml" {>= "4.03"}
"dune" {>= "1.11"}
"menhir"
"easy-format"
Expand Down
2 changes: 1 addition & 1 deletion atdgen-codec-runtime.opam
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ homepage: "https://github.com/ahrefs/atd"
bug-reports: "https://github.com/ahrefs/atd/issues"
depends: [
"dune" {>= "1.11"}
"ocaml" {>= "4.02"}
"ocaml" {>= "4.03"}
"odoc" {with-doc}
]
dev-repo: "git+https://github.com/ahrefs/atd.git"
Expand Down
2 changes: 1 addition & 1 deletion atdgen-cppo/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(install
(section bin)
(package atdgen)
(package atdgen-www)
(files atdgen-cppo cppo-json))
4 changes: 2 additions & 2 deletions atdgen-runtime/src/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name atdgen_runtime)
(public_name atdgen-runtime)
(name atdgen_www_runtime)
(public_name atdgen-www-runtime)
(libraries biniou yojson))
10 changes: 5 additions & 5 deletions atdgen-runtime/src/json_adapter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
(** Module signature required of any json adapter.
For example, an ATD annotation
[<json
adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field"]
adapter.ocaml="Atdgen_www_runtime.Json_adapter.Type_field"]
refers to the OCaml module
[Atdgen_runtime.Json_adapter.Type_field].
[Atdgen_www_runtime.Json_adapter.Type_field].
*)
module type S = sig
(** Convert a real json tree into an atd-compliant form. *)
Expand Down Expand Up @@ -46,7 +46,7 @@ end
type obj = [
| User of user
| ...
] <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
] <json adapter.ocaml="Atdgen_www_runtime.Json_adapter.Type_field">

type user = {
id: string;
Expand Down Expand Up @@ -102,7 +102,7 @@ end
type obj = [
| User of user
| ...
] <json adapter.ocaml="Atdgen_runtime.Json_adapter.One_field">
] <json adapter.ocaml="Atdgen_www_runtime.Json_adapter.One_field">

type user = {
id: string;
Expand Down Expand Up @@ -169,7 +169,7 @@ type payload = [
]}
and the module [My_adapter] defined as follows:
{[
module My_adapter = Atdgen_runtime.Json_adapter.Type_and_value_fields.Make(
module My_adapter = Atdgen_www_runtime.Json_adapter.Type_and_value_fields.Make(
struct
let type_field_name = "type"
let value_field_name = "payload"
Expand Down
2 changes: 1 addition & 1 deletion atdgen-runtime/src/util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ sig
Its preset behavior is to call [preset_unknown_field_handler]
which raises a [Failure] exception.

Usage: [!Atdgen_runtime.Util.Json.unknown_field_handler src_loc field_name]
Usage: [!Atdgen_www_runtime.Util.Json.unknown_field_handler src_loc field_name]
where [src_loc] is the location of the type definition
in the source ATD file and [field_name] is the unknown
JSON field name.
Expand Down
9 changes: 5 additions & 4 deletions atdgen-runtime.opam → atdgen-www-runtime.opam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Runtime library for code generated by atdgen"
synopsis: "Runtime library for code generated by atdgen-www"
description: """
This package should be used only in conjunction with the stdgen code
This package should be used only in conjunction with the atdgen-www code
generator"""
maintainer: ["Rudi Grinberg <[email protected]>"]
authors: [
Expand All @@ -25,13 +25,12 @@ license: "MIT"
homepage: "https://github.com/ahrefs/atd"
bug-reports: "https://github.com/ahrefs/atd/issues"
depends: [
"dune" {>= "2.8"}
"dune" {>= "1.11"}
"ocaml" {>= "4.08"}
"yojson" {>= "2.0.1"}
"biniou" {>= "1.0.6"}
"odoc" {with-doc}
]
dev-repo: "git+https://github.com/ahrefs/atd.git"
build: [
["dune" "subst"] {pinned}
[
Expand All @@ -42,6 +41,8 @@ build: [
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/ahrefs/atd.git"
7 changes: 4 additions & 3 deletions atdgen.opam → atdgen-www.opam
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ license: "MIT"
homepage: "https://github.com/ahrefs/atd"
bug-reports: "https://github.com/ahrefs/atd/issues"
depends: [
"ocaml" {>= "4.02"}
"ocaml" {>= "4.03"}
"dune" {>= "1.11"}
"atd" {>= "2.0.0"}
"atdgen-runtime" {>= "2.0.0"}
"atdgen-www-runtime" {>= "2.0.0"}
"atdgen-codec-runtime" {with-test}
"biniou" {>= "1.0.6"}
"yojson" {>= "1.7.0"}
"odoc" {with-doc}
"re"
]
dev-repo: "git+https://github.com/ahrefs/atd.git"
build: [
["dune" "subst"] {pinned}
[
Expand All @@ -54,6 +53,8 @@ build: [
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/ahrefs/atd.git"
4 changes: 2 additions & 2 deletions atdgen/bin/ag_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ let main () =
Arg.Unit (
fun () ->
set_once "unknown field handler" unknown_field_handler
"!Atdgen_runtime.Util.Json.unknown_field_handler"
"!Atdgen_www_runtime.Util.Json.unknown_field_handler"
),
"
Call !Atdgen_runtime.Util.Json.unknown_field_handler for every unknown JSON field
Call !Atdgen_www_runtime.Util.Json.unknown_field_handler for every unknown JSON field
found in the input instead of simply skipping them.
The initial behavior is to raise an exception.";

Expand Down
4 changes: 2 additions & 2 deletions atdgen/bin/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(executables
(libraries re atd atdgen_emit)
(names ag_main)
(public_names atdgen)
(package atdgen))
(public_names atdgen-www)
(package atdgen-www))
6 changes: 3 additions & 3 deletions atdgen/src/deprecated/atdgen.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[@@@deprecated "The runtime for Atdgen is now the module Atdgen_runtime existing
in the atdgen-runtime opam package"]
include Atdgen_runtime
[@@@deprecated "The runtime for Atdgen-www is now the module Atdgen_www_runtime existing
in the atdgen-www-runtime opam package"]
include Atdgen_www_runtime
8 changes: 4 additions & 4 deletions atdgen/src/deprecated/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; this is a deprecated library whose only purpose is to re-export the runtime
;; new users should be using atdgen_runtime
;; new users should be using atdgen_www_runtime
(library
(name atdgen)
(public_name atdgen)
(libraries atdgen-runtime))
(name atdgen_www)
(public_name atdgen-www)
(libraries atdgen_www_runtime))
44 changes: 22 additions & 22 deletions atdgen/src/ob_emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ let rec get_reader_name

let xreader s =
if tagged then
sprintf "Atdgen_runtime.Ob_run.read_%s" s
sprintf "Atdgen_www_runtime.Ob_run.read_%s" s
else
sprintf "Atdgen_runtime.Ob_run.get_%s_reader" s
sprintf "Atdgen_www_runtime.Ob_run.get_%s_reader" s
in
match x with
Unit (_, Unit, Unit) -> xreader "unit"
Expand Down Expand Up @@ -424,7 +424,7 @@ let rec make_writer ~tagged deref (x : ob_mapping) : Indent.t list =
List, `Array ->
let tag = get_biniou_tag x in
[
Line (sprintf "Atdgen_runtime.Ob_run.write_%slist" un);
Line (sprintf "Atdgen_www_runtime.Ob_run.write_%slist" un);
Block [
Line tag;
Line "(";
Expand All @@ -435,7 +435,7 @@ let rec make_writer ~tagged deref (x : ob_mapping) : Indent.t list =
| Array, `Array ->
let tag = get_biniou_tag x in
[
Line (sprintf "Atdgen_runtime.Ob_run.write_%sarray" un);
Line (sprintf "Atdgen_www_runtime.Ob_run.write_%sarray" un);
Block [
Line tag;
Line "(";
Expand All @@ -454,7 +454,7 @@ let rec make_writer ~tagged deref (x : ob_mapping) : Indent.t list =
| Option (_, x, Option, Option)
| Nullable (_, x, Nullable, Nullable) ->
[
Line (sprintf "Atdgen_runtime.Ob_run.write_%soption (" un);
Line (sprintf "Atdgen_www_runtime.Ob_run.write_%soption (" un);
Block (make_writer ~tagged:true deref x);
Line ")";
]
Expand Down Expand Up @@ -605,8 +605,8 @@ and make_table_writer deref tagged list_kind x =
in
let iter2 =
match list_kind with
List -> "Atdgen_runtime.Ob_run.list_iter2"
| Array -> "Atdgen_runtime.Ob_run.array_iter2"
List -> "Atdgen_www_runtime.Ob_run.list_iter2"
| Array -> "Atdgen_www_runtime.Ob_run.array_iter2"
in
let l = Array.to_list a in
let write_header =
Expand Down Expand Up @@ -726,7 +726,7 @@ let study_record ~ocaml_version fields =
in
if k = 0 then []
else
[ Line (sprintf "if %s then Atdgen_runtime.Ob_run.missing_fields %s %s;"
[ Line (sprintf "if %s then Atdgen_www_runtime.Ob_run.missing_fields %s %s;"
bool_expr bit_fields field_names) ]
in
init_fields, init_bits, set_bit, check_bits, create_record
Expand All @@ -738,7 +738,7 @@ let wrap_body ~tagged expected_tag body =
Annot ("fun", Line "fun ib ->");
Block [
Line (sprintf "if Bi_io.read_tag ib <> %i then \
Atdgen_runtime.Ob_run.read_error_at ib;"
Atdgen_www_runtime.Ob_run.read_error_at ib;"
expected_tag);
Inline body;
]
Expand All @@ -748,7 +748,7 @@ let wrap_body ~tagged expected_tag body =
Annot ("fun", Line "fun tag ->");
Block [
Line (sprintf "if tag <> %i then \
Atdgen_runtime.Ob_run.read_error () else"
Atdgen_www_runtime.Ob_run.read_error () else"
expected_tag);
Block [
Line "fun ib ->";
Expand All @@ -774,7 +774,7 @@ let wrap_bodies ~tagged l =
Line "match Bi_io.read_tag ib with";
Block [
Inline cases;
Line "| _ -> Atdgen_runtime.Ob_run.read_error_at ib"
Line "| _ -> Atdgen_www_runtime.Ob_run.read_error_at ib"
]
]
]
Expand All @@ -796,7 +796,7 @@ let wrap_bodies ~tagged l =
Line "function";
Block [
Inline cases;
Line "| _ -> Atdgen_runtime.Ob_run.read_error ()"
Line "| _ -> Atdgen_www_runtime.Ob_run.read_error ()"
]
]

Expand Down Expand Up @@ -832,7 +832,7 @@ let rec make_reader
a
)
);
Line "| _ -> Atdgen_runtime.Ob_run.unsupported_variant h has_arg";
Line "| _ -> Atdgen_www_runtime.Ob_run.unsupported_variant h has_arg";
]
];
Line ")"
Expand All @@ -853,8 +853,8 @@ let rec make_reader
(match o, b with
List, `Array ->
let f =
if tagged then "Atdgen_runtime.Ob_run.read_list"
else "Atdgen_runtime.Ob_run.get_list_reader"
if tagged then "Atdgen_www_runtime.Ob_run.read_list"
else "Atdgen_www_runtime.Ob_run.get_list_reader"
in
[
Line (f ^ " (");
Expand All @@ -863,8 +863,8 @@ let rec make_reader
]
| Array, `Array ->
let f =
if tagged then "Atdgen_runtime.Ob_run.read_array"
else "Atdgen_runtime.Ob_run.get_array_reader"
if tagged then "Atdgen_www_runtime.Ob_run.read_array"
else "Atdgen_www_runtime.Ob_run.get_array_reader"
in
[
Line (f ^ " (");
Expand All @@ -878,8 +878,8 @@ let rec make_reader
let body2 =
let f =
match list_kind with
List -> "Atdgen_runtime.Ob_run.read_list_value"
| Array -> "Atdgen_runtime.Ob_run.read_array_value"
List -> "Atdgen_www_runtime.Ob_run.read_list_value"
| Array -> "Atdgen_www_runtime.Ob_run.read_array_value"
in
[
Line (f ^ " (");
Expand Down Expand Up @@ -908,7 +908,7 @@ let rec make_reader
];
Line ")"
];
Line "| _ -> Atdgen_runtime.Ob_run.read_error_at ib";
Line "| _ -> Atdgen_www_runtime.Ob_run.read_error_at ib";
]
]
in
Expand Down Expand Up @@ -1112,7 +1112,7 @@ and make_tuple_reader deref ~ocaml_version a =
[
Line "let len = Bi_vint.read_uvint ib in";
Line (sprintf
"if len < %i then Atdgen_runtime.Ob_run.missing_tuple_fields len %s;"
"if len < %i then Atdgen_www_runtime.Ob_run.missing_tuple_fields len %s;"
min_length req_fields);
Inline read_cells;
Line (sprintf "for i = %i to len - 1 do Bi_io.skip ib done;" tup_len);
Expand Down Expand Up @@ -1169,7 +1169,7 @@ and make_table_reader deref ~ocaml_version loc list_kind x =
Inline init_bits;
Line "let readers =";
Block [
Line "Atdgen_runtime.Ob_run.array_init2 col_num ib (";
Line "Atdgen_www_runtime.Ob_run.array_init2 col_num ib (";
Block [
Line "fun col ib ->";
Block [
Expand Down
2 changes: 1 addition & 1 deletion atdgen/src/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ let ocaml_list_of_string s : atd_ocaml_list option =
let string_of_ocaml_list (x : atd_ocaml_list) =
match x with
List -> "list"
| Array -> "Atdgen_runtime.Util.ocaml_array"
| Array -> "Atdgen_www_runtime.Util.ocaml_array"

let path_of_target (target : target) =
match target with
Expand Down
Loading