next node: InterOpalTools,
prev node: Lazy,
up to node: User Subsystem : Reflections


Reflection

Signature of Reflection

As the reflection system should make available meta information at runtime, it must define several types which model the meta information. These types are used to talk in OPAL about OPAL. The data model of the core reflection system is given by a collection of free type definitions.

Declaration and imports

SIGNATURE Reflection

IMPORT Seq[name] ONLY seq
       Seq[type] ONLY seq

Name Reflection

A name determines a named object in an OPAL program, and is described by its identifier, kind and origin structure. Note that OPAL employs full overloading, such that all these components are required to identify a name uniquely.

TYPE name == name (identifier : denotation,
                   kind       : kind,
                   struct     : struct)

FUN = < : name ** name -> bool

Kind Reflection

A name represents either a sort or a value with type. These two possibilities are represented as kind. For example, the name int:SORT'Int in literal OPAL syntax is represented as name("int", sort, IntStruct). Here, IntStruct is a reflection of a structure, discussed below.

TYPE kind == sort
             value (type : type)

FUN = < : kind ** kind -> bool

Sort Reflection

A sort is uniquely identified by its name.

TYPE sort == sort (name : name)

FUN = < : sort ** sort -> bool

Structure Reflection

An OPAL structure is identified by its identifier and an instantiation list. An instantiation list is a sequence of names, which is empty if the structure has no parameters. For example the structure Int is represented as struct("Int", <>). The structure Seq[int] is represented as struct("Seq", IntName :: <>).

TYPE struct == struct (identifier : denotation,
                       instance   : seq[name])

FUN = < : struct ** struct -> bool

Type Reflection

An OPAL type, which can be either basic, a cartesian product or a function space is described by type.

Note, that apart from enquiring a type, you might also wish to construct your own type reflections and then try to match them against a given type reflection.

TYPE type == basic    (sort     : sort)
             product  (factors  : seq[type])
             function (domain   : type,
                       codomain : type)

FUN = < : type ** type -> bool

Value Reflection

A value is a reflection of a value. It stores the type of the reflected value as well as the value itself. However, the value is stored in an opaque way and cannot be observed directly.

See ReflectionBuild for details.

    
SORT value

FUN type : value -> type

-- These should be obsolete once generic standard order for free types
-- is implemented:

FUN < = : type ** type -> bool


next node: InterOpalTools,
prev node: Lazy,
up to node: User Subsystem : Reflections