Revert "Fix bound-identifier=? to compare binding names, not just symbolic names."
[bpt/guile.git] / test-suite / tests / elisp-compiler.test
index 7e013b8..230dc77 100644 (file)
@@ -1,6 +1,6 @@
-;;;; elisp-compiler.test --- Test the compiler for Elisp.
+;;;; elisp-compiler.test --- Test the compiler for Elisp.  -*- scheme -*-
 ;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;;; Daniel Kraft
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
@@ -26,7 +26,7 @@
 ; Macros to handle the compilation conveniently.
 
 (define-syntax compile-test
-  (syntax-rules (pass-if pass-if-exception)
+  (syntax-rules (pass-if pass-if-equal pass-if-exception)
     ((_ (pass-if test-name exp))
      (pass-if test-name (compile 'exp #:from 'elisp #:to 'value)))
     ((_ (pass-if test-name exp #:opts opts))
     (progn (setq depth 10 i depth)
            (setq code '(eval 0))
            (while (not (zerop i))
-             (setq code (\` (eval (quote (1+ (\, code))))))
+             (setq code (#{`}# (eval (quote (1+ (#{,}# code))))))
              (setq i (1- i)))
            (= (eval code) depth))))
 
     (progn (setq a 1 b 2)
            (and (eq (makunbound 'b) 'b)
                 (boundp 'a)
-                (not (boundp 'b)))))
-
-  (pass-if "disabled void check (all)"
-    (progn (makunbound 'a) a t)
-    #:opts '(#:disable-void-check all))
-  (pass-if "disabled void check (symbol list)"
-    (progn (makunbound 'a) a t)
-    #:opts '(#:disable-void-check (x y a b)))
-  (pass-if "without-void-checks"
-    (progn (makunbound 'a)
-           (= (without-void-checks (a) a 5) 5))))
+                (not (boundp 'b))))))
 
 (with-test-prefix/compile "Let and Let*"
 
          (lexical-let ((a 2) (b 42))
            (and (= a 2) (= (dyna) 1)
                 ((lambda (a) (and (= a 3) (= b 42) (= (dyna) 3))) 3)
+                ((lambda () (let ((a 3))
+                              (and (= a 3) (= (dyna) 1)))))
                 (= a 2) (= (dyna) 1)))
          (= a 1)))
 
          (= (funcall c2) 1)
          (= (funcall c2) 2)
          (= (funcall c1) 4)
-         (= (funcall c2) 3))))
+         (= (funcall c2) 3)))
+
+  (pass-if "always lexical option (all)"
+    (progn (setq a 0)
+           (defun dyna () a)
+           (let ((a 1))
+             (and (= a 1) (= (dyna) 0))))
+    #:opts '(#:always-lexical all))
+  (pass-if "always lexical option (list)"
+    (progn (setq a 0 b 0)
+           (defun dyna () a)
+           (defun dynb () b)
+           (let ((a 1)
+                 (b 1))
+             (and (= a 1) (= (dyna) 0)
+                  (= b 1) (= (dynb) 1))))
+    #:opts '(#:always-lexical (a)))
+  (pass-if "with-always-lexical"
+    (progn (setq a 0)
+           (defun dyna () a)
+           (with-always-lexical (a)
+             (let ((a 1))
+               (and (= a 1) (= (dyna) 0))))))
+
+  (pass-if "lexical lambda args"
+    (progn (setq a 1 b 1)
+           (defun dyna () a)
+           (defun dynb () b)
+           (with-always-lexical (a c)
+             ((lambda (a b &optional c)
+                (and (= a 3) (= (dyna) 1)
+                     (= b 2) (= (dynb) 2)
+                     (= c 1)))
+              3 2 1))))
+
+  ; Check if a lambda without dynamically bound arguments
+  ; is tail-optimized by doing a deep recursion that would otherwise overflow
+  ; the stack.
+  (pass-if "lexical lambda tail-recursion"
+    (with-always-lexical (i)
+      (setq to 1000000)
+      (defun iteration-1 (i)
+        (if (< i to)
+          (iteration-1 (1+ i))))
+      (iteration-1 0)
+      (setq x 0)
+      (defun iteration-2 ()
+        (if (< x to)
+          (setq x (1+ x))
+          (iteration-2)))
+      (iteration-2)
+      t)))
+
 
 (with-test-prefix/compile "defconst and defvar"
 
                 (flet ((foobar (lambda () 0))
                        (myfoo (symbol-function 'foobar)))
                   (and (= (myfoo) 42)
-                       (= (test) 0)))
+                       (= (test) 42)))
                 (flet* ((foobar (lambda () 0))
                         (myfoo (symbol-function 'foobar)))
-                  (= (myfoo) 0))
+                  (= (myfoo) 42))
                 (flet (foobar)
                   (defun foobar () 0)
-                  (= (test) 0))
+                  (= (test) 42))
                 (= (test) 42)))))
 
 (with-test-prefix/compile "Calling Functions"
          (equal '(1 2 . 3) '(1 2 . 3))))
 
   (pass-if "simple backquote"
-    (and (equal (\` 42) 42)
-         (equal (\` (1 (a))) '(1 (a)))
-         (equal (\` (1 . 2)) '(1 . 2))))
+    (and (equal (#{`}# 42) 42)
+         (equal (#{`}# (1 (a))) '(1 (a)))
+         (equal (#{`}# (1 . 2)) '(1 . 2))))
   (pass-if "unquote"
     (progn (setq a 42 l '(18 12))
-           (and (equal (\` (\, a)) 42)
-                (equal (\` (1 a ((\, l)) . (\, a))) '(1 a ((18 12)) . 42)))))
+           (and (equal (#{`}# (#{,}# a)) 42)
+                (equal (#{`}# (1 a ((#{,}# l)) . (#{,}# a))) '(1 a ((18 12)) . 42)))))
   (pass-if "unquote splicing"
     (progn (setq l '(18 12) empty '())
-           (and (equal (\` (\,@ l)) '(18 12))
-                (equal (\` (l 2 (3 (\,@ l)) ((\,@ l)) (\,@ l)))
+           (and (equal (#{`}# (#{,@}# l)) '(18 12))
+                (equal (#{`}# (l 2 (3 (#{,@}# l)) ((#{,@}# l)) (#{,@}# l)))
                        '(l 2 (3 18 12) (18 12) 18 12))
-                (equal (\` (1 2 (\,@ empty) 3)) '(1 2 3))))))
+                (equal (#{`}# (1 2 (#{,@}# empty) 3)) '(1 2 3))))))