| 1 |
;;;; |
| 2 |
;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya |
| 3 |
;;;; Copyright (c) 1990, Giuseppe Attardi |
| 4 |
;;;; Copyright (c) 2010, Juan Jose Garcia-Ripoll |
| 5 |
;;;; Copyright (c) 2021, Daniel Kochmański |
| 6 |
;;;; |
| 7 |
;;;; See file 'LICENSE' for the copyright details. |
| 8 |
;;;; |
| 9 |
|
| 10 |
(in-package #:compiler) |
| 11 |
|
| 12 |
(defun c1quote (args) |
| 13 |
(check-args-number 'QUOTE args 1 1) |
| 14 |
(c1constant-value (car args))) |
| 15 |
|
| 16 |
(defun c1declare (args) |
| 17 |
(cmperr "The declaration ~s was found in a bad place." (cons 'DECLARE args))) |
| 18 |
|
| 19 |
(defun c1the (args) |
| 20 |
(check-args-number 'THE args 2 2) |
| 21 |
;; FIXME: C1CHECKED-VALUE cannot check multiple values. |
| 22 |
(let ((type (first args))) |
| 23 |
(if (and (policy-the-is-checked) |
| 24 |
(not (and (consp type) |
| 25 |
(eq (first type) 'values)))) |
| 26 |
(c1checked-value args) |
| 27 |
(c1truly-the args)))) |
| 28 |
|
| 29 |
(defun c1truly-the (args) |
| 30 |
(check-args-number 'ext:truly-the args 2 2) |
| 31 |
(let* ((form (c1expr (second args))) |
| 32 |
(the-type (first args)) |
| 33 |
type) |
| 34 |
(setf type (values-type-and the-type (c1form-type form))) |
| 35 |
(if (values-type-primary-type type) |
| 36 |
(setf (c1form-type form) type) |
| 37 |
(cmpwarn "Type mismatch was found in ~s." (cons 'THE args))) |
| 38 |
form)) |
| 39 |
|
| 40 |
(defun c1compiler-let (args &aux (symbols nil) (values nil)) |
| 41 |
(when (endp args) (too-few-args 'ext:compiler-let 1 0)) |
| 42 |
(dolist (spec (car args)) |
| 43 |
(cond ((consp spec) |
| 44 |
(cmpck (not (and (symbolp (car spec)) |
| 45 |
(or (endp (cdr spec)) |
| 46 |
(endp (cddr spec))))) |
| 47 |
"The variable binding ~s is illegal." spec) |
| 48 |
(push (car spec) symbols) |
| 49 |
(push (if (endp (cdr spec)) nil (eval (second spec))) values)) |
| 50 |
((symbolp spec) |
| 51 |
(push spec symbols) |
| 52 |
(push nil values)) |
| 53 |
(t (cmperr "The variable binding ~s is illegal." spec)))) |
| 54 |
(setq symbols (nreverse symbols)) |
| 55 |
(setq values (nreverse values)) |
| 56 |
(setq args (progv symbols values (c1progn (cdr args)))) |
| 57 |
(make-c1form 'ext:compiler-let args symbols values args)) |
| 58 |
|
| 59 |
(defun c1function (args) |
| 60 |
(check-args-number 'FUNCTION args 1 1) |
| 61 |
(let ((fun (car args))) |
| 62 |
(cond ((si:valid-function-name-p fun) |
| 63 |
(add-fname fun) |
| 64 |
(ext:if-let ((funob (local-function-ref fun t))) |
| 65 |
(let ((var (fun-var funob))) |
| 66 |
(add-to-read-nodes var (make-c1form* 'VARIABLE :args var nil))) |
| 67 |
(make-c1form* 'FUNCTION |
| 68 |
:type 'FUNCTION |
| 69 |
:sp-change (not (and (symbolp fun) |
| 70 |
(si:get-sysprop fun 'NO-SP-CHANGE))) |
| 71 |
:args fun))) |
| 72 |
((and (consp fun) (member (car fun) '(LAMBDA EXT:LAMBDA-BLOCK))) |
| 73 |
(cmpck (endp (cdr fun)) |
| 74 |
"The lambda expression ~s is illegal." fun) |
| 75 |
(let (name body) |
| 76 |
(if (eq (first fun) 'lambda) |
| 77 |
(let ((decl (si:process-declarations (cddr fun)))) |
| 78 |
(setf name (or (function-block-name-declaration decl) |
| 79 |
(gensym "LAMBDA")) |
| 80 |
body (rest fun))) |
| 81 |
(setf name (second fun) |
| 82 |
body (cddr fun))) |
| 83 |
(c1expr `(flet ((,name ,@body)) #',name)))) |
| 84 |
(t (cmperr "The function ~s is illegal." fun))))) |