]> git.eshelyaron.com Git - emacs.git/commitdiff
add concat
authorAndrea Corallo <andrea_corallo@yahoo.it>
Fri, 24 May 2019 14:57:55 +0000 (16:57 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:33:38 +0000 (11:33 +0100)
src/comp.c
test/src/comp-tests.el

index 2e5f3342cbdc51290d75f813a18ade18710c4348..8745908708a7d6ae2a13d912e3a36ed9406f6972 100644 (file)
@@ -91,8 +91,10 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #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 <https://www.gnu.org/licenses/>.  */
   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;
index 36344d361fc04e1f9942e671a7fcb3dfcb83a86b..006336393dda37da508bff5d779038ed50e5566e 100644 (file)
 
   (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."