summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Identifiers.ml42
-rw-r--r--src/Types.ml97
-rw-r--r--src/main.ml139
3 files changed, 140 insertions, 138 deletions
diff --git a/src/Identifiers.ml b/src/Identifiers.ml
new file mode 100644
index 00000000..b46b00ee
--- /dev/null
+++ b/src/Identifiers.ml
@@ -0,0 +1,42 @@
+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` *)
diff --git a/src/Types.ml b/src/Types.ml
new file mode 100644
index 00000000..d435863e
--- /dev/null
+++ b/src/Types.ml
@@ -0,0 +1,97 @@
+open Identifiers
+
+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;
+}
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 ()