(make-temp-file (comp-c-func-name function-name "freefn-")
nil ".eln")))
(let* ((f (symbol-function function-name))
+ (byte-code (byte-compile function-name))
(c-name (comp-c-func-name function-name "F"))
- (func (make-comp-func-l :name function-name
- :c-name c-name
- :doc (documentation f t)
- :int-spec (interactive-form f)
- :command-modes (command-modes f)
- :speed (comp-spill-speed function-name)
- :pure (comp-spill-decl-spec function-name
- 'pure))))
+ (func
+ (if (comp-lex-byte-func-p byte-code)
+ (make-comp-func-l :name function-name
+ :c-name c-name
+ :doc (documentation f t)
+ :int-spec (interactive-form f)
+ :command-modes (command-modes f)
+ :speed (comp-spill-speed function-name)
+ :pure (comp-spill-decl-spec function-name
+ 'pure))
+ (make-comp-func-d :name function-name
+ :c-name c-name
+ :doc (documentation f t)
+ :int-spec (interactive-form f)
+ :command-modes (command-modes f)
+ :speed (comp-spill-speed function-name)
+ :pure (comp-spill-decl-spec function-name
+ 'pure)))))
(when (byte-code-function-p f)
(signal 'native-compiler-error
'("can't native compile an already byte-compiled function")))
- (setf (comp-func-byte-func func)
- (byte-compile (comp-func-name func)))
+ (setf (comp-func-byte-func func) byte-code)
(let ((lap (byte-to-native-lambda-lap
(gethash (aref (comp-func-byte-func func) 1)
byte-to-native-lambdas-h))))
(cl-assert lap)
(comp-log lap 2 t)
- (let ((arg-list (aref (comp-func-byte-func func) 0)))
- (setf (comp-func-l-args func)
- (comp-decrypt-arg-list arg-list function-name)
- (comp-func-lap func)
- lap
- (comp-func-frame-size func)
- (comp-byte-frame-size (comp-func-byte-func func))))
- (setf (comp-ctxt-top-level-forms comp-ctxt)
+ (if (comp-func-l-p func)
+ (let ((arg-list (aref (comp-func-byte-func func) 0)))
+ (setf (comp-func-l-args func)
+ (comp-decrypt-arg-list arg-list function-name)))
+ (setf (comp-func-d-lambda-list func) (cadr f)))
+ (setf (comp-func-lap func)
+ lap
+ (comp-func-frame-size func)
+ (comp-byte-frame-size (comp-func-byte-func func))
+ (comp-ctxt-top-level-forms comp-ctxt)
(list (make-byte-to-native-func-def :name function-name
:c-name c-name)))
(comp-add-func-to-ctxt func))))
--- /dev/null
+;;; comp-test-funcs-dyn2.el -*- lexical-binding: nil; no-byte-compile: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; Author: Alan Mackenzie <acm@muc.de>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; Test the compilation of a function under dynamic binding.
+
+;;; Code:
+
+(defun comp-tests-result-lambda ()
+ (lambda (bar) (car bar)))
+
+(provide 'comp-test-funcs-dyn2)
+;;; comp-test-funcs-dyn2.el ends here.
(eval-and-compile
(defconst comp-test-src (ert-resource-file "comp-test-funcs.el"))
- (defconst comp-test-dyn-src (ert-resource-file "comp-test-funcs-dyn.el")))
+ (defconst comp-test-dyn-src (ert-resource-file "comp-test-funcs-dyn.el"))
+ (defconst comp-test-dyn-src2 (ert-resource-file "comp-test-funcs-dyn2.el")))
(when (native-comp-available-p)
(message "Compiling tests...")
;; names used in this file.
(require 'comp-test-funcs comp-test-src)
(require 'comp-test-dyn-funcs comp-test-dyn-src) ;Non-standard feature name!
+(require 'comp-test-funcs-dyn2 comp-test-dyn-src2)
(defmacro comp-deftest (name args &rest docstring-and-body)
"Define a test for the native compiler tagging it as :nativecomp."
(equal (comp-mvar-typeset mvar)
comp-tests-cond-rw-expected-type))))))))
+(ert-deftest comp-tests-result-lambda ()
+ (native-compile 'comp-tests-result-lambda)
+ (should (eq (funcall (comp-tests-result-lambda) '(a . b)) 'a)))
;;; comp-tests.el ends here