SCL Registry

From Developer Documents
Revision as of 05:52, 2 August 2011 by Hannu Niemisto (talk | contribs) (Created page with "This pages documents a mechanism for finding and contributing SCL types and values in Simantics platform. Both types and values are identified by URIs. The last part of the URI ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This pages documents a mechanism for finding and contributing SCL types and values in Simantics platform.

Both types and values are identified by URIs. The last part of the URI is the name of the type or value and the prefix before the name is the namespace.

Types

Grammar and representation

SCL types are written according to the following grammar:

t ::= C                // Type constructor
    | a                // Type variable
    | t1 t2            // Type application
    | forall a. t      // Universal quantification
    | P t1 ... tn => t // Qualified type

Type constructor is either one capitalized identifier or concatenation of multiple identifiers with period (.). In the former case, the last identifier does not have to be capitalized. Type variable is always a one identifier that is not capitalized.

Types are represented in Java using the following subtypes of Type (org.simantics.scl.types)

TCon(String module, String name)
TVar()
TApply(Type function, Type parameter)
TForAll(TVar var, Type type)
TPred(TFuncApply predicate, Type type)

Some type constructors have special syntax:

a -> b   =   TApply(TApply(TCon(Types.BUILTIN, "->"), a), b)   
[a]      =   TApply(TCon(Types.BUILTIN, "[]"), a)
()       =   TCon(Types.BUILTIN, "()")
(a,b)    =   TApply(TApply(TCon(Types.BUILTIN, "(,)"), a), b)
(a,b,c)  =   TApply(TApply(TApply(TCon(Types.BUILTIN, "(,,)"), a), b), c)
...

A type is converted from a String to Type using Types.parseType.

Converting types to classes

In order to get a Java class from a type, TypeBindingScheme (org.simantics.scl.reflection) is needed. It describes which Java class each type constructor corresponds to. With a scheme s types are converted to classes with the following rules implemented in ReflectionUtils.getClass

c(C)                -->  s(C)
c(a)                --> Object.class
c(t1 t2)            --> c(t1)
c(forall a.t)       --> c(t)
c(P t1 ... tn => t) --> Function.class 

A singleton MinimalTypeBindingScheme implements TypeBindingScheme that uses extensions to find bindings from type constructors to classes. It must be extended elsewhere in order to get for example the types defined in the database.

Contributing type constructors