1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Caml Special Light *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1995 Institut National de Recherche en Informatique et *)
|
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Abstract syntax tree after typing *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
open Asttypes
|
|
|
|
|
|
|
|
(* Type expressions for the core language *)
|
|
|
|
|
|
|
|
type type_expr =
|
1996-04-22 04:15:41 -07:00
|
|
|
{ mutable desc: type_desc;
|
|
|
|
mutable level: int }
|
|
|
|
|
|
|
|
and type_desc =
|
|
|
|
Tvar
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tarrow of type_expr * type_expr
|
|
|
|
| Ttuple of type_expr list
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tconstr of Path.t * type_expr list * (Path.t * type_expr) list ref
|
|
|
|
| Tobject of type_expr * (Path.t * type_expr list) option ref
|
|
|
|
| Tfield of Label.t * type_expr * type_expr
|
|
|
|
| Tnil
|
|
|
|
| Tlink of type_expr
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Value descriptions *)
|
|
|
|
|
|
|
|
type value_description =
|
1995-07-25 04:40:07 -07:00
|
|
|
{ val_type: type_expr; (* Type of the val *)
|
1996-04-22 04:15:41 -07:00
|
|
|
val_kind: value_kind }
|
|
|
|
|
|
|
|
and value_kind =
|
|
|
|
Val_reg (* Regular value *)
|
|
|
|
| Val_prim of Primitive.description (* Primitive *)
|
|
|
|
| Val_ivar of mutable_flag (* Instance variable (mutable ?) *)
|
|
|
|
| Val_anc of (Label.t * Ident.t) list (* Ancestor *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Constructor descriptions *)
|
|
|
|
|
|
|
|
type constructor_description =
|
|
|
|
{ cstr_res: type_expr; (* Type of the result *)
|
|
|
|
cstr_args: type_expr list; (* Type of the arguments *)
|
|
|
|
cstr_arity: int; (* Number of arguments *)
|
|
|
|
cstr_tag: constructor_tag; (* Tag for heap blocks *)
|
1995-06-18 07:47:12 -07:00
|
|
|
cstr_consts: int; (* Number of constant constructors *)
|
|
|
|
cstr_nonconsts: int } (* Number of non-const constructors *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and constructor_tag =
|
1995-06-18 07:47:12 -07:00
|
|
|
Cstr_constant of int (* Constant constructor (an int) *)
|
|
|
|
| Cstr_block of int (* Regular constructor (a block) *)
|
1995-05-22 08:43:44 -07:00
|
|
|
| Cstr_exception of Path.t (* Exception constructor *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Record label descriptions *)
|
|
|
|
|
|
|
|
type label_description =
|
|
|
|
{ lbl_res: type_expr; (* Type of the result *)
|
|
|
|
lbl_arg: type_expr; (* Type of the argument *)
|
|
|
|
lbl_mut: mutable_flag; (* Is this a mutable field? *)
|
|
|
|
lbl_pos: int; (* Position in block *)
|
1995-07-27 10:46:55 -07:00
|
|
|
lbl_all: label_description array; (* All the labels in this type *)
|
|
|
|
lbl_repres: record_representation } (* Representation for this record *)
|
|
|
|
|
|
|
|
and record_representation =
|
|
|
|
Record_regular (* All fields are boxed / tagged *)
|
|
|
|
| Record_float (* All fields are floats *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
(* Type expressions for classes *)
|
|
|
|
|
|
|
|
module Vars : Map.S with type key = Label.t
|
|
|
|
|
|
|
|
type class_type =
|
|
|
|
{ cty_params: type_expr list;
|
|
|
|
cty_args: type_expr list;
|
|
|
|
cty_vars: (mutable_flag * type_expr) Vars.t;
|
|
|
|
cty_self: type_expr;
|
|
|
|
cty_concr: Label.t list;
|
|
|
|
mutable cty_new: type_expr option }
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Value expressions for the core language *)
|
|
|
|
|
|
|
|
type pattern =
|
|
|
|
{ pat_desc: pattern_desc;
|
|
|
|
pat_loc: Location.t;
|
|
|
|
pat_type: type_expr }
|
|
|
|
|
|
|
|
and pattern_desc =
|
|
|
|
Tpat_any
|
|
|
|
| Tpat_var of Ident.t
|
|
|
|
| Tpat_alias of pattern * Ident.t
|
|
|
|
| Tpat_constant of constant
|
|
|
|
| Tpat_tuple of pattern list
|
|
|
|
| Tpat_construct of constructor_description * pattern list
|
|
|
|
| Tpat_record of (label_description * pattern) list
|
|
|
|
| Tpat_or of pattern * pattern
|
|
|
|
|
|
|
|
type expression =
|
|
|
|
{ exp_desc: expression_desc;
|
|
|
|
exp_loc: Location.t;
|
|
|
|
exp_type: type_expr }
|
|
|
|
|
|
|
|
and expression_desc =
|
|
|
|
Texp_ident of Path.t * value_description
|
|
|
|
| Texp_constant of constant
|
|
|
|
| Texp_let of rec_flag * (pattern * expression) list * expression
|
|
|
|
| Texp_function of (pattern * expression) list
|
|
|
|
| Texp_apply of expression * expression list
|
|
|
|
| Texp_match of expression * (pattern * expression) list
|
|
|
|
| Texp_try of expression * (pattern * expression) list
|
|
|
|
| Texp_tuple of expression list
|
|
|
|
| Texp_construct of constructor_description * expression list
|
|
|
|
| Texp_record of (label_description * expression) list
|
|
|
|
| Texp_field of expression * label_description
|
|
|
|
| Texp_setfield of expression * label_description * expression
|
|
|
|
| Texp_array of expression list
|
|
|
|
| Texp_ifthenelse of expression * expression * expression option
|
|
|
|
| Texp_sequence of expression * expression
|
|
|
|
| Texp_while of expression * expression
|
|
|
|
| Texp_for of
|
|
|
|
Ident.t * expression * expression * direction_flag * expression
|
|
|
|
| Texp_when of expression * expression
|
1996-04-22 04:15:41 -07:00
|
|
|
| Texp_send of expression * Label.t
|
|
|
|
| Texp_new of Path.t
|
|
|
|
| Texp_instvar of Path.t * Path.t
|
|
|
|
| Texp_setinstvar of Path.t * Path.t * expression
|
|
|
|
| Texp_override of Path.t * (Path.t * expression) list
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Type definitions *)
|
|
|
|
|
|
|
|
type type_declaration =
|
1995-09-26 13:23:29 -07:00
|
|
|
{ type_params: type_expr list;
|
1995-05-04 03:15:53 -07:00
|
|
|
type_arity: int;
|
1995-09-26 13:23:29 -07:00
|
|
|
type_kind: type_kind;
|
|
|
|
type_manifest: type_expr option }
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and type_kind =
|
|
|
|
Type_abstract
|
|
|
|
| Type_variant of (string * type_expr list) list
|
|
|
|
| Type_record of (string * mutable_flag * type_expr) list
|
|
|
|
|
|
|
|
type exception_declaration = type_expr list
|
|
|
|
|
|
|
|
(* Type expressions for the module language *)
|
|
|
|
|
|
|
|
type module_type =
|
|
|
|
Tmty_ident of Path.t
|
|
|
|
| Tmty_signature of signature
|
|
|
|
| Tmty_functor of Ident.t * module_type * module_type
|
|
|
|
|
|
|
|
and signature = signature_item list
|
|
|
|
|
|
|
|
and signature_item =
|
|
|
|
Tsig_value of Ident.t * value_description
|
|
|
|
| Tsig_type of Ident.t * type_declaration
|
|
|
|
| Tsig_exception of Ident.t * exception_declaration
|
|
|
|
| Tsig_module of Ident.t * module_type
|
|
|
|
| Tsig_modtype of Ident.t * modtype_declaration
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tsig_class of Ident.t * class_type
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and modtype_declaration =
|
|
|
|
Tmodtype_abstract
|
|
|
|
| Tmodtype_manifest of module_type
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
(* Value expressions for classes *)
|
|
|
|
|
|
|
|
type class_field =
|
|
|
|
Cf_inher of
|
|
|
|
Path.t * expression list * (Label.t * Ident.t) list *
|
|
|
|
(Label.t * Ident.t) list
|
|
|
|
| Cf_val of Label.t * Ident.t * private_flag * expression option
|
|
|
|
| Cf_meth of Label.t * expression
|
|
|
|
|
|
|
|
type class_def =
|
|
|
|
{ cl_args: pattern list;
|
|
|
|
cl_field: class_field list;
|
|
|
|
cl_loc: Location.t }
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Value expressions for the module language *)
|
|
|
|
|
|
|
|
type module_expr =
|
|
|
|
{ mod_desc: module_expr_desc;
|
|
|
|
mod_loc: Location.t;
|
|
|
|
mod_type: module_type }
|
|
|
|
|
|
|
|
and module_expr_desc =
|
|
|
|
Tmod_ident of Path.t
|
|
|
|
| Tmod_structure of structure
|
|
|
|
| Tmod_functor of Ident.t * module_type * module_expr
|
|
|
|
| Tmod_apply of module_expr * module_expr * module_coercion
|
|
|
|
| Tmod_constraint of module_expr * module_type * module_coercion
|
|
|
|
|
|
|
|
and structure = structure_item list
|
|
|
|
|
|
|
|
and structure_item =
|
|
|
|
Tstr_eval of expression
|
|
|
|
| Tstr_value of rec_flag * (pattern * expression) list
|
|
|
|
| Tstr_primitive of Ident.t * value_description
|
|
|
|
| Tstr_type of (Ident.t * type_declaration) list
|
|
|
|
| Tstr_exception of Ident.t * exception_declaration
|
|
|
|
| Tstr_module of Ident.t * module_expr
|
|
|
|
| Tstr_modtype of Ident.t * module_type
|
|
|
|
| Tstr_open of Path.t
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tstr_class of (Ident.t * class_def) list
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and module_coercion =
|
|
|
|
Tcoerce_none
|
|
|
|
| Tcoerce_structure of (int * module_coercion) list
|
|
|
|
| Tcoerce_functor of module_coercion * module_coercion
|
1995-10-23 09:59:41 -07:00
|
|
|
| Tcoerce_primitive of Primitive.description
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Auxiliary functions over the a.s.t. *)
|
|
|
|
|
|
|
|
val pat_bound_idents: pattern -> Ident.t list
|
|
|
|
val let_bound_idents: (pattern * expression) list -> Ident.t list
|
1996-02-18 06:45:54 -08:00
|
|
|
val rev_let_bound_idents: (pattern * expression) list -> Ident.t list
|