Skip to content

Commit

Permalink
CR: add CONFIG macro
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Dec 17, 2024
1 parent c1c0e0b commit f4bd063
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
15 changes: 15 additions & 0 deletions compiler/lib/macro.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 1 addition & 16 deletions runtime/js/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f4bd063

Please sign in to comment.