From f4bd063dc85e9351de5e582c5e02fc3b25d7903b Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Tue, 17 Dec 2024 18:10:43 +0100 Subject: [PATCH] CR: add CONFIG macro --- compiler/lib/macro.ml | 15 +++++++++++++++ runtime/js/jslib.js | 17 +---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/lib/macro.ml b/compiler/lib/macro.ml index 69e36b6a83..4a2502d21c 100644 --- a/compiler/lib/macro.ml +++ b/compiler/lib/macro.ml @@ -23,6 +23,11 @@ type m = | Replace | Count of int ref +let string_of_effects_backend = function + | None -> "none" + | Some Config.Cps -> "cps" + | Some Config.Double_translation -> "double-translation" + class macro_mapper ~flags = object (m) inherit Js_traverse.map as super @@ -40,6 +45,16 @@ class macro_mapper ~flags = | Count count -> incr count; super#expression x) + | "CONFIG", [ J.Arg (J.EStr (Utf8 "effects")) ] -> ( + match flags with + | Replace -> + let s = string_of_effects_backend (Config.effects ()) in + J.EStr (Utf8_string.of_string_exn s) + | Count count -> + incr count; + super#expression x) + | "CONFIG", [ J.Arg (J.EStr (Utf8 s)) ] -> + failwith ("unsupported CONFIG parameter " ^ s) | "BLOCK", J.Arg (J.ENum tag) :: (_ :: _ as args) when List.for_all args ~f:(function | J.Arg _ -> true diff --git a/runtime/js/jslib.js b/runtime/js/jslib.js index 99697013a5..495bbf1566 100644 --- a/runtime/js/jslib.js +++ b/runtime/js/jslib.js @@ -139,23 +139,8 @@ function caml_jsoo_flags_use_js_string(unit) { } //Provides: caml_jsoo_flags_effects -//If: !effects -function caml_jsoo_flags_effects(unit) { - return "none"; -} - -//Provides: caml_jsoo_flags_effects -//If: effects -//If: !doubletranslate -function caml_jsoo_flags_effects(unit) { - return "cps"; -} - -//Provides: caml_jsoo_flags_effects -//If: effects -//If: doubletranslate function caml_jsoo_flags_effects(unit) { - return "double-translation"; + return CONFIG("effects"); } //Provides: caml_wrap_exception const (mutable)