Hello,

I hesitated to add this as an issue at GitHub.com (feature request), I
put it here first.

FriCAS supports what I would call preliminary support of FFI stuff via
a set of CL macros. I would like to suggest adding more types in this
regard. For example, it could be possible to add double-float arrays,
boolean and the like. I modified, and well tested, the following for
example. For information, only for SBCL and Clozure CL, but adding
those additional types for other CL implementations should be easy I
think:

===================================================
diff --git a/home/greg/Tmp/fricas/src/lisp/fricas-lisp.lisp
b/src/lisp/fricas-lisp.lisp
index 357aa063..8de10db7 100644
--- a/home/greg/Tmp/fricas/src/lisp/fricas-lisp.lisp
+++ b/src/lisp/fricas-lisp.lisp
@@ -363,10 +363,13 @@ with this hack and will try to convince the GCL
crowd to fix this.
 )

 (defvar *c_type_as_string* '(
+    (void "void")
+    (bool "bool")
     (int "int")
     (c-string "char *")
     (double "double")
     (char-* "char *")
+    (double-* "double *")
 ))

 (defun c_type_as_string(c_type) (nth 1 (assoc c_type *c_type_as_string*)))
@@ -465,10 +468,13 @@ with this hack and will try to convince the GCL
crowd to fix this.
 (eval-when (:compile-toplevel :load-toplevel :execute)

 (setf *c-type-to-ffi* '(
-    (int SB-ALIEN::int)
-    (c-string SB-ALIEN::c-string)
-    (double SB-ALIEN::double)
-    (char-* (sb-alien:* sb-alien:char))
+    (void    sb-alien::void)
+    (bool    (sb-alien::boolean 8))
+    (int      sb-alien::int)
+    (c-string (sb-alien::c-string))
+    (double   sb-alien::double-float)
+    (char-*   (sb-alien:* sb-alien:char))
+    (double-*   (sb-alien:* sb-alien:double-float))
 ))

 (defun c-args-to-sbcl (arguments)
@@ -490,10 +496,13 @@ with this hack and will try to convince the GCL
crowd to fix this.
 (eval-when (:compile-toplevel :load-toplevel :execute)

 (setf *c-type-to-ffi* '(
+    (void :void)
+    (bool :signed-byte)
     (int :int)
     (c-string :address)
     (double :double-float)
     (char-* :address)
+    (double-* :address)
 ))

 (defun c-args-to-openmcl (arguments)
@@ -518,7 +527,7 @@ with this hack and will try to convince the GCL
crowd to fix this.
                  `(ccl::external-call ,c-name ,@fargs ,l-ret))
                (fun-body
                   (if strs
-                     `(ccl::with-cstrs ,strs ,call-body)
+                     `(ccl::with-encoded-cstrs :utf-8  ,strs ,call-body)
                       call-body)))
                `(defun ,name ,largs ,fun-body))))

@@ -532,7 +541,7 @@ with this hack and will try to convince the GCL
crowd to fix this.

 (setf *c-type-to-ffi* '(
                  (int :int)
-                 (c-string  :cstring )
+                 (c-string  :cstring)
                  (double :double)
                  (char-* :pointer-void)
===================================================

The patch file is attached. One remark, I added UTF-8 to Clozure CL
encoded-cstrs in such a way some non-ascii characters can be used in
the Spad source code, SBCL has as default external format UTF-8. It
can be modified via sb-ext:*default-external-format* and
sb-ext:*default-c-string-external-format*. This is not an intent to
fully support UTF-8 in Spad code, it just allows, for example, to use:

    x quo y == ibinfunc("÷", x, y)
instead of (commented here)
    -- x quo y == ibinfunc("div", x, y)
x rem y == ibinfunc("%", x, y)

where ibinfunc is a macro that expands binary functions operating on integers.

Regards,

- Greg

PS: I am adding the content of this email to GitHub for record.

-- 
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/CAHnU2dbXyP3OHP561MgFcAMf7P9p%3Du3_ReYao1XH9GdUnFh4zA%40mail.gmail.com.

Attachment: fricas.patch
Description: Binary data

Reply via email to