diff options
author | Son Ho | 2021-11-03 12:04:57 +0100 |
---|---|---|
committer | Son Ho | 2021-11-03 12:04:57 +0100 |
commit | b582131d54a41a707c4ab75c3bc03251601fb230 (patch) | |
tree | dc72d71a86b4dbfecb4be77e47c489477154ba78 /src/main.ml | |
parent | 47a8983a5e95e306bddbcf031777ad781479fdd8 (diff) |
Split main.ml between Identifiers.ml and Types.ml
Diffstat (limited to '')
-rw-r--r-- | src/main.ml | 139 |
1 files changed, 1 insertions, 138 deletions
diff --git a/src/main.ml b/src/main.ml index 3b1fc58a..2248506a 100644 --- a/src/main.ml +++ b/src/main.ml @@ -1,141 +1,4 @@ -exception IntegerOverflow of unit - -(** Signature for a module describing an identifier. - - We often need identifiers (for definitions, variables, etc.) and in - order to make sure we don't mix them, we use a generative functor - (see [IdGen]). -*) -module type Id = sig - type id - - type 'a vector - - val zero : id - - val incr : id -> id - - val to_string : id -> string -end - -(** Generative functor for identifiers. - - See [Id]. -*) -module IdGen () : Id = struct - type id = int - - type 'a vector = 'a list (* TODO: use a map *) - - let zero = 0 - - let incr x = - (* Identifiers should never overflow (because max_int is a really big - * value - but we really want to make sure we detect overflows if - * they happen *) - if x == max_int then raise (IntegerOverflow ()) else x + 1 - - let to_string = string_of_int -end - -type name = string list -(** A name such as: `std::collections::vector` *) - -module TypeVarId = IdGen () - -module TypeDefId = IdGen () - -module VariantId = IdGen () - -module FieldId = IdGen () - -module RegionVarId = IdGen () - -type type_var = { - index : TypeVarId.id; (** Unique index identifying the variable *) - name : string; (** Variable name *) -} - -type region_var = { - index : RegionVarId.id; (** Unique index identifying the region *) - name : string option; (** Region name *) -} - -(** A region. - - Regions are used in function signatures (in which case we use region variable - ids) and in symbolic variables and projections (in which case we use region - ids). - *) -type 'rid region = - | Static (** Static region *) - | Var of 'rid (** Non-static region *) - -(** The type of erased regions. - - We could use unit, but having a dedicated type makes things more explicit. - *) -type erased_region = Erased - -type integer_type = - | Isize - | I8 - | I16 - | I32 - | I64 - | I128 - | Usize - | U8 - | U16 - | U32 - | U64 - | U128 - -type ref_kind = Mut | Shared - -type assumed_ty = Box - -type 'r ty = - | Adt of TypeDefId.id * 'r list * 'r ty list - | TypeVar of TypeVarId.id - | Bool - | Char - | Never - | Integer of integer_type - | Str - | Array of 'r ty (* TODO: there should be a constant with the array *) - | Slice of 'r ty - | Ref of 'r * 'r ty * ref_kind - | Tuple of 'r ty list - | Assumed of assumed_ty * 'r list * 'r ty - -type rty = RegionVarId.id region ty -(** Type with *R*egions. - - Used in function signatures and type definitions. - *) - -type ety = erased_region ty -(** Type with *E*rased regions. - - Used in function bodies, "general" value types, etc. - *) - -type field = { name : string; ty : rty } - -type variant = { name : string; fields : field FieldId.vector } - -type type_def_kind = - | Struct of field FieldId.vector - | Enum of variant VariantId.vector - -type type_def = { - def_id : TypeDefId.id; - name : name; - region_params : region_var RegionVarId.vector; - type_params : type_var TypeVarId.vector; - kind : type_def_kind; -} +open Identifiers module Id0 = IdGen () |