summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/comp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/comp.el')
-rw-r--r--lisp/emacs-lisp/comp.el41
1 files changed, 23 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 283c00103b5..e97832455b9 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1763,27 +1763,32 @@ Return value is the fall-through block name."
(_ (signal 'native-ice
"missing previous setimm while creating a switch"))))
+(defun comp--func-arity (subr-name)
+ "Like `func-arity' but invariant against primitive redefinitions.
+SUBR-NAME is the name of function."
+ (or (gethash subr-name comp-subr-arities-h)
+ (func-arity subr-name)))
+
(defun comp-emit-set-call-subr (subr-name sp-delta)
"Emit a call for SUBR-NAME.
SP-DELTA is the stack adjustment."
- (let ((subr (symbol-function subr-name))
- (nargs (1+ (- sp-delta))))
- (let* ((arity (func-arity subr))
- (minarg (car arity))
- (maxarg (cdr arity)))
- (when (eq maxarg 'unevalled)
- (signal 'native-ice (list "subr contains unevalled args" subr-name)))
- (if (eq maxarg 'many)
- ;; callref case.
- (comp-emit-set-call (comp-callref subr-name nargs (comp-sp)))
- ;; Normal call.
- (unless (and (>= maxarg nargs) (<= minarg nargs))
- (signal 'native-ice
- (list "incoherent stack adjustment" nargs maxarg minarg)))
- (let* ((subr-name subr-name)
- (slots (cl-loop for i from 0 below maxarg
- collect (comp-slot-n (+ i (comp-sp))))))
- (comp-emit-set-call (apply #'comp-call (cons subr-name slots))))))))
+ (let* ((nargs (1+ (- sp-delta)))
+ (arity (comp--func-arity subr-name))
+ (minarg (car arity))
+ (maxarg (cdr arity)))
+ (when (eq maxarg 'unevalled)
+ (signal 'native-ice (list "subr contains unevalled args" subr-name)))
+ (if (eq maxarg 'many)
+ ;; callref case.
+ (comp-emit-set-call (comp-callref subr-name nargs (comp-sp)))
+ ;; Normal call.
+ (unless (and (>= maxarg nargs) (<= minarg nargs))
+ (signal 'native-ice
+ (list "incoherent stack adjustment" nargs maxarg minarg)))
+ (let* ((subr-name subr-name)
+ (slots (cl-loop for i from 0 below maxarg
+ collect (comp-slot-n (+ i (comp-sp))))))
+ (comp-emit-set-call (apply #'comp-call (cons subr-name slots)))))))
(eval-when-compile
(defun comp-op-to-fun (x)