I do not recall whether I have talked about this before on the list.

I want to introduce a new function-like type into BitC: the method. A
method is a function associated with a structure type that does not
occupy storage within structure instances. Given:

  (defstruct (S 'a 'b) :val
     int32 i;
     m: (method 'a -> 'b))

  (define (S.m (by-ref S 'a 'b) 'a -> 'b)
    .. body of method ..)

  [ First argument is by-ref if the structure type is :val. If the 
    structure type is :ref, then it would simply be (S 'a 'b) ]

the application:

  (let ((s-inst (S int32 char)))
    (s-inst.m 3 #\c))

is conceptually equivalent to:

  (S.m s-inst 3 #\c)

or it would be, if this were syntactically expressible.


If S is a :ref type, we can then introduce "make-thunk":

  make-thunk: (fn inst:S meth:(S::method 'a -> 'b) -> (fn 'a -> 'b))

which is basically how the current procedure constructor works. It
creates a heap-allocated code block that can later be invoked to inject
a reference to S that the receiving procedure can receive.

Note that since methods have no slots they are not assignable.

Note further that a procedure object (up to information hiding) can be
implemented as a structure with a single distinguished method _fn.

So far, there is nothing novel or interesting here. The fun part comes
in the next message.

shap

_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to