KLOS progress

Working on KLOS in Kawa

I spent the last week in emacs (instead of IntelliJ) and wrote only Scheme. I’ve been reading the different variants of TinyCLOS and making it work on Kawa.

I first tried using r7rs-tinyclos as is in Kawa, but somehow that just crashes. I didn’t want to debug the crash so I just started with my KLOS repo and started writing the definitions of allocate-instance and allocate-entity and went from there. I learned a bit about how to setup an R7RS project in Kawa along the way, and it felt pretty productive.

Incidentally, the difference between allocate-instance and allocate-entity has to do with whether or not the object is funcallable. In an implementation that has funcallable instances, this distinction wouldn’t be necessary. In addition, because normal Scheme doesn’t have funcallable records, there needs to be an additional alist to map the closure (so it’s funcallable) and the actual object instance (in KLOS, I’m calling that *all-entities*.

By now I have code that allocates instances and entities (the (klos internals) library) and also defined the foundational classes ((klos class), defining <object>, <class> and <generic-function>, etc). I’ve also defined the instance-creation protocol (make, initialize, etc) but I need to fill that in and add tests.

The plan is to customize KLOS so that it matches a MOP that matches Dylan semantics. Dylan actually doesn’t expose the introspection protocol (compute-cal, compute-methods, etc…) so I don’t know if I need to expose that either.

Keywords with Joel

I had a good session with Joel last week and we started working on keywords. The cool thing I realized now is that the work for keywords has a lot of overlap with Call-site optimization for Common Lisp, and that’s also a direct link to Fast Generic Dispatch for Common Lisp, so it’s cool that all these things are coming together (multiple values is tied in with this too).

Specifically: I think the snippet idea from the Call-site optimization paper is the key piece to both supporting keywords and generic functions, so it’ll be neat to see if we can define a representation of that in Kotlin for Kiwi.

Syntax ideas

I’m warming up to the idea of defining foo::<type> as a way of specifying specializers. I see that Kawa has a similar syntax, and it’s also in Bigloo. Unfortunately, it doesn’t look like there’s a way for me to access the type specifier from Scheme in Kawa.

Remaining work

  • Finish defining the core generic functions in KLOS and write tests for them.
  • Make (singleton ...) classes work
  • Add standard method combinations (before, after, around)
  • Run Eddy test suite in Kawa + KLOS