comparison tests/automated/lisp-tests.el @ 5574:d4f334808463

Support inlining labels, bytecomp.el. lisp/ChangeLog addition: 2011-10-02 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-initial-macro-environment): Add #'declare to this, so it doesn't need to rely on #'cl-compiling file to determine when we're byte-compiling. Update #'labels to support declaring labels inline, as Common Lisp requires. * bytecomp.el (byte-compile-function-form): Don't error if FUNCTION is quoting a non-lambda, non-symbol, just return it. * cl-extra.el (cl-macroexpand-all): If a label name has been quoted, expand to the label placeholder quoted with 'function. This allows the byte compiler to distinguish between uses of the placeholder as data and uses in contexts where it should be inlined. * cl-macs.el: * cl-macs.el (cl-do-proclaim): When proclaming something as inline, if it is bound as a label, don't modify the symbol's plist; instead, treat the first element of its placeholder constant vector as a place to store compile information. * cl-macs.el (declare): Leave processing declarations while compiling to the implementation of #'declare in byte-compile-initial-macro-environment. tests/ChangeLog addition: 2011-10-02 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: * automated/lisp-tests.el (+): Test #'labels and inlining.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 02 Oct 2011 15:32:16 +0100
parents 58b38d5b32d0
children 071b810ceb18
comparison
equal deleted inserted replaced
5573:f0f1fd0d8486 5574:d4f334808463
2937 (Assert (eql (funcall times-four 4 4) 64)) 2937 (Assert (eql (funcall times-four 4 4) 64))
2938 (Assert (eql (funcall plus-twelve (funcall times-four 4) 4 4) 36)) 2938 (Assert (eql (funcall plus-twelve (funcall times-four 4) 4 4) 36))
2939 (Check-Error wrong-number-of-arguments (apply-partially)) 2939 (Check-Error wrong-number-of-arguments (apply-partially))
2940 (Assert (equal (funcall construct-list) '(5 6 7)))) 2940 (Assert (equal (funcall construct-list) '(5 6 7))))
2941 2941
2942 ;; Test labels and inlining.
2943 (labels
2944 ((+ (&rest arguments)
2945 ;; Shades of Java, hah.
2946 (mapconcat #'prin1-to-string arguments ", "))
2947 (print-with-commas (stream one two three four five)
2948 (princ (+ one two three four five) stream))
2949 (bookend (open close &rest arguments)
2950 (refer-to-bookend (concat open (apply #'+ arguments) close)))
2951 (refer-to-bookend (string)
2952 (bookend "[" "]" string "hello" "there")))
2953 (declare (inline + print-with-commas bookend refer-to-bookend))
2954 (macrolet
2955 ((with-first-arguments (&optional form)
2956 (append form (list 1 [hi there] 40 "this is a string" pi)))
2957 (with-second-arguments (&optional form)
2958 (append form (list pi e ''hello ''there [40 50 60])))
2959 (with-both-arguments (&optional form)
2960 (append form
2961 (macroexpand '(with-first-arguments))
2962 (macroexpand '(with-second-arguments)))))
2963
2964 (with-temp-buffer
2965 (Assert
2966 (equal
2967 (mapconcat #'prin1-to-string (with-first-arguments (list)) ", ")
2968 (with-first-arguments (print-with-commas (current-buffer))))
2969 "checking print-with-commas gives the expected result")
2970 (Assert
2971 (or
2972 (not (compiled-function-p (indirect-function #'print-with-commas)))
2973 (notany #'compiled-function-p
2974 (compiled-function-constants
2975 (indirect-function #'print-with-commas))))
2976 "checking the label + was inlined correctly")
2977 (insert ", ")
2978 ;; This call to + will be inline in compiled code, but there's
2979 ;; no easy way for us to check that:
2980 (Assert (null (insert (with-second-arguments (+)))))
2981 (Assert (equal
2982 (mapconcat #'prin1-to-string (with-both-arguments (list)) ", ")
2983 (buffer-string))
2984 "checking the buffer contents are as expected at the end.")
2985 (Assert (not (funcall (intern "eq") #'bookend #'refer-to-bookend))
2986 "checking two mutually recursive functions compiled OK"))))
2987
2942 ;;; end of lisp-tests.el 2988 ;;; end of lisp-tests.el