Skip to content

Commit 863b647

Browse files
committed
Split out exceptions
1 parent ef5b07b commit 863b647

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed

interpreter/exec/eval.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ let rec step (c : config) : config =
308308
| ThrowRef, Ref (NullRef _) :: vs ->
309309
vs, [Trapping "null exception reference" @@ e.at]
310310

311-
| ThrowRef, Ref (ExnRef (t, args)) :: vs ->
311+
| ThrowRef, Ref (Exn.(ExnRef (Exn (t, args)))) :: vs ->
312312
vs, [Throwing (t, args) @@ e.at]
313313

314314
| TryTable (bt, cs, es'), vs ->
@@ -1055,15 +1055,15 @@ let rec step (c : config) : config =
10551055

10561056
| Handler (n, {it = CatchRef (x1, x2); _} :: cs, (vs', {it = Throwing (a, vs0); at} :: es')), vs ->
10571057
if a == tag c.frame.inst x1 then
1058-
Ref (ExnRef (a, vs0)) :: vs0 @ vs, [Plain (Br x2) @@ e.at]
1058+
Ref Exn.(ExnRef (Exn (a, vs0))) :: vs0 @ vs, [Plain (Br x2) @@ e.at]
10591059
else
10601060
vs, [Handler (n, cs, (vs', {it = Throwing (a, vs0); at} :: es')) @@ e.at]
10611061

10621062
| Handler (n, {it = CatchAll x; _} :: cs, (vs', {it = Throwing (a, vs0); at} :: es')), vs ->
10631063
vs, [Plain (Br x) @@ e.at]
10641064

10651065
| Handler (n, {it = CatchAllRef x; _} :: cs, (vs', {it = Throwing (a, vs0); at} :: es')), vs ->
1066-
Ref (ExnRef (a, vs0)) :: vs, [Plain (Br x) @@ e.at]
1066+
Ref Exn.(ExnRef (Exn (a, vs0))) :: vs, [Plain (Br x) @@ e.at]
10671067

10681068
| Handler (n, [], (vs', {it = Throwing (a, vs0); at} :: es')), vs ->
10691069
vs, [Throwing (a, vs0) @@ at]

interpreter/runtime/exn.ml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
open Types
2+
open Value
3+
4+
type exn_ = Exn of Tag.t * value list
5+
6+
type ref_ += ExnRef of exn_
7+
8+
let alloc_exn tag vs =
9+
let TagT dt = Tag.type_of tag in
10+
assert Free.((def_type dt).types = Set.empty);
11+
let FuncT (ts1, ts2) = as_func_str_type (expand_def_type dt) in
12+
assert (List.length vs = List.length ts1);
13+
assert (ts2 = []);
14+
Exn (tag, vs)
15+
16+
let type_of_exn (Exn (tag, _)) =
17+
let TagT dt = Tag.type_of tag in
18+
dt
19+
20+
let () =
21+
let eq_ref' = !Value.eq_ref' in
22+
Value.eq_ref' := fun r1 r2 ->
23+
match r1, r2 with
24+
| ExnRef _, ExnRef _ -> failwith "eq_ref"
25+
| _, _ -> eq_ref' r1 r2
26+
27+
let () =
28+
let type_of_ref' = !Value.type_of_ref' in
29+
Value.type_of_ref' := function
30+
| ExnRef e -> DefHT (type_of_exn e)
31+
| r -> type_of_ref' r
32+
33+
let () =
34+
let string_of_ref' = !Value.string_of_ref' in
35+
Value.string_of_ref' := function
36+
| ExnRef (Exn (_tag, vs)) ->
37+
"(tag " ^ String.concat " " (List.map string_of_value vs) ^ ")"
38+
| r -> string_of_ref' r

interpreter/runtime/exn.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
open Types
2+
open Value
3+
4+
type exn_ = Exn of Tag.t * value list
5+
6+
type ref_ += ExnRef of exn_
7+
8+
val alloc_exn : Tag.t -> value list -> exn_
9+
10+
val type_of_exn : exn_ -> def_type

interpreter/runtime/instance.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ let () =
5454
| FuncRef _ -> "func"
5555
| r -> string_of_ref' r
5656

57-
let () =
58-
let eq_ref' = !Value.eq_ref' in
59-
Value.eq_ref' := fun r1 r2 ->
60-
match r1, r2 with
61-
| FuncRef f1, FuncRef f2 -> f1 == f2
62-
| _, _ -> eq_ref' r1 r2
63-
6457

6558
(* Projections *)
6659

interpreter/runtime/tag.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open Types
22

3-
type tag = {ty : tag_type}
3+
type tag
44
type t = tag
55

66
val alloc : tag_type -> tag

interpreter/runtime/value.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type value = Num of num | Vec of vec | Ref of ref_
1818
type t = value
1919

2020
type ref_ += NullRef of heap_type
21-
type ref_ += ExnRef of Tag.t * value list
2221

2322

2423
(* Injection & projection *)
@@ -109,7 +108,6 @@ let type_of_vec = type_of_vecop
109108
let type_of_ref' = ref (function _ -> assert false)
110109
let type_of_ref = function
111110
| NullRef t -> (Null, Match.bot_of_heap_type [] t)
112-
| ExnRef _ -> (NoNull, ExnHT)
113111
| r -> (NoNull, !type_of_ref' r)
114112

115113
let type_of_value = function
@@ -304,7 +302,6 @@ let hex_string_of_vec = function
304302
let string_of_ref' = ref (function _ -> "ref")
305303
let string_of_ref = function
306304
| NullRef _ -> "null"
307-
| ExnRef _ -> "exn"
308305
| r -> !string_of_ref' r
309306

310307
let string_of_value = function

interpreter/script/run.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ let assert_ref_pat r p =
401401
| RefTypePat Types.StructHT, Aggr.StructRef _
402402
| RefTypePat Types.ArrayHT, Aggr.ArrayRef _ -> true
403403
| RefTypePat Types.FuncHT, Instance.FuncRef _
404-
| RefTypePat Types.ExnHT, Value.ExnRef _
404+
| RefTypePat Types.ExnHT, Exn.ExnRef _
405405
| RefTypePat Types.ExternHT, _ -> true
406406
| NullPat, Value.NullRef _ -> true
407407
| _ -> false

interpreter/syntax/free.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ val func_type : Types.func_type -> t
2626
val global_type : Types.global_type -> t
2727
val table_type : Types.table_type -> t
2828
val memory_type : Types.memory_type -> t
29+
val tag_type : Types.tag_type -> t
2930
val extern_type : Types.extern_type -> t
3031

3132
val str_type : Types.str_type -> t

0 commit comments

Comments
 (0)