Define the tree IR
[tiger.ml.git] / compiler / src / lib / tiger / tiger_translate.ml
CommitLineData
cc540a7e
SK
1module List = ListLabels
2
3module Frame = Tiger_frame
4module Temp = Tiger_temp
5
6module Level = struct
7 type t =
8 { parent : t option
9 ; name : Temp.Label.t
10 ; formals : bool list
11 ; frame : Frame.t
12 }
13
14 let init =
15 let name = Temp.Label.gen () in
16 let formals = [] in
17 { parent = None
18 ; name
19 ; formals
20 ; frame = Frame.make ~name ~formals
21 }
22
23 let next t ~name ~formals =
24 (* Adding the extra parameter for the static link. See p. 142 *)
25 let formals = true :: formals in
26 { parent = Some t
27 ; name
28 ; formals
29 ; frame = Frame.make ~name ~formals
30 }
31
32 let formals = function {formals; _} ->
33 formals
34
35 let frame = function {frame; _} ->
36 frame
37end
38
42043503 39type exp = unit
cc540a7e
SK
40
41type access =
42 (* must know about static links *)
43 { level : Level.t
44 ; frame_access : Frame.access
45 }
46
47let alloc_local ~level ~escapes =
48 { level
49 ; frame_access = Frame.alloc_local (Level.frame level) ~escapes
50 }
51
52let formals ~level =
53 (* FIXME: This seems wrong. Should we call Frame.formals? *)
54 List.map (Level.formals level) ~f:(fun escapes ->
55 alloc_local ~level ~escapes
56 )
This page took 0.030672 seconds and 4 git commands to generate.