I had a look at the definitions of these two functions. Right now in cffi-ecl.lisp it seems that they are only called with basic types, for they call cffi-type->ecl-type which only deals with things like integers, doubles, etc.
Could I just produce a compiler macro that relies on this? The result would be much much simpler than this as it could be inlined and make use of ECL's embedded C statements.
Actually it would be nice if instead of a compiler macro I could define them to be just plain macros. Anything that prevents it?
Juanjo
(defun %mem-ref (ptr type &optional (offset 0)) "Dereference an object of TYPE at OFFSET bytes from PTR." (let* ((type (cffi-type->ecl-type type)) (type-size (ffi:size-of-foreign-type type))) (si:foreign-data-ref-elt (si:foreign-data-recast ptr (+ offset type-size) :void) offset type)))
On Sun, Apr 25, 2010 at 1:55 PM, Juan Jose Garcia-Ripoll juanjose.garciaripoll@googlemail.com wrote:
I had a look at the definitions of these two functions. Right now in cffi-ecl.lisp it seems that they are only called with basic types, for they call cffi-type->ecl-type which only deals with things like integers, doubles, etc.
Could I just produce a compiler macro that relies on this? The result would be much much simpler than this as it could be inlined and make use of ECL's embedded C statements.
Yes, you can rely that. The CFFI-SYS layer will only ever handle with those basic types. They are defined in src/types.lisp via DEFINE-BUILT-IN-FOREIGN-TYPE.
Actually it would be nice if instead of a compiler macro I could define them to be just plain macros. Anything that prevents it?
It might work for this particular case, but I'd prefer compiler macros. See DEFINE-MEM-ACCESSORS in cffi-sbcl.lisp for an example.
On Sun, Apr 25, 2010 at 4:21 PM, Luís Oliveira luismbo@gmail.com wrote:
On Sun, Apr 25, 2010 at 1:55 PM, Juan Jose Garcia-Ripoll juanjose.garciaripoll@googlemail.com wrote:
Actually it would be nice if instead of a compiler macro I could define
them
to be just plain macros. Anything that prevents it?
It might work for this particular case, but I'd prefer compiler macros. See DEFINE-MEM-ACCESSORS in cffi-sbcl.lisp for an example.
The problem with compiler macros is that they may stop working depending on the optimization settings.
Also it is not clear to me from the definitions whether %mem-set returns a value, or whether I can simply produce a form that does not return anything.
Juanjo
On Sun, Apr 25, 2010 at 4:37 PM, Juan Jose Garcia-Ripoll < juanjose.garciaripoll@googlemail.com> wrote:
Also it is not clear to me from the definitions whether %mem-set returns a value, or whether I can simply produce a form that does not return anything.
Assuming the worst case, namely that the value is needed, here goes a possible patch that implements inline expansions for both functions.
Juanjo