From ba8094b77dd7c028ecb56572289b8878facf25d7 Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Sun, 31 Aug 2025 15:07:57 +0200 Subject: [PATCH] print n expands --- - | 14 ++++++++++++++ sexpr.ml | 5 +++++ 2 files changed, 19 insertions(+) create mode 100644 - diff --git a/- b/- new file mode 100644 index 0000000..2aaa529 --- /dev/null +++ b/- @@ -0,0 +1,14 @@ +; number of macro expansions: 0 +(((((:cfg + (name "Complex CI/CD Pipeline") + (on + (push + (branches + (:seq "main" "release/*"))) + (pull_requests + (types + (:seq opened synchronize + reopened))) + (workflow_dispatch)) + (env (NODE_VERSION 20) + (PYTHON_VERSION "3.11"))))))) diff --git a/sexpr.ml b/sexpr.ml index 4149e07..bb4dddc 100644 --- a/sexpr.ml +++ b/sexpr.ml @@ -675,6 +675,8 @@ module SExprMacroExp = struct exception Not_Valid_Macro_Arg_Syntax exception FIXME of SExpr.t + let num_expands = ref 0;; + let assoc_all k li = li |> List.find_all (fun (x, _) -> x = k) @@ -824,6 +826,7 @@ module SExprMacroExp = struct and expand_macro args macro ctx = let margs, mbody = macro in let defs = match_macro_arg args margs ctx in + num_expands := !num_expands + 1; expand_macro_eval mbody defs and eval_while ctx s = begin let s, ch, ctx = eval ctx s in @@ -938,6 +941,8 @@ let () = let v = SExprMacroExp.sparse src in let v = SExprMacroExp.do_eval v in + Format.printf "; number of macro expansions: %d\n%!" !SExprMacroExp.num_expands; + Format.set_margin 40; Format.printf "%a@.@?" SExpr.pp_t v;