The remaining thing that I want to recover in all of this is existential
types, because those are pretty important for some real-world use cases
in kernels. What I'm about to propose is somewhat similar to Java
interfaces.
The new construct is DEFCAPSULE. A capsule is a structure-like type
having three properties:
It has an initial word of some undisclosed reference type.
It otherwise consists exclusively of methods.
It's implementation size is two pointers.
The definition:
(defcapsule (C 'a 'b)
m: (method 'a -> 'b))
introduces a meta-constructor C and a new type (C 'a 'b). The
metaconstructor is the interesting part.
If s is an instance of some structure type S, and C is a capsule type,
then the constructor call:
(C s)
is legal exactly if:
1. S is of reference type
2. For all methods "m" named in the declaration of C, a corresponding
method named "m" having compatible signature exists in S.
3. Any constraints on type variables that appear at the declaration of
C subsume the corresponding constraints on the type variables of S.
Note that C may have fewer type variables than S. Only those type
variables in S that appear in some method signature are required in C.
Two things happen as a consequence of a construction (C s):
1. A vtable-like structure is emitted that captures those methods
of S that are referenced by C.
2. A new instance c of type C is returned. This instance is two
words in size.
The important difference between a capsule and a structure w.r.t. method
invocation is that the capsule encapsulates the structure type.
Note that we can extend make-thunk in the obvious way, and that the
current procedure object implementation is, in effect, a capsule. If we
introduce a cardelli-style representation optimization:
Capsule having exactly one method do not emit a vtable, and instead
encode the method pointer directly within the capsule object.
we will have procedure objects exactly.
shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev