]> git.eshelyaron.com Git - emacs.git/commitdiff
add incoming &optional args support
authorAndrea Corallo <andrea_corallo@yahoo.it>
Sat, 3 Aug 2019 17:14:35 +0000 (19:14 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:33:57 +0000 (11:33 +0100)
lisp/emacs-lisp/comp.el
src/comp.c
test/src/comp-tests.el

index 71d747428d8a78c03dc7231b522e48cbac0bdd0f..71dd016ab0dbbf56736152d5cc68cf1807e5230d 100644 (file)
@@ -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))
index e4483ea4206b1d6a44143d21c7f3b3e555ea9041..c7f68c7078eb2de694eb81185b14d8281afe69c0 100644 (file)
@@ -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);
 
index 9fbff7639e9047a24fe6132e4245a88516071d1e..7cf2a12f4a208f692adeb112fd9b99e6e982cdac 100644 (file)
 
   (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))