| 1 | /* Execution of byte code produced by bytecomp.el. |
| 2 | Copyright (C) 1985, 1986, 1987, 1988, 1993 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GNU Emacs. |
| 5 | |
| 6 | GNU Emacs is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | GNU Emacs is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Emacs; see the file COPYING. If not, write to |
| 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. |
| 20 | |
| 21 | hacked on by jwz@lucid.com 17-jun-91 |
| 22 | o added a compile-time switch to turn on simple sanity checking; |
| 23 | o put back the obsolete byte-codes for error-detection; |
| 24 | o added a new instruction, unbind_all, which I will use for |
| 25 | tail-recursion elimination; |
| 26 | o made temp_output_buffer_show be called with the right number |
| 27 | of args; |
| 28 | o made the new bytecodes be called with args in the right order; |
| 29 | o added metering support. |
| 30 | |
| 31 | by Hallvard: |
| 32 | o added relative jump instructions; |
| 33 | o all conditionals now only do QUIT if they jump. |
| 34 | */ |
| 35 | |
| 36 | #include <config.h> |
| 37 | #include "lisp.h" |
| 38 | #include "buffer.h" |
| 39 | #include "charset.h" |
| 40 | #include "syntax.h" |
| 41 | |
| 42 | /* |
| 43 | * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for |
| 44 | * debugging the byte compiler...) |
| 45 | * |
| 46 | * define BYTE_CODE_METER to enable generation of a byte-op usage histogram. |
| 47 | */ |
| 48 | /* #define BYTE_CODE_SAFE */ |
| 49 | /* #define BYTE_CODE_METER */ |
| 50 | |
| 51 | \f |
| 52 | #ifdef BYTE_CODE_METER |
| 53 | |
| 54 | Lisp_Object Vbyte_code_meter, Qbyte_code_meter; |
| 55 | int byte_metering_on; |
| 56 | |
| 57 | #define METER_2(code1, code2) \ |
| 58 | XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \ |
| 59 | ->contents[(code2)]) |
| 60 | |
| 61 | #define METER_1(code) METER_2 (0, (code)) |
| 62 | |
| 63 | #define METER_CODE(last_code, this_code) \ |
| 64 | { \ |
| 65 | if (byte_metering_on) \ |
| 66 | { \ |
| 67 | if (METER_1 (this_code) != ((1<<VALBITS)-1)) \ |
| 68 | METER_1 (this_code)++; \ |
| 69 | if (last_code \ |
| 70 | && METER_2 (last_code, this_code) != ((1<<VALBITS)-1))\ |
| 71 | METER_2 (last_code, this_code)++; \ |
| 72 | } \ |
| 73 | } |
| 74 | |
| 75 | #else /* no BYTE_CODE_METER */ |
| 76 | |
| 77 | #define METER_CODE(last_code, this_code) |
| 78 | |
| 79 | #endif /* no BYTE_CODE_METER */ |
| 80 | \f |
| 81 | |
| 82 | Lisp_Object Qbytecode; |
| 83 | |
| 84 | /* Byte codes: */ |
| 85 | |
| 86 | #define Bvarref 010 |
| 87 | #define Bvarset 020 |
| 88 | #define Bvarbind 030 |
| 89 | #define Bcall 040 |
| 90 | #define Bunbind 050 |
| 91 | |
| 92 | #define Bnth 070 |
| 93 | #define Bsymbolp 071 |
| 94 | #define Bconsp 072 |
| 95 | #define Bstringp 073 |
| 96 | #define Blistp 074 |
| 97 | #define Beq 075 |
| 98 | #define Bmemq 076 |
| 99 | #define Bnot 077 |
| 100 | #define Bcar 0100 |
| 101 | #define Bcdr 0101 |
| 102 | #define Bcons 0102 |
| 103 | #define Blist1 0103 |
| 104 | #define Blist2 0104 |
| 105 | #define Blist3 0105 |
| 106 | #define Blist4 0106 |
| 107 | #define Blength 0107 |
| 108 | #define Baref 0110 |
| 109 | #define Baset 0111 |
| 110 | #define Bsymbol_value 0112 |
| 111 | #define Bsymbol_function 0113 |
| 112 | #define Bset 0114 |
| 113 | #define Bfset 0115 |
| 114 | #define Bget 0116 |
| 115 | #define Bsubstring 0117 |
| 116 | #define Bconcat2 0120 |
| 117 | #define Bconcat3 0121 |
| 118 | #define Bconcat4 0122 |
| 119 | #define Bsub1 0123 |
| 120 | #define Badd1 0124 |
| 121 | #define Beqlsign 0125 |
| 122 | #define Bgtr 0126 |
| 123 | #define Blss 0127 |
| 124 | #define Bleq 0130 |
| 125 | #define Bgeq 0131 |
| 126 | #define Bdiff 0132 |
| 127 | #define Bnegate 0133 |
| 128 | #define Bplus 0134 |
| 129 | #define Bmax 0135 |
| 130 | #define Bmin 0136 |
| 131 | #define Bmult 0137 |
| 132 | |
| 133 | #define Bpoint 0140 |
| 134 | /* Was Bmark in v17. */ |
| 135 | #define Bsave_current_buffer 0141 |
| 136 | #define Bgoto_char 0142 |
| 137 | #define Binsert 0143 |
| 138 | #define Bpoint_max 0144 |
| 139 | #define Bpoint_min 0145 |
| 140 | #define Bchar_after 0146 |
| 141 | #define Bfollowing_char 0147 |
| 142 | #define Bpreceding_char 0150 |
| 143 | #define Bcurrent_column 0151 |
| 144 | #define Bindent_to 0152 |
| 145 | #define Bscan_buffer 0153 /* No longer generated as of v18 */ |
| 146 | #define Beolp 0154 |
| 147 | #define Beobp 0155 |
| 148 | #define Bbolp 0156 |
| 149 | #define Bbobp 0157 |
| 150 | #define Bcurrent_buffer 0160 |
| 151 | #define Bset_buffer 0161 |
| 152 | #define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */ |
| 153 | #define Bread_char 0162 /* No longer generated as of v19 */ |
| 154 | #define Bset_mark 0163 /* this loser is no longer generated as of v18 */ |
| 155 | #define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */ |
| 156 | |
| 157 | #define Bforward_char 0165 |
| 158 | #define Bforward_word 0166 |
| 159 | #define Bskip_chars_forward 0167 |
| 160 | #define Bskip_chars_backward 0170 |
| 161 | #define Bforward_line 0171 |
| 162 | #define Bchar_syntax 0172 |
| 163 | #define Bbuffer_substring 0173 |
| 164 | #define Bdelete_region 0174 |
| 165 | #define Bnarrow_to_region 0175 |
| 166 | #define Bwiden 0176 |
| 167 | #define Bend_of_line 0177 |
| 168 | |
| 169 | #define Bconstant2 0201 |
| 170 | #define Bgoto 0202 |
| 171 | #define Bgotoifnil 0203 |
| 172 | #define Bgotoifnonnil 0204 |
| 173 | #define Bgotoifnilelsepop 0205 |
| 174 | #define Bgotoifnonnilelsepop 0206 |
| 175 | #define Breturn 0207 |
| 176 | #define Bdiscard 0210 |
| 177 | #define Bdup 0211 |
| 178 | |
| 179 | #define Bsave_excursion 0212 |
| 180 | #define Bsave_window_excursion 0213 |
| 181 | #define Bsave_restriction 0214 |
| 182 | #define Bcatch 0215 |
| 183 | |
| 184 | #define Bunwind_protect 0216 |
| 185 | #define Bcondition_case 0217 |
| 186 | #define Btemp_output_buffer_setup 0220 |
| 187 | #define Btemp_output_buffer_show 0221 |
| 188 | |
| 189 | #define Bunbind_all 0222 |
| 190 | |
| 191 | #define Bset_marker 0223 |
| 192 | #define Bmatch_beginning 0224 |
| 193 | #define Bmatch_end 0225 |
| 194 | #define Bupcase 0226 |
| 195 | #define Bdowncase 0227 |
| 196 | |
| 197 | #define Bstringeqlsign 0230 |
| 198 | #define Bstringlss 0231 |
| 199 | #define Bequal 0232 |
| 200 | #define Bnthcdr 0233 |
| 201 | #define Belt 0234 |
| 202 | #define Bmember 0235 |
| 203 | #define Bassq 0236 |
| 204 | #define Bnreverse 0237 |
| 205 | #define Bsetcar 0240 |
| 206 | #define Bsetcdr 0241 |
| 207 | #define Bcar_safe 0242 |
| 208 | #define Bcdr_safe 0243 |
| 209 | #define Bnconc 0244 |
| 210 | #define Bquo 0245 |
| 211 | #define Brem 0246 |
| 212 | #define Bnumberp 0247 |
| 213 | #define Bintegerp 0250 |
| 214 | |
| 215 | #define BRgoto 0252 |
| 216 | #define BRgotoifnil 0253 |
| 217 | #define BRgotoifnonnil 0254 |
| 218 | #define BRgotoifnilelsepop 0255 |
| 219 | #define BRgotoifnonnilelsepop 0256 |
| 220 | |
| 221 | #define BlistN 0257 |
| 222 | #define BconcatN 0260 |
| 223 | #define BinsertN 0261 |
| 224 | |
| 225 | #define Bconstant 0300 |
| 226 | #define CONSTANTLIM 0100 |
| 227 | |
| 228 | \f |
| 229 | /* Structure describing a value stack used during byte-code execution |
| 230 | in Fbyte_code. */ |
| 231 | |
| 232 | struct byte_stack |
| 233 | { |
| 234 | /* Program counter. This points into the byte_string below |
| 235 | and is relocated when that string is relocated. */ |
| 236 | unsigned char *pc; |
| 237 | |
| 238 | /* Top and bottom of stack. The bottom points to an area of memory |
| 239 | allocated with alloca in Fbyte_code. */ |
| 240 | Lisp_Object *top, *bottom; |
| 241 | |
| 242 | /* The string containing the byte-code, and its current address. |
| 243 | Storing this here protects it from GC because mark_byte_stack |
| 244 | marks it. */ |
| 245 | Lisp_Object byte_string; |
| 246 | unsigned char *byte_string_start; |
| 247 | |
| 248 | /* The vector of constants used during byte-code execution. Storing |
| 249 | this here protects it from GC because mark_byte_stack marks it. */ |
| 250 | Lisp_Object constants; |
| 251 | |
| 252 | /* Next entry in byte_stack_list. */ |
| 253 | struct byte_stack *next; |
| 254 | }; |
| 255 | |
| 256 | /* A list of currently active byte-code execution value stacks. |
| 257 | Fbyte_code adds an entry to the head of this list before it starts |
| 258 | processing byte-code, and it removed the entry again when it is |
| 259 | done. Signalling an error truncates the list analoguous to |
| 260 | gcprolist. */ |
| 261 | |
| 262 | struct byte_stack *byte_stack_list; |
| 263 | |
| 264 | \f |
| 265 | /* Mark objects on byte_stack_list. Called during GC. */ |
| 266 | |
| 267 | void |
| 268 | mark_byte_stack () |
| 269 | { |
| 270 | struct byte_stack *stack; |
| 271 | Lisp_Object *obj; |
| 272 | |
| 273 | for (stack = byte_stack_list; stack; stack = stack->next) |
| 274 | { |
| 275 | if (!stack->top) |
| 276 | abort (); |
| 277 | |
| 278 | for (obj = stack->bottom; obj <= stack->top; ++obj) |
| 279 | if (!XMARKBIT (*obj)) |
| 280 | { |
| 281 | mark_object (obj); |
| 282 | XMARK (*obj); |
| 283 | } |
| 284 | |
| 285 | if (!XMARKBIT (stack->byte_string)) |
| 286 | { |
| 287 | mark_object (&stack->byte_string); |
| 288 | XMARK (stack->byte_string); |
| 289 | } |
| 290 | |
| 291 | if (!XMARKBIT (stack->constants)) |
| 292 | { |
| 293 | mark_object (&stack->constants); |
| 294 | XMARK (stack->constants); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | |
| 300 | /* Unmark objects in the stacks on byte_stack_list. Relocate program |
| 301 | counters. Called when GC has completed. */ |
| 302 | |
| 303 | void |
| 304 | unmark_byte_stack () |
| 305 | { |
| 306 | struct byte_stack *stack; |
| 307 | Lisp_Object *obj; |
| 308 | |
| 309 | for (stack = byte_stack_list; stack; stack = stack->next) |
| 310 | { |
| 311 | for (obj = stack->bottom; obj <= stack->top; ++obj) |
| 312 | XUNMARK (*obj); |
| 313 | |
| 314 | XUNMARK (stack->byte_string); |
| 315 | XUNMARK (stack->constants); |
| 316 | |
| 317 | if (stack->byte_string_start != XSTRING (stack->byte_string)->data) |
| 318 | { |
| 319 | int offset = stack->pc - stack->byte_string_start; |
| 320 | stack->byte_string_start = XSTRING (stack->byte_string)->data; |
| 321 | stack->pc = stack->byte_string_start + offset; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | \f |
| 327 | /* Fetch the next byte from the bytecode stream */ |
| 328 | |
| 329 | #define FETCH *stack.pc++ |
| 330 | |
| 331 | /* Fetch two bytes from the bytecode stream and make a 16-bit number |
| 332 | out of them */ |
| 333 | |
| 334 | #define FETCH2 (op = FETCH, op + (FETCH << 8)) |
| 335 | |
| 336 | /* Push x onto the execution stack. This used to be #define PUSH(x) |
| 337 | (*++stackp = (x)) This oddity is necessary because Alliant can't be |
| 338 | bothered to compile the preincrement operator properly, as of 4/91. |
| 339 | -JimB */ |
| 340 | |
| 341 | #define PUSH(x) (top++, *top = (x)) |
| 342 | |
| 343 | /* Pop a value off the execution stack. */ |
| 344 | |
| 345 | #define POP (*top--) |
| 346 | |
| 347 | /* Discard n values from the execution stack. */ |
| 348 | |
| 349 | #define DISCARD(n) (top -= (n)) |
| 350 | |
| 351 | /* Get the value which is at the top of the execution stack, but don't |
| 352 | pop it. */ |
| 353 | |
| 354 | #define TOP (*top) |
| 355 | |
| 356 | /* Actions that must be performed before and after calling a function |
| 357 | that might GC. */ |
| 358 | |
| 359 | #define BEFORE_POTENTIAL_GC() stack.top = top |
| 360 | #define AFTER_POTENTIAL_GC() stack.top = NULL |
| 361 | |
| 362 | /* Garbage collect if we have consed enough since the last time. |
| 363 | We do this at every branch, to avoid loops that never GC. */ |
| 364 | |
| 365 | #define MAYBE_GC() \ |
| 366 | if (consing_since_gc > gc_cons_threshold) \ |
| 367 | { \ |
| 368 | BEFORE_POTENTIAL_GC (); \ |
| 369 | Fgarbage_collect (); \ |
| 370 | AFTER_POTENTIAL_GC (); \ |
| 371 | } \ |
| 372 | else |
| 373 | |
| 374 | /* Check for jumping out of range. */ |
| 375 | |
| 376 | #ifdef BYTE_CODE_SAFE |
| 377 | |
| 378 | #define CHECK_RANGE(ARG) \ |
| 379 | if (ARG >= bytestr_length) abort () |
| 380 | |
| 381 | #else /* not BYTE_CODE_SAFE */ |
| 382 | |
| 383 | #define CHECK_RANGE(ARG) |
| 384 | |
| 385 | #endif /* not BYTE_CODE_SAFE */ |
| 386 | |
| 387 | |
| 388 | DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0, |
| 389 | "Function used internally in byte-compiled code.\n\ |
| 390 | The first argument, BYTESTR, is a string of byte code;\n\ |
| 391 | the second, VECTOR, a vector of constants;\n\ |
| 392 | the third, MAXDEPTH, the maximum stack depth used in this function.\n\ |
| 393 | If the third argument is incorrect, Emacs may crash.") |
| 394 | (bytestr, vector, maxdepth) |
| 395 | Lisp_Object bytestr, vector, maxdepth; |
| 396 | { |
| 397 | int count = specpdl_ptr - specpdl; |
| 398 | #ifdef BYTE_CODE_METER |
| 399 | int this_op = 0; |
| 400 | int prev_op; |
| 401 | #endif |
| 402 | int op; |
| 403 | /* Lisp_Object v1, v2; */ |
| 404 | Lisp_Object *vectorp = XVECTOR (vector)->contents; |
| 405 | #ifdef BYTE_CODE_SAFE |
| 406 | int const_length = XVECTOR (vector)->size; |
| 407 | Lisp_Object *stacke; |
| 408 | #endif |
| 409 | int bytestr_length = STRING_BYTES (XSTRING (bytestr)); |
| 410 | struct byte_stack stack; |
| 411 | Lisp_Object *top; |
| 412 | Lisp_Object result; |
| 413 | |
| 414 | CHECK_STRING (bytestr, 0); |
| 415 | if (!VECTORP (vector)) |
| 416 | vector = wrong_type_argument (Qvectorp, vector); |
| 417 | CHECK_NUMBER (maxdepth, 2); |
| 418 | |
| 419 | stack.byte_string = bytestr; |
| 420 | stack.pc = stack.byte_string_start = XSTRING (bytestr)->data; |
| 421 | stack.constants = vector; |
| 422 | stack.bottom = (Lisp_Object *) alloca (XFASTINT (maxdepth) |
| 423 | * sizeof (Lisp_Object)); |
| 424 | top = stack.bottom - 1; |
| 425 | stack.top = NULL; |
| 426 | stack.next = byte_stack_list; |
| 427 | byte_stack_list = &stack; |
| 428 | |
| 429 | #ifdef BYTE_CODE_SAFE |
| 430 | stacke = stack.bottom - 1 + XFASTINT (maxdepth); |
| 431 | #endif |
| 432 | |
| 433 | while (1) |
| 434 | { |
| 435 | #ifdef BYTE_CODE_SAFE |
| 436 | if (top > stacke) |
| 437 | abort (); |
| 438 | else if (top < stack.bottom - 1) |
| 439 | abort (); |
| 440 | #endif |
| 441 | |
| 442 | #ifdef BYTE_CODE_METER |
| 443 | prev_op = this_op; |
| 444 | this_op = op = FETCH; |
| 445 | METER_CODE (prev_op, op); |
| 446 | #else |
| 447 | op = FETCH; |
| 448 | #endif |
| 449 | |
| 450 | switch (op) |
| 451 | { |
| 452 | case Bvarref + 7: |
| 453 | op = FETCH2; |
| 454 | goto varref; |
| 455 | |
| 456 | case Bvarref: |
| 457 | case Bvarref + 1: |
| 458 | case Bvarref + 2: |
| 459 | case Bvarref + 3: |
| 460 | case Bvarref + 4: |
| 461 | case Bvarref + 5: |
| 462 | op = op - Bvarref; |
| 463 | goto varref; |
| 464 | |
| 465 | /* This seems to be the most frequently executed byte-code |
| 466 | among the Bvarref's, so avoid a goto here. */ |
| 467 | case Bvarref+6: |
| 468 | op = FETCH; |
| 469 | varref: |
| 470 | { |
| 471 | Lisp_Object v1, v2; |
| 472 | |
| 473 | v1 = vectorp[op]; |
| 474 | if (SYMBOLP (v1)) |
| 475 | { |
| 476 | v2 = XSYMBOL (v1)->value; |
| 477 | if (MISCP (v2) || EQ (v2, Qunbound)) |
| 478 | v2 = Fsymbol_value (v1); |
| 479 | } |
| 480 | else |
| 481 | v2 = Fsymbol_value (v1); |
| 482 | PUSH (v2); |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | case Bgotoifnil: |
| 487 | MAYBE_GC (); |
| 488 | op = FETCH2; |
| 489 | if (NILP (POP)) |
| 490 | { |
| 491 | QUIT; |
| 492 | CHECK_RANGE (op); |
| 493 | stack.pc = stack.byte_string_start + op; |
| 494 | } |
| 495 | break; |
| 496 | |
| 497 | case Bcar: |
| 498 | { |
| 499 | Lisp_Object v1; |
| 500 | v1 = TOP; |
| 501 | if (CONSP (v1)) |
| 502 | TOP = XCAR (v1); |
| 503 | else if (NILP (v1)) |
| 504 | TOP = Qnil; |
| 505 | else |
| 506 | { |
| 507 | BEFORE_POTENTIAL_GC (); |
| 508 | Fcar (wrong_type_argument (Qlistp, v1)); |
| 509 | AFTER_POTENTIAL_GC (); |
| 510 | } |
| 511 | break; |
| 512 | } |
| 513 | |
| 514 | case Beq: |
| 515 | { |
| 516 | Lisp_Object v1; |
| 517 | v1 = POP; |
| 518 | TOP = EQ (v1, TOP) ? Qt : Qnil; |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | case Bmemq: |
| 523 | { |
| 524 | Lisp_Object v1; |
| 525 | v1 = POP; |
| 526 | TOP = Fmemq (TOP, v1); |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | case Bcdr: |
| 531 | { |
| 532 | Lisp_Object v1; |
| 533 | v1 = TOP; |
| 534 | if (CONSP (v1)) |
| 535 | TOP = XCDR (v1); |
| 536 | else if (NILP (v1)) |
| 537 | TOP = Qnil; |
| 538 | else |
| 539 | { |
| 540 | BEFORE_POTENTIAL_GC (); |
| 541 | Fcdr (wrong_type_argument (Qlistp, v1)); |
| 542 | AFTER_POTENTIAL_GC (); |
| 543 | } |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | case Bvarset+7: |
| 548 | op = FETCH2; |
| 549 | goto varset; |
| 550 | |
| 551 | case Bvarset: case Bvarset+1: case Bvarset+2: case Bvarset+3: |
| 552 | case Bvarset+4: case Bvarset+5: |
| 553 | op -= Bvarset; |
| 554 | goto varset; |
| 555 | |
| 556 | case Bvarset+6: |
| 557 | op = FETCH; |
| 558 | varset: |
| 559 | set_internal (vectorp[op], POP, current_buffer, 0); |
| 560 | /* Fset (vectorp[op], POP); */ |
| 561 | break; |
| 562 | |
| 563 | case Bdup: |
| 564 | { |
| 565 | Lisp_Object v1; |
| 566 | v1 = TOP; |
| 567 | PUSH (v1); |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | /* ------------------ */ |
| 572 | |
| 573 | case Bvarbind+6: |
| 574 | op = FETCH; |
| 575 | goto varbind; |
| 576 | |
| 577 | case Bvarbind+7: |
| 578 | op = FETCH2; |
| 579 | goto varbind; |
| 580 | |
| 581 | case Bvarbind: |
| 582 | case Bvarbind+1: |
| 583 | case Bvarbind+2: |
| 584 | case Bvarbind+3: |
| 585 | case Bvarbind+4: |
| 586 | case Bvarbind+5: |
| 587 | op -= Bvarbind; |
| 588 | varbind: |
| 589 | specbind (vectorp[op], POP); |
| 590 | break; |
| 591 | |
| 592 | case Bcall+6: |
| 593 | op = FETCH; |
| 594 | goto docall; |
| 595 | |
| 596 | case Bcall+7: |
| 597 | op = FETCH2; |
| 598 | goto docall; |
| 599 | |
| 600 | case Bcall: |
| 601 | case Bcall+1: |
| 602 | case Bcall+2: |
| 603 | case Bcall+3: |
| 604 | case Bcall+4: |
| 605 | case Bcall+5: |
| 606 | op -= Bcall; |
| 607 | docall: |
| 608 | { |
| 609 | BEFORE_POTENTIAL_GC (); |
| 610 | DISCARD (op); |
| 611 | #ifdef BYTE_CODE_METER |
| 612 | if (byte_metering_on && SYMBOLP (TOP)) |
| 613 | { |
| 614 | Lisp_Object v1, v2; |
| 615 | |
| 616 | v1 = TOP; |
| 617 | v2 = Fget (v1, Qbyte_code_meter); |
| 618 | if (INTEGERP (v2) |
| 619 | && XINT (v2) != ((1<<VALBITS)-1)) |
| 620 | { |
| 621 | XSETINT (v2, XINT (v2) + 1); |
| 622 | Fput (v1, Qbyte_code_meter, v2); |
| 623 | } |
| 624 | } |
| 625 | #endif |
| 626 | TOP = Ffuncall (op + 1, &TOP); |
| 627 | AFTER_POTENTIAL_GC (); |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | case Bunbind+6: |
| 632 | op = FETCH; |
| 633 | goto dounbind; |
| 634 | |
| 635 | case Bunbind+7: |
| 636 | op = FETCH2; |
| 637 | goto dounbind; |
| 638 | |
| 639 | case Bunbind: |
| 640 | case Bunbind+1: |
| 641 | case Bunbind+2: |
| 642 | case Bunbind+3: |
| 643 | case Bunbind+4: |
| 644 | case Bunbind+5: |
| 645 | op -= Bunbind; |
| 646 | dounbind: |
| 647 | BEFORE_POTENTIAL_GC (); |
| 648 | unbind_to (specpdl_ptr - specpdl - op, Qnil); |
| 649 | AFTER_POTENTIAL_GC (); |
| 650 | break; |
| 651 | |
| 652 | case Bunbind_all: |
| 653 | /* To unbind back to the beginning of this frame. Not used yet, |
| 654 | but will be needed for tail-recursion elimination. */ |
| 655 | BEFORE_POTENTIAL_GC (); |
| 656 | unbind_to (count, Qnil); |
| 657 | AFTER_POTENTIAL_GC (); |
| 658 | break; |
| 659 | |
| 660 | case Bgoto: |
| 661 | MAYBE_GC (); |
| 662 | QUIT; |
| 663 | op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */ |
| 664 | CHECK_RANGE (op); |
| 665 | stack.pc = stack.byte_string_start + op; |
| 666 | break; |
| 667 | |
| 668 | case Bgotoifnonnil: |
| 669 | MAYBE_GC (); |
| 670 | op = FETCH2; |
| 671 | if (!NILP (POP)) |
| 672 | { |
| 673 | QUIT; |
| 674 | CHECK_RANGE (op); |
| 675 | stack.pc = stack.byte_string_start + op; |
| 676 | } |
| 677 | break; |
| 678 | |
| 679 | case Bgotoifnilelsepop: |
| 680 | MAYBE_GC (); |
| 681 | op = FETCH2; |
| 682 | if (NILP (TOP)) |
| 683 | { |
| 684 | QUIT; |
| 685 | CHECK_RANGE (op); |
| 686 | stack.pc = stack.byte_string_start + op; |
| 687 | } |
| 688 | else DISCARD (1); |
| 689 | break; |
| 690 | |
| 691 | case Bgotoifnonnilelsepop: |
| 692 | MAYBE_GC (); |
| 693 | op = FETCH2; |
| 694 | if (!NILP (TOP)) |
| 695 | { |
| 696 | QUIT; |
| 697 | CHECK_RANGE (op); |
| 698 | stack.pc = stack.byte_string_start + op; |
| 699 | } |
| 700 | else DISCARD (1); |
| 701 | break; |
| 702 | |
| 703 | case BRgoto: |
| 704 | MAYBE_GC (); |
| 705 | QUIT; |
| 706 | stack.pc += (int) *stack.pc - 127; |
| 707 | break; |
| 708 | |
| 709 | case BRgotoifnil: |
| 710 | MAYBE_GC (); |
| 711 | if (NILP (POP)) |
| 712 | { |
| 713 | QUIT; |
| 714 | stack.pc += (int) *stack.pc - 128; |
| 715 | } |
| 716 | stack.pc++; |
| 717 | break; |
| 718 | |
| 719 | case BRgotoifnonnil: |
| 720 | MAYBE_GC (); |
| 721 | if (!NILP (POP)) |
| 722 | { |
| 723 | QUIT; |
| 724 | stack.pc += (int) *stack.pc - 128; |
| 725 | } |
| 726 | stack.pc++; |
| 727 | break; |
| 728 | |
| 729 | case BRgotoifnilelsepop: |
| 730 | MAYBE_GC (); |
| 731 | op = *stack.pc++; |
| 732 | if (NILP (TOP)) |
| 733 | { |
| 734 | QUIT; |
| 735 | stack.pc += op - 128; |
| 736 | } |
| 737 | else DISCARD (1); |
| 738 | break; |
| 739 | |
| 740 | case BRgotoifnonnilelsepop: |
| 741 | MAYBE_GC (); |
| 742 | op = *stack.pc++; |
| 743 | if (!NILP (TOP)) |
| 744 | { |
| 745 | QUIT; |
| 746 | stack.pc += op - 128; |
| 747 | } |
| 748 | else DISCARD (1); |
| 749 | break; |
| 750 | |
| 751 | case Breturn: |
| 752 | result = POP; |
| 753 | goto exit; |
| 754 | |
| 755 | case Bdiscard: |
| 756 | DISCARD (1); |
| 757 | break; |
| 758 | |
| 759 | case Bconstant2: |
| 760 | PUSH (vectorp[FETCH2]); |
| 761 | break; |
| 762 | |
| 763 | case Bsave_excursion: |
| 764 | record_unwind_protect (save_excursion_restore, |
| 765 | save_excursion_save ()); |
| 766 | break; |
| 767 | |
| 768 | case Bsave_current_buffer: |
| 769 | case Bsave_current_buffer_1: |
| 770 | record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); |
| 771 | break; |
| 772 | |
| 773 | case Bsave_window_excursion: |
| 774 | BEFORE_POTENTIAL_GC (); |
| 775 | TOP = Fsave_window_excursion (TOP); |
| 776 | AFTER_POTENTIAL_GC (); |
| 777 | break; |
| 778 | |
| 779 | case Bsave_restriction: |
| 780 | record_unwind_protect (save_restriction_restore, |
| 781 | save_restriction_save ()); |
| 782 | break; |
| 783 | |
| 784 | case Bcatch: |
| 785 | { |
| 786 | Lisp_Object v1; |
| 787 | v1 = POP; |
| 788 | BEFORE_POTENTIAL_GC (); |
| 789 | TOP = internal_catch (TOP, Feval, v1); |
| 790 | AFTER_POTENTIAL_GC (); |
| 791 | break; |
| 792 | } |
| 793 | |
| 794 | case Bunwind_protect: |
| 795 | record_unwind_protect (0, POP); |
| 796 | (specpdl_ptr - 1)->symbol = Qnil; |
| 797 | break; |
| 798 | |
| 799 | case Bcondition_case: |
| 800 | { |
| 801 | Lisp_Object v1; |
| 802 | v1 = POP; |
| 803 | v1 = Fcons (POP, v1); |
| 804 | BEFORE_POTENTIAL_GC (); |
| 805 | TOP = Fcondition_case (Fcons (TOP, v1)); |
| 806 | AFTER_POTENTIAL_GC (); |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case Btemp_output_buffer_setup: |
| 811 | BEFORE_POTENTIAL_GC (); |
| 812 | temp_output_buffer_setup (XSTRING (TOP)->data); |
| 813 | AFTER_POTENTIAL_GC (); |
| 814 | TOP = Vstandard_output; |
| 815 | break; |
| 816 | |
| 817 | case Btemp_output_buffer_show: |
| 818 | { |
| 819 | Lisp_Object v1; |
| 820 | v1 = POP; |
| 821 | BEFORE_POTENTIAL_GC (); |
| 822 | temp_output_buffer_show (TOP); |
| 823 | TOP = v1; |
| 824 | /* pop binding of standard-output */ |
| 825 | unbind_to (specpdl_ptr - specpdl - 1, Qnil); |
| 826 | AFTER_POTENTIAL_GC (); |
| 827 | break; |
| 828 | } |
| 829 | |
| 830 | case Bnth: |
| 831 | { |
| 832 | Lisp_Object v1, v2; |
| 833 | v1 = POP; |
| 834 | v2 = TOP; |
| 835 | BEFORE_POTENTIAL_GC (); |
| 836 | CHECK_NUMBER (v2, 0); |
| 837 | AFTER_POTENTIAL_GC (); |
| 838 | op = XINT (v2); |
| 839 | immediate_quit = 1; |
| 840 | while (--op >= 0) |
| 841 | { |
| 842 | if (CONSP (v1)) |
| 843 | v1 = XCDR (v1); |
| 844 | else if (!NILP (v1)) |
| 845 | { |
| 846 | immediate_quit = 0; |
| 847 | BEFORE_POTENTIAL_GC (); |
| 848 | v1 = wrong_type_argument (Qlistp, v1); |
| 849 | AFTER_POTENTIAL_GC (); |
| 850 | immediate_quit = 1; |
| 851 | op++; |
| 852 | } |
| 853 | } |
| 854 | immediate_quit = 0; |
| 855 | if (CONSP (v1)) |
| 856 | TOP = XCAR (v1); |
| 857 | else if (NILP (v1)) |
| 858 | TOP = Qnil; |
| 859 | else |
| 860 | { |
| 861 | BEFORE_POTENTIAL_GC (); |
| 862 | Fcar (wrong_type_argument (Qlistp, v1)); |
| 863 | AFTER_POTENTIAL_GC (); |
| 864 | } |
| 865 | break; |
| 866 | } |
| 867 | |
| 868 | case Bsymbolp: |
| 869 | TOP = SYMBOLP (TOP) ? Qt : Qnil; |
| 870 | break; |
| 871 | |
| 872 | case Bconsp: |
| 873 | TOP = CONSP (TOP) ? Qt : Qnil; |
| 874 | break; |
| 875 | |
| 876 | case Bstringp: |
| 877 | TOP = STRINGP (TOP) ? Qt : Qnil; |
| 878 | break; |
| 879 | |
| 880 | case Blistp: |
| 881 | TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil; |
| 882 | break; |
| 883 | |
| 884 | case Bnot: |
| 885 | TOP = NILP (TOP) ? Qt : Qnil; |
| 886 | break; |
| 887 | |
| 888 | case Bcons: |
| 889 | { |
| 890 | Lisp_Object v1; |
| 891 | v1 = POP; |
| 892 | TOP = Fcons (TOP, v1); |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | case Blist1: |
| 897 | TOP = Fcons (TOP, Qnil); |
| 898 | break; |
| 899 | |
| 900 | case Blist2: |
| 901 | { |
| 902 | Lisp_Object v1; |
| 903 | v1 = POP; |
| 904 | TOP = Fcons (TOP, Fcons (v1, Qnil)); |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | case Blist3: |
| 909 | DISCARD (2); |
| 910 | TOP = Flist (3, &TOP); |
| 911 | break; |
| 912 | |
| 913 | case Blist4: |
| 914 | DISCARD (3); |
| 915 | TOP = Flist (4, &TOP); |
| 916 | break; |
| 917 | |
| 918 | case BlistN: |
| 919 | op = FETCH; |
| 920 | DISCARD (op - 1); |
| 921 | TOP = Flist (op, &TOP); |
| 922 | break; |
| 923 | |
| 924 | case Blength: |
| 925 | TOP = Flength (TOP); |
| 926 | break; |
| 927 | |
| 928 | case Baref: |
| 929 | { |
| 930 | Lisp_Object v1; |
| 931 | v1 = POP; |
| 932 | TOP = Faref (TOP, v1); |
| 933 | break; |
| 934 | } |
| 935 | |
| 936 | case Baset: |
| 937 | { |
| 938 | Lisp_Object v1, v2; |
| 939 | v2 = POP; v1 = POP; |
| 940 | TOP = Faset (TOP, v1, v2); |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | case Bsymbol_value: |
| 945 | TOP = Fsymbol_value (TOP); |
| 946 | break; |
| 947 | |
| 948 | case Bsymbol_function: |
| 949 | TOP = Fsymbol_function (TOP); |
| 950 | break; |
| 951 | |
| 952 | case Bset: |
| 953 | { |
| 954 | Lisp_Object v1; |
| 955 | v1 = POP; |
| 956 | TOP = Fset (TOP, v1); |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | case Bfset: |
| 961 | { |
| 962 | Lisp_Object v1; |
| 963 | v1 = POP; |
| 964 | TOP = Ffset (TOP, v1); |
| 965 | break; |
| 966 | } |
| 967 | |
| 968 | case Bget: |
| 969 | { |
| 970 | Lisp_Object v1; |
| 971 | v1 = POP; |
| 972 | TOP = Fget (TOP, v1); |
| 973 | break; |
| 974 | } |
| 975 | |
| 976 | case Bsubstring: |
| 977 | { |
| 978 | Lisp_Object v1, v2; |
| 979 | v2 = POP; v1 = POP; |
| 980 | BEFORE_POTENTIAL_GC (); |
| 981 | TOP = Fsubstring (TOP, v1, v2); |
| 982 | AFTER_POTENTIAL_GC (); |
| 983 | break; |
| 984 | } |
| 985 | |
| 986 | case Bconcat2: |
| 987 | DISCARD (1); |
| 988 | TOP = Fconcat (2, &TOP); |
| 989 | break; |
| 990 | |
| 991 | case Bconcat3: |
| 992 | DISCARD (2); |
| 993 | TOP = Fconcat (3, &TOP); |
| 994 | break; |
| 995 | |
| 996 | case Bconcat4: |
| 997 | DISCARD (3); |
| 998 | TOP = Fconcat (4, &TOP); |
| 999 | break; |
| 1000 | |
| 1001 | case BconcatN: |
| 1002 | op = FETCH; |
| 1003 | DISCARD (op - 1); |
| 1004 | TOP = Fconcat (op, &TOP); |
| 1005 | break; |
| 1006 | |
| 1007 | case Bsub1: |
| 1008 | { |
| 1009 | Lisp_Object v1; |
| 1010 | v1 = TOP; |
| 1011 | if (INTEGERP (v1)) |
| 1012 | { |
| 1013 | XSETINT (v1, XINT (v1) - 1); |
| 1014 | TOP = v1; |
| 1015 | } |
| 1016 | else |
| 1017 | TOP = Fsub1 (v1); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | case Badd1: |
| 1022 | { |
| 1023 | Lisp_Object v1; |
| 1024 | v1 = TOP; |
| 1025 | if (INTEGERP (v1)) |
| 1026 | { |
| 1027 | XSETINT (v1, XINT (v1) + 1); |
| 1028 | TOP = v1; |
| 1029 | } |
| 1030 | else |
| 1031 | TOP = Fadd1 (v1); |
| 1032 | break; |
| 1033 | } |
| 1034 | |
| 1035 | case Beqlsign: |
| 1036 | { |
| 1037 | Lisp_Object v1, v2; |
| 1038 | v2 = POP; v1 = TOP; |
| 1039 | BEFORE_POTENTIAL_GC (); |
| 1040 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1, 0); |
| 1041 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2, 0); |
| 1042 | AFTER_POTENTIAL_GC (); |
| 1043 | if (FLOATP (v1) || FLOATP (v2)) |
| 1044 | { |
| 1045 | double f1, f2; |
| 1046 | |
| 1047 | f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1)); |
| 1048 | f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2)); |
| 1049 | TOP = (f1 == f2 ? Qt : Qnil); |
| 1050 | } |
| 1051 | else |
| 1052 | TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | case Bgtr: |
| 1057 | { |
| 1058 | Lisp_Object v1; |
| 1059 | v1 = POP; |
| 1060 | TOP = Fgtr (TOP, v1); |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | case Blss: |
| 1065 | { |
| 1066 | Lisp_Object v1; |
| 1067 | v1 = POP; |
| 1068 | TOP = Flss (TOP, v1); |
| 1069 | break; |
| 1070 | } |
| 1071 | |
| 1072 | case Bleq: |
| 1073 | { |
| 1074 | Lisp_Object v1; |
| 1075 | v1 = POP; |
| 1076 | TOP = Fleq (TOP, v1); |
| 1077 | break; |
| 1078 | } |
| 1079 | |
| 1080 | case Bgeq: |
| 1081 | { |
| 1082 | Lisp_Object v1; |
| 1083 | v1 = POP; |
| 1084 | TOP = Fgeq (TOP, v1); |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | case Bdiff: |
| 1089 | DISCARD (1); |
| 1090 | TOP = Fminus (2, &TOP); |
| 1091 | break; |
| 1092 | |
| 1093 | case Bnegate: |
| 1094 | { |
| 1095 | Lisp_Object v1; |
| 1096 | v1 = TOP; |
| 1097 | if (INTEGERP (v1)) |
| 1098 | { |
| 1099 | XSETINT (v1, - XINT (v1)); |
| 1100 | TOP = v1; |
| 1101 | } |
| 1102 | else |
| 1103 | TOP = Fminus (1, &TOP); |
| 1104 | break; |
| 1105 | } |
| 1106 | |
| 1107 | case Bplus: |
| 1108 | DISCARD (1); |
| 1109 | TOP = Fplus (2, &TOP); |
| 1110 | break; |
| 1111 | |
| 1112 | case Bmax: |
| 1113 | DISCARD (1); |
| 1114 | TOP = Fmax (2, &TOP); |
| 1115 | break; |
| 1116 | |
| 1117 | case Bmin: |
| 1118 | DISCARD (1); |
| 1119 | TOP = Fmin (2, &TOP); |
| 1120 | break; |
| 1121 | |
| 1122 | case Bmult: |
| 1123 | DISCARD (1); |
| 1124 | TOP = Ftimes (2, &TOP); |
| 1125 | break; |
| 1126 | |
| 1127 | case Bquo: |
| 1128 | DISCARD (1); |
| 1129 | TOP = Fquo (2, &TOP); |
| 1130 | break; |
| 1131 | |
| 1132 | case Brem: |
| 1133 | { |
| 1134 | Lisp_Object v1; |
| 1135 | v1 = POP; |
| 1136 | TOP = Frem (TOP, v1); |
| 1137 | break; |
| 1138 | } |
| 1139 | |
| 1140 | case Bpoint: |
| 1141 | { |
| 1142 | Lisp_Object v1; |
| 1143 | XSETFASTINT (v1, PT); |
| 1144 | PUSH (v1); |
| 1145 | break; |
| 1146 | } |
| 1147 | |
| 1148 | case Bgoto_char: |
| 1149 | BEFORE_POTENTIAL_GC (); |
| 1150 | TOP = Fgoto_char (TOP); |
| 1151 | AFTER_POTENTIAL_GC (); |
| 1152 | break; |
| 1153 | |
| 1154 | case Binsert: |
| 1155 | BEFORE_POTENTIAL_GC (); |
| 1156 | TOP = Finsert (1, &TOP); |
| 1157 | AFTER_POTENTIAL_GC (); |
| 1158 | break; |
| 1159 | |
| 1160 | case BinsertN: |
| 1161 | op = FETCH; |
| 1162 | BEFORE_POTENTIAL_GC (); |
| 1163 | DISCARD (op - 1); |
| 1164 | TOP = Finsert (op, &TOP); |
| 1165 | AFTER_POTENTIAL_GC (); |
| 1166 | break; |
| 1167 | |
| 1168 | case Bpoint_max: |
| 1169 | { |
| 1170 | Lisp_Object v1; |
| 1171 | XSETFASTINT (v1, ZV); |
| 1172 | PUSH (v1); |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | case Bpoint_min: |
| 1177 | { |
| 1178 | Lisp_Object v1; |
| 1179 | XSETFASTINT (v1, BEGV); |
| 1180 | PUSH (v1); |
| 1181 | break; |
| 1182 | } |
| 1183 | |
| 1184 | case Bchar_after: |
| 1185 | TOP = Fchar_after (TOP); |
| 1186 | break; |
| 1187 | |
| 1188 | case Bfollowing_char: |
| 1189 | { |
| 1190 | Lisp_Object v1; |
| 1191 | v1 = Ffollowing_char (); |
| 1192 | PUSH (v1); |
| 1193 | break; |
| 1194 | } |
| 1195 | |
| 1196 | case Bpreceding_char: |
| 1197 | { |
| 1198 | Lisp_Object v1; |
| 1199 | v1 = Fprevious_char (); |
| 1200 | PUSH (v1); |
| 1201 | break; |
| 1202 | } |
| 1203 | |
| 1204 | case Bcurrent_column: |
| 1205 | { |
| 1206 | Lisp_Object v1; |
| 1207 | XSETFASTINT (v1, current_column ()); |
| 1208 | PUSH (v1); |
| 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | case Bindent_to: |
| 1213 | BEFORE_POTENTIAL_GC (); |
| 1214 | TOP = Findent_to (TOP, Qnil); |
| 1215 | AFTER_POTENTIAL_GC (); |
| 1216 | break; |
| 1217 | |
| 1218 | case Beolp: |
| 1219 | PUSH (Feolp ()); |
| 1220 | break; |
| 1221 | |
| 1222 | case Beobp: |
| 1223 | PUSH (Feobp ()); |
| 1224 | break; |
| 1225 | |
| 1226 | case Bbolp: |
| 1227 | PUSH (Fbolp ()); |
| 1228 | break; |
| 1229 | |
| 1230 | case Bbobp: |
| 1231 | PUSH (Fbobp ()); |
| 1232 | break; |
| 1233 | |
| 1234 | case Bcurrent_buffer: |
| 1235 | PUSH (Fcurrent_buffer ()); |
| 1236 | break; |
| 1237 | |
| 1238 | case Bset_buffer: |
| 1239 | BEFORE_POTENTIAL_GC (); |
| 1240 | TOP = Fset_buffer (TOP); |
| 1241 | AFTER_POTENTIAL_GC (); |
| 1242 | break; |
| 1243 | |
| 1244 | case Binteractive_p: |
| 1245 | PUSH (Finteractive_p ()); |
| 1246 | break; |
| 1247 | |
| 1248 | case Bforward_char: |
| 1249 | BEFORE_POTENTIAL_GC (); |
| 1250 | TOP = Fforward_char (TOP); |
| 1251 | AFTER_POTENTIAL_GC (); |
| 1252 | break; |
| 1253 | |
| 1254 | case Bforward_word: |
| 1255 | BEFORE_POTENTIAL_GC (); |
| 1256 | TOP = Fforward_word (TOP); |
| 1257 | AFTER_POTENTIAL_GC (); |
| 1258 | break; |
| 1259 | |
| 1260 | case Bskip_chars_forward: |
| 1261 | { |
| 1262 | Lisp_Object v1; |
| 1263 | v1 = POP; |
| 1264 | BEFORE_POTENTIAL_GC (); |
| 1265 | TOP = Fskip_chars_forward (TOP, v1); |
| 1266 | AFTER_POTENTIAL_GC (); |
| 1267 | break; |
| 1268 | } |
| 1269 | |
| 1270 | case Bskip_chars_backward: |
| 1271 | { |
| 1272 | Lisp_Object v1; |
| 1273 | v1 = POP; |
| 1274 | BEFORE_POTENTIAL_GC (); |
| 1275 | TOP = Fskip_chars_backward (TOP, v1); |
| 1276 | AFTER_POTENTIAL_GC (); |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | case Bforward_line: |
| 1281 | BEFORE_POTENTIAL_GC (); |
| 1282 | TOP = Fforward_line (TOP); |
| 1283 | AFTER_POTENTIAL_GC (); |
| 1284 | break; |
| 1285 | |
| 1286 | case Bchar_syntax: |
| 1287 | BEFORE_POTENTIAL_GC (); |
| 1288 | CHECK_NUMBER (TOP, 0); |
| 1289 | AFTER_POTENTIAL_GC (); |
| 1290 | XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (XINT (TOP))]); |
| 1291 | break; |
| 1292 | |
| 1293 | case Bbuffer_substring: |
| 1294 | { |
| 1295 | Lisp_Object v1; |
| 1296 | v1 = POP; |
| 1297 | BEFORE_POTENTIAL_GC (); |
| 1298 | TOP = Fbuffer_substring (TOP, v1); |
| 1299 | AFTER_POTENTIAL_GC (); |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | case Bdelete_region: |
| 1304 | { |
| 1305 | Lisp_Object v1; |
| 1306 | v1 = POP; |
| 1307 | BEFORE_POTENTIAL_GC (); |
| 1308 | TOP = Fdelete_region (TOP, v1); |
| 1309 | AFTER_POTENTIAL_GC (); |
| 1310 | break; |
| 1311 | } |
| 1312 | |
| 1313 | case Bnarrow_to_region: |
| 1314 | { |
| 1315 | Lisp_Object v1; |
| 1316 | v1 = POP; |
| 1317 | BEFORE_POTENTIAL_GC (); |
| 1318 | TOP = Fnarrow_to_region (TOP, v1); |
| 1319 | AFTER_POTENTIAL_GC (); |
| 1320 | break; |
| 1321 | } |
| 1322 | |
| 1323 | case Bwiden: |
| 1324 | BEFORE_POTENTIAL_GC (); |
| 1325 | PUSH (Fwiden ()); |
| 1326 | AFTER_POTENTIAL_GC (); |
| 1327 | break; |
| 1328 | |
| 1329 | case Bend_of_line: |
| 1330 | BEFORE_POTENTIAL_GC (); |
| 1331 | TOP = Fend_of_line (TOP); |
| 1332 | AFTER_POTENTIAL_GC (); |
| 1333 | break; |
| 1334 | |
| 1335 | case Bset_marker: |
| 1336 | { |
| 1337 | Lisp_Object v1, v2; |
| 1338 | v1 = POP; |
| 1339 | v2 = POP; |
| 1340 | TOP = Fset_marker (TOP, v2, v1); |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | case Bmatch_beginning: |
| 1345 | TOP = Fmatch_beginning (TOP); |
| 1346 | break; |
| 1347 | |
| 1348 | case Bmatch_end: |
| 1349 | TOP = Fmatch_end (TOP); |
| 1350 | break; |
| 1351 | |
| 1352 | case Bupcase: |
| 1353 | TOP = Fupcase (TOP); |
| 1354 | break; |
| 1355 | |
| 1356 | case Bdowncase: |
| 1357 | TOP = Fdowncase (TOP); |
| 1358 | break; |
| 1359 | |
| 1360 | case Bstringeqlsign: |
| 1361 | { |
| 1362 | Lisp_Object v1; |
| 1363 | v1 = POP; |
| 1364 | TOP = Fstring_equal (TOP, v1); |
| 1365 | break; |
| 1366 | } |
| 1367 | |
| 1368 | case Bstringlss: |
| 1369 | { |
| 1370 | Lisp_Object v1; |
| 1371 | v1 = POP; |
| 1372 | TOP = Fstring_lessp (TOP, v1); |
| 1373 | break; |
| 1374 | } |
| 1375 | |
| 1376 | case Bequal: |
| 1377 | { |
| 1378 | Lisp_Object v1; |
| 1379 | v1 = POP; |
| 1380 | TOP = Fequal (TOP, v1); |
| 1381 | break; |
| 1382 | } |
| 1383 | |
| 1384 | case Bnthcdr: |
| 1385 | { |
| 1386 | Lisp_Object v1; |
| 1387 | v1 = POP; |
| 1388 | TOP = Fnthcdr (TOP, v1); |
| 1389 | break; |
| 1390 | } |
| 1391 | |
| 1392 | case Belt: |
| 1393 | { |
| 1394 | Lisp_Object v1, v2; |
| 1395 | if (CONSP (TOP)) |
| 1396 | { |
| 1397 | /* Exchange args and then do nth. */ |
| 1398 | v2 = POP; |
| 1399 | v1 = TOP; |
| 1400 | BEFORE_POTENTIAL_GC (); |
| 1401 | CHECK_NUMBER (v2, 0); |
| 1402 | AFTER_POTENTIAL_GC (); |
| 1403 | op = XINT (v2); |
| 1404 | immediate_quit = 1; |
| 1405 | while (--op >= 0) |
| 1406 | { |
| 1407 | if (CONSP (v1)) |
| 1408 | v1 = XCDR (v1); |
| 1409 | else if (!NILP (v1)) |
| 1410 | { |
| 1411 | immediate_quit = 0; |
| 1412 | BEFORE_POTENTIAL_GC (); |
| 1413 | v1 = wrong_type_argument (Qlistp, v1); |
| 1414 | AFTER_POTENTIAL_GC (); |
| 1415 | immediate_quit = 1; |
| 1416 | op++; |
| 1417 | } |
| 1418 | } |
| 1419 | immediate_quit = 0; |
| 1420 | if (CONSP (v1)) |
| 1421 | TOP = XCAR (v1); |
| 1422 | else if (NILP (v1)) |
| 1423 | TOP = Qnil; |
| 1424 | else |
| 1425 | { |
| 1426 | BEFORE_POTENTIAL_GC (); |
| 1427 | Fcar (wrong_type_argument (Qlistp, v1)); |
| 1428 | AFTER_POTENTIAL_GC (); |
| 1429 | } |
| 1430 | } |
| 1431 | else |
| 1432 | { |
| 1433 | v1 = POP; |
| 1434 | TOP = Felt (TOP, v1); |
| 1435 | } |
| 1436 | break; |
| 1437 | } |
| 1438 | |
| 1439 | case Bmember: |
| 1440 | { |
| 1441 | Lisp_Object v1; |
| 1442 | v1 = POP; |
| 1443 | TOP = Fmember (TOP, v1); |
| 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | case Bassq: |
| 1448 | { |
| 1449 | Lisp_Object v1; |
| 1450 | v1 = POP; |
| 1451 | TOP = Fassq (TOP, v1); |
| 1452 | break; |
| 1453 | } |
| 1454 | |
| 1455 | case Bnreverse: |
| 1456 | TOP = Fnreverse (TOP); |
| 1457 | break; |
| 1458 | |
| 1459 | case Bsetcar: |
| 1460 | { |
| 1461 | Lisp_Object v1; |
| 1462 | v1 = POP; |
| 1463 | TOP = Fsetcar (TOP, v1); |
| 1464 | break; |
| 1465 | } |
| 1466 | |
| 1467 | case Bsetcdr: |
| 1468 | { |
| 1469 | Lisp_Object v1; |
| 1470 | v1 = POP; |
| 1471 | TOP = Fsetcdr (TOP, v1); |
| 1472 | break; |
| 1473 | } |
| 1474 | |
| 1475 | case Bcar_safe: |
| 1476 | { |
| 1477 | Lisp_Object v1; |
| 1478 | v1 = TOP; |
| 1479 | if (CONSP (v1)) |
| 1480 | TOP = XCAR (v1); |
| 1481 | else |
| 1482 | TOP = Qnil; |
| 1483 | break; |
| 1484 | } |
| 1485 | |
| 1486 | case Bcdr_safe: |
| 1487 | { |
| 1488 | Lisp_Object v1; |
| 1489 | v1 = TOP; |
| 1490 | if (CONSP (v1)) |
| 1491 | TOP = XCDR (v1); |
| 1492 | else |
| 1493 | TOP = Qnil; |
| 1494 | break; |
| 1495 | } |
| 1496 | |
| 1497 | case Bnconc: |
| 1498 | DISCARD (1); |
| 1499 | TOP = Fnconc (2, &TOP); |
| 1500 | break; |
| 1501 | |
| 1502 | case Bnumberp: |
| 1503 | TOP = (NUMBERP (TOP) ? Qt : Qnil); |
| 1504 | break; |
| 1505 | |
| 1506 | case Bintegerp: |
| 1507 | TOP = INTEGERP (TOP) ? Qt : Qnil; |
| 1508 | break; |
| 1509 | |
| 1510 | #ifdef BYTE_CODE_SAFE |
| 1511 | case Bset_mark: |
| 1512 | BEFORE_POTENTIAL_GC (); |
| 1513 | error ("set-mark is an obsolete bytecode"); |
| 1514 | AFTER_POTENTIAL_GC (); |
| 1515 | break; |
| 1516 | case Bscan_buffer: |
| 1517 | BEFORE_POTENTIAL_GC (); |
| 1518 | error ("scan-buffer is an obsolete bytecode"); |
| 1519 | AFTER_POTENTIAL_GC (); |
| 1520 | break; |
| 1521 | #endif |
| 1522 | |
| 1523 | case 0: |
| 1524 | abort (); |
| 1525 | |
| 1526 | case 255: |
| 1527 | default: |
| 1528 | #ifdef BYTE_CODE_SAFE |
| 1529 | if (op < Bconstant) |
| 1530 | { |
| 1531 | abort (); |
| 1532 | } |
| 1533 | if ((op -= Bconstant) >= const_length) |
| 1534 | { |
| 1535 | abort (); |
| 1536 | } |
| 1537 | PUSH (vectorp[op]); |
| 1538 | #else |
| 1539 | PUSH (vectorp[op - Bconstant]); |
| 1540 | #endif |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | exit: |
| 1545 | |
| 1546 | byte_stack_list = byte_stack_list->next; |
| 1547 | |
| 1548 | /* Binds and unbinds are supposed to be compiled balanced. */ |
| 1549 | if (specpdl_ptr - specpdl != count) |
| 1550 | #ifdef BYTE_CODE_SAFE |
| 1551 | error ("binding stack not balanced (serious byte compiler bug)"); |
| 1552 | #else |
| 1553 | abort (); |
| 1554 | #endif |
| 1555 | |
| 1556 | return result; |
| 1557 | } |
| 1558 | |
| 1559 | void |
| 1560 | syms_of_bytecode () |
| 1561 | { |
| 1562 | Qbytecode = intern ("byte-code"); |
| 1563 | staticpro (&Qbytecode); |
| 1564 | |
| 1565 | defsubr (&Sbyte_code); |
| 1566 | |
| 1567 | #ifdef BYTE_CODE_METER |
| 1568 | |
| 1569 | DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter, |
| 1570 | "A vector of vectors which holds a histogram of byte-code usage.\n\ |
| 1571 | (aref (aref byte-code-meter 0) CODE) indicates how many times the byte\n\ |
| 1572 | opcode CODE has been executed.\n\ |
| 1573 | (aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,\n\ |
| 1574 | indicates how many times the byte opcodes CODE1 and CODE2 have been\n\ |
| 1575 | executed in succession."); |
| 1576 | DEFVAR_BOOL ("byte-metering-on", &byte_metering_on, |
| 1577 | "If non-nil, keep profiling information on byte code usage.\n\ |
| 1578 | The variable byte-code-meter indicates how often each byte opcode is used.\n\ |
| 1579 | If a symbol has a property named `byte-code-meter' whose value is an\n\ |
| 1580 | integer, it is incremented each time that symbol's function is called."); |
| 1581 | |
| 1582 | byte_metering_on = 0; |
| 1583 | Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0)); |
| 1584 | Qbyte_code_meter = intern ("byte-code-meter"); |
| 1585 | staticpro (&Qbyte_code_meter); |
| 1586 | { |
| 1587 | int i = 256; |
| 1588 | while (i--) |
| 1589 | XVECTOR (Vbyte_code_meter)->contents[i] = |
| 1590 | Fmake_vector (make_number (256), make_number (0)); |
| 1591 | } |
| 1592 | #endif |
| 1593 | } |