Commit | Line | Data |
---|---|---|
c0bdf964 SK |
1 | module List = ListLabels |
2 | ||
3 | module Map = Tiger_map | |
4 | module Symbol = Tiger_symbol | |
5 | module Type = Tiger_env_type | |
6 | ||
7 | type t = | |
8 | | Var of | |
9 | {ty : Type.t} | |
10 | | Fun of | |
11 | { formals : Type.t list | |
12 | ; result : Type.t | |
13 | } | |
14 | ||
15 | type env = | |
16 | (Symbol.t, t ) Map.t | |
17 | ||
18 | let built_in = | |
19 | [ ("print" , [Type.String] , Type.Unit ) | |
20 | ; ("flush" , [] , Type.Unit ) | |
21 | ; ("getchar" , [] , Type.String ) | |
22 | ; ("ord" , [Type.String] , Type.Int ) | |
23 | ; ("chr" , [Type.Int] , Type.String ) | |
24 | ; ("size" , [Type.String] , Type.Int ) | |
25 | ; ("substring" , [Type.String; Type.Int; Type.Int] , Type.String ) | |
26 | ; ("concat" , [Type.String; Type.String] , Type.String ) | |
27 | ; ("not" , [Type.Int] , Type.Int ) | |
28 | ; ("exit" , [Type.Int] , Type.Unit ) | |
29 | ] | |
30 | |> List.map ~f:(fun (name, formals, result) -> | |
31 | let key = Symbol.of_string name in | |
32 | let value = Fun {formals; result} in | |
33 | (key, value) | |
34 | ) | |
35 | |> Map.of_list |