Debian Codegraph @

doc/guide/src/ImplementSuffix.adoc

raw
1 = ImplementSuffix
2
3 <<ImplementSuffix#>> is a pass for the <<SXML#>>
4 <<IntermediateLanguage#>>, invoked from <<SXMLSimplify#>>.
5
6 == Description
7
8 This pass implements the `TopLevel_setSuffix` primitive, which
9 installs a function to exit the program.
10
11 == Implementation
12
13 * https://github.com/MLton/mlton/blob/master/mlton/xml/implement-suffix.fun[`implement-suffix.fun`]
14
15 == Details and Notes
16
17 <<ImplementSuffix#>> works by introducing a new `ref` cell to contain
18 the function of type `unit \-> unit` that should be called on program
19 exit.
20
21 * The following code (appropriately alpha-converted) is appended to the beginning of the <<SXML#>> program:
22 +
23 [source,sml]
24 ----
25 val z_0 =
26 fn a_0 =>
27 let
28 val x_0 =
29 "toplevel suffix not installed"
30 val x_1 =
31 MLton_bug (x_0)
32 in
33 x_1
34 end
35 val topLevelSuffixCell =
36 Ref_ref (z_0)
37 ----
38
39 * Any occurrence of
40 +
41 [source,sml]
42 ----
43 val x_0 =
44 TopLevel_setSuffix (f_0)
45 ----
46 +
47 is rewritten to
48 +
49 [source,sml]
50 ----
51 val x_0 =
52 Ref_assign (topLevelSuffixCell, f_0)
53 ----
54
55 * The following code (appropriately alpha-converted) is appended to the end of the <<SXML#>> program:
56 +
57 [source,sml]
58 ----
59 val f_0 =
60 Ref_deref (topLevelSuffixCell)
61 val z_0 =
62 ()
63 val x_0 =
64 f_0 z_0
65 ----