-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathspectest.ml
More file actions
64 lines (53 loc) · 1.93 KB
/
Copy pathspectest.ml
File metadata and controls
64 lines (53 loc) · 1.93 KB
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
(*
* Simple collection of functions useful for writing test cases.
*)
open Types
open Value
open Instance
let global (GlobalT (_, t) as gt) =
let v =
match t with
| NumT I32T -> Num (I32 666l)
| NumT I64T -> Num (I64 666L)
| NumT F32T -> Num (F32 (F32.of_float 666.6))
| NumT F64T -> Num (F64 (F64.of_float 666.6))
| VecT V128T -> Vec (V128 (V128.I32x4.of_lanes [666l; 666l; 666l; 666l]))
| RefT (_, t) -> Ref (NullRef t)
| BotT -> assert false
in ExternGlobal (Global.alloc gt v)
let table =
let tt = TableT (I32AT, {min = 10L; max = Some 20L}, (Null, FuncHT)) in
ExternTable (Table.alloc tt (NullRef FuncHT))
let table64 =
let tt = TableT (I64AT, {min = 10L; max = Some 20L}, (Null, FuncHT)) in
ExternTable (Table.alloc tt (NullRef FuncHT))
let memory =
let mt = MemoryT (I32AT, {min = 1L; max = Some 2L}, PageT 0x10000) in
ExternMemory (Memory.alloc mt)
let func f ts1 ts2 =
let dt = DefT (RecT [SubT (Final, [], FuncT (ts1, ts2))], 0l) in
ExternFunc (Func.alloc_host dt (f ts1 ts2))
let print_value v =
Printf.printf "%s : %s\n"
(string_of_value v) (string_of_valtype (type_of_value v))
let print _ts1 _ts2 vs =
List.iter print_value vs;
flush_all ();
[]
let lookup name t =
match Utf8.encode name, t with
| "print", _ -> func print [] []
| "print_i32", _ -> func print [NumT I32T] []
| "print_i64", _ -> func print [NumT I64T] []
| "print_f32", _ -> func print [NumT F32T] []
| "print_f64", _ -> func print [NumT F64T] []
| "print_i32_f32", _ -> func print [NumT I32T; NumT F32T] []
| "print_f64_f64", _ -> func print [NumT F64T; NumT F64T] []
| "global_i32", _ -> global (GlobalT (Cons, NumT I32T))
| "global_i64", _ -> global (GlobalT (Cons, NumT I64T))
| "global_f32", _ -> global (GlobalT (Cons, NumT F32T))
| "global_f64", _ -> global (GlobalT (Cons, NumT F64T))
| "table", _ -> table
| "table64", _ -> table64
| "memory", _ -> memory
| _ -> raise Not_found