File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ let rec simpl_dexpr (de : dexpr) : dexpr =
169169 | Done -> Dzero
170170 | Dlit f when f <> 0. -> Dzero
171171 | Dzero -> Done
172- | _ -> de
172+ | de -> Dunop ( " ! " , de)
173173 end
174174 | Dite (dec , det , dee ) -> begin
175175 match (simpl_dexpr dec, simpl_dexpr det, simpl_dexpr dee) with
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ let main_statements_with_context (p : program) : stmt list =
153153 Errors. raise_error
154154 " This Bir program has no context constants and conditions stored"
155155
156- let main_statements_with_reset (p : program ) : stmt list =
156+ let main_statements_with_context_and_tgv_init (p : program ) : stmt list =
157157 match p.context with
158158 | Some context ->
159159 context.unused_inputs_init_stmts @ main_statements_with_context p
Original file line number Diff line number Diff line change @@ -62,6 +62,23 @@ type program_context = {
6262 adhoc_specs_conds_stmts : stmt list ;
6363 unused_inputs_init_stmts : stmt list ;
6464}
65+ (* * This record allows to store statements generated from the m_spec file
66+ without modifying the [Bir.program] function map. Thus the map reflects the
67+ computation strictly as described in M and MPP.
68+
69+ Bir module public interface can then provide access to the statements
70+ associated with the declared main function either:
71+
72+ - as defined in M source,
73+ - composed with the m_spec constant assignations and conditions,
74+ - composed with an initialisation of the variable dictionnary and the m_spec
75+ features.
76+
77+ Initialisation of the variables at the [Bir] level including unused
78+ variables is necessary to the [Bir.interpreter] but frowned upon in code
79+ generation backends where the data structure size incites to use idiomatic
80+ efficient methods of initialisation instead of resting upon a row of
81+ assignments. *)
6582
6683type program = {
6784 mpp_functions : mpp_function FunctionMap .t ;
@@ -93,7 +110,7 @@ val main_statements : program -> stmt list
93110
94111val main_statements_with_context : program -> stmt list
95112
96- val main_statements_with_reset : program -> stmt list
113+ val main_statements_with_context_and_tgv_init : program -> stmt list
97114
98115val get_all_statements : program -> stmt list
99116
Original file line number Diff line number Diff line change @@ -144,4 +144,4 @@ and get_code_locs_stmts (p : Bir.program) (stmts : Bir.stmt list)
144144 locs
145145
146146let get_code_locs (p : Bir.program ) : code_locs =
147- get_code_locs_stmts p (Bir. main_statements_with_reset p) []
147+ get_code_locs_stmts p (Bir. main_statements_with_context_and_tgv_init p) []
Original file line number Diff line number Diff line change @@ -753,8 +753,19 @@ module Make (N : Bir_number.NumberInterface) = struct
753753 try
754754 let ctx =
755755 evaluate_stmts p ctx
756- (Bir. main_statements_with_reset p)
756+ (Bir. main_statements_with_context_and_tgv_init p)
757757 [] code_loc_start_value
758+ (* For the interpreter to operate properly, all input variables must be
759+ declared at some point, even if they aren't used as input (either
760+ contextual constants or entered at interpreter prompt). The M program
761+ doesn't include default assignation for non-entered input variables,
762+ so unused inputs are not declared in the main statements.
763+
764+ The use of main_statement_with_context_and_tgv_init ensures every
765+ variable from the TGV dictionnary is assigned to "undefined" by
766+ default, before context statements overload the contextual constants
767+ according to the spec file and interpreter prompt assignements
768+ overload entered variables. *)
758769 in
759770 ctx
760771 with RuntimeError (e , ctx ) ->
Original file line number Diff line number Diff line change @@ -74,4 +74,4 @@ let format_rules fmt rules =
7474
7575let format_program fmt (p : program ) =
7676 Format. fprintf fmt " %a%a" format_rules p.rules_and_verifs format_stmts
77- (Bir. main_statements_with_reset p)
77+ (Bir. main_statements_with_context_and_tgv_init p)
You can’t perform that action at this time.
0 commit comments