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

Commit cfbb9a3

Browse files
committed
No local var option
1 parent c649468 commit cfbb9a3

5 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/irj_checker/irj_checker.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
this program. If not, see <https://www.gnu.org/licenses/>. *)
1515

1616
(** The Irj_checker Module is a simple entry point to use the Mlang IRJ file
17-
parser in order to perform syntactic checks on test files or produce other IR
18-
test formats.
17+
parser in order to perform syntactic checks on test files or produce other
18+
IR test formats.
1919
20-
Usage: irj_checker.exe [--message-format=VAL] <test_file.irj> [transformation-target]*)
20+
Usage: irj_checker.exe [--message-format=VAL] <test_file.irj>
21+
[transformation-target]*)
2122

2223
open Cmdliner
2324
open Mlang

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)
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 dgfip_flags
228-
execution_mode
228+
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,21 @@ let dgfip_options =
182182
"Specify DGFiP options (use --dgfip_options=--help to display DGFiP \
183183
specific options)")
184184

185+
let no_local_vars =
186+
Arg.(
187+
value & flag
188+
& info [ "no-local-vars" ]
189+
~doc:
190+
"(experimental) Does not generate local vars for definitions and \
191+
evaluation.")
192+
185193
let mlang_t f =
186194
Term.(
187195
const f $ files $ applications $ without_dgfip_m $ debug $ var_info_debug
188196
$ display_time $ dep_graph_file $ no_print_cycles $ backend $ output
189197
$ run_all_tests $ dgfip_test_filter $ run_test $ mpp_function
190198
$ optimize_unsafe_float $ precision $ roundops $ comparison_error_margin_cli
191-
$ income_year_cli $ m_clean_calls $ dgfip_options)
199+
$ income_year_cli $ m_clean_calls $ dgfip_options $ no_local_vars)
192200

193201
let info =
194202
let doc =
@@ -296,6 +304,8 @@ let dgfip_flags = ref Dgfip_options.default_flags
296304

297305
let execution_mode = ref Extraction
298306

307+
let no_local_var = ref false
308+
299309
(* Default value for the epsilon slack when comparing things in the
300310
interpreter *)
301311
let comparison_error_margin = ref 0.000001
@@ -310,7 +320,7 @@ let set_all_arg_refs (files_ : files) applications_ (without_dgfip_m_ : bool)
310320
(income_year_ : int option) (value_sort_ : value_sort)
311321
(round_ops_ : round_ops) (backend_ : backend) (dgfip_test_filter_ : bool)
312322
(mpp_function_ : string) (dgfip_flags_ : Dgfip_options.flags)
313-
(execution_mode_ : execution_mode) =
323+
(execution_mode_ : execution_mode) (no_local_var_ : bool) =
314324
source_files := files_;
315325
application_names := applications_;
316326
without_dgfip_m := without_dgfip_m_;
@@ -333,6 +343,7 @@ let set_all_arg_refs (files_ : files) applications_ (without_dgfip_m_ : bool)
333343
dgfip_test_filter := dgfip_test_filter_;
334344
mpp_function := mpp_function_;
335345
dgfip_flags := dgfip_flags_;
346+
no_local_var := no_local_var_;
336347
match output_file_ with
337348
| None -> ()
338349
| Some o -> (

src/mlang/utils/cli.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ val mlang_t :
4040
int option ->
4141
bool ->
4242
string list option ->
43+
bool ->
4344
'a) ->
4445
'a Cmdliner.Term.t
4546
(** Mlang binary command-line arguments parsing function *)
@@ -140,6 +141,8 @@ val dgfip_flags : Dgfip_options.flags ref
140141

141142
val execution_mode : execution_mode ref
142143

144+
val no_local_var : bool ref
145+
143146
val set_all_arg_refs :
144147
(* files *) files ->
145148
(* applications *) string list ->
@@ -161,6 +164,7 @@ val set_all_arg_refs :
161164
(* mpp_function *) string ->
162165
(* dgfip_flags *) Dgfip_options.flags ->
163166
(* execution_mode *) execution_mode ->
167+
(* no_local_var *) bool ->
164168
unit
165169

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

0 commit comments

Comments
 (0)