From a5524504164ed9077984b90ecf5067d1e8bcbdb2 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 24 May 2019 16:57:55 +0200 Subject: [PATCH] add concat --- src/comp.c | 28 ++++++++++++++++++++-------- test/src/comp-tests.el | 9 +++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/comp.c b/src/comp.c index 2e5f3342cbd..8745908708a 100644 --- a/src/comp.c +++ b/src/comp.c @@ -91,8 +91,10 @@ along with GNU Emacs. If not, see . */ #define STR(s) #s -/* With most of the ops we need to do the same stuff so this save some - typing. */ +/* With most of the ops we need to do the same stuff so this macros are meant + to save some typing. */ + +/* Generate appropriate case and emit convential calls to function. */ #define CASE_CALL_NARGS(name, nargs) \ case B##name: \ @@ -101,6 +103,14 @@ along with GNU Emacs. If not, see . */ PUSH (gcc_jit_lvalue_as_rvalue (res)); \ break +/* Emit calls to functions with prototype (ptrdiff_t nargs, Lisp_Object *args) + This is done aggregating args into the scratch_call_area. */ + +#define EMIT_SCRATCH_CALL_N(name, nargs) \ + pop (nargs, &stack, args); \ + res = jit_emit_callN (name, nargs, args); \ + PUSH (gcc_jit_lvalue_as_rvalue (res)) + /* The compiler context */ typedef struct { @@ -588,14 +598,19 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, CASE_CALL_NARGS (substring, 3); case Bconcat2: - printf("Bconcat2\n"); + EMIT_SCRATCH_CALL_N ("Fconcat", 2); break; case Bconcat3: - printf("Bconcat3\n"); + EMIT_SCRATCH_CALL_N ("Fconcat", 3); break; case Bconcat4: - printf("Bconcat4\n"); + EMIT_SCRATCH_CALL_N ("Fconcat", 4); break; + case BconcatN: + op = FETCH; + EMIT_SCRATCH_CALL_N ("Fconcat", op); + break; + case Bsub1: printf("Bsub1\n"); break; @@ -864,9 +879,6 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, case BRgotoifnonnilelsepop: printf("BRgotoifnonnilelsepop\n"); break; - case BconcatN: - printf("BconcatN\n"); - break; case BinsertN: printf("BinsertN\n"); break; diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 36344d361fc..006336393dd 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -106,6 +106,15 @@ (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))))) + (byte-compile #'comp-tests-concat-f) + (native-compile #'comp-tests-concat-f) + + (should (string= (comp-tests-concat-f "bar") "abcdabcabfoobar"))) (ert-deftest comp-tests-ffuncall () "Testing varset." -- 2.39.5