Hi,

I was wondering if a syntax macro guru could come up with something to
simplify the following Jolt code, which works, but is full of manifest
constants and internal magic (notably the relationship between the
lambda, StaticBlockClosure, and state Array).  If so, then we will
have a simple way to create closures that can be passed from Jolt to
Pepsi.

(define call-methods
    (lambda (obj)
      (let ((class [obj class])
            (domain [obj domain])
            (state [Array new: '4])
            (cb (lambda (_closure self m)
                  ;; Gather up the methods we'll use in the test.
                  (let ((_state (long@ (+ self 8)))
                        (name [[m name] _bytes]))
                    (cond ((== 0 (strcmp name "method"))
                           (set-long@ _state m))
                          ((== 0 (strcmp name "Fail"))
                           (set-long@ (+ _state 4) m))
                          ((== 0 (strcmp name "Values"))
                           (set-long@ (+ _state 8) m))
                          ((== 0 (strcmp name ".ctor"))
                           ;; Check it's the ctor that takes two args:
                           ;; as you see a constructor is a method like any 
other.
                           (let ((sig [m signature]))
                             (if (== 2 [[sig arity] _integerValue])
                                 (set-long@ (+ _state 12) m))))))
                  ;; Return non-nil to ask for more methods.
                  1))
            (closure [StatefulBlockClosure function_: cb arity_: 1 state_: 
[state _elements]]))

        ;; Pass the closure to Pepsi.
        [class whileTrueWithMethod: closure]

        ;; Deconstruct the modified state array.
        (let ((method [state at: '0])
              (fail [state at: '1])
              (mvalues [state at: '2])
              (ctor [state at: '3]))

          ;; FIXME: Call the methods.
          (printf "%p, %p, %p, %p\n" method fail mvalues ctor)

          ;; Now we'll call method () on obj: since it takes no arguments
          ;; we can pass 0 to MonoMethod invoke.
          ;; The method will print the updated value.
          [method invoke: obj '0]))))

Thanks for any advice you can offer,

-- 
Michael FIG <[EMAIL PROTECTED]> //\
   http://michael.fig.org/    \//
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to