4 <:AST:> is the <:IntermediateLanguage:> produced by the <:FrontEnd:>
5 and translated by <:Elaborate:> to <:CoreML:>.
9 The abstract syntax tree produced by the <:FrontEnd:>.
13 * <!ViewGitFile(mlton,master,mlton/ast/ast-programs.sig)>
14 * <!ViewGitFile(mlton,master,mlton/ast/ast-programs.fun)>
15 * <!ViewGitFile(mlton,master,mlton/ast/ast-modules.sig)>
16 * <!ViewGitFile(mlton,master,mlton/ast/ast-modules.fun)>
17 * <!ViewGitFile(mlton,master,mlton/ast/ast-core.sig)>
18 * <!ViewGitFile(mlton,master,mlton/ast/ast-core.fun)>
19 * <!ViewGitDir(mlton,master,mlton/ast)>
23 The <:AST:> <:IntermediateLanguage:> has no independent type
24 checker. Type inference is performed on an AST program as part of
27 == Details and Notes ==
29 === Source locations ===
31 MLton makes use of a relatively clean method for annotating the
32 abstract syntax tree with source location information. Every source
33 program phrase is "wrapped" with the `WRAPPED` interface:
37 sys::[./bin/InclGitFile.py mlton master mlton/control/wrapped.sig 8:19]
40 The key idea is that `node'` is the type of an unannotated syntax
41 phrase and `obj` is the type of its annotated counterpart. In the
42 implementation, every `node'` is annotated with a `Region.t`
43 (<!ViewGitFile(mlton,master,mlton/control/region.sig)>,
44 <!ViewGitFile(mlton,master,mlton/control/region.sml)>), which describes the
45 syntax phrase's left source position and right source position, where
46 `SourcePos.t` (<!ViewGitFile(mlton,master,mlton/control/source-pos.sig)>,
47 <!ViewGitFile(mlton,master,mlton/control/source-pos.sml)>) denotes a
48 particular file, line, and column. A typical use of the `WRAPPED`
49 interface is illustrated by the following code:
53 sys::[./bin/InclGitFile.py mlton master mlton/ast/ast-core.sig 46:65]
56 Thus, AST nodes are cleanly separated from source locations. By way
57 of contrast, consider the approach taken by <:SMLNJ:SML/NJ> (and also
58 by the <:CKitLibrary:CKit Library>). Each datatype denoting a syntax
59 phrase dedicates a special constructor for annotating source
63 datatype pat = WildPat (* empty pattern *)
64 | AppPat of {constr:pat,argument:pat} (* application *)
65 | MarkPat of pat * region (* mark a pattern *)
68 The main drawback of this approach is that static type checking is not
69 sufficient to guarantee that the AST emitted from the front-end is