| 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) 1984, Taiichi Yuasa and Masami Hagiya. |
| 6 |
;;;; Copyright (c) 1990, Giuseppe Attardi. |
| 7 |
;;;; Copyright (c) 2010, Juan Jose Garcia-Ripoll |
| 8 |
;;;; |
| 9 |
;;;; See file 'LICENSE' for the copyright details. |
| 10 |
;;;; |
| 11 |
|
| 12 |
;;;; CMPENV-DECLAIM -- Proclamations local to the current file |
| 13 |
;;;; |
| 14 |
;;;; One implementation of DECLAIM that uses the compiler environment |
| 15 |
;;;; providing a "base" set of entries that all other environments |
| 16 |
;;;; stem from. |
| 17 |
;;;; |
| 18 |
|
| 19 |
(in-package "COMPILER") |
| 20 |
|
| 21 |
(defun process-declaim-args (args) |
| 22 |
(flet ((add-variables (env types specials) |
| 23 |
(loop for name in specials |
| 24 |
unless (assoc name types) |
| 25 |
do (let ((v (make-global-var name :kind 'special))) |
| 26 |
(setf env (cmp-env-register-var v env nil)))) |
| 27 |
(loop for (name . type) in types |
| 28 |
for specialp = (or (si:specialp name) (member name specials)) |
| 29 |
for kind = (if specialp 'SPECIAL 'GLOBAL) |
| 30 |
for v = (make-global-var name :type type :kind kind) |
| 31 |
do (setf env (cmp-env-register-var v env nil))) |
| 32 |
env)) |
| 33 |
(multiple-value-bind (body specials types ignored others doc all) |
| 34 |
(c1body `((DECLARE ,@args)) nil) |
| 35 |
(declare (ignore body doc all)) |
| 36 |
(when ignored |
| 37 |
(cmpwarn-style "IGNORE/IGNORABLE declarations in DECLAIM are ignored")) |
| 38 |
(reduce #'add-one-declaration others |
| 39 |
:initial-value (add-variables *cmp-env* types specials)) |
| 40 |
(reduce #'add-one-declaration others |
| 41 |
:initial-value (add-variables *cmp-env-root* types specials))))) |
| 42 |
|
| 43 |
(defmacro declaim (&rest declarations) |
| 44 |
`(locally (declare (notinline mapc)) |
| 45 |
(ext:with-backend |
| 46 |
:c/c++ (eval-when (:compile-toplevel) |
| 47 |
(c::process-declaim-args ',declarations)) |
| 48 |
:bytecodes (eval-when (:compile-toplevel) |
| 49 |
(mapc 'proclaim ',declarations))) |
| 50 |
(eval-when (:load-toplevel :execute) |
| 51 |
(mapc 'proclaim ',declarations)))) |
| 52 |
|
| 53 |
(defmacro ext::c-declaim (&rest declarations) |
| 54 |
`(ext:with-backend |
| 55 |
:c/c++ (eval-when (:compile-toplevel) |
| 56 |
(c::process-declaim-args ',declarations)))) |