Debian Codegraph @

src/cmp/cmpenv-proclaim.lsp

raw
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-PROCLAIM -- Proclamations for the compiler
13 ;;;;
14 ;;;; One implementation of PROCLAIM that uses symbol properties to
15 ;;;; store the proclamations. This has the disadvantage that
16 ;;;; proclamations can not be easily cleaned up.
17 ;;;;
18 ;;;; The following code is to be coordinated with that in sysfun.lsp
19 ;;;; and proclamations.lsp
20 ;;;;
21
22 (in-package #-ecl-new "COMPILER" #+ecl-new "C-ENV")
23
24 (defun proclaim (decl &aux decl-name)
25 (unless (listp decl)
26 (error "The proclamation specification ~s is not a list" decl))
27 (case (setf decl-name (car decl))
28 (cl:SPECIAL
29 (dolist (var (cdr decl))
30 (if (symbolp var)
31 (si:*make-special var)
32 (error "Syntax error in proclamation ~s" decl))))
33 (cl:OPTIMIZE
34 (dolist (x (cdr decl))
35 (when (symbolp x) (setq x (list x 3)))
36 (if (or (not (consp x))
37 (not (consp (cdr x)))
38 (not (numberp (second x)))
39 (not (<= 0 (second x) 3)))
40 (warn "The OPTIMIZE proclamation ~s is illegal." x)
41 (case (car x)
42 (DEBUG (setq *debug* (second x)))
43 (SAFETY (setq *safety* (second x)))
44 (SPACE (setq *space* (second x)))
45 (SPEED (setq *speed* (second x)))
46 (COMPILATION-SPEED (setq *compilation-speed* (second x)))
47 (t (warn "The OPTIMIZE quality ~s is unknown." (car x)))))))
48 (cl:TYPE
49 (if (consp (cdr decl))
50 (proclaim-var (second decl) (cddr decl))
51 (error "Syntax error in proclamation ~s" decl)))
52 (cl:FTYPE
53 (if (atom (rest decl))
54 (error "Syntax error in proclamation ~a" decl)
55 (multiple-value-bind (type-name args)
56 (si::normalize-type (second decl) *cmp-env*)
57 (if (eq type-name 'FUNCTION)
58 (dolist (v (cddr decl))
59 (proclaim-function v args))
60 (error "In an FTYPE proclamation, found ~A which is not a function type."
61 (second decl))))))
62 (cl:INLINE
63 (proclaim-inline (cdr decl)))
64 (cl:NOTINLINE
65 (proclaim-notinline (cdr decl)))
66 ((OBJECT cl:IGNORE cl:DYNAMIC-EXTENT cl:IGNORABLE)
67 ;; FIXME! IGNORED!
68 (dolist (var (cdr decl))
69 (unless (si::valid-function-name-p var)
70 (error "Not a valid function name ~s in ~s proclamation" var decl-name))))
71 (cl:DECLARATION
72 (validate-alien-declaration (rest decl) #'error)
73 (setf si::*alien-declarations* (append (rest decl) si:*alien-declarations*)))
74 (SI::C-EXPORT-FNAME
75 (dolist (x (cdr decl))
76 (cond ((symbolp x)
77 (multiple-value-bind (found c-name)
78 (si:mangle-name x t)
79 (if found
80 (error "The function ~s is already in the runtime.~%C-EXPORT-FNAME declaration ignored." x)
81 (si:put-sysprop x 'Lfun c-name))))
82 ((consp x)
83 (destructuring-bind (c-name lisp-name) x
84 (if (si:mangle-name lisp-name)
85 (error "The function ~s is already in the runtime.~%C-EXPORT-FNAME declaration ignored." lisp-name)
86 (si:put-sysprop lisp-name 'Lfun c-name))))
87 (t
88 (error "Syntax error in proclamation ~s" decl)))))
89 ((cl:ARRAY cl:ATOM cl:BASE-CHAR cl:BIGNUM cl:BIT cl:BIT-VECTOR cl:CHARACTER cl:COMPILED-FUNCTION
90 cl:COMPLEX cl:CONS cl:DOUBLE-FLOAT cl:EXTENDED-CHAR cl:FIXNUM cl:FLOAT cl:HASH-TABLE cl:INTEGER cl:KEYWORD cl:LIST
91 cl:LONG-FLOAT cl:NIL cl:NULL cl:NUMBER cl:PACKAGE cl:PATHNAME cl:RANDOM-STATE cl:RATIO cl:RATIONAL
92 cl:READTABLE cl:SEQUENCE cl:SHORT-FLOAT cl:SIMPLE-ARRAY cl:SIMPLE-BIT-VECTOR
93 cl:SIMPLE-STRING cl:SIMPLE-VECTOR cl:SINGLE-FLOAT cl:STANDARD-CHAR cl:STREAM cl:STRING
94 cl:SYMBOL cl:T cl:VECTOR cl:SIGNED-BYTE cl:UNSIGNED-BYTE cl:FUNCTION)
95 (proclaim-var decl-name (cdr decl)))
96 (otherwise
97 (cond ((member (car decl) si:*alien-declarations*))
98 ((multiple-value-bind (ok type)
99 (valid-type-specifier decl-name)
100 (when ok
101 (proclaim-var type (rest decl))
102 t)))
103 ((maybe-add-policy decl *cmp-env-root*))
104 ((let ((proclaimer (si:get-sysprop (car decl) :proclaim)))
105 (when (functionp proclaimer)
106 (mapc proclaimer (rest decl))
107 t)))
108 (t
109 (warn "Unknown declaration specifier ~s" decl-name))))))
110
111 (defun proclaim-var (type vl)
112 (dolist (var vl)
113 (if (symbolp var)
114 (let ((type1 (si:get-sysprop var 'CMP-TYPE)))
115 (setq type1 (if type1 (type-and type1 type) type))
116 (unless type1
117 (warn
118 "Inconsistent type declaration was found for the variable ~s."
119 var)
120 (setq type1 T))
121 (si:put-sysprop var 'CMP-TYPE type1))
122 (warn "The variable name ~s is not a symbol." var))))
123