summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2020-02-21 12:16:20 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2020-02-25 16:40:11 +0100
commit03c07c88d90b5747456b9d286bace2dd4a713aac (patch)
treebc5df98ed38273b010731c2c380b69758b237b56
parent64af3c94a6197cd0c6a283880c900eeb5bf12961 (diff)
downloademacs-03c07c88d90b5747456b9d286bace2dd4a713aac.tar.gz
Generate 'substring' byte op (bug#39709)
The 'substring' byte op was not emitted, apparently by mistake. Fix. Suggested by Mark Oteiza <mvoteiza@udel.edu>. * lisp/emacs-lisp/bytecomp.el (byte-defop-compiler): Add '1-3' clause. (byte-compile-one-to-three-args): New. * lisp/emacs-lisp/byte-opt.el (byte-compile-side-effect-free-ops): Add 'byte-substring'. * test/lisp/emacs-lisp/bytecomp-tests.el (byte-opt-testsuite-arith-data): Test 'substring'.
-rw-r--r--lisp/emacs-lisp/byte-opt.el2
-rw-r--r--lisp/emacs-lisp/bytecomp.el10
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el7
3 files changed, 16 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index fe0930c684b..4f72251aed5 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1515,7 +1515,7 @@
byte-eqlsign byte-gtr byte-lss byte-leq byte-geq byte-diff byte-negate
byte-plus byte-max byte-min byte-mult byte-char-after byte-char-syntax
byte-buffer-substring byte-string= byte-string< byte-nthcdr byte-elt
- byte-member byte-assq byte-quo byte-rem)
+ byte-member byte-assq byte-quo byte-rem byte-substring)
byte-compile-side-effect-and-error-free-ops))
;; This crock is because of the way DEFVAR_BOOL variables work.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 24a36393b2e..63348456a15 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3487,7 +3487,7 @@ the opcode to be used. If function is a list, the first element
is the function and the second element is the bytecode-symbol.
The second element may be nil, meaning there is no opcode.
COMPILE-HANDLER is the function to use to compile this byte-op, or
-may be the abbreviations 0, 1, 2, 3, 0-1, or 1-2.
+may be the abbreviations 0, 1, 2, 2-and, 3, 0-1, 1-2, 1-3, or 2-3.
If it is nil, then the handler is \"byte-compile-SYMBOL.\""
(let (opcode)
(if (symbolp function)
@@ -3506,6 +3506,7 @@ If it is nil, then the handler is \"byte-compile-SYMBOL.\""
(0-1 . byte-compile-zero-or-one-arg)
(1-2 . byte-compile-one-or-two-args)
(2-3 . byte-compile-two-or-three-args)
+ (1-3 . byte-compile-one-to-three-args)
)))
compile-handler
(intern (concat "byte-compile-"
@@ -3690,6 +3691,13 @@ These implicitly `and' together a bunch of two-arg bytecodes."
((= len 4) (byte-compile-three-args form))
(t (byte-compile-subr-wrong-args form "2-3")))))
+(defun byte-compile-one-to-three-args (form)
+ (let ((len (length form)))
+ (cond ((= len 2) (byte-compile-three-args (append form '(nil nil))))
+ ((= len 3) (byte-compile-three-args (append form '(nil))))
+ ((= len 4) (byte-compile-three-args form))
+ (t (byte-compile-subr-wrong-args form "1-3")))))
+
(defun byte-compile-noop (_form)
(byte-compile-constant nil))
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index de11ae22d50..d4ceb47c36e 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -347,7 +347,12 @@
((eq x 't) 99)
(t 999))))
'((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c)
- (t c) (x "a") (x "c") (x c) (x d) (x e))))
+ (t c) (x "a") (x "c") (x c) (x d) (x e)))
+
+ ;; `substring' bytecode generation (bug#39709).
+ (substring "abcdef")
+ (substring "abcdef" 2)
+ (substring "abcdef" 3 2))
"List of expression for test.
Each element will be executed by interpreter and with
bytecompiled code, and their results compared.")