X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_env_value.ml;fp=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_env_value.ml;h=80f145e490981f38474459f8efdd7e8d02320993;hb=c0bdf964d389a2b9465fad44aa1f1f849c72140f;hp=0000000000000000000000000000000000000000;hpb=b762cacb0f9df0b034bb75e67c4b64151e338e92;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_env_value.ml b/compiler/src/lib/tiger/tiger_env_value.ml new file mode 100644 index 0000000..80f145e --- /dev/null +++ b/compiler/src/lib/tiger/tiger_env_value.ml @@ -0,0 +1,35 @@ +module List = ListLabels + +module Map = Tiger_map +module Symbol = Tiger_symbol +module Type = Tiger_env_type + +type t = + | Var of + {ty : Type.t} + | Fun of + { formals : Type.t list + ; result : Type.t + } + +type env = + (Symbol.t, t ) Map.t + +let built_in = + [ ("print" , [Type.String] , Type.Unit ) + ; ("flush" , [] , Type.Unit ) + ; ("getchar" , [] , Type.String ) + ; ("ord" , [Type.String] , Type.Int ) + ; ("chr" , [Type.Int] , Type.String ) + ; ("size" , [Type.String] , Type.Int ) + ; ("substring" , [Type.String; Type.Int; Type.Int] , Type.String ) + ; ("concat" , [Type.String; Type.String] , Type.String ) + ; ("not" , [Type.Int] , Type.Int ) + ; ("exit" , [Type.Int] , Type.Unit ) + ] + |> List.map ~f:(fun (name, formals, result) -> + let key = Symbol.of_string name in + let value = Fun {formals; result} in + (key, value) + ) + |> Map.of_list