I have code that could be adapted for this purpose. It is designed to add automatic type checking for methods and to allow optimizations to be turned off. I don't think it would be too hard to adapt it to changing optimization settings.
Here is the code. I could work on adapting it if no one else is interested. Let me know.
#| simple-header
$Id: lift.lisp,v 1.28 2005/02/08 01:42:27 gwking Exp $ $Author: gwking $ $Date: 2005/02/08 01:42:27 $
Copyright (c) 2001-2005 Gary Warren King (gwking@cs.umass.edu)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|# (in-package user)
(defvar *optimizations-to-ignore* '() "Declarations in this list are ignored in defmethod* and defun* forms.")
;;; ------------------------------------------------------------------------ ---
(defvar *add-check-types* t "If true (the default), type declarations are parsed and check-types are added for each of them.")
;;; ------------------------------------------------------------------------ ---
#+test (setf *add-check-types* t *optimizations-to-ignore* '(list type optimize))
;;; ------------------------------------------------------------------------ ---
(defmacro defmethod* (name &rest args) `(defmethod ,name ,@(parse-defun args)))
;;; ------------------------------------------------------------------------ ---
(defmacro defun* (name args &body body) `(defun ,name ,args ,@(parse-defun body)))
;;; ------------------------------------------------------------------------ ---
(defun parse-defun (forms) ;; minor optimization (when (and (not *add-check-types*) (null *optimizations-to-ignore*)) (return-from parse-defun forms))
(let ((check-types nil)) (labels ((do-it (body) (cond ((null body) nil) ((atom body) body) ((eq (first body) 'declare) (multiple-value-bind (parsed-version checks) (parse-declare body) (setf check-types (append check-types checks)) parsed-version)) (t (when (and (consp (car body)) check-types (not (eq (first (car body)) 'declare))) (setf body (append check-types body)) (setf check-types nil)) (cons (do-it (car body)) (do-it (cdr body))))))) (do-it forms))))
;;; ------------------------------------------------------------------------ ---
(defun parse-declare (declaration) "Takes a single declare form and returns 2 values: (1) the declarations (with declarations of type *optimizations-to-ignore* removed) (2) a list of CHECK-TYPE forms that enforce all the type declarations from the DECLAREs (if *ADD-CHECK-TYPES* is true)." (assert (member (first declaration) '(declare declaim proclaim))) (let ((checks nil) (final-declares nil)) (dolist (dcl (rest declaration)) ;; add the check-types (when (and *add-check-types* (type-declaration-p dcl)) (destructuring-bind (type &rest vars) (if (eq (first dcl) 'type) (rest dcl) dcl) (dolist (var vars) (push `(check-type ,var ,type) checks)))) ;; filter the declarations (unless (member (first dcl) *optimizations-to-ignore*) (push dcl final-declares))) (values (cons 'declare (nreverse final-declares)) (nreverse checks))))
;;; ------------------------------------------------------------------------ ---
(defun type-declaration-p (declaration) (and (consp declaration) (not (member (first declaration) '(dynamic-extent ignore optimize inline special ignorable notinline))) (or (eq (first declaration) 'type) #+MCL (ccl:type-specifier-p (first declaration)) #-MCL (find (first declaration) '(sequence symbol number character hash-table function readtable package pathname stream random-state condition restart standard-object structure-object) :test 'subtypep))))
On Mar 8, 2005, at 2:48 PM, Kick Damien-DKICK1 wrote:
Edi Weitz [edi@agharta.de] wrote:
On Tue, 8 Mar 2005 13:17:41 -0600, Kick Damien-DKICK1 DKICK1@motorola.com wrote:
New code: (EVAL-WHEN (EVAL COMPILE LOAD) (DEFVAR *STANDARD-SPEED-AND-SAFETY* '((SPEED 0) (SAFETY 3)))) (DEFUN FOO () (DECLARE (OPTIMIZE #.*STANDARD-SPEED-AND-SAFETY*)) ...)
Looks cool to me. How about a patch for CL-PPCRE?
I'd be more than happy to be able to help with something like this. Should be able to find spare time to put something together by <pause> I dunno, next week.
-- Damien Kick _______________________________________________ cl-ppcre-devel site list cl-ppcre-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-ppcre-devel