aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorBill Wohler2014-02-23 18:04:35 -0800
committerBill Wohler2014-02-23 18:04:35 -0800
commit3e93bafb95608467e438ba7f725fd1f020669f8c (patch)
treef2f90109f283e06a18caea3cb2a2623abcfb3a92 /src/bytecode.c
parent791c0d7634e44bb92ca85af605be84ff2ae08963 (diff)
parente918e27fdf331e89268fc2c9d7cf838d3ecf7aa7 (diff)
downloademacs-3e93bafb95608467e438ba7f725fd1f020669f8c.tar.gz
emacs-3e93bafb95608467e438ba7f725fd1f020669f8c.zip
Merge from trunk; up to 2014-02-23T23:41:17Z!lekktu@gmail.com.
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c156
1 files changed, 117 insertions, 39 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index bd8abe85e04..0ea646a9741 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1,5 +1,5 @@
1/* Execution of byte code produced by bytecomp.el. 1/* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2013 Free Software Foundation, 2 Copyright (C) 1985-1988, 1993, 2000-2014 Free Software Foundation,
3 Inc. 3 Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -59,7 +59,8 @@ by Hallvard:
59 indirect threaded, using GCC's computed goto extension. This code, 59 indirect threaded, using GCC's computed goto extension. This code,
60 as currently implemented, is incompatible with BYTE_CODE_SAFE and 60 as currently implemented, is incompatible with BYTE_CODE_SAFE and
61 BYTE_CODE_METER. */ 61 BYTE_CODE_METER. */
62#if defined (__GNUC__) && !defined (BYTE_CODE_SAFE) && !defined (BYTE_CODE_METER) 62#if (defined __GNUC__ && !defined __STRICT_ANSI__ \
63 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
63#define BYTE_CODE_THREADED 64#define BYTE_CODE_THREADED
64#endif 65#endif
65 66
@@ -140,6 +141,10 @@ DEFINE (Bunbind5, 055) \
140DEFINE (Bunbind6, 056) \ 141DEFINE (Bunbind6, 056) \
141DEFINE (Bunbind7, 057) \ 142DEFINE (Bunbind7, 057) \
142 \ 143 \
144DEFINE (Bpophandler, 060) \
145DEFINE (Bpushconditioncase, 061) \
146DEFINE (Bpushcatch, 062) \
147 \
143DEFINE (Bnth, 070) \ 148DEFINE (Bnth, 070) \
144DEFINE (Bsymbolp, 071) \ 149DEFINE (Bsymbolp, 071) \
145DEFINE (Bconsp, 072) \ 150DEFINE (Bconsp, 072) \
@@ -285,8 +290,10 @@ enum byte_code_op
285 290
286#ifdef BYTE_CODE_SAFE 291#ifdef BYTE_CODE_SAFE
287 Bscan_buffer = 0153, /* No longer generated as of v18. */ 292 Bscan_buffer = 0153, /* No longer generated as of v18. */
288 Bset_mark = 0163 /* this loser is no longer generated as of v18 */ 293 Bset_mark = 0163, /* this loser is no longer generated as of v18 */
289#endif 294#endif
295
296 B__dummy__ = 0 /* Pacify C89. */
290}; 297};
291 298
292/* Whether to maintain a `top' and `bottom' field in the stack frame. */ 299/* Whether to maintain a `top' and `bottom' field in the stack frame. */
@@ -313,9 +320,11 @@ struct byte_stack
313 Lisp_Object byte_string; 320 Lisp_Object byte_string;
314 const unsigned char *byte_string_start; 321 const unsigned char *byte_string_start;
315 322
323#if BYTE_MARK_STACK
316 /* The vector of constants used during byte-code execution. Storing 324 /* The vector of constants used during byte-code execution. Storing
317 this here protects it from GC because mark_byte_stack marks it. */ 325 this here protects it from GC because mark_byte_stack marks it. */
318 Lisp_Object constants; 326 Lisp_Object constants;
327#endif
319 328
320 /* Next entry in byte_stack_list. */ 329 /* Next entry in byte_stack_list. */
321 struct byte_stack *next; 330 struct byte_stack *next;
@@ -323,7 +332,7 @@ struct byte_stack
323 332
324/* A list of currently active byte-code execution value stacks. 333/* A list of currently active byte-code execution value stacks.
325 Fbyte_code adds an entry to the head of this list before it starts 334 Fbyte_code adds an entry to the head of this list before it starts
326 processing byte-code, and it removed the entry again when it is 335 processing byte-code, and it removes the entry again when it is
327 done. Signaling an error truncates the list analogous to 336 done. Signaling an error truncates the list analogous to
328 gcprolist. */ 337 gcprolist. */
329 338
@@ -379,12 +388,12 @@ unmark_byte_stack (void)
379} 388}
380 389
381 390
382/* Fetch the next byte from the bytecode stream */ 391/* Fetch the next byte from the bytecode stream. */
383 392
384#define FETCH *stack.pc++ 393#define FETCH *stack.pc++
385 394
386/* Fetch two bytes from the bytecode stream and make a 16-bit number 395/* Fetch two bytes from the bytecode stream and make a 16-bit number
387 out of them */ 396 out of them. */
388 397
389#define FETCH2 (op = FETCH, op + (FETCH << 8)) 398#define FETCH2 (op = FETCH, op + (FETCH << 8))
390 399
@@ -404,7 +413,7 @@ unmark_byte_stack (void)
404#define DISCARD(n) (top -= (n)) 413#define DISCARD(n) (top -= (n))
405 414
406/* Get the value which is at the top of the execution stack, but don't 415/* Get the value which is at the top of the execution stack, but don't
407 pop it. */ 416 pop it. */
408 417
409#define TOP (*top) 418#define TOP (*top)
410 419
@@ -473,6 +482,12 @@ If the third argument is incorrect, Emacs may crash. */)
473 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL); 482 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
474} 483}
475 484
485static void
486bcall0 (Lisp_Object f)
487{
488 Ffuncall (1, &f);
489}
490
476/* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and 491/* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
477 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, 492 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
478 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp 493 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
@@ -486,21 +501,25 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
486 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) 501 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
487{ 502{
488 ptrdiff_t count = SPECPDL_INDEX (); 503 ptrdiff_t count = SPECPDL_INDEX ();
504 ptrdiff_t volatile count_volatile;
489#ifdef BYTE_CODE_METER 505#ifdef BYTE_CODE_METER
490 int this_op = 0; 506 int volatile this_op = 0;
491 int prev_op; 507 int prev_op;
492#endif 508#endif
493 int op; 509 int op;
494 /* Lisp_Object v1, v2; */ 510 /* Lisp_Object v1, v2; */
495 Lisp_Object *vectorp; 511 Lisp_Object *vectorp;
512 Lisp_Object *volatile vectorp_volatile;
496#ifdef BYTE_CODE_SAFE 513#ifdef BYTE_CODE_SAFE
497 ptrdiff_t const_length; 514 ptrdiff_t volatile const_length;
498 Lisp_Object *stacke; 515 Lisp_Object *volatile stacke;
499 ptrdiff_t bytestr_length; 516 ptrdiff_t volatile bytestr_length;
500#endif 517#endif
501 struct byte_stack stack; 518 struct byte_stack stack;
519 struct byte_stack volatile stack_volatile;
502 Lisp_Object *top; 520 Lisp_Object *top;
503 Lisp_Object result; 521 Lisp_Object result;
522 enum handlertype type;
504 523
505#if 0 /* CHECK_FRAME_FONT */ 524#if 0 /* CHECK_FRAME_FONT */
506 { 525 {
@@ -535,7 +554,9 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
535 554
536 stack.byte_string = bytestr; 555 stack.byte_string = bytestr;
537 stack.pc = stack.byte_string_start = SDATA (bytestr); 556 stack.pc = stack.byte_string_start = SDATA (bytestr);
557#if BYTE_MARK_STACK
538 stack.constants = vector; 558 stack.constants = vector;
559#endif
539 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth)) 560 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
540 memory_full (SIZE_MAX); 561 memory_full (SIZE_MAX);
541 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top); 562 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
@@ -565,9 +586,9 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
565 if (nargs < mandatory) 586 if (nargs < mandatory)
566 /* Too few arguments. */ 587 /* Too few arguments. */
567 Fsignal (Qwrong_number_of_arguments, 588 Fsignal (Qwrong_number_of_arguments,
568 Fcons (Fcons (make_number (mandatory), 589 list2 (Fcons (make_number (mandatory),
569 rest ? Qand_rest : make_number (nonrest)), 590 rest ? Qand_rest : make_number (nonrest)),
570 Fcons (make_number (nargs), Qnil))); 591 make_number (nargs)));
571 else 592 else
572 { 593 {
573 for (; i < nonrest; i++) 594 for (; i < nonrest; i++)
@@ -586,9 +607,8 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
586 else 607 else
587 /* Too many arguments. */ 608 /* Too many arguments. */
588 Fsignal (Qwrong_number_of_arguments, 609 Fsignal (Qwrong_number_of_arguments,
589 Fcons (Fcons (make_number (mandatory), 610 list2 (Fcons (make_number (mandatory), make_number (nonrest)),
590 make_number (nonrest)), 611 make_number (nargs)));
591 Fcons (make_number (nargs), Qnil)));
592 } 612 }
593 else if (! NILP (args_template)) 613 else if (! NILP (args_template))
594 /* We should push some arguments on the stack. */ 614 /* We should push some arguments on the stack. */
@@ -656,9 +676,12 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
656 the table clearer. */ 676 the table clearer. */
657#define LABEL(OP) [OP] = &&insn_ ## OP 677#define LABEL(OP) [OP] = &&insn_ ## OP
658 678
659#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 679#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
660# pragma GCC diagnostic push 680# pragma GCC diagnostic push
661# pragma GCC diagnostic ignored "-Woverride-init" 681# pragma GCC diagnostic ignored "-Woverride-init"
682#elif defined __clang__
683# pragma GCC diagnostic push
684# pragma GCC diagnostic ignored "-Winitializer-overrides"
662#endif 685#endif
663 686
664 /* This is the dispatch table for the threaded interpreter. */ 687 /* This is the dispatch table for the threaded interpreter. */
@@ -672,7 +695,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
672#undef DEFINE 695#undef DEFINE
673 }; 696 };
674 697
675#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 698#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
676# pragma GCC diagnostic pop 699# pragma GCC diagnostic pop
677#endif 700#endif
678 701
@@ -751,7 +774,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
751 { 774 {
752 BEFORE_POTENTIAL_GC (); 775 BEFORE_POTENTIAL_GC ();
753 wrong_type_argument (Qlistp, v1); 776 wrong_type_argument (Qlistp, v1);
754 AFTER_POTENTIAL_GC ();
755 } 777 }
756 NEXT; 778 NEXT;
757 } 779 }
@@ -786,7 +808,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
786 { 808 {
787 BEFORE_POTENTIAL_GC (); 809 BEFORE_POTENTIAL_GC ();
788 wrong_type_argument (Qlistp, v1); 810 wrong_type_argument (Qlistp, v1);
789 AFTER_POTENTIAL_GC ();
790 } 811 }
791 NEXT; 812 NEXT;
792 } 813 }
@@ -1056,8 +1077,8 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1056 1077
1057 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */ 1078 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
1058 { 1079 {
1059 register ptrdiff_t count1 = SPECPDL_INDEX (); 1080 ptrdiff_t count1 = SPECPDL_INDEX ();
1060 record_unwind_protect (Fset_window_configuration, 1081 record_unwind_protect (restore_window_configuration,
1061 Fcurrent_window_configuration (Qnil)); 1082 Fcurrent_window_configuration (Qnil));
1062 BEFORE_POTENTIAL_GC (); 1083 BEFORE_POTENTIAL_GC ();
1063 TOP = Fprogn (TOP); 1084 TOP = Fprogn (TOP);
@@ -1071,7 +1092,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1071 save_restriction_save ()); 1092 save_restriction_save ());
1072 NEXT; 1093 NEXT;
1073 1094
1074 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */ 1095 CASE (Bcatch): /* Obsolete since 24.4. */
1075 { 1096 {
1076 Lisp_Object v1; 1097 Lisp_Object v1;
1077 BEFORE_POTENTIAL_GC (); 1098 BEFORE_POTENTIAL_GC ();
@@ -1081,11 +1102,65 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1081 NEXT; 1102 NEXT;
1082 } 1103 }
1083 1104
1105 CASE (Bpushcatch): /* New in 24.4. */
1106 type = CATCHER;
1107 goto pushhandler;
1108 CASE (Bpushconditioncase): /* New in 24.4. */
1109 {
1110 extern EMACS_INT lisp_eval_depth;
1111 extern int poll_suppress_count;
1112 extern int interrupt_input_blocked;
1113 struct handler *c;
1114 Lisp_Object tag;
1115 int dest;
1116
1117 type = CONDITION_CASE;
1118 pushhandler:
1119 tag = POP;
1120 dest = FETCH2;
1121
1122 PUSH_HANDLER (c, tag, type);
1123 c->bytecode_dest = dest;
1124 c->bytecode_top = top;
1125 count_volatile = count;
1126 stack_volatile = stack;
1127 vectorp_volatile = vectorp;
1128
1129 if (sys_setjmp (c->jmp))
1130 {
1131 struct handler *c = handlerlist;
1132 int dest;
1133 top = c->bytecode_top;
1134 dest = c->bytecode_dest;
1135 handlerlist = c->next;
1136 PUSH (c->val);
1137 CHECK_RANGE (dest);
1138 stack = stack_volatile;
1139 stack.pc = stack.byte_string_start + dest;
1140 }
1141
1142 count = count_volatile;
1143 vectorp = vectorp_volatile;
1144 NEXT;
1145 }
1146
1147 CASE (Bpophandler): /* New in 24.4. */
1148 {
1149 handlerlist = handlerlist->next;
1150 NEXT;
1151 }
1152
1084 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */ 1153 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1085 record_unwind_protect (Fprogn, POP); 1154 {
1086 NEXT; 1155 Lisp_Object handler = POP;
1156 /* Support for a function here is new in 24.4. */
1157 record_unwind_protect (NILP (Ffunctionp (handler))
1158 ? unwind_body : bcall0,
1159 handler);
1160 NEXT;
1161 }
1087 1162
1088 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */ 1163 CASE (Bcondition_case): /* Obsolete since 24.4. */
1089 { 1164 {
1090 Lisp_Object handlers, body; 1165 Lisp_Object handlers, body;
1091 handlers = POP; 1166 handlers = POP;
@@ -1164,14 +1239,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1164 } 1239 }
1165 1240
1166 CASE (Blist1): 1241 CASE (Blist1):
1167 TOP = Fcons (TOP, Qnil); 1242 TOP = list1 (TOP);
1168 NEXT; 1243 NEXT;
1169 1244
1170 CASE (Blist2): 1245 CASE (Blist2):
1171 { 1246 {
1172 Lisp_Object v1; 1247 Lisp_Object v1;
1173 v1 = POP; 1248 v1 = POP;
1174 TOP = Fcons (TOP, Fcons (v1, Qnil)); 1249 TOP = list2 (TOP, v1);
1175 NEXT; 1250 NEXT;
1176 } 1251 }
1177 1252
@@ -1360,7 +1435,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1360 Lisp_Object v1; 1435 Lisp_Object v1;
1361 BEFORE_POTENTIAL_GC (); 1436 BEFORE_POTENTIAL_GC ();
1362 v1 = POP; 1437 v1 = POP;
1363 TOP = Fgtr (TOP, v1); 1438 TOP = arithcompare (TOP, v1, ARITH_GRTR);
1364 AFTER_POTENTIAL_GC (); 1439 AFTER_POTENTIAL_GC ();
1365 NEXT; 1440 NEXT;
1366 } 1441 }
@@ -1370,7 +1445,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1370 Lisp_Object v1; 1445 Lisp_Object v1;
1371 BEFORE_POTENTIAL_GC (); 1446 BEFORE_POTENTIAL_GC ();
1372 v1 = POP; 1447 v1 = POP;
1373 TOP = Flss (TOP, v1); 1448 TOP = arithcompare (TOP, v1, ARITH_LESS);
1374 AFTER_POTENTIAL_GC (); 1449 AFTER_POTENTIAL_GC ();
1375 NEXT; 1450 NEXT;
1376 } 1451 }
@@ -1380,7 +1455,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1380 Lisp_Object v1; 1455 Lisp_Object v1;
1381 BEFORE_POTENTIAL_GC (); 1456 BEFORE_POTENTIAL_GC ();
1382 v1 = POP; 1457 v1 = POP;
1383 TOP = Fleq (TOP, v1); 1458 TOP = arithcompare (TOP, v1, ARITH_LESS_OR_EQUAL);
1384 AFTER_POTENTIAL_GC (); 1459 AFTER_POTENTIAL_GC ();
1385 NEXT; 1460 NEXT;
1386 } 1461 }
@@ -1390,7 +1465,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1390 Lisp_Object v1; 1465 Lisp_Object v1;
1391 BEFORE_POTENTIAL_GC (); 1466 BEFORE_POTENTIAL_GC ();
1392 v1 = POP; 1467 v1 = POP;
1393 TOP = Fgeq (TOP, v1); 1468 TOP = arithcompare (TOP, v1, ARITH_GRTR_OR_EQUAL);
1394 AFTER_POTENTIAL_GC (); 1469 AFTER_POTENTIAL_GC ();
1395 NEXT; 1470 NEXT;
1396 } 1471 }
@@ -1631,7 +1706,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1631 c = XFASTINT (TOP); 1706 c = XFASTINT (TOP);
1632 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 1707 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1633 MAKE_CHAR_MULTIBYTE (c); 1708 MAKE_CHAR_MULTIBYTE (c);
1634 XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]); 1709 XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
1635 } 1710 }
1636 NEXT; 1711 NEXT;
1637 1712
@@ -1877,7 +1952,10 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1877 /* Actually this is Bstack_ref with offset 0, but we use Bdup 1952 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1878 for that instead. */ 1953 for that instead. */
1879 /* CASE (Bstack_ref): */ 1954 /* CASE (Bstack_ref): */
1880 error ("Invalid byte opcode"); 1955 call3 (intern ("error"),
1956 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1957 make_number (op),
1958 make_number ((stack.pc - 1) - stack.byte_string_start));
1881 1959
1882 /* Handy byte-codes for lexical binding. */ 1960 /* Handy byte-codes for lexical binding. */
1883 CASE (Bstack_ref1): 1961 CASE (Bstack_ref1):
@@ -1950,11 +2028,11 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1950 2028
1951 /* Binds and unbinds are supposed to be compiled balanced. */ 2029 /* Binds and unbinds are supposed to be compiled balanced. */
1952 if (SPECPDL_INDEX () != count) 2030 if (SPECPDL_INDEX () != count)
1953#ifdef BYTE_CODE_SAFE 2031 {
1954 error ("binding stack not balanced (serious byte compiler bug)"); 2032 if (SPECPDL_INDEX () > count)
1955#else 2033 unbind_to (count, Qnil);
1956 emacs_abort (); 2034 error ("binding stack not balanced (serious byte compiler bug)");
1957#endif 2035 }
1958 2036
1959 return result; 2037 return result;
1960} 2038}