The System Library (SLIB)

The B-Toolkit is supplied with a set of reusable machines which encapsulate basic state and data-structures, and provide basic abstract types.

These library machines are described here. The text of the machines is presented separately.



The Role of the System Library

Static and persistent data of an implementation must be held by an imported machine. Ultimately, the bottom level implementation must import a Library machine if static or persistent data is required (i.e. if you are implementing a state-machine).

A library machine is used simply by importing or seeing the machine in the construct you are writing. When a predefined machine is imported into an implementation, actual parameters must be supplied. However when seeing an existing machine no parameters should be supplied.

Each library machine is formally specified, and the readable formal specification is available in the development environment after the machine has been committed.

The manipulation of an object can be performed outside the state-machine to which the object belongs, using the TYPE machines of the Library.

Simple i/o can be performed using the i/o machines.

Persistence of data can be achieved using the file i/o machines.



Naming of Library Machines and their Operations

The naming of library machines and their operations follows a uniform scheme.

Library machines with state have to be renamed when they are imported into a development. These machines and their operations, therefore, all have names starting with Rename, which is automatically replaced by a new prefix supplied in the importing machine at the time that the library machine is committed from the library.

The TYPE machines in the library have no state, and need not be renamed. They can be cited in a SEES clause wherever they are required.

Operations in library machines are named according to a uniform pattern described in the text below.



Library Machines

Library Machines are organised into five groups as follows.



Multiple Objects Machines

A Multiple Object Machine is a repository for structured objects. In this sub-library we have: In most applications of B to software development, the Multiple Objects Machines are used for representing the main part of the information which an application maintains. Composite object structures which are suitable for representing complex information structures can also be constructed.

For example, by using combinations of the Multiple Objects Machines we can construct a suitable representation for files of records with different field types. Types can be simple types (SCALAR, BOOL, BITS) or more complex (Sets of Strings, Sequences of Sets of Strings, Sets of Sequences of BITS etc). Such constructions gives the formal B design language the equivalent power of a modern high level programming notation.

When importing a Multiple Object Machine it must be instantiated with respect to the size of store which will be pre-allocated for storing its objects, and with respect to the type of elements which actually will populate the structured objects. A multiple object machine can store a number of objects of the required type (e.g. sequences of BOOL, sets of SCALARS, sets of SEQOBJ).

Composite object structures can be constructed. For example a `Sequences of Sets of SCALARS' is constructed by using a Set Object machine instantiated with SCALAR in combination with a Sequence Object machine instantiated with SETOBJ.

When providing a design using a machine as a repository then elements of different types can be stored within the same machine; e.g. a sequence object machine instantiated with `BOOL or SCALAR' (written BOOL \/ SCALAR) can store Boolean values as well as scalar values (positive integers) within the same sequence.

All Multiple Objects Machines offer the following facilities:

Machine Rename_set_obj

The general multiple object operations, which are described above, are provided: In addition, this machine offers special operations for set manipulation and enquiring about the stored sets:

Machine Rename_seq_obj

The general multiple object operations, which are described above, are provided: In addition, this machine offers special operations for manipulation of sequences, and enquiring about stored sequences:

Rename_str_obj

The String Machine is a repository for sequences of bytes (seq(0..255)). It is often used for storing text strings. The facilities for strings offered in the library and the the B translators enable strings to be treated as simple objects, which can be transferred from one machine to another using operation which will transfers the entire structured string object. (Also available in the form of a Fixed Function Machine)

The general multiple object operations, which are described above, are provided:

In addition, this machine offers special operations for manipulation of strings, and enquiring about stored strings:

Machine Rename_fnc_obj

This machine stores partial Functions over an initial interval of Natural Numbers. The interval (its fields) will be determined when the machine is instantiated.

The general multiple object operations, which are described above, are provided:

In addition, this machine offers special operations for manipulation of functions, and enquiring about stored functions:

Machine Rename_ffnc_obj

This machine stores partial Functions over an initial interval of Natural Numbers. The interval (its fields) will be determined when the machine is instantiated. The general multiple object operations, which are described above, are provided: This machine also offers the operations for manipulation of functions, and enquiring about stored functions as are available for the standard Function Object Machine: In addition, special operations for multiple field manipulation are provided:



Programming Concepts Machines

These machine offer an extension of the basic data structures of variable and array which are available in most languages. We have: These machines are commonly used to record transitory information within an application, or used as `anchors' for information stored in the Multiple Object Machines.

Variables can be instantiated to any type, e.g a variable of type BOOL can hold a boolean value, and a variable of type SEQOBJ (an anchor) can hold an token denoting a sequence within the Sequence Object Machine.

When providing a design using a machine as a repository, then elements of different types can be stored within the same machine. For example instantiating a machine with BOOL \/ SCALAR will enable a machine to have both boolean values as well as scalar values within a single structure.

All Programming Concepts Machines offer the following facilities:

Note that when saving several structures on the same file then the restores must be performed in the same order as the saves were performed; different dump files can be used by using file_io operations.

Also note that these primitive operations appear as `procedure calls' within the algorithms of a B implementation; however in the generated implementation (the C-Code) all the simple operations from the Programming Concepts Machines are `in-lined' (no procedure calls are involved).

Machine Rename_Vvar

This Variable machine offers all the facilities described above, and can be instantiated to any type (SCALAR, BOOL, BITS, SETOBJ, etc.) We have:

Machine Rename_Nvar

This Variable machine, can hold only Numbers, and offers all the facilities available for a Programming Concepts Machine: In addition the following operations are provided:

Machine Rename_Varr

This Array machine can be used to store several values of any type. The type is determined by instantiation.

This machine offers all the facilities available for a Programming Concepts Machine:

In addition the following operations are provided:

Machine Rename_Narr

This Array machine can be used to store several Numbers.

This machine offers all the facilities available for a Programming Concepts Machine:

In addition the following operations are provided: In addition the following operations are provided:



Client-Server Machines

Machine Rename_Client / Rename_Server

These two machines are used as a pair to establish a Socket (TCP/IP) Client-Server Connection.

For the Client machine:

For the Server machine:



Mathematical Concepts Machines

The Mathematical Concepts Machines allow the programmer to design using higher level concepts, which are likely to match more closely the concepts used in a set theoretical specification, hence making the design step more reliable. We have: The Mathematical Concepts Machines are either used for storing transitory information or for `anchors' to information stored within a Multiple Object Machine. When importing Mathematical Concepts Machine its type and its capacity must be given by instantiation. When providing a design using a machine as a repository then elements of different types can be stored within the same machine. For example instantiating a machine with BOOL \/ SCALAR will enable a machine to have both boolean values as well as scalar values within a single structure. A Mathematical Concepts Machine offers the following common facilities:

Machine Rename_set

A set machine provides access to a single set structure. It offers the common operation for Mathematical Concepts Machine: In addition it offers:

Machine Rename_Vseq

This sequence machine provides access to a single sequence. The type of the elements of the sequence can be determined through instantiation. It offers the common operations for Mathematical Concepts Machine: In addition it offers:

Machine Rename_Nseq

This sequence machine provides access to a single sequence of numbers. It offers the common operations for Mathematical Concepts Machine: It offers the common sequence operation: In addition the Number Sequence Machine offers:

Machine Rename_Vfnc

This function machine provides access to a single partial function over numbers (mapping). The type of elements which the function returns can be determined through instantiation. It offers the common operations for Mathematical Concepts Machine: In addition it offers:

Machine Rename_Nfnc

This function machine provides access to a single partial function over numbers (mapping). The function will return numbers. It offers the common operations for Mathematical Concepts Machine: It offers:

Machine Rename_Vffnc

This function machine provides access to a single partial function over numbers (mapping). The type of elements which the function returns can be determined through instantiation. It offers the common operations for Mathematical Concepts Machine: It offers the additional operations: Some special operation for manipulation of segments of fields:



Input Output Machines

The Input Output Machines offers an application some simple input and output facilities:

Machine basic_io

This machine provides operations for writing to the terminal display and reading from the keyboard:

Machine Rename_token_io

This IO facility allows for a value of any elementary type to be read from the keyboard and written to the screen. NoteThis includes SEQOBJ, SETOBJ etc., since all these are represented as a single machine word) We have: (Rename_GET_TOK, Rename_GET_PROMPT_TOK, Rename_PUT_TOK)



File Machines

Machine Rename_File_io

A new file can be introduced by importing an instance of the file_io machine. This new file can be opened for writing/appending by Rename_OPEN_READ/ Rename_OPEN_APPEND. All subsequent `saves' will now be written to that file. The file can be opened for reading by Rename_OPEN_WRITE. All subsequent `restores' will now be read from that file. Rename_CLOSE will close the file. A file should always be closed to ensure that all written information is properly recorded.

Machine file_dump

This machine provides the default dump file (TMP.file), which is known by all object machines. Unless otherwise specified this file can be used for `saving' and `restoring'. open_write_dump_file will open the dump file for saving. open_read_dump_file will open the dump file for restoring. close_dump_file will close the dumpfile. A file should always be closed to ensure that all written information is properly recorded.

Machine Rename_file_dump

This machine provides the renamble dump file (Rename.dump). Rename_open_write_dump_file will open the dump file for saving. Rename_open_read_dump_file will open the dump file for restoring. Rename_close_dump_file will close the dumpfile. A file should always be closed to ensure that all written information is properly recorded.



Type Machines

The following machines allow for the manipulation of local variables introduced in an algorithm within an implementation. A value might be retrieved from the state of an object machine into a local variable, and then modified using the operation provided by the Type Operation Machines before stored into an object machine.

Machine Bool_TYPE / Bool_TYPE_Ops

Introduce the type BOOL which consists only of the values TRUE and FALSE. The Bool machines provide the familiar boolean operations:

Machine String_TYPE / String_TYP_Ops

These machines introduce the types CHAR and STRING. The operation CPY_STR must be used for assigning a value of type string to a local variable; the operations ASSIGN_ANY_STR, EN_STR, VAL_ITH_CHAR and HAR_TO_NAT are also provided.

Machine Scalar_TYPE / Scalar_TYPE_Ops

This machines introduce the type of SCALAR (= 0..2147483646). The following operations are provided: Note that the normal syntax available in programming languages can be used within an algorithm of a B implementation. e.g ` :=' for assignment, ` +' for ADD, ` =' for EQL. However, if this syntax is used then no checks will be made by the B-Toolkit for over-flow.

Machine Int_TYPE / Int_TYPE_Ops

This machines introduce the type of INT (=- 2147483647 to +2147483646). The following operations are provided: Note that the normal syntax available in programming languages can be used within an algorithm of a B implementation. e.g ` :=' for assignment, ` +' for ADDI, ` =' for EQLI. However, if this syntax is used then no checks will be made by the B-Toolkit for over-flow.

Machine Bit_TYPE / Bit_TYPE_Ops

This machine introduces the type of BITS as a set of sequences of length 32. The most significant bit position is 1, the least significant position is 32. We have:
A full on-line help listing is available in the Contents Page
Also available in the form of a complete Index.
Blogo © B-Core (UK) Limited, Last updated: 22 Feb 2002