diff --git a/compiler/driver.ml b/compiler/driver.ml index 2a1c1561..3459b16c 100644 --- a/compiler/driver.ml +++ b/compiler/driver.ml @@ -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\"..." diff --git a/compiler/plugin.ml b/compiler/plugin.ml index e7f9437a..83a149a4 100644 --- a/compiler/plugin.ml +++ b/compiler/plugin.ml @@ -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 }) diff --git a/compiler/plugin.mli b/compiler/plugin.mli index acfdf56a..0d69561a 100644 --- a/compiler/plugin.mli +++ b/compiler/plugin.mli @@ -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 ->