forked from CakeML/cakeml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RuntimeProgScript.sml
56 lines (40 loc) · 1.41 KB
/
RuntimeProgScript.sml
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
(*
Module that contains a few special functions, e.g. a function for
forcing a full GC to run, a function for producing debug output.
*)
open preamble ml_translatorLib ml_progLib cfDivTheory
mloptionTheory basisFunctionsLib
val _ = new_theory "RuntimeProg";
val _ = translation_extends "cfDiv";
val _ = ml_prog_update (open_module "Runtime");
val fullGC_def = Define `
fullGC (u:unit) = force_unit_type u (force_gc_to_run 0 0)`;
val () = next_ml_names := ["fullGC"];
val result = translate fullGC_def;
val fail_def = Define `
fail (u:unit) = force_unit_type u (force_out_of_memory_error u)`;
val () = next_ml_names := ["fail"];
val result = translate fail_def;
val debugMsg_def = Define `
debugMsg s = empty_ffi s`;
val () = next_ml_names := ["debugMsg"];
val result = translate debugMsg_def;
val exit =
``[Dletrec (unknown_loc)
["exit","i",
Let (SOME "y") (App (WordFromInt W8) [Var (Short "i")])
(Let (SOME "x") (App Aw8alloc [Lit(IntLit 1);
Var (Short "y")])
(App (FFI "exit") [Lit(StrLit ""); Var (Short "x")]))]]``
val _ = append_prog exit
val abort = process_topdecs `fun abort u = case u of () => exit 1`
val _ = append_prog abort
val _ = process_topdecs `
fun assert cond msg =
if cond
then ()
else (debugMsg msg;
abort());`
|> append_prog;
val _ = ml_prog_update (close_module NONE);
val _ = export_theory();