Module Cobol_ir.Types

Data representation

Representations are parametric in the type 'f of field values, as well as the type 'r of record memory.

type 'f field =
  1. | Field_constant of 'f immutable_field
  2. | Field_in_memory of 'f mutable_field

Manipulated COBOL fields may either be constant or lie in memory.

and 'f mutable_field = {
  1. field_value : 'f addressable_field;
  2. field_initial_value : 'f immutable_field option;
  3. field_definition : Cobol_data.Types.field_definition Cobol_common.Srcloc.TYPES.with_loc;
}

A field in memory is addressable and may have an initial value. It always comes from a definition in a COBOL source.

and 'f addressable_field =
  1. | Fixed_field of 'f

Adressable fields may either be fixed, or require subscript data.

and 'f immutable_field = 'f

We directly map immutable fields with their value representation.

and 'r record_handle = {
  1. record_memory : 'r;
  2. record_definition : Cobol_data.Types.record;
}

Handle for record memory; we just keep the definition.

Module representation

In addition to the type variables above, the type of modules is parametric in the type 'm of module memory.

module FIELDS_MAP = Cobol_unit.Resolver_map
type 'f fields_map = 'f mutable_field FIELDS_MAP.t

Named fields are always associated with fields that lie in memory (immutable fields typically come from literals in source programs).

type 'f fields_data = {
  1. map : 'f fields_map;
  2. working_storage : 'f mutable_field list;
  3. local_storage : 'f mutable_field list;
}

Structure that gathers elements from the DATA DIVISION of a module.

type 'f statement =
  1. | Core_display of {
    1. fields : 'f field array;
    2. advancing : bool;
    }
  2. | Core_stop of {
    1. optional_status : 'f field option;
    }

High-level statements for the PROCEDURE DIVISION.

type 'f code_block = 'f statement Cobol_common.Srcloc.TYPES.with_loc list

A block of code that is amenable to interpretation; for now, only a list of statements.

type ('f, 'm) module_handle = {
  1. module_memory : 'm;
  2. module_unit : Cobol_unit.Types.t;
  3. module_fields : 'f fields_data;
  4. module_proc : 'f code_block;
  5. mutable module_initialized : bool;
}
type unsupported_stuff = ..
type unsupported_stuff +=
  1. | Statement of Cobol_ptree.statement
  2. | Term : 'a Cobol_ptree.term -> unsupported_stuff
  3. | Field_in_occurs
  4. | Variable_length_field
type undefined_stuff =
  1. | Data_reference of Cobol_ptree.qualname
type ambiguous_stuff =
  1. | Data_reference of Cobol_ptree.qualname
type error = ..
type error +=
  1. | Unsupported of {
    1. loc : Cobol_common.Srcloc.TYPES.srcloc;
    2. stuff : unsupported_stuff;
    }
  2. | Undefined of {
    1. loc : Cobol_common.Srcloc.TYPES.srcloc;
    2. stuff : undefined_stuff;
    }
  3. | Ambiguous of {
    1. loc : Cobol_common.Srcloc.TYPES.srcloc;
    2. stuff : ambiguous_stuff;
    3. candidates : Cobol_ptree.qualname NEL.t;
    }
type errors = error NEL.t
exception FATAL of errors
type computation_state =
  1. | Running
  2. | Stopping of int
type ('f, 'r, 'm) value_manager = {
  1. create_record_data : Cobol_data.Types.record -> 'r record_handle;
  2. create_mutable_field : Cobol_data.Types.field_definition Cobol_common.Srcloc.TYPES.with_loc -> 'r record_handle -> ('f mutable_field, errors) Stdlib.result;
  3. create_field_from_literal : Cobol_ptree.literal Cobol_common.Srcloc.TYPES.with_loc -> ('f immutable_field, errors) Stdlib.result;
  4. create_module : name:string -> source_file:string -> 'm;
  5. enter_module : ('f, 'm) module_handle -> params:'f array -> unit;
  6. leave_module : ('f, 'm) module_handle -> unit;
  7. init_field : vm:('f, 'r, 'm) value_manager -> 'f mutable_field -> (unit, errors) Stdlib.result;
  8. field_as_int : vm:('f, 'r, 'm) value_manager -> 'f field -> (int, errors) Stdlib.result;
  9. display_fields : vm:('f, 'r, 'm) value_manager -> advancing:bool -> 'f field array -> (unit, errors) Stdlib.result;
}