forked from WebAssembly/exception-handling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance.ml
64 lines (51 loc) · 1.61 KB
/
instance.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
open Types
type module_inst =
{
types : func_type list;
funcs : func_inst list;
tables : table_inst list;
memories : memory_inst list;
events : event_inst list;
globals : global_inst list;
exports : export_inst list;
elems : elem_inst list;
datas : data_inst list;
}
and func_inst = module_inst ref Func.t
and table_inst = Table.t
and memory_inst = Memory.t
and event_inst = func_type
and global_inst = Global.t
and export_inst = Ast.name * extern
and elem_inst = Values.ref_ list ref
and data_inst = string ref
and extern =
| ExternFunc of func_inst
| ExternTable of table_inst
| ExternMemory of memory_inst
| ExternEvent of event_inst
| ExternGlobal of global_inst
(* Reference types *)
type Values.ref_ += FuncRef of func_inst
let () =
let type_of_ref' = !Values.type_of_ref' in
Values.type_of_ref' := function
| FuncRef _ -> FuncRefType
| r -> type_of_ref' r
let () =
let string_of_ref' = !Values.string_of_ref' in
Values.string_of_ref' := function
| FuncRef _ -> "func"
| r -> string_of_ref' r
(* Auxiliary functions *)
let empty_module_inst =
{ types = []; funcs = []; tables = []; memories = []; events = [];
globals = []; exports = []; elems = []; datas = [] }
let extern_type_of = function
| ExternFunc func -> ExternFuncType (Func.type_of func)
| ExternTable tab -> ExternTableType (Table.type_of tab)
| ExternMemory mem -> ExternMemoryType (Memory.type_of mem)
| ExternGlobal glob -> ExternGlobalType (Global.type_of glob)
| ExternEvent event -> ExternEventType event
let export inst name =
try Some (List.assoc name inst.exports) with Not_found -> None