-
Notifications
You must be signed in to change notification settings - Fork 523
Expand file tree
/
Copy pathenv.ml
More file actions
46 lines (34 loc) · 1.06 KB
/
env.ml
File metadata and controls
46 lines (34 loc) · 1.06 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
(*
* Emulation of (a subset of) the `env` module currently used by Binaryen,
* so that we can run modules generated by Binaryen. This is a stopgap until
* we have agreement on what libc should look like.
*)
open Values
open Types
open Instance
let error msg = raise (Eval.Crash (Source.no_region, msg))
let type_error v t =
error
("type error, expected " ^ string_of_value_type t ^
", got " ^ string_of_value_type (type_of_value v))
let empty = function
| [] -> ()
| _vs -> error "type error, too many arguments"
let single = function
| [] -> error "type error, missing arguments"
| [v] -> v
| _vs -> error "type error, too many arguments"
let int = function
| Num (I32 i) -> Int32.to_int i
| v -> type_error v (NumType I32Type)
let abort vs =
empty vs;
print_endline "Abort!";
exit (-1)
let exit vs =
exit (int (single vs))
let lookup name t =
match Utf8.encode name, t with
| "abort", ExternFuncType t -> ExternFunc (Func.alloc_host t abort)
| "exit", ExternFuncType t -> ExternFunc (Func.alloc_host t exit)
| _ -> raise Not_found