[CM] MCL 5 with CLM

Rick Taube taube@uiuc.edu
Fri, 17 Oct 2003 07:57:54 -0500


> Now I'm confused!  Can I assume that CLM using MCL 5 will be

MCL5 is OSX-only.

>  Is MCL 5 some sort of commercial openmcl, so I
> can use the openmcl FFI?

MCL5.0 uses apple "frameworks" not shlibs so you have to grovel around 
a bit i think.  (sorry, Im not really up on MCL5.0 -- I bascially gave 
up on it and am really just using OpenMCL at this point...) To compare 
the two, this is waht Gramme did for MCL5.0:

----------------------------------MCL5.0:
(defmacro MidiOpen (name)
   `(with-cstrs ((s ,name))
      (ccl::ppc-ff-call (get-fun-addr "MidiOpen" *midishare*)
                        :address s :signed-halfword)))

(defmacro get-fun-addr (name framework)
   `(lookup-function-in-framework ,name ,framework))

(defun lookup-function-in-framework (symbol-name bundle)
   (let* ((addr (#_CFBundleGetFunctionPointerForName
                 bundle (CFSTR symbol-name))))
     (if (%null-ptr-p addr)
       (error "Couldn't resolve address of foreign function ~s"
              symbol-name)
       ;; This may be a little confusing: MCL uses fixnums (whose low 2
       ;; bits are zero) to represent function addresses (whose low 2 
bits
       ;; are zero ...)Shove the pointer in a buffer, fetch a signed 
32-bit
       ;; integer, shift it right 2 bits ... voila.
       (rlet ((buf :long))
         (setf (%get-ptr buf) addr)
         (ash (%get-signed-long buf) -2)))))

---------------------------------------------------
This is what I do in OpenMCL:

(defun MidiOpen (name)
   (ccl:with-cstrs ((s name))
     (#_MidiOpen s)))

The #_ is an OpenMCL readmacro that expands into:

(CCL::%FF-CALL (CCL::%REFERENCE-EXTERNAL-ENTRY-POINT (LOAD-TIME-VALUE 
	(CCL:EXTERNAL "_MidiOpen"))) :ADDRESS "foo" :SIGNED-HALFWORD)


I hope this helps!