Skip to content

Commit 575dff5

Browse files
authored
flambda-backend: CMM traps (oxcaml#72)
1 parent 8a87272 commit 575dff5

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

testsuite/tests/asmgen/catch-try-float.cmm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ arguments = "-DFLOAT_CATCH -DFUN=catch_try_float main.c"
77
(function "catch_try_float" (b:float)
88
(+f 10.0
99
(catch
10-
(try (exit lbl 100.0)
10+
(try (exit(1) lbl 100.0)
1111
with var 456.0)
1212
with (lbl x:float) (+f x 1000.0))))

testsuite/tests/asmgen/catch-try.cmm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ arguments = "-DINT_INT -DFUN=catch_exit main.c"
77
(function "catch_exit" (b:int)
88
(+ 33
99
(catch
10-
(try (exit lbl 12)
10+
(try (exit(1) lbl 12)
1111
with var 456)
1212
with (lbl x:val) (+ x 789))))

testsuite/tools/parsecmm.mly

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let make_switch n selector caselist =
3737
let index = Array.make n 0 in
3838
let casev = Array.of_list caselist in
3939
let dbg = Debuginfo.none in
40-
let actv = Array.make (Array.length casev) (Cexit(0,[]), dbg) in
40+
let actv = Array.make (Array.length casev) (Cexit(Cmm.Lbl 0,[],[]), dbg) in
4141
for i = 0 to Array.length casev - 1 do
4242
let (posl, e) = casev.(i) in
4343
List.iter (fun pos -> index.(pos) <- i) posl;
@@ -206,6 +206,9 @@ componentlist:
206206
component { [$1] }
207207
| componentlist STAR component { $3 :: $1 }
208208
;
209+
traps:
210+
LPAREN INTCONST RPAREN { List.init $2 (fun _ -> Pop) }
211+
| /**/ { [] }
209212
expr:
210213
INTCONST { Cconst_int ($1, debuginfo ()) }
211214
| FLOATCONST { Cconst_float (float_of_string $1, debuginfo ()) }
@@ -241,22 +244,22 @@ expr:
241244
match $3 with
242245
Cconst_int (x, _) when x <> 0 -> $4
243246
| _ -> Cifthenelse($3, debuginfo (), $4, debuginfo (),
244-
(Cexit(lbl0,[])),
247+
(Cexit(Cmm.Lbl lbl0,[],[])),
245248
debuginfo ()) in
246249
Ccatch(Nonrecursive, [lbl0, [], Ctuple [], debuginfo ()],
247250
Ccatch(Recursive,
248-
[lbl1, [], Csequence(body, Cexit(lbl1, [])), debuginfo ()],
249-
Cexit(lbl1, []))) }
250-
| LPAREN EXIT IDENT exprlist RPAREN
251-
{ Cexit(find_label $3, List.rev $4) }
251+
[lbl1, [], Csequence(body, Cexit(Cmm.Lbl lbl1, [], [])), debuginfo ()],
252+
Cexit(Cmm.Lbl lbl1, [], []))) }
253+
| LPAREN EXIT traps IDENT exprlist RPAREN
254+
{ Cexit(Cmm.Lbl (find_label $4), List.rev $5, $3) }
252255
| LPAREN CATCH sequence WITH catch_handlers RPAREN
253256
{ let handlers = $5 in
254257
List.iter (fun (_, l, _, _) ->
255258
List.iter (fun (x, _) -> unbind_ident x) l) handlers;
256259
Ccatch(Recursive, handlers, $3) }
257-
| EXIT { Cexit(0,[]) }
260+
| EXIT { Cexit(Cmm.Lbl 0,[],[]) }
258261
| LPAREN TRY sequence WITH bind_ident sequence RPAREN
259-
{ unbind_ident $5; Ctrywith($3, $5, $6, debuginfo ()) }
262+
{ unbind_ident $5; Ctrywith($3, Regular, $5, $6, debuginfo ()) }
260263
| LPAREN VAL expr expr RPAREN
261264
{ let open Asttypes in
262265
Cop(Cload (Word_val, Mutable), [access_array $3 $4 Arch.size_addr],

0 commit comments

Comments
 (0)