Module Bmdtc (.ml)


module Bmdtc: sig .. end
Bombs-Must-Detonate: BMDLang Type Checker

Bombs-Must-Detonate: BMDLang Type Checker Signature
Author(s): Brian Go, Brian Go



type bmdtype =
| TyInt
| TyFloat
| TyString
| TyBool
| TyVoid
| TyList of bmdtype
| TyEnumType of string
| TyEnum of string
| TyStruct of string
| TyArray of bmdtype
| TyArrow of bmdtype list * bmdtype
| TyRef of bmdtype
| TyTemplate of string
Used to type any element of the AST

type typeenvdef =
| TyEnumDef of string * string list
| TyStructDef of string * (string * bmdtype) list * Ast.data_type list
| TyFunDef of string * bmdtype
| TyVarDef of string * bmdtype
| TyTemplateDef of string list
| TyIncludeDef of string
Used to keep track of the typing environment during typechecking

Used to keep track of the typing environment during typechecking

exception Type_error of string
val elim_repeats : 'a list -> 'a list
Eliminates duplicate entries in a list
val link_buffer : string list Pervasives.ref
Linker header information buffer
val reset_link_buffer : unit -> unit
Clears the linker header information buffer

Resets the buffer which stores the linker header information generated by the typechecker.

val get_link_buffer : unit -> string
Gets the contents of the linker header infromation

Gets the linker header information.

val append_link_buffer : string -> unit
Appends a string to the linker buffer
val raise_type_error : string list -> 'a
Raises a type error from the concatenated string list
val concat : string list -> string
Renaming of String.concat ""
val concat_commas : string list -> string
Concatenates a list with commas. No comma after the final element.
val get_first : ('a * 'b) list -> 'a list
Replaces an association list by a list of keys
val get_second : ('a * 'b) list -> 'b list
Replaces an association list by a list of values
val isdef_struct : string -> typeenvdef list -> bool
Checks if the given struct name is defined in the environment
val isdef_enum : string -> typeenvdef list -> bool
Checks if the given enum is defined in the environment
val isdef_var : string -> typeenvdef list -> bool
Checks if the given variable is defined in the environment
val isdef_fun : string -> typeenvdef list -> bool
Checks if the given function is defined in the environment
val isdef_templated : string -> typeenvdef list -> bool
Checks if the given template definition is defined in the environment
val remove_template_def : typeenvdef list -> typeenvdef list
Removes the most recent template definition from the environment
val isdef_ident : string -> typeenvdef list -> bool
Checks if the given identifier is defined as a struct, enum, variable, or function in the environment
val gettype_var : string -> typeenvdef list -> bmdtype
Gets the type of the given variable from the environment. Raises Not_found if not defined.
val gettype_fun : string -> typeenvdef list -> bmdtype
Gets the type of the given function from the environment. Raises Not_found if not defined.
val is_enum_value : string -> string -> typeenvdef list -> bool
Checks if s2 is an enum value of enum type s1. Raises Not_found if s1 is not an enum type.
val isdef_include : string -> typeenvdef list -> bool
Checks if file "name" has been included in the given environment
val indexof : 'a -> 'a list -> int -> int
Finds the index of a value in a list. Raises Not_found if it is not in the list
val get_enum_value : string -> string -> typeenvdef list -> int
Casts enum value s1.s2 to an integer. Raises Not_found if s1.s2 is not defined
val get_nvalues_enum : string -> typeenvdef list -> int
Gets the total number of values of enum type ename. Raises Not_found if ename is not an enum type
val is_struct_value : string -> string -> typeenvdef list -> bool
Checks if s2 is a field of struct s1 from the environment. Raises Not_found if s1 is not a struct
val gettype_struct : string -> string -> typeenvdef list -> bmdtype
Gets the data type of field s2 of struct s1 from the environment. Raises Not_found if s1 is not a struct
val getfield_struct : string -> string -> typeenvdef list -> int
Returns the integer index of field s2 in struct s1 as determined by environment env
val getfields_struct : string -> typeenvdef list -> (string * bmdtype) list
Returns the (string * bmdtype) list of struct fields of struct s1. Raises Not_found if s1 is not defined.
val nfields_struct : string -> typeenvdef list -> int
Gets the number of fields of struct sname from the environment. Raises Not_found if sname is not defined.
val get_struct_data_type_list : string -> typeenvdef list -> Ast.data_type list
Gets the AST data types of the struct fields
val annotate_data_type : Ast.data_type -> typeenvdef list -> unit
Annotates the data type AST element with information that will be needed by the IR
val make_struct_type_list : Ast.var_declare list -> typeenvdef list -> Ast.data_type list
Creates a list of AST data type elements correlated with the struct fields
val string_of_type : bmdtype -> string
Gives a string representation of the given type

Gives a string representation of a given type.

val expanded_string_of_enum : string -> typeenvdef list -> string
Gives an expanded string representation of the given enum type detailing its total number of values
val expanded_string_of_struct : string -> typeenvdef list -> string
Gives an expanded string representation of the given struct type which includes the expanded representation of each of its fields
val expanded_string_of_type : bmdtype -> typeenvdef list -> string
Gives a string representation of the given type with expanded represnetations of structs and enums
val isallowed_binop : Ast.binop -> bmdtype -> bmdtype -> bool
Checks if op is a valid operator on values of type t1 and t2
val gettype_binop : Ast.binop -> bmdtype -> bmdtype -> bmdtype
Gets the type of the result of operator op on values of type t1 and t2. Type error if invalid operator.
val type_data_types : Ast.data_type list -> typeenvdef list -> bmdtype list
Types a list of AST data type element
val type_data_type : Ast.data_type -> typeenvdef list -> bmdtype
Types a single AST data type element
val structdef_list : Ast.var_declare list ->
typeenvdef list -> (string * bmdtype) list
Types the declaration of a list of struct fields. Initial values not allowed, type error if they are.
val vardef_arglist : (Ast.data_type * string) list ->
typeenvdef list -> typeenvdef list
Types an argument list to a function, adding the arguments as variable declarations to the environment.
val type_value : Ast.value -> typeenvdef list -> bmdtype * typeenvdef list
Types a value
val string_of_type_list : bmdtype list -> string
Produces a comma-separated string representation of a list of types
val are_assoclists_compatible : (string * bmdtype) list -> (string * bmdtype) list -> bool
Checks if association list l1 has no conflicting key/value pairs with association list l2
val unify_types : bmdtype -> bmdtype -> (string * bmdtype) list
Returns an association list of template types to bmdtypes. Type error if t2 cannot be unified to t1.
val insert_template_types : (string * bmdtype) list ->
typeenvdef list -> bmdtype -> bmdtype
Uses the association list (substitution list) template_map (key: template string, value: bmdtype) to type the given data type with those substitutions
val apply_arrow_type : bmdtype -> bmdtype list -> typeenvdef list -> bmdtype
Apply argtypes to the arrow type, making sure there are no template inconsistencies, and get the return type
val type_function_call_value : Ast.function_call ->
typeenvdef list -> bmdtype * typeenvdef list
Types a function call as a value-producer (checks argument types, gives the return type). Updates the linker header with inferred remote call types.
val type_binop : Ast.value_producer ->
Ast.binop ->
Ast.value_producer ->
typeenvdef list -> bmdtype * typeenvdef list
Types a binary operation vp1 op vp2. Type error if not a valid operation
val type_prefix_unop : Ast.pre_unop ->
Ast.value_producer ->
typeenvdef list -> bmdtype * typeenvdef list
Types a unary operation expression. Type error if not a valid operation.
val type_array_value_producer : Ast.value_producer list ->
typeenvdef list -> bmdtype * typeenvdef list
Types an array value producer (i.e. . Error if empty (we need to infer the type), or if values of different types are used.
val type_value_producer_list : Ast.value_producer list ->
typeenvdef list -> bmdtype * typeenvdef list
Types a list of value producers (i.e. elem1; elem2;...) Error if empty or if values of different types are used.
val type_list_value_producer : Ast.list_value_producer ->
typeenvdef list -> bmdtype * typeenvdef list
Types a list value producer
val type_value_producer : Ast.value_producer ->
typeenvdef list -> bmdtype * typeenvdef list
Types a value producer
val type_value_producer_list_nonuniform : Ast.value_producer list ->
typeenvdef list -> bmdtype list * typeenvdef list
Returns a list of types, i.e. for parameters
val type_variable_identifier : Ast.var_ident ->
typeenvdef list -> bmdtype * typeenvdef list
Types a variable identifier
val type_var_assign : Ast.var_assign ->
typeenvdef list -> bmdtype * typeenvdef list
Types a variable assignment
val type_var_declaration : Ast.var_declare ->
typeenvdef list -> bmdtype * typeenvdef list
Types a variable declaration
val type_conditional : Ast.conditional ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types a conditional expression
val type_continued_conditional : Ast.continued_conditional ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types an else case
val type_loop : Ast.loop ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types a loop
val type_function_call : Ast.function_call ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types a function call expression. This is not a value producer, so regardless of return type the expression will have type void
val type_expression : Ast.expression ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types an expression. We use void to indicate a successful typing, since expressions have no actual type.
val type_expression_list : Ast.expression list ->
typeenvdef list ->
bmdtype -> bmdtype * typeenvdef list
Types an expression list. Checks if all expressions are validly (void) typed, and then returns void type. Otherwise raises type errors
val type_program : Ast.src_program ->
typeenvdef list -> bmdtype * typeenvdef list
Types a program (top-level expression list
val type_global_expression : Ast.global_expression ->
typeenvdef list -> bmdtype * typeenvdef list
Types a top level expression
val is_typed : Ast.src_program -> bool
Determines whether an AST is validly typed. Prints typing exceptions.

Determines whether an AST is validly typed. Prints typing exceptions.