From c77ad1866d0e559db41118ad5a2c306c81fa3c21 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sat, 3 Aug 2019 19:14:35 +0200 Subject: [PATCH] add incoming &optional args support --- lisp/emacs-lisp/comp.el | 7 +++---- src/comp.c | 10 +++++----- test/src/comp-tests.el | 12 ++++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 71d747428d8..71dd016ab0d 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -674,10 +674,9 @@ the annotation emission." (comp-emit-block 'entry) (comp-emit-annotation (concat "Lisp function: " (symbol-name (comp-func-symbol-name func)))) - (cl-loop for i below (comp-args-min (comp-func-args func)) - do (progn - (cl-incf (comp-sp)) - (comp-emit `(setpar ,(comp-slot) ,i)))) + (cl-loop for i below (comp-args-max (comp-func-args func)) + do (cl-incf (comp-sp)) + do (comp-emit `(setpar ,(comp-slot) ,i))) ;; Body (comp-emit-block 'bb_1) (mapc #'comp-limplify-lap-inst (comp-func-lap func)) diff --git a/src/comp.c b/src/comp.c index e4483ea4206..c7f68c7078e 100644 --- a/src/comp.c +++ b/src/comp.c @@ -2096,14 +2096,14 @@ DEFUN ("comp-add-func-to-ctxt", Fcomp_add_func_to_ctxt, Scomp_add_func_to_ctxt, char *c_name = (char *) SDATA (FUNCALL1 (comp-func-c-func-name, func)); Lisp_Object args = FUNCALL1 (comp-func-args, func); EMACS_INT frame_size = XFIXNUM (FUNCALL1 (comp-func-frame-size, func)); - EMACS_INT min_args = XFIXNUM (FUNCALL1 (comp-args-min, args)); - /* EMACS_INT max_args = XFIXNUM (FUNCALL1 (comp-args-max, args)); */ - bool ncall = !NILP (FUNCALL1 (comp-args-ncall-conv, args)); + /* EMACS_INT min_args = XFIXNUM (FUNCALL1 (comp-args-min, args)); */ + EMACS_INT max_args = XFIXNUM (FUNCALL1 (comp-args-max, args)); + bool ncall = !NILP (FUNCALL1 (comp-args-ncall-conv, args)); if (!ncall) { comp.func = - emit_func_declare (c_name, comp.lisp_obj_type, min_args, + emit_func_declare (c_name, comp.lisp_obj_type, max_args, NULL, GCC_JIT_FUNCTION_EXPORTED, false); } else @@ -2204,7 +2204,7 @@ DEFUN ("comp-compile-and-load-ctxt", Fcomp_compile_and_load_ctxt, x->s.function.a0 = gcc_jit_result_get_code(gcc_res, c_name); eassert (x->s.function.a0); x->s.min_args = XFIXNUM (FUNCALL1 (comp-args-min, args)); - x->s.max_args = XFIXNUM (FUNCALL1 (comp-args-min, args)); + x->s.max_args = XFIXNUM (FUNCALL1 (comp-args-max, args)); x->s.symbol_name = symbol_name; defsubr(x); diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 9fbff7639e9..7cf2a12f4a2 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -156,13 +156,13 @@ (should (equal (comp-tests-ffuncall-caller-f) '(1 2 3))) - ;; (defun comp-tests-ffuncall-callee-optional-f (a b &optional c d) - ;; (list a b c d)) - ;; (native-compile #'comp-tests-ffuncall-callee-optional-f) + (defun comp-tests-ffuncall-callee-optional-f (a b &optional c d) + (list a b c d)) + (native-compile #'comp-tests-ffuncall-callee-optional-f) - ;; (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3 4) '(1 2 3 4))) - ;; (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3) '(1 2 3 nil))) - ;; (should (equal (comp-tests-ffuncall-callee-optional-f 1 2) '(1 2 nil nil))) + (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3 4) '(1 2 3 4))) + (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3) '(1 2 3 nil))) + (should (equal (comp-tests-ffuncall-callee-optional-f 1 2) '(1 2 nil nil))) ;; (defun comp-tests-ffuncall-callee-rest-f (a b &rest c) ;; (list a b c)) -- 2.39.5