guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on ST-Object data-structure setup


From: ken . dickey
Subject: Re: Advice on ST-Object data-structure setup
Date: Sat, 20 Apr 2024 08:08:00 -0700
User-agent: Roundcube Webmail/1.3.7

On 2024-04-20 02:49, Mikael Djurfeldt wrote:

Have you looked at Guile's OOP system GOOPS?

Thanks, Mikael.

I have implemented a number of object systems, including CLOS style systems such as GOOPS.

The mismatch here is in the overhead of the multimethod dispatch.

I would like something fairly efficient -- and without using caches if possible.

You probably know/have seen this, but back to basics...

If you look at the `behavior` function in https://github.com/KenDickey/Crosstalk/blob/master/guile-st-kernel.scm you will see that the basic dispatch mechanism is (primLookup: (behavior self) selectorSym) where the lookup is just a hash-table lookup with suitable failure handling.

(define (primLookup: methodDict symbol)
  (hashtable-ref methodDict
                 symbol
                 (lambda (self . rest-args)
                   (send-failed self symbol rest-args)))
                   ;; (make-messageSend self symbol rest-args)))
)

The natural way to interoperate with Scheme data types is to use type tag as an array index into a vector of functions which return a suitable behavior/hash-table.

For generic Smalltalk objects, this is just the first slot of a vector of value slots. For typical Scheme objects, this is a method-dictionary for that kind of object. So Scheme vectors, numbers, #true, closures, and so forth just work as expected when viewed as Smalltalk Arrays, numbers, true, BlockClosures..

So after optimization, dispatch mechanics is just mask the tag, shift, index, hash, apply.

The hard parts have to do with thisContext (call/cc interactions) keeping a proper debugging context, and Smalltalk`become`.

It appears that Guile has evolved to have suitable low-level mechanisms to be able to do this.

I find things out by writing code.  "If it works, it must be possible."

So my investigation is to get a basic Smalltalk working and then get into the compilation and runtime mechanics to see if I can make this efficient enough.

Starting with a CLOS style dispatch is a bit further from where I want to end up.

Thanks again for the thoughtful comments,
-KenD



reply via email to

[Prev in Thread] Current Thread [Next in Thread]