aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorKen Raeburn2015-11-01 01:42:21 -0400
committerKen Raeburn2015-11-01 01:42:21 -0400
commit39372e1a1032521be74575bb06f95a3898fbae30 (patch)
tree754bd242a23d2358ea116126fcb0a629947bd9ec /src/bytecode.c
parent6a3121904d76e3b2f63007341d48c5c1af55de80 (diff)
parente11aaee266da52937a3a031cb108fe13f68958c3 (diff)
downloademacs-39372e1a1032521be74575bb06f95a3898fbae30.tar.gz
emacs-39372e1a1032521be74575bb06f95a3898fbae30.zip
merge from trunk
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c156
1 files changed, 91 insertions, 65 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 1be3e5c6188..476836b1f40 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-2015 Free Software Foundation,
3 Inc. 3 Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -36,8 +36,10 @@ by Hallvard:
36#include <config.h> 36#include <config.h>
37 37
38#include "lisp.h" 38#include "lisp.h"
39#include "blockinput.h"
39#include "character.h" 40#include "character.h"
40#include "buffer.h" 41#include "buffer.h"
42#include "keyboard.h"
41#include "syntax.h" 43#include "syntax.h"
42#include "window.h" 44#include "window.h"
43 45
@@ -67,7 +69,6 @@ by Hallvard:
67 69
68#ifdef BYTE_CODE_METER 70#ifdef BYTE_CODE_METER
69 71
70Lisp_Object Qbyte_code_meter;
71#define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2) 72#define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
72#define METER_1(code) METER_2 (0, code) 73#define METER_1(code) METER_2 (0, code)
73 74
@@ -141,6 +142,10 @@ DEFINE (Bunbind5, 055) \
141DEFINE (Bunbind6, 056) \ 142DEFINE (Bunbind6, 056) \
142DEFINE (Bunbind7, 057) \ 143DEFINE (Bunbind7, 057) \
143 \ 144 \
145DEFINE (Bpophandler, 060) \
146DEFINE (Bpushconditioncase, 061) \
147DEFINE (Bpushcatch, 062) \
148 \
144DEFINE (Bnth, 070) \ 149DEFINE (Bnth, 070) \
145DEFINE (Bsymbolp, 071) \ 150DEFINE (Bsymbolp, 071) \
146DEFINE (Bconsp, 072) \ 151DEFINE (Bconsp, 072) \
@@ -288,12 +293,10 @@ enum byte_code_op
288 Bscan_buffer = 0153, /* No longer generated as of v18. */ 293 Bscan_buffer = 0153, /* No longer generated as of v18. */
289 Bset_mark = 0163, /* this loser is no longer generated as of v18 */ 294 Bset_mark = 0163, /* this loser is no longer generated as of v18 */
290#endif 295#endif
291
292 B__dummy__ = 0 /* Pacify C89. */
293}; 296};
294 297
295/* Whether to maintain a `top' and `bottom' field in the stack frame. */ 298/* Whether to maintain a `top' and `bottom' field in the stack frame. */
296#define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK) 299#define BYTE_MAINTAIN_TOP BYTE_CODE_SAFE
297 300
298/* Structure describing a value stack used during byte-code execution 301/* Structure describing a value stack used during byte-code execution
299 in Fbyte_code. */ 302 in Fbyte_code. */
@@ -316,58 +319,23 @@ struct byte_stack
316 Lisp_Object byte_string; 319 Lisp_Object byte_string;
317 const unsigned char *byte_string_start; 320 const unsigned char *byte_string_start;
318 321
319#if BYTE_MARK_STACK
320 /* The vector of constants used during byte-code execution. Storing
321 this here protects it from GC because mark_byte_stack marks it. */
322 Lisp_Object constants;
323#endif
324
325 /* Next entry in byte_stack_list. */ 322 /* Next entry in byte_stack_list. */
326 struct byte_stack *next; 323 struct byte_stack *next;
327}; 324};
328 325
329/* A list of currently active byte-code execution value stacks. 326/* A list of currently active byte-code execution value stacks.
330 Fbyte_code adds an entry to the head of this list before it starts 327 Fbyte_code adds an entry to the head of this list before it starts
331 processing byte-code, and it removed the entry again when it is 328 processing byte-code, and it removes the entry again when it is
332 done. Signaling an error truncates the list analogous to 329 done. Signaling an error truncates the list. */
333 gcprolist. */
334 330
335/* struct byte_stack *byte_stack_list; */ 331/* struct byte_stack *byte_stack_list; */
336 332
337 333
338/* Mark objects on byte_stack_list. Called during GC. */ 334/* Relocate program counters in the stacks on byte_stack_list. Called
339 335 when GC has completed. */
340#if BYTE_MARK_STACK
341void
342mark_byte_stack (struct byte_stack *stack)
343{
344 Lisp_Object *obj;
345
346 for (; stack; stack = stack->next)
347 {
348 /* If STACK->top is null here, this means there's an opcode in
349 Fbyte_code that wasn't expected to GC, but did. To find out
350 which opcode this is, record the value of `stack', and walk
351 up the stack in a debugger, stopping in frames of Fbyte_code.
352 The culprit is found in the frame of Fbyte_code where the
353 address of its local variable `stack' is equal to the
354 recorded value of `stack' here. */
355 eassert (stack->top);
356
357 for (obj = stack->bottom; obj <= stack->top; ++obj)
358 mark_object (*obj);
359
360 mark_object (stack->byte_string);
361 mark_object (stack->constants);
362 }
363}
364#endif
365
366/* Unmark objects in the stacks on byte_stack_list. Relocate program
367 counters. Called when GC has completed. */
368 336
369void 337void
370unmark_byte_stack (struct byte_stack *stack) 338relocate_byte_stack (struct byte_stack *stack)
371{ 339{
372 for (; stack; stack = stack->next) 340 for (; stack; stack = stack->next)
373 { 341 {
@@ -383,7 +351,11 @@ unmark_byte_stack (struct byte_stack *stack)
383 351
384/* Fetch the next byte from the bytecode stream. */ 352/* Fetch the next byte from the bytecode stream. */
385 353
354#ifdef BYTE_CODE_SAFE
355#define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
356#else
386#define FETCH *stack.pc++ 357#define FETCH *stack.pc++
358#endif
387 359
388/* Fetch two bytes from the bytecode stream and make a 16-bit number 360/* Fetch two bytes from the bytecode stream and make a 16-bit number
389 out of them. */ 361 out of them. */
@@ -475,6 +447,12 @@ If the third argument is incorrect, Emacs may crash. */)
475 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL); 447 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
476} 448}
477 449
450static void
451bcall0 (Lisp_Object f)
452{
453 Ffuncall (1, &f);
454}
455
478/* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and 456/* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
479 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, 457 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
480 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp 458 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
@@ -489,7 +467,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
489{ 467{
490 ptrdiff_t count = SPECPDL_INDEX (); 468 ptrdiff_t count = SPECPDL_INDEX ();
491#ifdef BYTE_CODE_METER 469#ifdef BYTE_CODE_METER
492 int this_op = 0; 470 int volatile this_op = 0;
493 int prev_op; 471 int prev_op;
494#endif 472#endif
495 int op; 473 int op;
@@ -503,6 +481,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
503 struct byte_stack stack; 481 struct byte_stack stack;
504 Lisp_Object *top; 482 Lisp_Object *top;
505 Lisp_Object result; 483 Lisp_Object result;
484 enum handlertype type;
506 485
507#if 0 /* CHECK_FRAME_FONT */ 486#if 0 /* CHECK_FRAME_FONT */
508 { 487 {
@@ -537,9 +516,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
537 516
538 stack.byte_string = bytestr; 517 stack.byte_string = bytestr;
539 stack.pc = stack.byte_string_start = SDATA (bytestr); 518 stack.pc = stack.byte_string_start = SDATA (bytestr);
540#if BYTE_MARK_STACK
541 stack.constants = vector;
542#endif
543 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth)) 519 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
544 memory_full (SIZE_MAX); 520 memory_full (SIZE_MAX);
545 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top); 521 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
@@ -1075,7 +1051,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1075 save_restriction_save ()); 1051 save_restriction_save ());
1076 NEXT; 1052 NEXT;
1077 1053
1078 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */ 1054 CASE (Bcatch): /* Obsolete since 24.4. */
1079 { 1055 {
1080 Lisp_Object v1; 1056 Lisp_Object v1;
1081 BEFORE_POTENTIAL_GC (); 1057 BEFORE_POTENTIAL_GC ();
@@ -1085,11 +1061,58 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1085 NEXT; 1061 NEXT;
1086 } 1062 }
1087 1063
1064 CASE (Bpushcatch): /* New in 24.4. */
1065 type = CATCHER;
1066 goto pushhandler;
1067 CASE (Bpushconditioncase): /* New in 24.4. */
1068 {
1069 struct handler *c;
1070 Lisp_Object tag;
1071 int dest;
1072
1073 type = CONDITION_CASE;
1074 pushhandler:
1075 tag = POP;
1076 dest = FETCH2;
1077
1078 PUSH_HANDLER (c, tag, type);
1079 c->bytecode_dest = dest;
1080 c->bytecode_top = top;
1081
1082 if (sys_setjmp (c->jmp))
1083 {
1084 struct handler *c = handlerlist;
1085 int dest;
1086 top = c->bytecode_top;
1087 dest = c->bytecode_dest;
1088 handlerlist = c->next;
1089 PUSH (c->val);
1090 CHECK_RANGE (dest);
1091 /* Might have been re-set by longjmp! */
1092 stack.byte_string_start = SDATA (stack.byte_string);
1093 stack.pc = stack.byte_string_start + dest;
1094 }
1095
1096 NEXT;
1097 }
1098
1099 CASE (Bpophandler): /* New in 24.4. */
1100 {
1101 handlerlist = handlerlist->next;
1102 NEXT;
1103 }
1104
1088 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */ 1105 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1089 record_unwind_protect (unwind_body, POP); 1106 {
1090 NEXT; 1107 Lisp_Object handler = POP;
1108 /* Support for a function here is new in 24.4. */
1109 record_unwind_protect (NILP (Ffunctionp (handler))
1110 ? unwind_body : bcall0,
1111 handler);
1112 NEXT;
1113 }
1091 1114
1092 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */ 1115 CASE (Bcondition_case): /* Obsolete since 24.4. */
1093 { 1116 {
1094 Lisp_Object handlers, body; 1117 Lisp_Object handlers, body;
1095 handlers = POP; 1118 handlers = POP;
@@ -1364,7 +1387,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1364 Lisp_Object v1; 1387 Lisp_Object v1;
1365 BEFORE_POTENTIAL_GC (); 1388 BEFORE_POTENTIAL_GC ();
1366 v1 = POP; 1389 v1 = POP;
1367 TOP = Fgtr (TOP, v1); 1390 TOP = arithcompare (TOP, v1, ARITH_GRTR);
1368 AFTER_POTENTIAL_GC (); 1391 AFTER_POTENTIAL_GC ();
1369 NEXT; 1392 NEXT;
1370 } 1393 }
@@ -1374,7 +1397,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1374 Lisp_Object v1; 1397 Lisp_Object v1;
1375 BEFORE_POTENTIAL_GC (); 1398 BEFORE_POTENTIAL_GC ();
1376 v1 = POP; 1399 v1 = POP;
1377 TOP = Flss (TOP, v1); 1400 TOP = arithcompare (TOP, v1, ARITH_LESS);
1378 AFTER_POTENTIAL_GC (); 1401 AFTER_POTENTIAL_GC ();
1379 NEXT; 1402 NEXT;
1380 } 1403 }
@@ -1384,7 +1407,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1384 Lisp_Object v1; 1407 Lisp_Object v1;
1385 BEFORE_POTENTIAL_GC (); 1408 BEFORE_POTENTIAL_GC ();
1386 v1 = POP; 1409 v1 = POP;
1387 TOP = Fleq (TOP, v1); 1410 TOP = arithcompare (TOP, v1, ARITH_LESS_OR_EQUAL);
1388 AFTER_POTENTIAL_GC (); 1411 AFTER_POTENTIAL_GC ();
1389 NEXT; 1412 NEXT;
1390 } 1413 }
@@ -1394,7 +1417,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1394 Lisp_Object v1; 1417 Lisp_Object v1;
1395 BEFORE_POTENTIAL_GC (); 1418 BEFORE_POTENTIAL_GC ();
1396 v1 = POP; 1419 v1 = POP;
1397 TOP = Fgeq (TOP, v1); 1420 TOP = arithcompare (TOP, v1, ARITH_GRTR_OR_EQUAL);
1398 AFTER_POTENTIAL_GC (); 1421 AFTER_POTENTIAL_GC ();
1399 NEXT; 1422 NEXT;
1400 } 1423 }
@@ -1881,7 +1904,10 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1881 /* Actually this is Bstack_ref with offset 0, but we use Bdup 1904 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1882 for that instead. */ 1905 for that instead. */
1883 /* CASE (Bstack_ref): */ 1906 /* CASE (Bstack_ref): */
1884 error ("Invalid byte opcode"); 1907 call3 (Qerror,
1908 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1909 make_number (op),
1910 make_number ((stack.pc - 1) - stack.byte_string_start));
1885 1911
1886 /* Handy byte-codes for lexical binding. */ 1912 /* Handy byte-codes for lexical binding. */
1887 CASE (Bstack_ref1): 1913 CASE (Bstack_ref1):
@@ -1954,11 +1980,11 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1954 1980
1955 /* Binds and unbinds are supposed to be compiled balanced. */ 1981 /* Binds and unbinds are supposed to be compiled balanced. */
1956 if (SPECPDL_INDEX () != count) 1982 if (SPECPDL_INDEX () != count)
1957#ifdef BYTE_CODE_SAFE 1983 {
1958 error ("binding stack not balanced (serious byte compiler bug)"); 1984 if (SPECPDL_INDEX () > count)
1959#else 1985 unbind_to (count, Qnil);
1960 emacs_abort (); 1986 error ("binding stack not balanced (serious byte compiler bug)");
1961#endif 1987 }
1962 1988
1963 return result; 1989 return result;
1964} 1990}
@@ -1972,9 +1998,9 @@ syms_of_bytecode (void)
1972 1998
1973 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter, 1999 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1974 doc: /* A vector of vectors which holds a histogram of byte-code usage. 2000 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1975\(aref (aref byte-code-meter 0) CODE) indicates how many times the byte 2001(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1976opcode CODE has been executed. 2002opcode CODE has been executed.
1977\(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0, 2003(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1978indicates how many times the byte opcodes CODE1 and CODE2 have been 2004indicates how many times the byte opcodes CODE1 and CODE2 have been
1979executed in succession. */); 2005executed in succession. */);
1980 2006