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

Commit dc40d4f

Browse files
committed
Documentation
1 parent 21de4ce commit dc40d4f

8 files changed

Lines changed: 91 additions & 58 deletions

File tree

src/mlang/index.mld

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@ and basically all programs typecheck ; however {!module: Mlang.M_frontend.Valida
2828
Mlang.M_ir.Com
2929
Mlang.M_ir.Format_mir
3030
Mlang.M_ir.Mir
31-
Mlang.M_ir.Mir_interpreter
3231
Mlang.M_ir.Mir_number
3332
Mlang.M_ir.Mir_roundops }
3433

34+
{1 Interpreter}
35+
36+
The intepreter is the reference for the M semantics. The C code Mlang generates must
37+
follow it.
38+
The main interpreter module is {!module: Mlang.Mir_interpreter.Eval} which defines two
39+
functions: {!Mlang.Mir_interpreter.Eval.evaluate_program} and {!Mlang.Mir_interpreter.Eval.evaluate_expr}. It also defines several modules that evaluates programs and expression
40+
with different float precisions.
41+
42+
{!modules:
43+
Mlang.Mir_interpreter.Anomalies
44+
Mlang.Mir_interpreter.Context
45+
Mlang.Mir_interpreter.Eval
46+
Mlang.Mir_interpreter.Functions
47+
Mlang.Mir_interpreter.Print
48+
Mlang.Mir_interpreter.Types }
49+
3550
{1 Testing}
3651

3752
Mlang comes with a testing framework for M programs that is based on

src/mlang/m_ir/mir.mli

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
- Constants have been inlined.
2323
- Loops (FunCallLoop, Loop) have been unrolled.
2424
- Chaining, domain and verification calculations have been unified into
25-
Target calculations.
26-
This filtering is performed by {!M_frontend.Expander}, {!M_frontend.Validator} and
27-
{!M_frontend.Mast_to_mir}.
25+
Target calculations. This filtering is performed by
26+
{!M_frontend.Expander}, {!M_frontend.Validator} and
27+
{!M_frontend.Mast_to_mir}.
2828
29-
The structural difference between {!M_frontend.Mast} and Mir common types are
30-
the replacement of {!Mir.Com.m_var_name} by {!M_ir.Com.Var.t} and
31-
{!M_frontend.Mast.error_name} by {!M_ir.Com.Error.t}.
32-
*)
29+
The structural difference between {!M_frontend.Mast} and Mir common types
30+
are the replacement of {!Mir.Com.m_var_name} by {!M_ir.Com.Var.t} and
31+
{!M_frontend.Mast.error_name} by {!M_ir.Com.Error.t}. *)
3332

3433
type set_value = Com.Var.t Com.set_value
3534

@@ -64,8 +63,7 @@ type stats = {
6463
max_nb_args : int;
6564
table_map : Com.Var.t IntMap.t;
6665
}
67-
(** A set of constants relative to the program and its selected
68-
applications. *)
66+
(** A set of constants relative to the program and its selected applications. *)
6967

7068
type program = {
7169
program_safe_prefix : string;

src/mlang/m_ir/mir_number.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ MakeComparable (struct
234234
let is_nan_or_inf x = not (Mpfrf.number_p x)
235235
end)
236236

237-
module IntervalNumber : NumberInterface = MakeComparable (struct
238-
type t = { down : Mpfrf.t; up : Mpfrf.t }
237+
type interval = { down : Mpfrf.t; up : Mpfrf.t }
238+
239+
module IntervalNumber : NumberInterface with type t = interval =
240+
MakeComparable (struct
241+
type t = interval
239242

240243
let v (x : Mpfrf.t) (y : Mpfrf.t) : t = { down = x; up = y }
241244

src/mlang/m_ir/mir_number.mli

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
You should have received a copy of the GNU General Public License along with
1515
this program. If not, see <https://www.gnu.org/licenses/>. *)
1616

17+
type interval = { down : Mpfrf.t; up : Mpfrf.t }
18+
1719
module type NumberInterface = sig
1820
type t
1921

@@ -68,8 +70,8 @@ module type NumberInterface = sig
6870
val is_zero : t -> bool
6971

7072
val compare : ?epsilon:float -> Com.comp_op -> t -> t -> bool
71-
(** Returns the comparison between two numbers in the precision context
72-
of the current configuration. *)
73+
(** Returns the comparison between two numbers in the precision context of the
74+
current configuration. *)
7375
end
7476

7577
module RegularFloatNumber : NumberInterface with type t = float
@@ -78,7 +80,7 @@ val mpfr_floor : Mpfrf.t -> Mpfrf.t
7880

7981
module MPFRNumber : NumberInterface with type t = Mpfrf.t
8082

81-
module IntervalNumber : NumberInterface
83+
module IntervalNumber : NumberInterface with type t = interval
8284

8385
module RationalNumber : NumberInterface with type t = Mpqf.t
8486

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
val raise : 'a Types.ctx -> M_ir.Com.Error.t -> string option -> bool
2-
(** Adds the anomaly to the context and returns [true] if the said anomaly
3-
is blocking, [false] otherwise. *)
2+
(** Adds the anomaly to the context and returns [true] if the said anomaly is
3+
blocking, [false] otherwise. *)
44

55
val clean : 'a Types.ctx -> unit
6-
(** Cleans the context from its unfinalized and unarchived
7-
anomalies. *)
6+
(** Cleans the context from its unfinalized and unarchived anomalies. *)
87

98
val clean_finalized : 'a Types.ctx -> unit
109
(** Cleans the context from its finalized anomalies. *)
1110

1211
val finalize : mode_corr:bool -> 'a Types.ctx -> unit
13-
(** Moves the raised anomalies to the finalized anomalies (and the
14-
archived anomalies if [mode_corr] is [true]). *)
12+
(** Moves the raised anomalies to the finalized anomalies (and the archived
13+
anomalies if [mode_corr] is [true]). *)
1514

1615
val export : mode_corr:bool -> 'a Types.ctx -> unit
17-
(** Moves the finalized anomalies to the exported anomalies (and the
18-
archived anomalies if [mode_corr] is [true]). *)
16+
(** Moves the finalized anomalies to the exported anomalies (and the archived
17+
anomalies if [mode_corr] is [true]). *)

src/mlang/mir_interpreter/context.mli

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ module type S = sig
1111
M_ir.Com.Var.t ->
1212
M_ir.Com.variable_space * M_ir.Com.Var.t * int
1313
(** Returns the variable identifier and its space, with an offset integer.
14-
This offset integer is 0 for TGV variables
15-
*)
14+
This offset integer is 0 for TGV variables *)
1615

1716
val get_var_tab :
1817
custom_float Types.ctx -> M_ir.Com.Var.t -> int -> M_ir.Com.Var.t
19-
(** [get_var_tab ctx vs v i]
20-
Each cell of a table is a separate variable. This function
21-
returns the variable representing the cell [i] in table [v].
18+
(** [get_var_tab ctx vs v i] Each cell of a table is a separate variable. This
19+
function returns the variable representing the cell [i] in table [v].
2220
Fails if the variable in argument is not a table. *)
2321

2422
val get_var_value_org :
@@ -110,9 +108,8 @@ val empty_ctx :
110108
(** [empty_ctx ?inputs ?events p]
111109
112110
Creates a fresh context for executing the program [p] or expressions within
113-
the context of [p] (for example, with variables declared in [p].
114-
Parameters [inputs] and [events] are required for interpreting the whole
115-
program. *)
111+
the context of [p] (for example, with variables declared in [p]. Parameters
112+
[inputs] and [events] are required for interpreting the whole program. *)
116113

117114
module Make (N : M_ir.Mir_number.NumberInterface) :
118115
S with type custom_float := N.t

src/mlang/mir_interpreter/eval.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module type S = sig
3535
(** Evaluates an expression. *)
3636

3737
val evaluate_program : ctx -> unit
38-
(** Evaluates a whole program. Proper initialisation of inputs and events
39-
is required before calling this function (through [update_ctx_with_inputs]
38+
(** Evaluates a whole program. Proper initialisation of inputs and events is
39+
required before calling this function (through [update_ctx_with_inputs]
4040
and [update_ctx_with_events]. *)
4141

4242
(** {2 Helpers} *)

src/mlang/mir_interpreter/eval.mli

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
val exit_on_rte : bool ref
44

5+
(** {2 Generic evaluation functions} *)
6+
7+
val evaluate_program :
8+
p:M_ir.Mir.program ->
9+
inputs:M_ir.Com.literal M_ir.Com.Var.Map.t ->
10+
events:(M_ir.Com.literal, M_ir.Com.Var.t) M_ir.Com.event_value StrMap.t list ->
11+
sort:Config.value_sort ->
12+
round_ops:Config.round_ops ->
13+
M_ir.Com.literal M_ir.Com.Var.Map.t * M_ir.Com.Error.Set.t
14+
(** Evaluates a whole program and returns the given back variables, as well as
15+
the set of anomalies. The evaluation engine is selected from [sort] and
16+
[roundops]. *)
17+
18+
val evaluate_expr :
19+
p:M_ir.Mir.program ->
20+
e:M_ir.Mir.expression Pos.marked ->
21+
sort:Config.value_sort ->
22+
round_ops:Config.round_ops ->
23+
M_ir.Com.literal
24+
(** Evaluates a single expression. The evaluation engine is selected from [sort]
25+
and [roundops]. *)
26+
27+
(** {2 Generic module type} *)
28+
529
module type S = sig
630
type custom_float
731

@@ -16,8 +40,8 @@ module type S = sig
1640
(** Evaluates an expression. *)
1741

1842
val evaluate_program : ctx -> unit
19-
(** Evaluates a whole program. Proper initialisation of inputs and events
20-
is required before calling this function (through [update_ctx_with_inputs]
43+
(** Evaluates a whole program. Proper initialisation of inputs and events is
44+
required before calling this function (through [update_ctx_with_inputs]
2145
and [update_ctx_with_events]. *)
2246

2347
(** {2 Helpers} *)
@@ -47,52 +71,47 @@ module Make
4771
(** These modules are instanes of Make with modules defined in
4872
{!module: M_ir.Mir_number} and {!module: M_ir.Mir_roundops}. *)
4973

74+
(** Float with default rounding strategy. *)
5075
module FloatDefInterp : S with type custom_float = float
5176

77+
(** Float with multithread rounding strategy. *)
5278
module FloatMultInterp : S with type custom_float = float
5379

80+
(** Float with mainframe rounding strategy. *)
5481
module FloatMfInterp : S with type custom_float = float
5582

83+
(** Multiple-precision floating-point with default rounding strategy. *)
5684
module MPFRDefInterp : S with type custom_float = Mpfrf.t
5785

86+
(** Multiple-precision floating-point with multithread rounding strategy. *)
5887
module MPFRMultInterp : S with type custom_float = Mpfrf.t
5988

89+
(** Multiple-precision floating-point with mainframe rounding strategy. *)
6090
module MPFRMfInterp : S with type custom_float = Mpfrf.t
6191

92+
(** Multiple precision integer arithmetic with default rounding strategy. *)
6293
module BigIntDefInterp : S with type custom_float = Mpzf.t
6394

95+
(** Multiple precision integer arithmetic with multihtread rounding strategy. *)
6496
module BigIntMultInterp : S with type custom_float = Mpzf.t
6597

98+
(** Multiple precision integer arithmetic with mainframe rounding strategy. *)
6699
module BigIntMfInterp : S with type custom_float = Mpzf.t
67100

68-
module IntvDefInterp : S
101+
(** Multiple-precision floating-point intervals with default rounding strategy. *)
102+
module IntvDefInterp : S with type custom_float = M_ir.Mir_number.interval
69103

70-
module IntvMultInterp : S
104+
(** Multiple-precision floating-point intervals with multithread rounding strategy. *)
105+
module IntvMultInterp : S with type custom_float = M_ir.Mir_number.interval
71106

72-
module IntvMfInterp : S
107+
(** Multiple-precision floating-point intervals with mainframe rounding strategy. *)
108+
module IntvMfInterp : S with type custom_float = M_ir.Mir_number.interval
73109

110+
(** Multiple-precision rationals with default rounding strategy. *)
74111
module RatDefInterp : S with type custom_float = Mpqf.t
75112

113+
(** Multiple-precision rationals with multithread rounding strategy. *)
76114
module RatMultInterp : S with type custom_float = Mpqf.t
77115

116+
(** Multiple-precision rationals with mainframe rounding strategy. *)
78117
module RatMfInterp : S with type custom_float = Mpqf.t
79-
80-
val evaluate_program :
81-
p:M_ir.Mir.program ->
82-
inputs:M_ir.Com.literal M_ir.Com.Var.Map.t ->
83-
events:(M_ir.Com.literal, M_ir.Com.Var.t) M_ir.Com.event_value StrMap.t list ->
84-
sort:Config.value_sort ->
85-
round_ops:Config.round_ops ->
86-
M_ir.Com.literal M_ir.Com.Var.Map.t * M_ir.Com.Error.Set.t
87-
(** Evaluates a whole program and returns the given back variables, as
88-
well as the set of anomalies.
89-
The evaluation engine is selected from [sort] and [roundops]. *)
90-
91-
val evaluate_expr :
92-
p:M_ir.Mir.program ->
93-
e:M_ir.Mir.expression Pos.marked ->
94-
sort:Config.value_sort ->
95-
round_ops:Config.round_ops ->
96-
M_ir.Com.literal
97-
(** Evaluates a single expression.
98-
The evaluation engine is selected from [sort] and [roundops]. *)

0 commit comments

Comments
 (0)