Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

Commit 778b1d3

Browse files
committed
No local var option
1 parent 5a44e0c commit 778b1d3

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/mlang/backend_compilers/decoupledExpr.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,19 @@ let collapse_constr (stacks : local_stacks) (ctx : local_vars) (constr : constr)
149149
let push_with_kind (stacks : local_stacks) (ctx : local_vars) (kind : dflag)
150150
(constr : constr) =
151151
let expr, ekind, lv = constr stacks ctx in
152-
let expr = if kind = ekind then expr else cast kind expr in
153-
let stacks, lv, expr = store_local stacks lv Anon kind expr in
154-
(stacks, lv, expr)
152+
if !Cli.no_local_var then (stacks, lv, expr)
153+
else
154+
let expr = if kind = ekind then expr else cast kind expr in
155+
let stacks, lv, expr = store_local stacks lv Anon kind expr in
156+
(stacks, lv, expr)
155157

156158
(* eval and store without enforcing kind *)
157159
let push (stacks : local_stacks) (ctx : local_vars) (constr : constr) =
158160
let expr, kind, lv = constr stacks ctx in
159-
let stacks, lv, expr = store_local stacks lv Anon kind expr in
160-
(stacks, lv, expr, kind)
161+
if !Cli.no_local_var then (stacks, lv, expr, kind)
162+
else
163+
let stacks, lv, expr = store_local stacks lv Anon kind expr in
164+
(stacks, lv, expr, kind)
161165

162166
(** smart constructors *)
163167

src/mlang/driver.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let set_opts (files : string list) (application_names : string list)
159159
(optimize_unsafe_float : bool) (precision : string option)
160160
(roundops : string option) (comparison_error_margin : float option)
161161
(income_year : int option) (m_clean_calls : bool) (lazy_c_generation : bool)
162-
(dgfip_options : string list option) =
162+
(dgfip_options : string list option) (no_local_var : bool) =
163163
let value_sort =
164164
let precision = Option.get precision in
165165
if precision = "double" then Cli.RegularFloat
@@ -225,7 +225,7 @@ let set_opts (files : string list) (application_names : string list)
225225
var_info_debug display_time dep_graph_file print_cycles output
226226
optimize_unsafe_float m_clean_calls comparison_error_margin income_year
227227
value_sort round_ops backend dgfip_test_filter mpp_function
228-
lazy_c_generation dgfip_flags execution_mode
228+
lazy_c_generation dgfip_flags execution_mode no_local_var
229229

230230
let run_single_test m_program test =
231231
Mir_interpreter.repl_debug := true;

src/mlang/utils/cli.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,22 @@ let dgfip_options =
190190
"Specify DGFiP options (use --dgfip_options=--help to display DGFiP \
191191
specific options)")
192192

193+
let no_local_vars =
194+
Arg.(
195+
value & flag
196+
& info [ "no-local-vars" ]
197+
~doc:
198+
"(experimental) Does not generate local vars for definitions and \
199+
evaluation.")
200+
193201
let mlang_t f =
194202
Term.(
195203
const f $ files $ applications $ without_dgfip_m $ debug $ var_info_debug
196204
$ display_time $ dep_graph_file $ no_print_cycles $ backend $ output
197205
$ run_all_tests $ dgfip_test_filter $ run_test $ mpp_function
198206
$ optimize_unsafe_float $ precision $ roundops $ comparison_error_margin_cli
199-
$ income_year_cli $ m_clean_calls $ lazy_c_gen $ dgfip_options)
207+
$ income_year_cli $ m_clean_calls $ lazy_c_gen $ dgfip_options
208+
$ no_local_vars)
200209

201210
let info =
202211
let doc =
@@ -306,6 +315,8 @@ let dgfip_flags = ref Dgfip_options.default_flags
306315

307316
let execution_mode = ref Extraction
308317

318+
let no_local_var = ref false
319+
309320
(* Default value for the epsilon slack when comparing things in the
310321
interpreter *)
311322
let comparison_error_margin = ref 0.000001
@@ -320,7 +331,8 @@ let set_all_arg_refs (files_ : files) applications_ (without_dgfip_m_ : bool)
320331
(income_year_ : int option) (value_sort_ : value_sort)
321332
(round_ops_ : round_ops) (backend_ : backend) (dgfip_test_filter_ : bool)
322333
(mpp_function_ : string) (lazy_c_generation_ : bool)
323-
(dgfip_flags_ : Dgfip_options.flags) (execution_mode_ : execution_mode) =
334+
(dgfip_flags_ : Dgfip_options.flags) (execution_mode_ : execution_mode)
335+
(no_local_var_ : bool) =
324336
source_files := files_;
325337
application_names := applications_;
326338
without_dgfip_m := without_dgfip_m_;
@@ -344,6 +356,7 @@ let set_all_arg_refs (files_ : files) applications_ (without_dgfip_m_ : bool)
344356
mpp_function := mpp_function_;
345357
lazy_c_generation := lazy_c_generation_;
346358
dgfip_flags := dgfip_flags_;
359+
no_local_var := no_local_var_;
347360
match output_file_ with
348361
| None -> ()
349362
| Some o -> (

src/mlang/utils/cli.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ val mlang_t :
4141
bool ->
4242
bool ->
4343
string list option ->
44+
bool ->
4445
'a) ->
4546
'a Cmdliner.Term.t
4647
(** Mlang binary command-line arguments parsing function *)
@@ -143,6 +144,8 @@ val dgfip_flags : Dgfip_options.flags ref
143144

144145
val execution_mode : execution_mode ref
145146

147+
val no_local_var : bool ref
148+
146149
val set_all_arg_refs :
147150
(* files *) files ->
148151
(* applications *) string list ->
@@ -165,6 +168,7 @@ val set_all_arg_refs :
165168
(* lazy_c_generation *) bool ->
166169
(* dgfip_flags *) Dgfip_options.flags ->
167170
(* execution_mode *) execution_mode ->
171+
(* no_local_var *) bool ->
168172
unit
169173

170174
val add_prefix_to_each_line : string -> (int -> string) -> string

0 commit comments

Comments
 (0)