Skip to content

Commit

Permalink
typing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
butterunderflow committed Feb 8, 2024
1 parent 30896fc commit ab607e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/typing/check.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@@@warning "-27"]
[@@@warning "-27"]

type ty = Syntax.Parsetree.type_expr

Expand Down
5 changes: 3 additions & 2 deletions lib/typing/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
(pps ppx_sexp_conv)))

(env
(dev
(flags (:standard -w -32))))
(dev
(flags
(:standard -w -32))))
23 changes: 22 additions & 1 deletion lib/typing/env.ml
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
type t
open Types

type t = {
values : (string * ty) list;
types : ty_def list;
modules : (string * mod_ty) list;
}

let add_value x ty env = { env with values = (x, ty) :: env.values }

let add_module m ty env = { env with modules = (m, ty) :: env.modules }

let add_type_def def env = { env with types = def :: env.types }

let get_value_type x env = List.assoc x env.values

let get_module_sig m env = List.assoc m env.modules

let get_type_def tn env =
List.find
(function Syntax.Parsetree.TDAdt (x, _, _) | TDAlias (x, _) -> x = tn)
env.types
2 changes: 2 additions & 0 deletions lib/typing/types.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type ty = Syntax.Parsetree.type_expr

type mod_ty = Syntax.Parsetree.mod_type

type ty_def = Syntax.Parsetree.type_def

0 comments on commit ab607e7

Please sign in to comment.