Changeset 6222
- Timestamp:
- Apr 8, 2007, 9:13:30 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/lib/macros.lisp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/lib/macros.lisp
r5974 r6222 691 691 (%defparameter ',var ,value ,doc))) 692 692 693 (defmacro defglobal (&environment env var value &optional doc) 693 694 (defmacro defstatic (&environment env var value &optional doc) 695 "Syntax is like DEFPARAMETER. Proclaims the symbol to be special, 696 but also asserts that it will never be given a per-thread dynamic 697 binding. The value of the variable can be changed (via SETQ, etc.), 698 but since all threads access the same static binding of the variable, 699 such changes should be made with care." 694 700 (if (and doc (not (stringp doc))) (signal-program-error "~S is not a string." doc)) 695 701 (if (and (compile-file-environment-p env) (not *fasl-save-doc-strings*)) … … 701 707 702 708 709 (defmacro defglobal (&rest args) 710 "Synonym for DEFSTATIC." 711 `(defstatic ,@args)) 712 713 703 714 (defmacro defloadvar (&environment env var value &optional doc) 704 715 `(progn 705 (def var ,var ,@(if doc `(nil,doc)))716 (defstatic ,var ,nil ,@(if doc `(,doc))) 706 717 (def-ccl-pointers ,var () 707 718 (setq ,var ,value)) 708 719 ',var)) 720 721 709 722 710 723 … … 1150 1163 `(multiple-value-call #'list ,form)) 1151 1164 1152 (defmacro multiple-value-bind (varlist values-form &body body &environment env) 1153 (multiple-value-bind (body decls) 1154 (parse-body body env) 1155 (let ((ignore (make-symbol "IGNORE"))) 1156 `(multiple-value-call #'(lambda (&optional ,@varlist &rest ,ignore) 1157 (declare (ignore ,ignore)) 1158 ,@decls 1159 ,@body) 1160 ,values-form)))) 1161 1162 (defmacro multiple-value-setq (vars val) 1163 (if vars 1164 `(values (setf (values ,@(mapcar #'(lambda (s) (require-type s 'symbol)) vars)) ,val)) 1165 `(prog1 ,val))) 1166 1167 (defmacro nth-value (n form) 1168 "Evaluate FORM and return the Nth value (zero based). This involves no 1169 consing when N is a trivial constant integer." 1170 `(car (nthcdr ,n (multiple-value-list ,form)))) 1165 1171 1166 1172 1167 … … 1324 1319 (defmacro with-macptrs (varlist &rest body &environment env) 1325 1320 (multiple-value-bind (body other-decls) (parse-body body env) 1326 (collect ((bindings) 1321 (collect ((temp-bindings) 1322 (temp-decls) 1323 (bindings) 1327 1324 (our-decls) 1328 1325 (inits)) 1329 1326 (dolist (var varlist) 1327 (let* ((temp (gensym))) 1328 (temp-decls temp) 1330 1329 (if (consp var) 1331 1330 (progn 1332 1331 (our-decls (car var)) 1333 (bindings `(,(car var) (%null-ptr))) 1332 (temp-bindings `(,temp (%null-ptr))) 1333 (bindings `(,(car var) ,temp)) 1334 1334 (if (cdr var) 1335 (inits `(%setf-macptr , (car var),@(cdr var)))))1335 (inits `(%setf-macptr ,temp ,@(cdr var))))) 1336 1336 (progn 1337 1337 (our-decls var) 1338 ( bindings `(,var (%null-ptr))))))1339 `(let* ,(bindings)1340 (declare (dynamic-extent ,@(our-decls))1341 (declare (type macptr ,@(our-decls)))1342 ,@other-decls)1338 (temp-bindings `(,temp (%null-ptr))) 1339 (bindings `(,var ,temp)))))) 1340 `(let* ,(temp-bindings) 1341 (declare (dynamic-extent ,@(temp-decls))) 1342 (declare (type macptr ,@(temp-decls))) 1343 1343 ,@(inits) 1344 ,@body)))) 1344 (let* ,(bindings) 1345 (declare (type macptr ,@(our-decls))) 1346 ,@other-decls 1347 ,@body))))) 1348 1345 1349 1346 1350 (defmacro with-loading-file (filename &rest body) … … 1592 1596 &rest body &environment env) 1593 1597 (let* ((encoding (get-character-encoding encoding-name)) 1594 (str (gensym))) 1598 (nul-vector (character-encoding-nul-encoding encoding)) 1599 (str (gensym)) 1600 (len (gensym)) 1601 (i (gensym))) 1595 1602 (multiple-value-bind (body decls) (parse-body body env nil) 1596 1603 `(let* ((,str ,string)) 1597 1604 (%stack-block ((,sym (cstring-encoded-length-in-bytes ,encoding ,str ,start ,end) :clear t)) 1598 1605 ,@decls 1599 (encode-string-to-memory ,encoding ,sym 0 ,str ,start ,end) 1606 (let* ((,len (encode-string-to-memory ,encoding ,sym 0 ,str ,start ,end))) 1607 (declare (fixnum ,len)) 1608 (dotimes (,i (length ,nul-vector)) 1609 (setf (%get-unsigned-byte ,sym ,len) (aref ,nul-vector ,i)) 1610 (incf ,len))) 1600 1611 ,@body))))) 1601 1612 … … 2784 2795 (dolist (item inits result) 2785 2796 (let* ((name (car item)) 2786 (record-name (cadr item)) 2787 (inits (cddr item)) 2788 (ftype (%foreign-type-or-record record-name))) 2797 (record-name (cadr item)) 2798 (inits (cddr item)) 2799 (ftype (%foreign-type-or-record record-name)) 2800 (ordinal (foreign-type-ordinal ftype)) 2801 (ordinal-form (if (< ordinal max-canonical-foreign-type-ordinal) 2802 ordinal 2803 `(foreign-type-ordinal (load-time-value (%foreign-type-or-record ',record-name)))))) 2804 (setq result (nconc result `((%set-macptr-type ,name ,ordinal-form)))) 2789 2805 (if (typep ftype 'foreign-record-type) 2790 (setq result (nconc result (%foreign-record-field-forms name ftype record-name inits)))2791 (progn 2792 ;(setq result (nconc result `((%assert-macptr-ftype ,name ,ftype)))) 2793 (when inits2794 (if (and ftype (null (cdr inits)))2806 (setq result 2807 (nconc result (%foreign-record-field-forms name ftype record-name inits))) 2808 (progn 2809 (when inits 2810 (if (and ftype (null (cdr inits))) 2795 2811 (setq result 2796 2812 (nconc result 2797 2813 `((setf ,(%foreign-access-form name ftype 0 nil) 2798 ,(car inits)))))2814 ,(car inits))))) 2799 2815 (error "Unexpected or malformed initialization forms: ~s in field type: ~s" 2800 2816 inits record-name)))))))) … … 2825 2841 (%foreign-type-or-record-size recname :bytes)) 2826 2842 2827 (defmacro make-record (record-name &rest initforms) 2828 "Expand into code which allocates and initalizes an instance of the type 2829 denoted by typespec, on the foreign heap. The record is allocated using the 2830 C function malloc, and the user of make-record must explicitly call the C 2831 function free to deallocate the record, when it is no longer needed." 2843 (defun make-record-form (record-name allocator &rest initforms) 2832 2844 (let* ((ftype (%foreign-type-or-record record-name)) 2845 (ordinal (foreign-type-ordinal ftype)) 2846 (ordinal-form (if (< ordinal max-canonical-foreign-type-ordinal) 2847 ordinal 2848 `(foreign-type-ordinal (load-time-value (%foreign-type-or-record ',record-name))))) 2833 2849 (bits (ensure-foreign-type-bits ftype)) 2834 2850 (bytes (if bits … … 2838 2854 (p (gensym)) 2839 2855 (bzero (read-from-string "#_bzero"))) 2840 `(let* ((,p (malloc ,bytes))) 2856 `(let* ((,p (,allocator ,bytes))) 2857 (%set-macptr-type ,p ,ordinal-form) 2841 2858 (,bzero ,p ,bytes) 2842 2859 ,@(%foreign-record-field-forms p ftype record-name initforms) 2843 2860 ,p))) 2861 2862 (defmacro make-record (record-name &rest initforms) 2863 "Expand into code which allocates and initalizes an instance of the type 2864 denoted by typespec, on the foreign heap. The record is allocated using the 2865 C function malloc, and the user of make-record must explicitly call the C 2866 function free to deallocate the record, when it is no longer needed." 2867 (apply 'make-record-form record-name 'malloc initforms)) 2868 2869 (defmacro make-gcable-record (record-name &rest initforms) 2870 "Like MAKE-RECORD, only advises the GC that the foreign memory can 2871 be deallocated if the returned pointer becomes garbage." 2872 (apply 'make-record-form record-name '%new-gcable-ptr initforms)) 2873 2874 (defmacro copy-record (type source dest) 2875 (let* ((size (* (%foreign-type-or-record-size type :words) #+64-bit-target 1 #+32-bit-target 2)) 2876 (src (gensym "SRC")) 2877 (dst (gensym "DST")) 2878 (accessor #+64-bit-target '%get-unsigned-long #+32-bit-target '%get-unsigned-word) 2879 (i (gensym "I")) 2880 (j (gensym "J"))) 2881 `(with-macptrs ((,src ,source) 2882 (,dst ,dest)) 2883 (do* ((,i 0 (+ ,i #+64-bit-target 4 #+32-bit-target 2)) 2884 (,j 0 (+ ,j 1))) 2885 ((= ,j ,size)) 2886 (declare (fixnum ,i)) 2887 (setf (,accessor ,dst ,i) (,accessor ,src ,i)))))) 2888 2889 2890 2844 2891 2845 2892 (defmacro with-terminal-input (&body body) … … 3408 3455 (the (unsigned-byte 8) (ash ,arg -24))))))))))) 3409 3456 3457 3458 (defmacro multiple-value-bind (varlist values-form &body body &environment env) 3459 (multiple-value-bind (body decls) 3460 (parse-body body env) 3461 (let ((ignore (make-symbol "IGNORE"))) 3462 `(multiple-value-call #'(lambda (&optional ,@varlist &rest ,ignore) 3463 (declare (ignore ,ignore)) 3464 ,@decls 3465 ,@body) 3466 ,values-form)))) 3467 3468 (defmacro multiple-value-setq (vars val) 3469 (if vars 3470 `(values (setf (values ,@(mapcar #'(lambda (s) (require-type s 'symbol)) vars)) ,val)) 3471 `(prog1 ,val))) 3472 3473 (defmacro nth-value (n form) 3474 "Evaluate FORM and return the Nth value (zero based). This involves no 3475 consing when N is a trivial constant integer." 3476 `(car (nthcdr ,n (multiple-value-list ,form))))
Note:
See TracChangeset
for help on using the changeset viewer.
