mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Add support for dcalc plugins
previously only lcalc and scalc where available
This commit is contained in:
parent
3cf64edb39
commit
feeee4016e
@ -289,6 +289,13 @@ let driver source_file (options : Cli.options) : int =
|
||||
(Shared_ast.Expr.format ~debug:options.debug prgm.decl_ctx)
|
||||
result)
|
||||
results
|
||||
| `Plugin (Plugin.Dcalc p) ->
|
||||
let output_file, _ = get_output_format ~ext:p.Plugin.extension () in
|
||||
Cli.debug_print "Compiling program through backend \"%s\"..."
|
||||
p.Plugin.name;
|
||||
p.Plugin.apply ~source_file ~output_file ~scope:options.ex_scope
|
||||
(Shared_ast.Program.untype prgm)
|
||||
type_ordering
|
||||
| (`OCaml | `Interpret_Lcalc | `Python | `Lcalc | `Scalc | `Plugin _)
|
||||
as backend -> (
|
||||
Cli.debug_print "Compiling program into lambda calculus...";
|
||||
@ -375,6 +382,7 @@ let driver source_file (options : Cli.options) : int =
|
||||
Cli.debug_print "Writing to %s..."
|
||||
(Option.value ~default:"stdout" output_file);
|
||||
Lcalc.To_ocaml.format_program fmt prgm type_ordering
|
||||
| `Plugin (Plugin.Dcalc _) -> assert false
|
||||
| `Plugin (Plugin.Lcalc p) ->
|
||||
let output_file, _ =
|
||||
get_output_format ~ext:p.Plugin.extension ()
|
||||
@ -411,7 +419,7 @@ let driver source_file (options : Cli.options) : int =
|
||||
with_output
|
||||
@@ fun fmt ->
|
||||
Scalc.To_python.format_program fmt prgm type_ordering
|
||||
| `Plugin (Plugin.Lcalc _) -> assert false
|
||||
| `Plugin (Plugin.Dcalc _ | Plugin.Lcalc _) -> assert false
|
||||
| `Plugin (Plugin.Scalc p) ->
|
||||
let output_file, _ = get_output ~ext:p.Plugin.extension () in
|
||||
Cli.debug_print "Compiling program through backend \"%s\"..."
|
||||
|
@ -31,16 +31,22 @@ type 'ast gen = {
|
||||
}
|
||||
|
||||
type t =
|
||||
| Dcalc of Shared_ast.untyped Dcalc.Ast.program gen
|
||||
| Lcalc of Shared_ast.untyped Lcalc.Ast.program gen
|
||||
| Scalc of Scalc.Ast.program gen
|
||||
|
||||
let name = function Lcalc { name; _ } | Scalc { name; _ } -> name
|
||||
let name = function
|
||||
| Dcalc { name; _ } | Lcalc { name; _ } | Scalc { name; _ } -> name
|
||||
|
||||
let backend_plugins : (string, t) Hashtbl.t = Hashtbl.create 17
|
||||
|
||||
let register t =
|
||||
Hashtbl.replace backend_plugins (String.lowercase_ascii (name t)) t
|
||||
|
||||
module PluginAPI = struct
|
||||
let register_dcalc ~name ~extension apply =
|
||||
register (Dcalc { name; extension; apply })
|
||||
|
||||
let register_lcalc ~name ~extension apply =
|
||||
register (Lcalc { name; extension; apply })
|
||||
|
||||
|
@ -33,6 +33,7 @@ type 'ast gen = {
|
||||
}
|
||||
|
||||
type t =
|
||||
| Dcalc of Shared_ast.untyped Dcalc.Ast.program gen
|
||||
| Lcalc of Shared_ast.untyped Lcalc.Ast.program gen
|
||||
| Scalc of Scalc.Ast.program gen
|
||||
|
||||
@ -48,6 +49,12 @@ val load_dir : string -> unit
|
||||
(** {2 plugin-facing API} *)
|
||||
|
||||
module PluginAPI : sig
|
||||
val register_dcalc :
|
||||
name:string ->
|
||||
extension:string ->
|
||||
Shared_ast.untyped Dcalc.Ast.program plugin_apply_fun_typ ->
|
||||
unit
|
||||
|
||||
val register_lcalc :
|
||||
name:string ->
|
||||
extension:string ->
|
||||
|
Loading…
Reference in New Issue
Block a user