General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Oil Reference ManualOIL's Support LibraryThe library functions are grouped according to classes of functions. Within each class a C definition of the function is presented, followed by a brief description of the semantics of the function. The next section describes the five C types used and defined by the library. These types are defined entirely by the functions in OIL's library. The follow-on section describes operator identification using set of possible types which is the most general identification method supported by OIL. Should a call to an OIL function for operator identification or coercion sequence construction fail, special values are returned. Functions are supplied to test for these special values allowing production of error messages for these error cases. Besides operator identification using set of possible types, there is also a simpler identification algorithm which is strictly bottom up. It is useful when the full power of OIL is not necessary and the efficiency of a one pass algorithm can be utilized. Looking at an operator's type signature is fundamental to propagating the constraints of an operator's type signature out from the node it labels. OIL supplies a function to examine any given operator's function signature, Coercion sequences are fundamental to most uses of OIL and constructing and examining coercion sequences is critical to examining them for code generation purposes. Creating instances of specified classes. OIL's CLASS construct allows for easy support of most type constructors. OIL allows a type constructor to be specified and then instantiated to create a type which conforms to the specification of the CLASS. Names are an enumeration of the identifiers in the specification for easy comparisons. When a class is instantiated all its operators have new unique signatures based on the created type, but the names of corresponding operators are the same as those used in the specification of the class operator. Construction of types, operators, identifications and classes can be performed by the library functions. Thus should a particular application need to build and define a unique class, coercion or any OIL object it can be done during the compilation using these functions.
Library TypesThe semantics of the functions are described in terms of the basic types understood by OIL.
There is one other type which is important for use of the ADT and that is the name of a class, type or operator. A name is represented as a definition table key (see The Definition Table Module of Definition Table) and each identifier in the OIL specification has a unique name associated with it. This allows a class operator to be treated the same regardless of its arguments. But since the argument signature of an instantiated class operator will refer to the types used to instantiate the class, the type specific information can be referenced as needed.
Set of Possible Types
The functions The set of types (tOilTypeSet) returned describes the the union of the result types of any of the operators which can be identified by (oi) with any combination of argument types selected by the argument type sets, (at*.) Also in this set are types which can be reached from identified operators by means of a coercion sequence. tOilTypeSet OilIdResultTS1( oi:tOilOp, ats:tOilTypeSet ); tOilTypeSet OilIdResultTS2( oi:tOilOp, ats1,ats2:tOilTypeSet ); tOilTypeSet OilIdResultTS3( oi:tOilOp, ats1,ats2,ats3:tOilTypeSet );
The functions tOilOp OilIdOpTS1( rt:tOilType, oi:tOilOp, ats:tOilTypeSet ); tOilOp OilIdOpTS2( rt:tOilType, oi:tOilOp, ats1,ats2:tOilTypeSet ); tOilOp OilIdOpTS3( rt:tOilType, oi:tOilOp, ats1,ats2,ats3:tOilTypeSet );
Suppose that an operator indication can identify only a single operator,
but it is used in an inappropriate context for that operator.
Functions tOilOp OilNoOverload( oi:tOilOp, OilIdOpTS*( ... ));
The function
tOilTypeSet OilTypeToSet( t:tOilType );
The function
tOilType OilSelectTypeFromTS( ts:tOilTypeSet );
The following equation is true for any type OilSelectTypeFromTS( OilTypeToSet( t ) ) = t
The function
tOilType OilBalance( ts1,ts2:tOilTypeSet );The following is true for all type sets ts1 and ts2 :
OilBalance( ts1,ts2 ) = OilSelectTypeFromTS( ts1 AND ts2 )
One other important operation on sets is a test for set membership.
This operation is performed on a type set by the function
int OilSetIncludes( s:tOilTypeSet, t:tOilType );
Validating operator identification
The function
int OilIsValidOp( op: tOilOp );
Simpler operator identification
The function tOilOp OilIdOp1( oi: tOilOp, at: tOilType ); tOilOp OilIdOp2( oi: tOilOp, at1,at2: tOilType ); tOilOp OilIdOp3( oi: tOilOp, at1,at2,at3: tOilType );
Looking at an operator's type signatureThe functionOilGetArgType allows us to get the type of the
n'th argument (arg) of an operator(op.) The 0'th argument
returns the result type from the function signature.
tOilType OilGetArgType( op:tOilOp, arg:int ); Coercion sequences
The function
tOilCoercionSeq OilCoerce( t1,t2:tOilType );
These operations on coercion sequences (
The function
The function
The function int OilEmptyCS( cs: tOilCoercionSeq ); tOilOp OilHeadCS( cs: tOilCoercionSeq ); tOilCoercionSeq OilTailCS( cs: tOilCoercionSeq );
The function
int OilIsValidCS( cs: tOilCoercionSeq );
Instantiate ClassesWhen a class is instantiated a new type is created and the set of operators and coercions defined for that class are created using the created class and the types indicated by the parameters to build the actual function signatures for the created operators. The `is coercible to' relation is enhanced by all the coercions defined by the instantiation. Classes can be instantiated by calling one of the functions: tOilType OilClassInst0( c:tOilClass, n:DefTableKey ); tOilType OilClassInst1( c:tOilClass, n:DefTableKey, at:tOilType ); tOilType OilClassInst2( c:tOilClass, n:DefTableKey, at1,at2:tOilType ); Constraints: The number of parameters defined for the class must match the number of types supplied as arguments.
Name FunctionsEach type, operator and class has a name associated with it. There is a function for retrieving the name associated with a specific type during attribution: DefTableKey OilTypeName( t:tOilType ); DefTableKey OilOpName( op:tOilOp ); DefTableKey OilClassName( c:tOilClass );
If the identifier
Compile TimeThe OIL library has all of the necessary functions for the construction of OIL entities during the execution of the generated compiler. This capability allows the changing of the OIL schema in more detailed ways than simply instantiating an already specified class. The different capabilities for modifying the schema are:
TypesIn addition to class instantiation, a new type may be constructed with the functionOilNewType . Its only argument is the name to be associated
with the new type.
tOilType OilNewType( id:DefTableKey );
OperatorsConstructing a new operator is a two step process, first a new argument signature must be constructed and then a new operator with that signature can be constructed using the functionOilNewOp . Besides the
argument signature, OilNewOp requires the name of the new
operator(id ), and the cost of the new operator(cost .)
tOilOp OilNewOp(id:DefTableKey,sig:tOilArgSig,cost:int);
Argument SignaturesArgument signatures are built in two steps: an empty signature is constructed withOilNewArgSig and then a type is pushed onto the
front of the signature using OilAddArgSig .
tOilArgSig OilNewArgSig(dummy:int); tOilArgSig OilAddArgSig( arg:tOilType, sig:tOilArgSig );Note that by convention, the last type pushed onto the signature is the result type of the created operator.
CoercionsAny operator with an argument signature of length 2 can be a coercion by simply applyingOilAddCoercion on it.
int OilAddCoercion( op:tOilOp ); Constraints A check is not made that the signature is of length 2.
IdentificationsA relationship between an operator indication (ind ) and an operator
(op ) is established by simply
supplying them to the OilAddIdentification function.
OilAddIdentification returns the value of op .
tOilOp OilAddIdentification( ind, op:tOilOp ); Constraints A check is not made regarding the redundancy of the new identification with respect to the existing schema. You can have ambiguity of which operator is identified by any given indication and operand signature. OIL will choose the most recently declared, least cost identification.
ClassesClasses are very complex entities and are constructed in stages. First an empty class in created usingOilNewClass . The argument id
specifies the name of the class and the argument argNum specifies
how many parameters the class has.
tOilClass OilNewClass(id:DefTableKey,argNum:int);
To an existing class( tOilClassOp OilAddClassOp(id:DefTableKey,sig:tOilClassArgSig,cost:int, c:tOilClass);
With a class operator we can create an identification of an instantiated
class operator( int OilAddClassOpId(ind:tOilOp,op:tOilClassOp);
The function int OilAddClassCoercion(op:tOilClassOp);
Building a class argument signature is similar to constructing a simple
argument signature but it is complicated by the fact that a class argument needs
to be described in terms of a parameter binding. A class argument's
parameter binding determines the value of the parameter when the class
is instantiated. Like simple signatures we first build an empty class
signature and then push arguments onto it. An empty class signature is
created with tOilClassArgSig OilNewClassSigArg(dummy:int); tOilClassArgSig OilAddClassSigArg( td:tOilClassSigArgDesc, st:tOilType, pi:int, cs:tOilClassArgSig );The extra arguments to OilAddClassSigArg describe the possible
bindings which will instantiate the class signature.
|