Skip to content

Commit

Permalink
Minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
noeensarguet committed Nov 27, 2023
1 parent 906230c commit 9ca3ac1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 46 deletions.
14 changes: 9 additions & 5 deletions src/irj_parser/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
(ocamlopt_flags
(-O3 -ccopt -static))))

(executable
(name main)
(package irj_parser)
(public_name irj_parser.exe)
(libraries irj_parser))
(library
(name irj_include)
(public_name irj_parser))

(ocamllex irj_lexer)

(menhir
(modules irj_parser)
(flags --strict --explain))
14 changes: 8 additions & 6 deletions src/irj_parser/src/irj_ast.ml → src/irj_parser/irj_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>. *)

type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position }
type pos = {
pos_filename : string;
pos_loc : Lexing.position * Lexing.position;
}

let mk_position sloc =
{ pos_filename = (fst sloc).Lexing.pos_fname; pos_loc = sloc }

exception
StructuredError of (string * (string option * t) list * (unit -> unit) option)
exception TestParsingError of (string * pos)
(* duplication of some of the utils *)

type literal = I of int | F of float

type var_value = string * literal * t
type var_value = string * literal * pos

(* type var_values = var_value list *)

type calc_error = string * t
type calc_error = string * pos

(* type calc_errors = calc_error list *)

Expand All @@ -49,7 +51,7 @@ type rappel = {
(* MMYYYY *)
decl_2042_rect : int option;
(* 0 or 1 *)
pos : t;
pos : pos;
}

type prim_data_block = {
Expand Down
9 changes: 4 additions & 5 deletions src/irj_parser/src/irj_file.ml → src/irj_parser/irj_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ let parse_file (test_name : string) : irj_file =
in
let f =
try Irj_parser.irj_file Irj_lexer.token filebuf with
| StructuredError e ->
| TestParsingError e ->
close_in input;
raise (StructuredError e)
raise (TestParsingError e)
| Irj_parser.Error ->
close_in input;
raise
(StructuredError
(TestParsingError
( "Test syntax error",
[ (None, mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) ],
None ))
mk_position (filebuf.lex_start_p, filebuf.lex_curr_p) ))
in
close_in input;
f
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ open Irj_parser
open Irj_ast

let error lb msg =
raise (StructuredError ("Lexing error : " ^ msg,
[ (None, mk_position (Lexing.lexeme_start_p lb, Lexing.lexeme_end_p lb)) ],
None))
raise (TestParsingError ("Lexing error : " ^ msg,
mk_position (Lexing.lexeme_start_p lb, Lexing.lexeme_end_p lb)))

module StrMap = Map.Make (String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
%{ open Irj_ast

let error (sp, ep) msg =
raise (StructuredError ("Parse error : " ^ msg, [ (None, mk_position (sp, ep)) ], None))

raise (TestParsingError ("Parse error : " ^ msg, mk_position (sp, ep)))
%}

%token<string> SYMBOL NAME
Expand Down
Empty file removed src/irj_parser/main.ml
Empty file.
15 changes: 0 additions & 15 deletions src/irj_parser/src/dune

This file was deleted.

16 changes: 9 additions & 7 deletions src/mlang/test_framework/test_interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>. *)

open Irj_ast
open Irj_include

let convert_pos (sloc : Irj_ast.t) : Pos.t =
{ pos_filename = sloc.pos_filename; pos_loc = sloc.pos_loc }
let convert_pos (pos : Irj_ast.pos) =
Pos.make_position pos.pos_filename pos.pos_loc

(* enforces type compatibility (the type t is defined in exactly the same way in
Irj_ast and in Pos) *)
(* enforces type compatibility (the type Irj_ast.pos is defined in exactly the
same way as Pos.t) *)

let to_ast_literal (value : Irj_ast.literal) : Mast.literal =
match value with I i -> Float (float_of_int i) | F f -> Float f
Expand All @@ -42,7 +42,7 @@ let find_var_of_name (p : Mir.program) (name : string Pos.marked) :
v2.Mir.Variable.execution_number)
(Pos.VarNameToID.find name p.program_idmap))

let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file)
let to_MIR_function_and_inputs (program : Bir.program) (t : Irj_ast.irj_file)
(test_error_margin : float) :
Bir_interface.bir_function * Mir.literal Bir.VariableMap.t =
let func_variable_inputs, input_file =
Expand All @@ -53,7 +53,9 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file)
|> Bir.(var_from_mir default_tgv)
in
let lit =
match value with I i -> Mir.Float (float_of_int i) | F f -> Float f
match value with
| Irj_ast.I i -> Mir.Float (float_of_int i)
| F f -> Float f
in
(Bir.VariableMap.add var () fv, Bir.VariableMap.add var lit in_f))
(Bir.VariableMap.empty, Bir.VariableMap.empty)
Expand Down
4 changes: 1 addition & 3 deletions src/mlang/utils/pos.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

(** {2 Source code position} *)

type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position }
(* opened this type. Not very satisfactory but necessary to enforce the
compatibility of this type t and that of the module Irj_parser *)
type t

val make_position : string -> Lexing.position * Lexing.position -> t

Expand Down

0 comments on commit 9ca3ac1

Please sign in to comment.