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

Commit d9a8170

Browse files
committed
Adding option to write raw formulas completely instead of binary operations between temporary variables
1 parent 224a6bf commit d9a8170

4 files changed

Lines changed: 27 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
@@ -170,15 +170,19 @@ let collapse_constr (stacks : local_stacks) (ctx : local_vars) (constr : constr)
170170
let push_with_kind (stacks : local_stacks) (ctx : local_vars) (kind : dflag)
171171
(constr : constr) =
172172
let expr, ekind, lv = constr stacks ctx in
173-
let expr = if kind = ekind then expr else cast kind expr in
174-
let stacks, lv, expr = store_local stacks lv Anon kind expr in
175-
(stacks, lv, expr)
173+
if !Cli.no_local_var then (stacks, lv, expr)
174+
else
175+
let expr = if kind = ekind then expr else cast kind expr in
176+
let stacks, lv, expr = store_local stacks lv Anon kind expr in
177+
(stacks, lv, expr)
176178

177179
(* eval and store without enforcing kind *)
178180
let push (stacks : local_stacks) (ctx : local_vars) (constr : constr) =
179181
let expr, kind, lv = constr stacks ctx in
180-
let stacks, lv, expr = store_local stacks lv Anon kind expr in
181-
(stacks, lv, expr, kind)
182+
if !Cli.no_local_var then (stacks, lv, expr, kind)
183+
else
184+
let stacks, lv, expr = store_local stacks lv Anon kind expr in
185+
(stacks, lv, expr, kind)
182186

183187
(** smart constructors *)
184188

src/mlang/driver.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ let driver (files : string list) (application_names : string list)
182182
(precision : string option) (roundops : string option)
183183
(comparison_error_margin : float option) (income_year : int option)
184184
(m_clean_calls : bool) (dgfip_options : string list option)
185-
(only_compile_new : bool) =
185+
(only_compile_new : bool) (no_local_var : bool) =
186186
Format.printf "Only compile new? %b@." only_compile_new;
187187
let value_sort =
188188
let precision = Option.get precision in
@@ -230,7 +230,7 @@ let driver (files : string list) (application_names : string list)
230230
Cli.set_all_arg_refs files application_names without_dgfip_m debug stats
231231
var_info_debug display_time dep_graph_file print_cycles output
232232
optimize_unsafe_float m_clean_calls comparison_error_margin income_year
233-
value_sort round_ops only_compile_new;
233+
value_sort round_ops only_compile_new no_local_var;
234234
let dgfip_flags = process_dgfip_options backend dgfip_options in
235235
(* Reading the project metadata, if any, to spare us some ĉompilation time *)
236236
let metadata = File_metadata.make ~output in

src/mlang/utils/cli.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,20 @@ let only_compil_new =
192192
~doc:
193193
"(experimental) Only parses & compiles files that have been changed.")
194194

195+
let no_local_var =
196+
Arg.(
197+
value & flag
198+
& info [ "no-local-var" ]
199+
~doc:"(experimental) Does not use local vars to encode C assignments.")
200+
195201
let mlang_t f =
196202
Term.(
197203
const f $ files $ applications $ without_dgfip_m $ debug $ stats
198204
$ var_info_debug $ display_time $ dep_graph_file $ no_print_cycles $ backend
199205
$ output $ run_all_tests $ dgfip_test_filter $ run_test $ mpp_function
200206
$ optimize_unsafe_float $ precision $ roundops $ comparison_error_margin_cli
201-
$ income_year_cli $ m_clean_calls $ dgfip_options $ only_compil_new)
207+
$ income_year_cli $ m_clean_calls $ dgfip_options $ only_compil_new
208+
$ no_local_var)
202209

203210
let info =
204211
let doc =
@@ -288,6 +295,8 @@ let round_ops = ref RODefault
288295

289296
let only_compile_new = ref false
290297

298+
let no_local_var = ref false
299+
291300
(* Default value for the epsilon slack when comparing things in the
292301
interpreter *)
293302
let comparison_error_margin = ref 0.000001
@@ -301,7 +310,7 @@ let set_all_arg_refs (files_ : string list) applications_
301310
(output_file_ : string option) (optimize_unsafe_float_ : bool)
302311
(m_clean_calls_ : bool) (comparison_error_margin_ : float option)
303312
(income_year_ : int option) (value_sort_ : value_sort)
304-
(round_ops_ : round_ops) (only_compile_new_ : bool) =
313+
(round_ops_ : round_ops) (only_compile_new_ : bool) (no_local_var_ : bool) =
305314
source_files := files_;
306315
application_names := applications_;
307316
without_dgfip_m := without_dgfip_m_;
@@ -321,6 +330,7 @@ let set_all_arg_refs (files_ : string list) applications_
321330
value_sort := value_sort_;
322331
round_ops := round_ops_;
323332
only_compile_new := only_compile_new_;
333+
no_local_var := no_local_var_;
324334
match output_file_ with
325335
| None -> ()
326336
| Some o -> (

src/mlang/utils/cli.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ val mlang_t :
4242
bool ->
4343
string list option ->
4444
bool ->
45+
bool ->
4546
'a) ->
4647
'a Cmdliner.Term.t
4748
(** Mlang binary command-line arguments parsing function *)
@@ -123,6 +124,8 @@ val round_ops : round_ops ref
123124

124125
val only_compile_new : bool ref
125126

127+
val no_local_var : bool ref
128+
126129
val set_all_arg_refs :
127130
(* files *) string list ->
128131
(* applications *) string list ->
@@ -141,6 +144,7 @@ val set_all_arg_refs :
141144
value_sort ->
142145
round_ops ->
143146
(* only_compile_new *) bool ->
147+
(* no_local_var *) bool ->
144148
unit
145149

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

0 commit comments

Comments
 (0)