From 4ce6c85438093aafd5b09a0c647c7e40af2eb20f Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Thu, 20 May 2010 12:41:38 +0200 Subject: [PATCH] Split out the sequence macros into a separate file --- src/lsp/seqlib.lsp | 38 ++++--------------------------- src/lsp/seqmacros.lsp | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 src/lsp/seqmacros.lsp diff --git a/src/lsp/seqlib.lsp b/src/lsp/seqlib.lsp index b0cdae089..17e32bd34 100644 --- a/src/lsp/seqlib.lsp +++ b/src/lsp/seqlib.lsp @@ -12,9 +12,12 @@ ;;;; sequence routines - (in-package "SYSTEM") +#+ecl-min +(eval-when (:execute) + (load (merge-pathnames "seqmacros.lsp" *load-truename*))) + (defun seqtype (sequence) (declare (si::c-local)) (cond ((listp sequence) 'list) @@ -33,39 +36,6 @@ (optimize (speed 3) (safety 0))) (funcall f x)) -(eval-when (:compile-toplevel :execute) - (defmacro with-predicate ((predicate) &body body) - `(let ((,predicate (si::coerce-to-function ,predicate))) - (macrolet ((,predicate (&rest args) - `(locally (declare (optimize (safety 0) (speed 3))) - (funcall (the function ,',predicate) ,@args)))) - ,@body))) - (defmacro with-key ((akey) &body body) - `(let ((,akey (if ,akey (si::coerce-to-function ,akey) #'identity))) - (macrolet ((,akey (value) - `(locally (declare (optimize (safety 0) (speed 3))) - (funcall (the function ,',akey) ,value)))) - ,@body))) - (defmacro with-tests (&whole whole (test test-not &optional key) &body body) - (when key - (setf body `((with-key (,key) ,@body)))) - `(let ((,test (if ,test (si::coerce-to-function ,test))) - (,test-not (if ,test-not (si::coerce-to-function ,test-not)))) - (and test test-not (test-error)) - (macrolet ((compare (v1 v2) - `(locally (declare (optimize (safety 0) (speed 3))) - (cond (test (funcall (the function test) ,v1 ,v2)) - (test-not (not (funcall (the function test-not) - ,v1 ,v2))) - (t (eql ,v1 ,v2)))) - )) - ,@body))) - (defmacro with-start-end (start end seq &body body) - `(multiple-value-bind (,start ,end) - (sequence-start-end 'subseq ,seq ,start ,end) - (declare (fixnum ,start ,end)) - ,@body))) - (defun reduce (function sequence &key from-end (start 0) diff --git a/src/lsp/seqmacros.lsp b/src/lsp/seqmacros.lsp new file mode 100644 index 000000000..71052bcc1 --- /dev/null +++ b/src/lsp/seqmacros.lsp @@ -0,0 +1,52 @@ +;;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: SYSTEM -*- +;;;; +;;;; Copyright (c) 2010, Juan Jose Garcia-Ripoll +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU Library General Public +;;;; License as published by the Free Software Foundation; either +;;;; version 2 of the License, or (at your option) any later version. +;;;; +;;;; See file '../Copyright' for full details. +;;;; +;;;; SEQMACROS -- Macros that are used to expand sequence routines +;;;; + +(in-package "SYSTEM") + +(defmacro with-predicate ((predicate) &body body) + `(let ((,predicate (si::coerce-to-function ,predicate))) + (macrolet ((,predicate (&rest args) + `(locally (declare (optimize (safety 0) (speed 3))) + (funcall (the function ,',predicate) ,@args)))) + ,@body))) + +(defmacro with-key ((akey) &body body) + `(let ((,akey (if ,akey (si::coerce-to-function ,akey) #'identity))) + (macrolet ((,akey (value) + `(locally (declare (optimize (safety 0) (speed 3))) + (funcall (the function ,',akey) ,value)))) + ,@body))) + +(defmacro with-tests (&whole whole (test test-not &optional key) &body body) + (when key + (setf body `((with-key (,key) ,@body)))) + `(let ((,test (if ,test (si::coerce-to-function ,test))) + (,test-not (if ,test-not (si::coerce-to-function ,test-not)))) + (and test test-not (test-error)) + (macrolet ((compare (v1 v2) + `(locally (declare (optimize (safety 0) (speed 3))) + (cond (test (funcall (the function test) ,v1 ,v2)) + (test-not (not (funcall (the function test-not) + ,v1 ,v2))) + (t (eql ,v1 ,v2)))) + )) + ,@body))) + +(defmacro with-start-end (start end seq &body body) + `(multiple-value-bind (,start ,end) + (sequence-start-end 'subseq ,seq ,start ,end) + (declare (fixnum ,start ,end)) + ,@body)) + +