Define the environments (for types and values)
[tiger.ml.git] / compiler / src / lib / tiger / tiger_env_value.ml
diff --git a/compiler/src/lib/tiger/tiger_env_value.ml b/compiler/src/lib/tiger/tiger_env_value.ml
new file mode 100644 (file)
index 0000000..80f145e
--- /dev/null
@@ -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
This page took 0.028734 seconds and 4 git commands to generate.