Skip to content

Commit

Permalink
Fix small bugs in fldiff and the fexpr parser/printer (ocaml-flambda#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin authored Mar 9, 2023
1 parent cc8d97a commit 6edf34f
Show file tree
Hide file tree
Showing 7 changed files with 2,163 additions and 1,982 deletions.
1,699 changes: 916 additions & 783 deletions middle_end/flambda2/parser/flambda_lex.ml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion middle_end/flambda2/parser/flambda_lex.mll
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ let keyword_table =
"inlining_state", KWD_INLINING_STATE;
"int32", KWD_INT32;
"int64", KWD_INT64;
"land", KWD_LAND;
"let", KWD_LET;
"lsl", KWD_LSL;
"lsr", KWD_LSR;
Expand Down Expand Up @@ -187,8 +188,9 @@ let oct_literal =
'0' ['o' 'O'] ['0'-'7'] ['0'-'7' '_']*
let bin_literal =
'0' ['b' 'B'] ['0'-'1'] ['0'-'1' '_']*
let sign = ['-']
let int_literal =
decimal_literal | hex_literal | oct_literal | bin_literal
sign? (decimal_literal | hex_literal | oct_literal | bin_literal)
let float_literal =
['0'-'9'] ['0'-'9' '_']*
('.' ['0'-'9' '_']* )?
Expand Down Expand Up @@ -243,6 +245,7 @@ rule token = parse
| "%" { PERCENT }
| "<" { LESS }
| ">" { GREATER }
| "<>" { LESSGREATER }
| "<=" { LESSEQUAL }
| ">=" { GREATEREQUAL }
| "?" { QMARK }
Expand Down
2,424 changes: 1,230 additions & 1,194 deletions middle_end/flambda2/parser/flambda_parser.ml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions middle_end/flambda2/parser/flambda_parser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type token =
| MINUS
| LPAREN
| LESSMINUS
| LESSGREATER
| LESSEQUALDOT
| LESSEQUAL
| LESSDOT
Expand Down
10 changes: 7 additions & 3 deletions middle_end/flambda2/parser/flambda_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ let make_boxed_const_int (i, m) : static_data =
%token LESSEQUAL [@symbol "<="]
%token LESSEQUALDOT [@symbol "<=."]
%token LESSMINUS [@symbol "<-"]
%token LESSGREATER [@symbol "<>"]
%token LPAREN [@symbol "("]
%token MINUS [@symbol "-"]
%token MINUSDOT [@symbol "-."]
Expand Down Expand Up @@ -306,9 +307,10 @@ code:
MINUSGREATER; ret_cont = continuation_id;
exn_cont = exn_continuation_id;
ret_arity = return_arity;
is_tupled = boption(KWD_TUPLED);
EQUAL; body = expr;
{ let recursive, inline, id, newer_version_of, code_size = header in
{ let recursive, inline, id, newer_version_of, code_size, is_tupled =
header
in
{ id; newer_version_of; param_arity = None; ret_arity; recursive; inline;
params_and_body = { params; closure_var; region_var; depth_var;
ret_cont; exn_cont; body };
Expand All @@ -321,8 +323,9 @@ code_header:
inline = option(inline);
KWD_SIZE LPAREN; code_size = code_size; RPAREN;
newer_version_of = option(newer_version_of);
is_tupled = boption(KWD_TUPLED);
id = code_id;
{ recursive, inline, id, newer_version_of, code_size }
{ recursive, inline, id, newer_version_of, code_size, is_tupled }
;

newer_version_of:
Expand Down Expand Up @@ -463,6 +466,7 @@ binary_float_arith_op:
int_comp:
| LESS { fun s -> Yielding_bool (Lt s) }
| GREATER { fun s -> Yielding_bool (Gt s) }
| LESSGREATER { fun s -> Yielding_bool Neq }
| LESSEQUAL { fun s -> Yielding_bool (Le s) }
| GREATEREQUAL { fun s -> Yielding_bool (Ge s) }
| QMARK { fun s -> Yielding_int_like_compare_functions s }
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/print_fexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ and code_binding ppf
inline code_size cs
(pp_option ~space:Before (pp_like "newer_version_of(%a)" code_id))
newer_version_of
(fun ppf is_tupled -> if is_tupled then Format.fprintf ppf "tupled@ ")
(fun ppf is_tupled -> if is_tupled then Format.fprintf ppf "@ tupled@ ")
is_tupled code_id id;
let { params; closure_var; region_var; depth_var; ret_cont; exn_cont; body } =
params_and_body
Expand Down
4 changes: 4 additions & 0 deletions middle_end/flambda2/tests/tools/fldiff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ let _ =
let file2 = Sys.argv.(2) in
let unit1 = Test_utils.parse_flambda file1 in
let unit2 = Test_utils.parse_flambda file2 in
let modname1 =
Parse_flambda.make_compilation_unit ~filename:file1 ~extension:".fl" ()
in
Compilation_unit.set_current (Some modname1);
Format.printf "%a@."
(Compare.Comparison.print Flambda_unit.print)
(Compare.flambda_units unit1 unit2)
Expand Down

0 comments on commit 6edf34f

Please sign in to comment.