From ac297b67bb5fbd4488023ca693a1dc62f012da5d Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sun, 14 Jul 2019 10:57:46 +0200 Subject: [PATCH] concat support --- lisp/emacs-lisp/comp.el | 27 +++++++++++++++++---------- test/src/comp-tests.el | 16 ++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 3c6ce6e5828..ddebc295b4d 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -297,18 +297,21 @@ If the calle function is known to have a return type propagate it." (defun comp-limplify-lap-inst (inst) "Limplify LAP instruction INST accumulating in `comp-limple'." - (let ((op (car inst))) + (let ((op (car inst)) + (arg (if (consp (cdr inst)) + (cadr inst) + (cdr inst)))) (comp-op-case (byte-stack-ref (comp-copy-slot-n (- (comp-sp) (cdr inst) 1))) (byte-varref (comp-emit-set-call `(call Fsymbol_value ,(make-comp-mvar :const-vld t - :constant (cadr inst))))) + :constant arg)))) (byte-varset (comp-emit `(call set_internal ,(make-comp-mvar :const-vld t - :constant (cadr inst)) + :constant arg) ,(comp-slot)))) (byte-varbind) (byte-call) @@ -356,9 +359,12 @@ If the calle function is known to have a return type propagate it." (byte-fset) (byte-get) (byte-substring) - (byte-concat2) - (byte-concat3) - (byte-concat4) + (byte-concat2 + (comp-emit-set-call `(callref Fconcat 2 ,(comp-sp)))) + (byte-concat3 + (comp-emit-set-call `(callref Fconcat 3 ,(comp-sp)))) + (byte-concat4 + (comp-emit-set-call `(callref Fconcat 4 ,(comp-sp)))) (byte-sub1) (byte-add1) (byte-eqlsign) @@ -411,8 +417,7 @@ If the calle function is known to have a return type propagate it." (byte-goto-if-nil-else-pop) (byte-goto-if-not-nil-else-pop) (byte-return - (comp-emit (list 'return (comp-slot-next))) - `(return ,(comp-slot-next))) + (comp-emit (list 'return (comp-slot-next)))) (byte-discard t) (byte-dup (comp-copy-slot-n (1- (comp-sp)))) @@ -450,14 +455,16 @@ If the calle function is known to have a return type propagate it." (byte-numberp) (byte-integerp) (byte-listN) - (byte-concatN) + (byte-concatN + (comp-stack-adjust (- (1- arg))) + (comp-emit-set-call `(callref Fconcat ,arg ,(comp-sp)))) (byte-insertN) (byte-stack-set) (byte-stack-set2) (byte-discardN) (byte-switch) (byte-constant - (comp-set-const (cadr inst)))))) + (comp-set-const arg))))) (defun comp-limplify (func) "Given FUNC and return compute its LIMPLE ir." diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 1030900752d..d3b2929abfc 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -132,14 +132,14 @@ (should (= (comp-tests-symbol-value-f) 3))) -;; (ert-deftest comp-tests-concat () -;; "Testing concatX opcodes." -;; (defun comp-tests-concat-f (x) -;; (concat "a" "b" "c" "d" -;; (concat "a" "b" "c" (concat "a" "b" (concat "foo" x))))) -;; (native-compile #'comp-tests-concat-f) - -;; (should (string= (comp-tests-concat-f "bar") "abcdabcabfoobar"))) +(ert-deftest comp-tests-concat () + "Testing concatX opcodes." + (defun comp-tests-concat-f (x) + (concat "a" "b" "c" "d" + (concat "a" "b" "c" (concat "a" "b" (concat "foo" x))))) + (native-compile #'comp-tests-concat-f) + + (should (string= (comp-tests-concat-f "bar") "abcdabcabfoobar"))) ;; (ert-deftest comp-tests-ffuncall () ;; "Test calling conventions." -- 2.39.5