Source

olfend / predef.ml

Full commit
(* the predefined module *)
module Ident = struct
  open Ident
  let predef = create_with_stamp "*predef*" (-1)
  let int    = create "int"
  let float  = create "float"
  let bool   = create "bool"
  let string = create "string"
  let char   = create "char"
end

module Path = struct
  open Path
  let predef = of_ident Ident.predef
  let in_predef id = Dot (predef, id, -1)
  let int    = in_predef (Ident.int)
  let float  = in_predef (Ident.float)
  let bool   = in_predef (Ident.bool)
  let string = in_predef (Ident.string)
  let char   = in_predef (Ident.char)
end

module Decl = struct
  open Types
  let abstract id = { name = id; params = []; kind = Abstract }
  let int = abstract Ident.int
  let float = abstract Ident.float
  let bool = abstract Ident.bool
  let string = abstract Ident.string
  let char = abstract Ident.char

  let decls = [ int;
                float;
                bool;
                string;
                char ]
end


module Sig = struct
  let predef = List.map (fun decl -> Types.Type [decl]) Decl.decls
end

module Env = struct
  open Env
  let predef = { vars = (Ident.predef, Path.predef, Module (Sig.predef, Env.of_signature Path.predef Sig.predef))
                        :: List.map (fun d -> d.Types.name, Path.in_predef d.Types.name, Typedecl d) Decl.decls;
                 globals = [] }
end

module Type = struct
  let int    = Types.Constr (Path.int    , Decl.int, [])
  let float  = Types.Constr (Path.float  , Decl.float, [])
  let bool   = Types.Constr (Path.bool   , Decl.bool, [])
  let string = Types.Constr (Path.string , Decl.string, [])
  let char   = Types.Constr (Path.char   , Decl.char, [])
end

module Poly = struct
  open Types.Poly
  let int    = of_type Type.int
  let float  = of_type Type.float
  let bool   = of_type Type.bool
  let string = of_type Type.string
  let char   = of_type Type.char
end