ad274638137d7ef5369993f81a04b7a6b27b6410
[tiger.ml.git] / compiler / src / lib / tiger / tiger_env_value.ml
1 module List = ListLabels
2
3 module Map = Tiger_map
4 module Symbol = Tiger_symbol
5 module Temp = Tiger_temp
6 module Translate = Tiger_translate
7 module Type = Tiger_env_type
8
9 type t =
10 | Var of
11 { access : Tiger_translate.access
12 ; ty : Tiger_env_type.t
13 }
14 | Fun of
15 { formals : Tiger_env_type.t list
16 ; result : Tiger_env_type.t
17 ; level : Tiger_translate.Level.t
18 ; label : Tiger_temp.Label.t
19 }
20
21 type env =
22 (Symbol.t, t ) Map.t
23
24 let built_in =
25 [ ("print" , [Type.String] , Type.Unit )
26 ; ("flush" , [] , Type.Unit )
27 ; ("getchar" , [] , Type.String )
28 ; ("ord" , [Type.String] , Type.Int )
29 ; ("chr" , [Type.Int] , Type.String )
30 ; ("size" , [Type.String] , Type.Int )
31 ; ("substring" , [Type.String; Type.Int; Type.Int] , Type.String )
32 ; ("concat" , [Type.String; Type.String] , Type.String )
33 ; ("not" , [Type.Int] , Type.Int )
34 ; ("exit" , [Type.Int] , Type.Unit )
35 ]
36 |> List.map ~f:(fun (name, formals, result) ->
37 let key = Symbol.of_string name in
38 let level = Translate.Level.init in
39 let label = Temp.Label.gen () in
40 let value = Fun {formals; result; level; label} in
41 (key, value)
42 )
43 |> Map.of_list
This page took 0.08142 seconds and 5 git commands to generate.