Just experimented with something interesting recently.

CFFI: is a portable library that abstracts different lisp's
FFI interface.

We have our own abstraction "fricas-foreign-call" defined for
each lisp, but with CFFI, we can have this for all lisp:

=========
(eval-when (:compile-toplevel :load-toplevel :execute)

  (setf *c-type-to-ffi*
        '((int      :int)
          (c-string :string)
          (double   :double)))

  (defun c-args-to-cffi (arguments)
    (mapcar (lambda (x) (list (nth 0 x) (c-type-to-ffi (nth 1 x))))
            arguments))

  (defun cffi-foreign-call (name c-name return-type arguments)
    (let ((cffi-args (c-args-to-cffi arguments))
          (cffi-ret (c-type-to-ffi return-type)))
      `(cffi:defcfun (,c-name ,name) ,cffi-ret ,@cffi-args)))

  (defmacro fricas-foreign-call (name c-name return-type &rest arguments)
    (cffi-foreign-call name c-name return-type arguments)
    ))
===========

C2FFI: this is Clang-based FFI wrapper generator.  It can automatically
generate FFI bindings for every function.

AUTOWRAP: this is based on C2FFI, makes it easier to use.

Following few lines generates full bindings to mpfr:

====
(ql:quickload "cl-autowrap") ;; use quicklisp to install and load
(autowrap:c-include "/usr/include/mpfr.h" :spec-path '(cl-autowrap-test)) ;; this single line generates full bindings
(cffi-sys:%load-foreign-library "mpfr" "libmpfr.so") ;; load the library
(mpfr-get-version) ;; calls the generated function and returns "4.1.0-p7"
====

On 7/1/22 09:21, Waldek Hebisch wrote:

Not only.  We could make more use of GMP than we make now,
but there are also other possibilities.  One is to have
fast routines for polynomials mod p.  We could use BLAS
to speed up linear algebra.


--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/e5586d94-c303-e1a6-0014-7e68c96e2a8d%40gmail.com.

Reply via email to