compile.lsp 1.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Oct 10 20:54:20 2002
;;;; Contains: Tests for COMPILE, COMPILED-FUNCTION-P, COMPILED-FUNCTION

(in-package :cl-test)

(deftest compile.1
  (progn
    (fmakunbound 'compile.1-fn)
    (values
     (defun compile.1-fn (x) x)
     (compiled-function-p 'compile.1-fn)
pfdietz's avatar
pfdietz committed
14
15
16
     (let ((x (compile 'compile.1-fn)))
       (or (eqt x 'compile.1-fn)
	   (notnot (compiled-function-p x))))
17
18
19
20
21
     (compiled-function-p 'compile.1-fn)
     (not (compiled-function-p #'compile.1-fn))
     (fmakunbound 'compile.1-fn)))
  compile.1-fn
  nil
pfdietz's avatar
pfdietz committed
22
  t
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  nil
  nil
  compile.1-fn)


;;; COMPILE returns three values (function, warnings-p, failure-p)
(deftest compile.2
  (let* ((results (multiple-value-list
		   (compile nil '(lambda (x y) (cons y x)))))
	 (fn (car results)))
    (values (length results)
	    (funcall fn 'a 'b)
	    (second results)
	    (third results)))
  3
  (b . a)
  nil
  nil)

;;; Compile does not coalesce literal constants
(deftest compile.3
  (let ((x (list 'a 'b))
	(y (list 'a 'b)))
46
47
    (and (not (eqt x y))
	 (funcall (compile nil `(lambda () (eqt ',x ',y))))))
48
49
50
51
52
  nil)

(deftest compile.4
  (let ((x (copy-seq "abc"))
	(y (copy-seq "abc")))
53
54
    (and (not (eqt x y))
	 (funcall (compile nil `(lambda () (eqt ,x ,y))))))
55
56
57
58
  nil)

(deftest compile.5
  (let ((x (copy-seq "abc")))
59
    (funcall (compile nil `(lambda () (eqt ,x ,x)))))
60
61
62
63
  t)

(deftest compile.6
  (let ((x (copy-seq "abc")))
64
    (funcall (compile nil `(lambda () (eqt ',x ',x)))))
65
66
  t)

67
68
(deftest compile.7
  (let ((x (copy-seq "abc")))
69
    (eqt x (funcall (compile nil `(lambda () ,x)))))
70
  t)
71

72
73
(deftest compile.8
  (let ((x (list 'a 'b)))
74
    (eqt x (funcall (compile nil `(lambda () ',x)))))
75
  t)
76
77
78
79
80
81
82
83

(deftest compile.9
  (classify-error (compile))
  program-error)

(deftest compile.10
  (classify-error (compile nil '(lambda () nil) 'garbage))
  program-error)