summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-03-21 03:05:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-03-22 10:29:07 -0700
commitebbc7fb10c1763d81fadb6328e9f9f4b9f833b28 (patch)
tree820b334d14b4b8a8f8a6ebc14b452e120c2312ef /share
parent4836fb69ecb23561ae2462071aa15cf44f0eaa87 (diff)
downloadtxr-ebbc7fb10c1763d81fadb6328e9f9f4b9f833b28.tar.gz
txr-ebbc7fb10c1763d81fadb6328e9f9f4b9f833b28.tar.bz2
txr-ebbc7fb10c1763d81fadb6328e9f9f4b9f833b28.zip
ffi: support float type as variadic argument.
The float type promotes to double when passed as a variadic argument. This patch adds internal FFI types which models that promotion. It uses double for its C type, while still performing the range checks for float. Also, the types be-float and le-float are rejected from being variadic arguments. * share/txr/stdlib/ffi.tl (analyze-argtypes): Rewrite function, adding validation and substitution for the variadic part of the argument type list. Map float type to double, and reject be-float and le-float. * txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/ffi.tl18
1 files changed, 12 insertions, 6 deletions
diff --git a/share/txr/stdlib/ffi.tl b/share/txr/stdlib/ffi.tl
index e171cb47..480faf5d 100644
--- a/share/txr/stdlib/ffi.tl
+++ b/share/txr/stdlib/ffi.tl
@@ -54,12 +54,18 @@
(t exp)))
(defun sys:analyze-argtypes (form argtypes)
- (let ((p (posq : argtypes)))
- (when p
- (if (zerop p)
- (compile-error form "variadic with zero fixed arguments not allowed")
- (del [argtypes p])))
- (list* (length argtypes) p argtypes)))
+ (tree-bind (: ftypes vtypes) (split* argtypes (op where (op eq :)))
+ (when vtypes
+ (when (null ftypes)
+ (compile-error form "variadic with zero fixed arguments not allowed"))
+ (set vtypes
+ (collect-each ((vt vtypes))
+ (caseq vt
+ ((float) 'double)
+ ((be-float le-float)
+ (compile-error form "variadic argument cannot be of type ~s"
+ vt))))))
+ (list* (+ (len ftypes) (len vtypes)) (len ftypes) (append ftypes vtypes))))
(defmacro deffi (:form f :env e name fun-expr rettype argtypes)