refactor(runtimes): add runtime_ocaml and runtime_jsoo in the catala package

This commit is contained in:
Emile Rolley 2022-07-19 19:17:02 +02:00
parent cd33ed9de7
commit 0c180e12f9
20 changed files with 139 additions and 11 deletions

View File

@ -7,7 +7,7 @@
(library
(name clerk_driver)
(public_name clerk.driver)
(libraries catala.runtime catala.utils ninja_utils cmdliner re ANSITerminal)
(libraries catala.runtime_ocaml catala.utils ninja_utils cmdliner re ANSITerminal)
(modules clerk_driver))
(executable

View File

@ -18,6 +18,7 @@
[@@@ocaml.warning "-7-34"]
open Utils
module Runtime = Runtime_ocaml.Runtime
module ScopeName : Uid.Id with type info = Uid.MarkedString.info =
Uid.Make (Uid.MarkedString) ()

View File

@ -18,6 +18,7 @@
(** Abstract syntax tree of the default calculus intermediate representation *)
open Utils
module Runtime = Runtime_ocaml.Runtime
module ScopeName : Uid.Id with type info = Uid.MarkedString.info
module StructName : Uid.Id with type info = Uid.MarkedString.info
module StructFieldName : Uid.Id with type info = Uid.MarkedString.info

View File

@ -1,7 +1,7 @@
(library
(name dcalc)
(public_name catala.dcalc)
(libraries bindlib unionFind utils re camomile runtime)
(libraries bindlib unionFind utils re camomile catala.runtime_ocaml)
(preprocess
(pps visitors.ppx)))

View File

@ -18,6 +18,7 @@
open Utils
module A = Ast
module Runtime = Runtime_ocaml.Runtime
(** {1 Helpers} *)

View File

@ -10,7 +10,7 @@
dcalc
lcalc
scalc
runtime
catala.runtime_ocaml
verification)
(modules plugin driver))
@ -22,7 +22,11 @@
(modules catala_web_interpreter)
(preprocess
(pps js_of_ocaml-ppx))
(libraries catala.driver js_of_ocaml))
(libraries
catala.driver
js_of_ocaml
catala.runtime_ocaml
catala.runtime_jsoo))
(executable
(name catala)

View File

@ -106,9 +106,9 @@ Two more modules contain additional features for the compiler:
{li {{: utils.html} Compiler utilities}}
}
The Catala runtime documentation is available here:
The Catala runtimes documentation is available here:
{!modules: Runtime}
{!modules: Runtime_ocaml.Runtime Runtime_jsoo.Runtime}
Last, it is possible to customize the backend to the compiler using a plugin
mechanism. The API is defined inside the following module:

View File

@ -15,6 +15,7 @@
the License. *)
open Utils
module Runtime = Runtime_ocaml.Runtime
module D = Dcalc.Ast
type lit =

View File

@ -15,6 +15,7 @@
the License. *)
open Utils
module Runtime = Runtime_ocaml.Runtime
(** Abstract syntax tree for the lambda calculus *)

View File

@ -1,7 +1,7 @@
(library
(name lcalc)
(public_name catala.lcalc)
(libraries bindlib dcalc scopelang runtime)
(libraries bindlib dcalc scopelang catala.runtime_ocaml)
(preprocess
(pps visitors.ppx)))

View File

@ -1,7 +1,7 @@
(library
(name scalc)
(public_name catala.scalc)
(libraries bindlib lcalc runtime))
(libraries bindlib lcalc catala.runtime_ocaml))
(documentation
(package catala)

View File

@ -18,6 +18,7 @@
open Utils
open Ast
open Lcalc.Backends
module Runtime = Runtime_ocaml.Runtime
module D = Dcalc.Ast
module L = Lcalc.Ast

View File

@ -16,6 +16,8 @@
the License. *)
open Utils
module Runtime = Runtime_ocaml.Runtime
(** Translation from {!module: Surface.Ast} to {!module: Desugaring.Ast}.
- Removes syntactic sugars

View File

@ -5,7 +5,7 @@
bindlib
utils
dcalc
runtime
catala.runtime_ocaml
calendar
(select
z3backend.ml

4
runtimes/dune Normal file
View File

@ -0,0 +1,4 @@
(dirs jsoo ocaml)
(documentation
(package catala))

5
runtimes/jsoo/dune Normal file
View File

@ -0,0 +1,5 @@
(library
(name runtime_jsoo)
(public_name catala.runtime_jsoo)
(libraries catala.runtime_ocaml js_of_ocaml)
(modules runtime))

50
runtimes/jsoo/runtime.ml Normal file
View File

@ -0,0 +1,50 @@
(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
Emile Rolley <emile.rolley@tuta.io>.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)
open Js_of_ocaml
class type source_position =
object
method fileName : Js.js_string Js.t Js.prop
method startLine : int Js.prop
method endLine : int Js.prop
method startColumn : int Js.prop
method endColumn : int Js.prop
method lawHeadings : Js.js_string Js.t Js.js_array Js.t Js.prop
end
class type raw_event =
object
method eventType : Js.js_string Js.t Js.prop
method information : Js.js_string Js.t Js.js_array Js.t Js.prop
method sourcePosition : source_position Js.t Js.optdef Js.prop
method loggedValueJson : Js.js_string Js.t Js.prop
end
class type event =
object
method data : Js.js_string Js.t Js.prop
end
class type duration =
object
method years : int Js.prop
method months : int Js.prop
method days : int Js.prop
end
(* let duration_of_jsoo d = *)
(* Runtime.duration_of_numbers d##.years d##.months d##.days *)

53
runtimes/jsoo/runtime.mli Normal file
View File

@ -0,0 +1,53 @@
(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
Emile Rolley <emile.rolley@tuta.io>.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)
(** Runtime used by generated web API via
{{:http://ocsigen.org/js_of_ocaml/latest/manual/overview} [js_of_ocaml]}. *)
open Js_of_ocaml
class type source_position =
object
method fileName : Js.js_string Js.t Js.prop
method startLine : int Js.prop
method endLine : int Js.prop
method startColumn : int Js.prop
method endColumn : int Js.prop
method lawHeadings : Js.js_string Js.t Js.js_array Js.t Js.prop
end
class type raw_event =
object
method eventType : Js.js_string Js.t Js.prop
method information : Js.js_string Js.t Js.js_array Js.t Js.prop
method sourcePosition : source_position Js.t Js.optdef Js.prop
method loggedValueJson : Js.js_string Js.t Js.prop
end
class type event =
object
method data : Js.js_string Js.t Js.prop
end
class type duration =
object
method years : int Js.prop
method months : int Js.prop
method days : int Js.prop
end
(* let duration_of_jsoo d = *)
(* Runtime.duration_of_numbers d##.years d##.months d##.days *)

View File

@ -1,6 +1,6 @@
(library
(name runtime)
(public_name catala.runtime)
(name runtime_ocaml)
(public_name catala.runtime_ocaml)
(preprocess
(pps ppx_yojson_conv))
(libraries calendar zarith zarith_stubs_js)

View File

@ -248,7 +248,11 @@ val date_of_numbers : int -> int -> int -> date
(**{2 Durations} *)
val duration_of_numbers : int -> int -> int -> duration
(** Usage : [duration_of_numbers year mounth day]. *)
val duration_to_years_months_days : duration -> int * int * int
(**{2 Times} *)
val duration_to_string : duration -> string
(**{1 Defaults} *)