| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 2008. Juan Jose Garcia-Ripol |
| 6 |
;;;; |
| 7 |
;;;; See file 'LICENSE' for the copyright details. |
| 8 |
;;;; |
| 9 |
;;;; CMPOPT-TYPE -- Optimizations for selected types of expresions |
| 10 |
;;;; |
| 11 |
|
| 12 |
(in-package "COMPILER") |
| 13 |
|
| 14 |
(define-compiler-macro dotimes ((variable limit &rest output) &body body) |
| 15 |
(multiple-value-bind (declarations body) |
| 16 |
(si:process-declarations body nil) |
| 17 |
(ext:with-unique-names (%limit) |
| 18 |
`(block nil |
| 19 |
(let ((,%limit ,limit)) |
| 20 |
(declare (:read-only ,%limit)) |
| 21 |
(ext:compiler-typecase ,%limit |
| 22 |
(fixnum |
| 23 |
;; %LIMIT will be type checked by the compiler to be |
| 24 |
;; a fixnum. We may thus just increase the counter. |
| 25 |
(let ((,variable 0)) |
| 26 |
(declare (fixnum ,variable) |
| 27 |
,@declarations) |
| 28 |
(si::while (< ,variable ,%limit) |
| 29 |
,@body |
| 30 |
(locally (declare (optimize (safety 0))) |
| 31 |
(setq ,variable (1+ ,variable)))) |
| 32 |
,@output)) |
| 33 |
(t |
| 34 |
(let ((,variable 0)) |
| 35 |
(declare ,@declarations) |
| 36 |
(si::while (< ,variable ,%limit) |
| 37 |
,@body |
| 38 |
(setq ,variable (1+ ,variable))) |
| 39 |
,@output)))))))) |