Object Expression


An object expression defines the behavior of an object -- how it responds to an incoming message. The object expression is an expression because it evaluates to an object with the behavior it defines. It is the means for defining object behavior in E.

The components of an object expression are:

BNF:
["/**" docComment
 "*/"] "def" (String | "_") auditors behavior
 
XML DTD:
<!ELEMENT objectExpr
 (DocComment, String, auditors, %behavior;)>
Java:

The DocComment is output directly as the same DocComment, except that we may yet define some tag transformations.

If the behavior name is present and conforms to the above conventions, then a top level object expression compiles to a Java "public final" class, and a nested object expression compiles to a Java public nested class, not an inner class. In other words, it compiles to a class declared "static public" inside the scope of its containing class, but not inside the scope of any methods or instances. At the position in the generated Java code corresponding to the appearance of the object expression we generate a call to the nested class's constructor, so the nested class must appear textually earlier.

If the behavior name is absent ("_") we synthesize one that follows the above conventions but whose last segment (the one after the last "$") is a number unique in this context. This corresponds to the Java convention for anonymous inner classes, even though we're generating a nested rather than inner class. After compiling the Java to bytecodes, it would be good to mark these names as "synthetic" in the .class file.

The auditors do their audit prior to the code being translated to Java, and the results of the auditing protocol are kept elsewhere in the TCB without needing compiler support.

Finally, the behavior is compiled in Java code, as described in methodicalExpr and plumbingExpr.

Example:
in Kernel-E:
in XML:
in Java:
x

Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.

AltStyle によって変換されたページ (->オリジナル) /