Debian Codegraph @

src/cmp/cmpenv-var.lsp

raw
1
2 ;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya
3 ;;;; Copyright (c) 1990, Giuseppe Attardi
4 ;;;; Copyright (c) 2003, Juan Jose Garcia-Ripoll
5 ;;;; Copyright (c) 2023, Daniel Kochmański
6 ;;;;
7 ;;;; See file 'LICENSE' for the copyright details.
8
9 (in-package #:compiler)
10
11 (defun declare-special (name &optional (env *cmp-env*))
12 (when (cmp-env-search-symbol-macro name env)
13 (cmperr "Symbol ~A cannot be declared special and appear in a symbol-macrolet." name))
14 (cmp-env-register-var (make-global-var name :warn nil :kind 'SPECIAL) env nil))
15
16 ;;; A special binding creates a var object with the kind field SPECIAL,
17 ;;; whereas a special declaration without binding creates a var object with
18 ;;; the kind field GLOBAL. Thus a reference to GLOBAL may need to make sure
19 ;;; that the variable has a value.
20
21 ;;; Bootstrap problem: proclaim needs this function:
22 ;;;
23 ;;; Check if a variable has been declared as a special variable with a global
24 ;;; value.
25
26 (defun check-global (name)
27 (member name *global-vars*))
28
29 (defun si::register-global (name)
30 (pushnew name *global-vars*)
31 (values))
32
33 (defun special-variable-p (name)
34 "Return true if NAME is associated to a special variable in the lexical environment."
35 (or (si:specialp name)
36 (check-global name)
37 (let ((v (cmp-env-search-var name *cmp-env-root*)))
38 ;; Fixme! Revise the declamation code to ensure whether
39 ;; we also have to consider 'GLOBAL here.
40 (and v (eq (var-kind v) 'SPECIAL)))))
41
42 (defun constant-variable-p (name)
43 (si:constp name))
44
45 (defun local-variable-p (name &optional (env *cmp-env*))
46 (let ((record (cmp-env-search-var name env)))
47 (and record (var-p record))))
48
49 (defun symbol-macro-p (name &optional (env *cmp-env*))
50 (let ((record (cmp-env-search-var name env)))
51 (and record (not (var-p record)))))
52
53 (defun read-only-variable-p (name other-decls)
54 (dolist (i other-decls nil)
55 (when (and (eq (car i) :READ-ONLY)
56 (member name (rest i)))
57 (return t))))
58
59 (defun variable-type-in-env (name &optional (env *cmp-env*))
60 (let ((var (cmp-env-search-var name env)))
61 (cond ((var-p var)
62 (var-type var))
63 ((si:get-sysprop name 'CMP-TYPE))
64 (t))))