P2(ID:8022/)


Extensions to Ansi C (rather than C++) to enable better use and control of abstractions. Follow on to the P++ part of the Predator project

Batory et al, U Texas 1994


Related languages
P++ => P2   Evolution of

References:
  • Batory, Don; Geraci, Bart J; Thomas, Jeff "Introductory P2 System Manual" Edition 0.8, August 1994 view details Abstract: P2 is a state-of-the-art generator for data structures. It is an extension of ANSI C that allows programmers to interact with complex data structures using high-level and easy-to-use abstractions. With minimal specifications from programmers, P2 replaces program references to these abstractions with C code that implements them. The number of potential implementations of the basic P2 abstractions is already large and is open-ended. Extract: The Container/Cursor Overview
    The Container/Cursor Overview
    The paradigm used in P2 is the container/cursor model. A container is a collection of objects called elements. Elements are referenced by a structure called a cursor. With respect to the container, a cursor can:
  • move backwards and forwards through the container
  • start at the beginning or the end of the container
  • add, delete, swap, and update elements
    A qualified cursor points only to elements that share some characteristic. Qualified cursors have two properties: a predicate, which restricts the cursor to point only to elements that satisfy the predicate, and an orderby clause, which specifies the order in which the cursor retrieves elements from the container.
    The power of qualified cursors is the ability of the P2 system to optimize operations based on their qualifications. If a cursor is restricted to all even numbers, then the procedure that is generated by P2 for searching that container will have this test embedded. The disadvantage is that to a certain extent, we cannot have dynamically (run-time) cursor predicates that are common in interactive environments.
    P2 programs are written in terms of operations on cursors and containers and without regard to how they are implemented. This, in principle, enables di erent implementations of cursors and containers to be "plugged in" without requiring program modifications.
    Ultimately, however, a specification of how cursors and containers are to be implemented must be provided to the P2 compiler, as the compiler replaces cursor and container declarations and operations with their corresponding C implementation. An implementation specification comes in two parts: a type expression and its annotations.

    A type expression is a composition of P2 building blocks; it specifies a stacking of layers that defines the general characteristics of the data structure that P2 is to generate. Additional information,
    such as key fields, array sizes, etc., are called annotations. The combination of type expressions
    and annotations is the sole means for specifying data structure implementations. Among the characteristics that can be defined by type expressions and annotations are:
     Whether elements are ordered or not, and if so, under what field is the element ordered.
     If the container uses transient or persistent storage.
     Details of searching and deletion strategies.
     Whether or not the container should contain a maximal number of elements
    As mentioned earlier, the power of P2 programs stem from the separation of cursor and container abstractions and their implementations; by altering a P2 program's type expression(s), containers and cursors can be assigned radically di erent implementations. This significantly simplifies tuning.
    Resources