Mercurial > hg > xemacs-beta
annotate src/bytecode.c @ 5408:9fc91aa3a927
Converted tooltalk to GPLv3 according to GPLv3 source survey analysis.
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Tue, 19 Oct 2010 23:34:53 +0200 |
parents | 308d34e9f07d |
children | 46491edfd94a |
rev | line source |
---|---|
428 | 1 /* Execution of byte code produced by bytecomp.el. |
2 Implementation of compiled-function objects. | |
3 Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
4 Copyright (C) 1995, 2002, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5206
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
428 | 9 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5206
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5206
diff
changeset
|
11 option) any later version. |
428 | 12 |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5206
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 20 |
21 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
22 | |
23 /* This file has been Mule-ized. */ | |
24 | |
25 | |
26 /* Authorship: | |
27 | |
28 FSF: long ago. | |
29 | |
30 hacked on by jwz@jwz.org 1991-06 | |
31 o added a compile-time switch to turn on simple sanity checking; | |
32 o put back the obsolete byte-codes for error-detection; | |
33 o added a new instruction, unbind_all, which I will use for | |
34 tail-recursion elimination; | |
35 o made temp_output_buffer_show be called with the right number | |
36 of args; | |
37 o made the new bytecodes be called with args in the right order; | |
38 o added metering support. | |
39 | |
40 by Hallvard: | |
41 o added relative jump instructions; | |
42 o all conditionals now only do QUIT if they jump. | |
43 | |
44 Ben Wing: some changes for Mule, 1995-06. | |
45 | |
46 Martin Buchholz: performance hacking, 1998-09. | |
47 See Internals Manual, Evaluation. | |
48 */ | |
49 | |
50 #include <config.h> | |
51 #include "lisp.h" | |
52 #include "backtrace.h" | |
53 #include "buffer.h" | |
54 #include "bytecode.h" | |
55 #include "opaque.h" | |
56 #include "syntax.h" | |
872 | 57 #include "window.h" |
428 | 58 |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
59 #define NUM_REMEMBERED_BYTE_OPS 100 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
60 |
3092 | 61 #ifdef NEW_GC |
62 static Lisp_Object | |
63 make_compiled_function_args (int totalargs) | |
64 { | |
65 Lisp_Compiled_Function_Args *args; | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
66 args = XCOMPILED_FUNCTION_ARGS |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
67 (ALLOC_SIZED_LISP_OBJECT |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
68 (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
69 Lisp_Object, args, totalargs), |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
70 compiled_function_args)); |
3092 | 71 args->size = totalargs; |
72 return wrap_compiled_function_args (args); | |
73 } | |
74 | |
75 static Bytecount | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
76 size_compiled_function_args (Lisp_Object obj) |
3092 | 77 { |
78 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, | |
79 Lisp_Object, args, | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
80 XCOMPILED_FUNCTION_ARGS (obj)->size); |
3092 | 81 } |
82 | |
83 static const struct memory_description compiled_function_args_description[] = { | |
84 { XD_LONG, offsetof (Lisp_Compiled_Function_Args, size) }, | |
85 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Compiled_Function_Args, args), | |
86 XD_INDIRECT(0, 0) }, | |
87 { XD_END } | |
88 }; | |
89 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
90 DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT ("compiled-function-args", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
91 compiled_function_args, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
92 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
93 compiled_function_args_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
94 size_compiled_function_args, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
95 Lisp_Compiled_Function_Args); |
3092 | 96 #endif /* NEW_GC */ |
97 | |
428 | 98 EXFUN (Ffetch_bytecode, 1); |
99 | |
100 Lisp_Object Qbyte_code, Qcompiled_functionp, Qinvalid_byte_code; | |
101 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
102 |
428 | 103 enum Opcode /* Byte codes */ |
104 { | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
105 #define OPCODE(sym, val) B##sym = val, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
106 #include "bytecode-ops.h" |
428 | 107 }; |
108 typedef enum Opcode Opcode; | |
109 | |
110 Lisp_Object * execute_rare_opcode (Lisp_Object *stack_ptr, | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
111 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
112 Lisp_Object *stack_beg, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
113 Lisp_Object *stack_end, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
114 #endif /* ERROR_CHECK_BYTE_CODE */ |
442 | 115 const Opbyte *program_ptr, |
428 | 116 Opcode opcode); |
117 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
118 #ifndef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
119 |
4974
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
120 /* Normally we would use `x' instead of `0' in the argument list, to avoid |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
121 problems if `x' (an expression) has side effects, and warnings if `x' |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
122 contains variables or parameters that are otherwise unused. But in |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
123 this case `x' contains references to vars and params that exist only |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
124 when ERROR_CHECK_BYTE_CODE, and leaving in `x' would result in compile |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
125 errors. */ |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
126 # define bytecode_assert(x) disabled_assert (0) |
fe0d3106cc36
fix compile problems in bytecode.c when no error-check-byte-code (issue 666)
Ben Wing <ben@xemacs.org>
parents:
4970
diff
changeset
|
127 # define bytecode_assert_with_message(x, msg) disabled_assert(0) |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
128 # define bytecode_abort_with_message(msg) abort_with_message (msg) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
129 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
130 #else /* ERROR_CHECK_BYTE_CODE */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
131 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
132 # define bytecode_assert(x) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
133 ((x) ? (void) 0 : assert_failed_with_remembered_ops (__FILE__, __LINE__, #x)) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
134 # define bytecode_assert_with_message(x, msg) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
135 ((x) ? (void) 0 : assert_failed_with_remembered_ops (__FILE__, __LINE__, msg)) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
136 # define bytecode_abort_with_message(msg) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
137 assert_failed_with_remembered_ops (__FILE__, __LINE__, msg) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
138 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
139 /* Table mapping opcodes to their names. This handles opcodes like |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
140 Bvarref+7, but it doesn't list any of the Bconstant+N opcodes; those |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
141 are handled specially. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
142 Ascbyte *opcode_name_table[256]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
143 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
144 /* Circular queue remembering the most recent operations. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
145 Opcode remembered_ops[NUM_REMEMBERED_BYTE_OPS]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
146 int remembered_op_next_pos, num_remembered; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
147 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
148 static void |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
149 remember_operation (Opcode op) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
150 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
151 remembered_ops[remembered_op_next_pos] = op; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
152 remembered_op_next_pos = |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
153 (remembered_op_next_pos + 1) % NUM_REMEMBERED_BYTE_OPS; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
154 if (num_remembered < NUM_REMEMBERED_BYTE_OPS) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
155 num_remembered++; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
156 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
157 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
158 static void |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
159 assert_failed_with_remembered_ops (const Ascbyte *file, int line, |
4970 | 160 const Ascbyte *msg_to_abort_with) |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
161 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
162 Ascbyte *msg = |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
163 alloca_array (Ascbyte, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
164 NUM_REMEMBERED_BYTE_OPS*50 + strlen (msg_to_abort_with)); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
165 int i; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
166 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
167 if (msg_to_abort_with) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
168 strcpy (msg, msg_to_abort_with); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
169 strcat (msg, "\n\nRecent bytecodes, oldest first:\n\n"); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
170 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
171 for (i = 0; i < num_remembered; i++) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
172 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
173 Ascbyte msg2[50]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
174 int pos; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
175 Opcode op; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
176 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
177 sprintf (msg2, "%5d: ", i - num_remembered + 1); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
178 strcat (msg, msg2); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
179 pos = (remembered_op_next_pos + NUM_REMEMBERED_BYTE_OPS + |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
180 i - num_remembered) % NUM_REMEMBERED_BYTE_OPS; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
181 op = remembered_ops[pos]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
182 if (op >= Bconstant) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
183 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
184 sprintf (msg2, "constant+%d", op - Bconstant); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
185 strcat (msg, msg2); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
186 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
187 else |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
188 { |
4970 | 189 const Ascbyte *opname = opcode_name_table[op]; |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
190 if (!opname) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
191 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
192 stderr_out ("Internal error! NULL pointer in opcode_name_table, opcode %d\n", op); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
193 strcat (msg, "NULL"); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
194 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
195 else |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
196 strcat (msg, opname); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
197 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
198 sprintf (msg2, " (%d)\n", op); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
199 strcat (msg, msg2); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
200 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
201 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
202 assert_failed (file, line, msg); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
203 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
204 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
205 #endif /* ERROR_CHECK_BYTE_CODE */ |
428 | 206 |
207 | |
208 #ifdef BYTE_CODE_METER | |
209 | |
210 Lisp_Object Vbyte_code_meter, Qbyte_code_meter; | |
211 int byte_metering_on; | |
212 | |
213 static void | |
214 meter_code (Opcode prev_opcode, Opcode this_opcode) | |
215 { | |
216 if (byte_metering_on) | |
217 { | |
218 Lisp_Object *p = XVECTOR_DATA (XVECTOR_DATA (Vbyte_code_meter)[this_opcode]); | |
219 p[0] = INT_PLUS1 (p[0]); | |
220 if (prev_opcode) | |
221 p[prev_opcode] = INT_PLUS1 (p[prev_opcode]); | |
222 } | |
223 } | |
224 | |
225 #endif /* BYTE_CODE_METER */ | |
226 | |
227 | |
228 static Lisp_Object | |
229 bytecode_negate (Lisp_Object obj) | |
230 { | |
231 retry: | |
232 | |
1983 | 233 if (INTP (obj)) return make_integer (- XINT (obj)); |
428 | 234 if (FLOATP (obj)) return make_float (- XFLOAT_DATA (obj)); |
1983 | 235 if (CHARP (obj)) return make_integer (- ((int) XCHAR (obj))); |
236 if (MARKERP (obj)) return make_integer (- ((int) marker_position (obj))); | |
237 #ifdef HAVE_BIGNUM | |
238 if (BIGNUMP (obj)) BIGNUM_ARITH_RETURN (obj, neg); | |
239 #endif | |
240 #ifdef HAVE_RATIO | |
241 if (RATIOP (obj)) RATIO_ARITH_RETURN (obj, neg); | |
242 #endif | |
4678
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
243 #ifdef HAVE_BIGFLOAT |
b5e1d4f6b66f
Make #'floor, #'ceiling, #'round, #'truncate conform to Common Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
244 if (BIGFLOATP (obj)) BIGFLOAT_ARITH_RETURN (obj, neg); |
1983 | 245 #endif |
428 | 246 |
247 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj); | |
248 goto retry; | |
249 } | |
250 | |
251 static Lisp_Object | |
252 bytecode_nreverse (Lisp_Object list) | |
253 { | |
254 REGISTER Lisp_Object prev = Qnil; | |
255 REGISTER Lisp_Object tail = list; | |
256 | |
257 while (!NILP (tail)) | |
258 { | |
259 REGISTER Lisp_Object next; | |
260 CHECK_CONS (tail); | |
261 next = XCDR (tail); | |
262 XCDR (tail) = prev; | |
263 prev = tail; | |
264 tail = next; | |
265 } | |
266 return prev; | |
267 } | |
268 | |
269 | |
270 /* We have our own two-argument versions of various arithmetic ops. | |
271 Only two-argument arithmetic operations have their own byte codes. */ | |
4910
6bc1f3f6cf0d
Make canoncase visible to Lisp; use it with chars in internal_equalp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4906
diff
changeset
|
272 int |
428 | 273 bytecode_arithcompare (Lisp_Object obj1, Lisp_Object obj2) |
274 { | |
1983 | 275 #ifdef WITH_NUMBER_TYPES |
276 switch (promote_args (&obj1, &obj2)) | |
277 { | |
278 case FIXNUM_T: | |
279 { | |
280 EMACS_INT ival1 = XREALINT (obj1), ival2 = XREALINT (obj2); | |
281 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0; | |
282 } | |
283 #ifdef HAVE_BIGNUM | |
284 case BIGNUM_T: | |
285 return bignum_cmp (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)); | |
286 #endif | |
287 #ifdef HAVE_RATIO | |
288 case RATIO_T: | |
289 return ratio_cmp (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
290 #endif | |
1995 | 291 #ifdef HAVE_BIGFLOAT |
292 case BIGFLOAT_T: | |
293 return bigfloat_cmp (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); | |
294 #endif | |
295 default: /* FLOAT_T */ | |
1983 | 296 { |
297 double dval1 = XFLOAT_DATA (obj1), dval2 = XFLOAT_DATA (obj2); | |
298 return dval1 < dval2 ? -1 : dval1 > dval2 ? 1 : 0; | |
299 } | |
300 } | |
301 #else /* !WITH_NUMBER_TYPES */ | |
428 | 302 retry: |
303 | |
304 { | |
305 EMACS_INT ival1, ival2; | |
306 | |
307 if (INTP (obj1)) ival1 = XINT (obj1); | |
308 else if (CHARP (obj1)) ival1 = XCHAR (obj1); | |
309 else if (MARKERP (obj1)) ival1 = marker_position (obj1); | |
310 else goto arithcompare_float; | |
311 | |
312 if (INTP (obj2)) ival2 = XINT (obj2); | |
313 else if (CHARP (obj2)) ival2 = XCHAR (obj2); | |
314 else if (MARKERP (obj2)) ival2 = marker_position (obj2); | |
315 else goto arithcompare_float; | |
316 | |
317 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0; | |
318 } | |
319 | |
320 arithcompare_float: | |
321 | |
322 { | |
323 double dval1, dval2; | |
324 | |
325 if (FLOATP (obj1)) dval1 = XFLOAT_DATA (obj1); | |
326 else if (INTP (obj1)) dval1 = (double) XINT (obj1); | |
327 else if (CHARP (obj1)) dval1 = (double) XCHAR (obj1); | |
328 else if (MARKERP (obj1)) dval1 = (double) marker_position (obj1); | |
329 else | |
330 { | |
331 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1); | |
332 goto retry; | |
333 } | |
334 | |
335 if (FLOATP (obj2)) dval2 = XFLOAT_DATA (obj2); | |
336 else if (INTP (obj2)) dval2 = (double) XINT (obj2); | |
337 else if (CHARP (obj2)) dval2 = (double) XCHAR (obj2); | |
338 else if (MARKERP (obj2)) dval2 = (double) marker_position (obj2); | |
339 else | |
340 { | |
341 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2); | |
342 goto retry; | |
343 } | |
344 | |
345 return dval1 < dval2 ? -1 : dval1 > dval2 ? 1 : 0; | |
346 } | |
1983 | 347 #endif /* WITH_NUMBER_TYPES */ |
428 | 348 } |
349 | |
350 static Lisp_Object | |
351 bytecode_arithop (Lisp_Object obj1, Lisp_Object obj2, Opcode opcode) | |
352 { | |
1983 | 353 #ifdef WITH_NUMBER_TYPES |
354 switch (promote_args (&obj1, &obj2)) | |
355 { | |
356 case FIXNUM_T: | |
357 { | |
358 EMACS_INT ival1 = XREALINT (obj1), ival2 = XREALINT (obj2); | |
359 switch (opcode) | |
360 { | |
361 case Bplus: ival1 += ival2; break; | |
362 case Bdiff: ival1 -= ival2; break; | |
363 case Bmult: | |
364 #ifdef HAVE_BIGNUM | |
365 /* Due to potential overflow, we compute using bignums */ | |
366 bignum_set_long (scratch_bignum, ival1); | |
367 bignum_set_long (scratch_bignum2, ival2); | |
368 bignum_mul (scratch_bignum, scratch_bignum, scratch_bignum2); | |
369 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
370 #else | |
371 ival1 *= ival2; break; | |
372 #endif | |
373 case Bquo: | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
374 if (ival2 == 0) |
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
375 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
1983 | 376 ival1 /= ival2; |
377 break; | |
378 case Bmax: if (ival1 < ival2) ival1 = ival2; break; | |
379 case Bmin: if (ival1 > ival2) ival1 = ival2; break; | |
380 } | |
381 return make_integer (ival1); | |
382 } | |
383 #ifdef HAVE_BIGNUM | |
384 case BIGNUM_T: | |
385 switch (opcode) | |
386 { | |
387 case Bplus: | |
388 bignum_add (scratch_bignum, XBIGNUM_DATA (obj1), | |
389 XBIGNUM_DATA (obj2)); | |
390 break; | |
391 case Bdiff: | |
392 bignum_sub (scratch_bignum, XBIGNUM_DATA (obj1), | |
393 XBIGNUM_DATA (obj2)); | |
394 break; | |
395 case Bmult: | |
396 bignum_mul (scratch_bignum, XBIGNUM_DATA (obj1), | |
397 XBIGNUM_DATA (obj2)); | |
398 break; | |
399 case Bquo: | |
400 if (bignum_sign (XBIGNUM_DATA (obj2)) == 0) | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
401 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
1983 | 402 bignum_div (scratch_bignum, XBIGNUM_DATA (obj1), |
403 XBIGNUM_DATA (obj2)); | |
404 break; | |
405 case Bmax: | |
406 return bignum_gt (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)) | |
407 ? obj1 : obj2; | |
408 case Bmin: | |
409 return bignum_lt (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)) | |
410 ? obj1 : obj2; | |
411 } | |
412 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
413 #endif | |
414 #ifdef HAVE_RATIO | |
415 case RATIO_T: | |
416 switch (opcode) | |
417 { | |
418 case Bplus: | |
419 ratio_add (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
420 break; | |
421 case Bdiff: | |
422 ratio_sub (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
423 break; | |
424 case Bmult: | |
425 ratio_mul (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
426 break; | |
427 case Bquo: | |
428 if (ratio_sign (XRATIO_DATA (obj2)) == 0) | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
429 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
1983 | 430 ratio_div (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); |
431 break; | |
432 case Bmax: | |
433 return ratio_gt (XRATIO_DATA (obj1), XRATIO_DATA (obj2)) | |
434 ? obj1 : obj2; | |
435 case Bmin: | |
436 return ratio_lt (XRATIO_DATA (obj1), XRATIO_DATA (obj2)) | |
437 ? obj1 : obj2; | |
438 } | |
439 return make_ratio_rt (scratch_ratio); | |
440 #endif | |
441 #ifdef HAVE_BIGFLOAT | |
442 case BIGFLOAT_T: | |
443 bigfloat_set_prec (scratch_bigfloat, max (XBIGFLOAT_GET_PREC (obj1), | |
444 XBIGFLOAT_GET_PREC (obj2))); | |
445 switch (opcode) | |
446 { | |
447 case Bplus: | |
448 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
449 XBIGFLOAT_DATA (obj2)); | |
450 break; | |
451 case Bdiff: | |
452 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
453 XBIGFLOAT_DATA (obj2)); | |
454 break; | |
455 case Bmult: | |
456 bigfloat_mul (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
457 XBIGFLOAT_DATA (obj2)); | |
458 break; | |
459 case Bquo: | |
460 if (bigfloat_sign (XBIGFLOAT_DATA (obj2)) == 0) | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
461 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
1983 | 462 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (obj1), |
463 XBIGFLOAT_DATA (obj2)); | |
464 break; | |
465 case Bmax: | |
466 return bigfloat_gt (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)) | |
467 ? obj1 : obj2; | |
468 case Bmin: | |
469 return bigfloat_lt (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)) | |
470 ? obj1 : obj2; | |
471 } | |
472 return make_bigfloat_bf (scratch_bigfloat); | |
473 #endif | |
1995 | 474 default: /* FLOAT_T */ |
475 { | |
476 double dval1 = XFLOAT_DATA (obj1), dval2 = XFLOAT_DATA (obj2); | |
477 switch (opcode) | |
478 { | |
479 case Bplus: dval1 += dval2; break; | |
480 case Bdiff: dval1 -= dval2; break; | |
481 case Bmult: dval1 *= dval2; break; | |
482 case Bquo: | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
483 if (dval2 == 0.0) |
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
484 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
1995 | 485 dval1 /= dval2; |
486 break; | |
487 case Bmax: if (dval1 < dval2) dval1 = dval2; break; | |
488 case Bmin: if (dval1 > dval2) dval1 = dval2; break; | |
489 } | |
490 return make_float (dval1); | |
491 } | |
1983 | 492 } |
493 #else /* !WITH_NUMBER_TYPES */ | |
428 | 494 EMACS_INT ival1, ival2; |
495 int float_p; | |
496 | |
497 retry: | |
498 | |
499 float_p = 0; | |
500 | |
501 if (INTP (obj1)) ival1 = XINT (obj1); | |
502 else if (CHARP (obj1)) ival1 = XCHAR (obj1); | |
503 else if (MARKERP (obj1)) ival1 = marker_position (obj1); | |
504 else if (FLOATP (obj1)) ival1 = 0, float_p = 1; | |
505 else | |
506 { | |
507 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1); | |
508 goto retry; | |
509 } | |
510 | |
511 if (INTP (obj2)) ival2 = XINT (obj2); | |
512 else if (CHARP (obj2)) ival2 = XCHAR (obj2); | |
513 else if (MARKERP (obj2)) ival2 = marker_position (obj2); | |
514 else if (FLOATP (obj2)) ival2 = 0, float_p = 1; | |
515 else | |
516 { | |
517 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2); | |
518 goto retry; | |
519 } | |
520 | |
521 if (!float_p) | |
522 { | |
523 switch (opcode) | |
524 { | |
525 case Bplus: ival1 += ival2; break; | |
526 case Bdiff: ival1 -= ival2; break; | |
527 case Bmult: ival1 *= ival2; break; | |
528 case Bquo: | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
529 if (ival2 == 0) |
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
530 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
428 | 531 ival1 /= ival2; |
532 break; | |
533 case Bmax: if (ival1 < ival2) ival1 = ival2; break; | |
534 case Bmin: if (ival1 > ival2) ival1 = ival2; break; | |
535 } | |
536 return make_int (ival1); | |
537 } | |
538 else | |
539 { | |
540 double dval1 = FLOATP (obj1) ? XFLOAT_DATA (obj1) : (double) ival1; | |
541 double dval2 = FLOATP (obj2) ? XFLOAT_DATA (obj2) : (double) ival2; | |
542 switch (opcode) | |
543 { | |
544 case Bplus: dval1 += dval2; break; | |
545 case Bdiff: dval1 -= dval2; break; | |
546 case Bmult: dval1 *= dval2; break; | |
547 case Bquo: | |
4717
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
548 if (dval2 == 0) |
fcc7e89d5e68
Properly handle continuable divide-by-zero errors. Fix truncation of a
Jerry James <james@xemacs.org>
parents:
4678
diff
changeset
|
549 signal_error_2 (Qarith_error, "division by zero", obj1, obj2); |
428 | 550 dval1 /= dval2; |
551 break; | |
552 case Bmax: if (dval1 < dval2) dval1 = dval2; break; | |
553 case Bmin: if (dval1 > dval2) dval1 = dval2; break; | |
554 } | |
555 return make_float (dval1); | |
556 } | |
1983 | 557 #endif /* WITH_NUMBER_TYPES */ |
428 | 558 } |
559 | |
560 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
561 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
562 /*********************** The instruction array *********************/ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
563 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
564 /* Check that there are at least LEN elements left in the end of the |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
565 instruction array before fetching them. Note that we allow for |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
566 PROGRAM_PTR == PROGRAM_END after the fetch -- that means there are |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
567 no more elements to fetch next time around, but we might exit before |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
568 next time comes. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
569 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
570 When checking the destination if jumps, however, we don't allow |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
571 PROGRAM_PTR to equal PROGRAM_END, since we will always be fetching |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
572 another instruction after the jump. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
573 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
574 #define CHECK_OPCODE_SPACE(len) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
575 bytecode_assert (program_ptr + len <= program_end) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
576 |
428 | 577 /* Read next uint8 from the instruction stream. */ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
578 #define READ_UINT_1 \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
579 (CHECK_OPCODE_SPACE (1), (unsigned int) (unsigned char) *program_ptr++) |
428 | 580 |
581 /* Read next uint16 from the instruction stream. */ | |
582 #define READ_UINT_2 \ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
583 (CHECK_OPCODE_SPACE (2), \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
584 program_ptr += 2, \ |
428 | 585 (((unsigned int) (unsigned char) program_ptr[-1]) * 256 + \ |
586 ((unsigned int) (unsigned char) program_ptr[-2]))) | |
587 | |
588 /* Read next int8 from the instruction stream. */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
589 #define READ_INT_1 \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
590 (CHECK_OPCODE_SPACE (1), (int) (signed char) *program_ptr++) |
428 | 591 |
592 /* Read next int16 from the instruction stream. */ | |
593 #define READ_INT_2 \ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
594 (CHECK_OPCODE_SPACE (2), \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
595 program_ptr += 2, \ |
428 | 596 (((int) ( signed char) program_ptr[-1]) * 256 + \ |
597 ((int) (unsigned char) program_ptr[-2]))) | |
598 | |
599 /* Read next int8 from instruction stream; don't advance program_pointer */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
600 #define PEEK_INT_1 \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
601 (CHECK_OPCODE_SPACE (1), (int) (signed char) program_ptr[0]) |
428 | 602 |
603 /* Read next int16 from instruction stream; don't advance program_pointer */ | |
604 #define PEEK_INT_2 \ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
605 (CHECK_OPCODE_SPACE (2), \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
606 (((int) ( signed char) program_ptr[1]) * 256) | \ |
428 | 607 ((int) (unsigned char) program_ptr[0])) |
608 | |
609 /* Do relative jumps from the current location. | |
610 We only do a QUIT if we jump backwards, for efficiency. | |
611 No infloops without backward jumps! */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
612 #define JUMP_RELATIVE(jump) do { \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
613 int _JR_jump = (jump); \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
614 if (_JR_jump < 0) QUIT; \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
615 /* Check that where we're going to is in range. Note that we don't use \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
616 CHECK_OPCODE_SPACE() -- that only checks the end, and it allows \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
617 program_ptr == program_end, which we don't allow. */ \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
618 bytecode_assert (program_ptr + _JR_jump >= program && \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
619 program_ptr + _JR_jump < program_end); \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
620 program_ptr += _JR_jump; \ |
428 | 621 } while (0) |
622 | |
623 #define JUMP JUMP_RELATIVE (PEEK_INT_2) | |
624 #define JUMPR JUMP_RELATIVE (PEEK_INT_1) | |
625 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
626 #define JUMP_NEXT (CHECK_OPCODE_SPACE (2), (void) (program_ptr += 2)) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
627 #define JUMPR_NEXT (CHECK_OPCODE_SPACE (1), (void) (program_ptr += 1)) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
628 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
629 /*********************** The stack array *********************/ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
630 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
631 /* NOTE: The stack array doesn't work quite like you'd expect. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
632 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
633 STACK_PTR points to the value on the top of the stack. Popping a value |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
634 fetches the value from the STACK_PTR and then decrements it. Pushing a |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
635 value first increments it, then writes the new value. STACK_PTR - |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
636 STACK_BEG is the number of elements on the stack. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
637 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
638 This means that when STACK_PTR == STACK_BEG, the stack is empty, and |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
639 the space at STACK_BEG is never written to -- the first push will write |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
640 into the space directly after STACK_BEG. This is why the call to |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
641 alloca_array() below has a count of `stack_depth + 1', and why |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
642 we GCPRO1 (stack_ptr[1]) -- the value at stack_ptr[0] is unused and |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
643 uninitialized. |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
644 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
645 Also, STACK_END actually points to the last usable storage location, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
646 and does not point past the end, like you'd expect. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
647 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
648 #define CHECK_STACKPTR_OFFSET(len) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
649 bytecode_assert (stack_ptr + (len) >= stack_beg && \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
650 stack_ptr + (len) <= stack_end) |
428 | 651 |
652 /* Push x onto the execution stack. */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
653 #define PUSH(x) (CHECK_STACKPTR_OFFSET (1), *++stack_ptr = (x)) |
428 | 654 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
655 /* Pop a value, which may be multiple, off the execution stack. */ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
656 #define POP_WITH_MULTIPLE_VALUES (CHECK_STACKPTR_OFFSET (-1), *stack_ptr--) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
657 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
658 /* Pop a value off the execution stack, treating multiple values as single. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
659 #define POP (IGNORE_MULTIPLE_VALUES (POP_WITH_MULTIPLE_VALUES)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
660 |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
661 /* ..._UNSAFE() means it evaluates its argument more than once. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
662 #define DISCARD_PRESERVING_MULTIPLE_VALUES_UNSAFE(n) \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
663 (CHECK_STACKPTR_OFFSET (-(n)), stack_ptr -= (n)) |
428 | 664 |
665 /* Discard n values from the execution stack. */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
666 #define DISCARD(n) do { \ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
667 int _discard_n = (n); \ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
668 if (1 != multiple_value_current_limit) \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
669 { \ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
670 int i; \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
671 for (i = 0; i < _discard_n; i++) \ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
672 { \ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
673 CHECK_STACKPTR_OFFSET (-1); \ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
674 *stack_ptr = ignore_multiple_values (*stack_ptr); \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
675 stack_ptr--; \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
676 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
677 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
678 else \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
679 { \ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
680 CHECK_STACKPTR_OFFSET (-_discard_n); \ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
681 stack_ptr -= _discard_n; \ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
682 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
683 } while (0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
684 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
685 /* Get the value, which may be multiple, at the top of the execution stack; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
686 and leave it there. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
687 #define TOP_WITH_MULTIPLE_VALUES (*stack_ptr) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
688 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
689 #define TOP_ADDRESS (stack_ptr) |
428 | 690 |
691 /* Get the value which is at the top of the execution stack, | |
692 but don't pop it. */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
693 #define TOP (IGNORE_MULTIPLE_VALUES (TOP_WITH_MULTIPLE_VALUES)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
694 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
695 #define TOP_LVALUE (*stack_ptr) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
696 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
697 |
428 | 698 |
1920 | 699 /* See comment before the big switch in execute_optimized_program(). */ |
1884 | 700 #define GCPRO_STACK (gcpro1.nvars = stack_ptr - stack_beg) |
701 | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
702 |
428 | 703 /* The actual interpreter for byte code. |
704 This function has been seriously optimized for performance. | |
705 Don't change the constructs unless you are willing to do | |
706 real benchmarking and profiling work -- martin */ | |
707 | |
708 | |
814 | 709 Lisp_Object |
442 | 710 execute_optimized_program (const Opbyte *program, |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
711 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
712 Elemcount program_length, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
713 #endif |
428 | 714 int stack_depth, |
715 Lisp_Object *constants_data) | |
716 { | |
717 /* This function can GC */ | |
442 | 718 REGISTER const Opbyte *program_ptr = (Opbyte *) program; |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
719 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
720 const Opbyte *program_end = program_ptr + program_length; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
721 #endif |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
722 /* See comment above explaining the `+ 1' */ |
1884 | 723 Lisp_Object *stack_beg = alloca_array (Lisp_Object, stack_depth + 1); |
724 REGISTER Lisp_Object *stack_ptr = stack_beg; | |
428 | 725 int speccount = specpdl_depth (); |
726 struct gcpro gcpro1; | |
727 | |
728 #ifdef BYTE_CODE_METER | |
4925 | 729 Opcode this_opcode = (Opcode) 0; |
428 | 730 Opcode prev_opcode; |
731 #endif | |
732 | |
733 #ifdef ERROR_CHECK_BYTE_CODE | |
734 Lisp_Object *stack_end = stack_beg + stack_depth; | |
735 #endif | |
736 | |
1920 | 737 /* We used to GCPRO the whole interpreter stack before entering this while |
738 loop (21.5.14 and before), but that interferes with collection of weakly | |
739 referenced objects. Although strictly speaking there's no promise that | |
740 weak references will disappear by any given point in time, they should | |
741 be collected at the first opportunity. Waiting until exit from the | |
742 function caused test failures because "stale" objects "above" the top of | |
743 the stack were still GCPROed, and they were not getting collected until | |
744 after exit from the (byte-compiled) test! | |
745 | |
746 Now the idea is to dynamically adjust the array of GCPROed objects to | |
747 include only the "active" region of the stack. | |
748 | |
749 We use the "GCPRO1 the array base and set the nvars member" method. It | |
750 would be slightly inefficient but correct to use GCPRO1_ARRAY here. It | |
751 would just redundantly set nvars. | |
752 #### Maybe it would be clearer to use GCPRO1_ARRAY and do GCPRO_STACK | |
753 after the switch? | |
754 | |
755 GCPRO_STACK is something of a misnomer, because it suggests that a | |
756 struct gcpro is initialized each time. This is false; only the nvars | |
757 member of a single struct gcpro is being adjusted. This works because | |
758 each time a new object is assigned to a stack location, the old object | |
759 loses its reference and is effectively UNGCPROed, and the new object is | |
760 automatically GCPROed as long as nvars is correct. Only when we | |
761 return from the interpreter do we need to finalize the struct gcpro | |
762 itself, and that's done at case Breturn. | |
763 */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
764 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
765 /* See comment above explaining the `[1]' */ |
428 | 766 GCPRO1 (stack_ptr[1]); |
1758 | 767 |
428 | 768 while (1) |
769 { | |
770 REGISTER Opcode opcode = (Opcode) READ_UINT_1; | |
1920 | 771 |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
772 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
773 remember_operation (opcode); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
774 #endif |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
775 |
1920 | 776 GCPRO_STACK; /* Get nvars right before maybe signaling. */ |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
777 /* #### NOTE: This code should probably never get triggered, since we |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
778 now catch the problems earlier, farther down, before we ever set |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
779 a bad value for STACK_PTR. */ |
428 | 780 #ifdef ERROR_CHECK_BYTE_CODE |
781 if (stack_ptr > stack_end) | |
563 | 782 stack_overflow ("byte code stack overflow", Qunbound); |
428 | 783 if (stack_ptr < stack_beg) |
563 | 784 stack_overflow ("byte code stack underflow", Qunbound); |
428 | 785 #endif |
786 | |
787 #ifdef BYTE_CODE_METER | |
788 prev_opcode = this_opcode; | |
789 this_opcode = opcode; | |
790 meter_code (prev_opcode, this_opcode); | |
791 #endif | |
792 | |
793 switch (opcode) | |
794 { | |
795 REGISTER int n; | |
796 | |
797 default: | |
798 if (opcode >= Bconstant) | |
799 PUSH (constants_data[opcode - Bconstant]); | |
800 else | |
1884 | 801 { |
802 /* We're not sure what these do, so better safe than sorry. */ | |
803 /* GCPRO_STACK; */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
804 stack_ptr = execute_rare_opcode (stack_ptr, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
805 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
806 stack_beg, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
807 stack_end, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
808 #endif /* ERROR_CHECK_BYTE_CODE */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
809 program_ptr, opcode); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
810 CHECK_STACKPTR_OFFSET (0); |
1884 | 811 } |
428 | 812 break; |
813 | |
814 case Bvarref: | |
815 case Bvarref+1: | |
816 case Bvarref+2: | |
817 case Bvarref+3: | |
818 case Bvarref+4: | |
819 case Bvarref+5: n = opcode - Bvarref; goto do_varref; | |
820 case Bvarref+7: n = READ_UINT_2; goto do_varref; | |
821 case Bvarref+6: n = READ_UINT_1; /* most common */ | |
822 do_varref: | |
823 { | |
824 Lisp_Object symbol = constants_data[n]; | |
825 Lisp_Object value = XSYMBOL (symbol)->value; | |
826 if (SYMBOL_VALUE_MAGIC_P (value)) | |
1920 | 827 /* I GCPRO_STACKed Fsymbol_value elsewhere, but I dunno why. */ |
828 /* GCPRO_STACK; */ | |
428 | 829 value = Fsymbol_value (symbol); |
830 PUSH (value); | |
831 break; | |
832 } | |
833 | |
834 case Bvarset: | |
835 case Bvarset+1: | |
836 case Bvarset+2: | |
837 case Bvarset+3: | |
838 case Bvarset+4: | |
839 case Bvarset+5: n = opcode - Bvarset; goto do_varset; | |
840 case Bvarset+7: n = READ_UINT_2; goto do_varset; | |
841 case Bvarset+6: n = READ_UINT_1; /* most common */ | |
842 do_varset: | |
843 { | |
844 Lisp_Object symbol = constants_data[n]; | |
440 | 845 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol); |
428 | 846 Lisp_Object old_value = symbol_ptr->value; |
847 Lisp_Object new_value = POP; | |
1661 | 848 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value)) |
428 | 849 symbol_ptr->value = new_value; |
1884 | 850 else { |
851 /* Fset may call magic handlers */ | |
852 /* GCPRO_STACK; */ | |
428 | 853 Fset (symbol, new_value); |
1884 | 854 } |
855 | |
428 | 856 break; |
857 } | |
858 | |
859 case Bvarbind: | |
860 case Bvarbind+1: | |
861 case Bvarbind+2: | |
862 case Bvarbind+3: | |
863 case Bvarbind+4: | |
864 case Bvarbind+5: n = opcode - Bvarbind; goto do_varbind; | |
865 case Bvarbind+7: n = READ_UINT_2; goto do_varbind; | |
866 case Bvarbind+6: n = READ_UINT_1; /* most common */ | |
867 do_varbind: | |
868 { | |
869 Lisp_Object symbol = constants_data[n]; | |
440 | 870 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol); |
428 | 871 Lisp_Object old_value = symbol_ptr->value; |
872 Lisp_Object new_value = POP; | |
873 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value)) | |
874 { | |
875 specpdl_ptr->symbol = symbol; | |
876 specpdl_ptr->old_value = old_value; | |
877 specpdl_ptr->func = 0; | |
878 specpdl_ptr++; | |
879 specpdl_depth_counter++; | |
880 | |
881 symbol_ptr->value = new_value; | |
853 | 882 |
883 #ifdef ERROR_CHECK_CATCH | |
884 check_specbind_stack_sanity (); | |
885 #endif | |
428 | 886 } |
887 else | |
1884 | 888 { |
889 /* does an Fset, may call magic handlers */ | |
890 /* GCPRO_STACK; */ | |
891 specbind_magic (symbol, new_value); | |
892 } | |
428 | 893 break; |
894 } | |
895 | |
896 case Bcall: | |
897 case Bcall+1: | |
898 case Bcall+2: | |
899 case Bcall+3: | |
900 case Bcall+4: | |
901 case Bcall+5: | |
902 case Bcall+6: | |
903 case Bcall+7: | |
904 n = (opcode < Bcall+6 ? opcode - Bcall : | |
905 opcode == Bcall+6 ? READ_UINT_1 : READ_UINT_2); | |
1920 | 906 /* #### Shouldn't this be just before the Ffuncall? |
907 Neither Fget nor Fput can GC. */ | |
1884 | 908 /* GCPRO_STACK; */ |
428 | 909 DISCARD (n); |
910 #ifdef BYTE_CODE_METER | |
911 if (byte_metering_on && SYMBOLP (TOP)) | |
912 { | |
913 Lisp_Object val = Fget (TOP, Qbyte_code_meter, Qnil); | |
914 if (INTP (val)) | |
915 Fput (TOP, Qbyte_code_meter, make_int (XINT (val) + 1)); | |
916 } | |
917 #endif | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
918 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
919 TOP_LVALUE = Ffuncall (n + 1, TOP_ADDRESS); |
428 | 920 break; |
921 | |
922 case Bunbind: | |
923 case Bunbind+1: | |
924 case Bunbind+2: | |
925 case Bunbind+3: | |
926 case Bunbind+4: | |
927 case Bunbind+5: | |
928 case Bunbind+6: | |
929 case Bunbind+7: | |
930 UNBIND_TO (specpdl_depth() - | |
931 (opcode < Bunbind+6 ? opcode-Bunbind : | |
932 opcode == Bunbind+6 ? READ_UINT_1 : READ_UINT_2)); | |
933 break; | |
934 | |
935 | |
936 case Bgoto: | |
937 JUMP; | |
938 break; | |
939 | |
940 case Bgotoifnil: | |
941 if (NILP (POP)) | |
942 JUMP; | |
943 else | |
944 JUMP_NEXT; | |
945 break; | |
946 | |
947 case Bgotoifnonnil: | |
948 if (!NILP (POP)) | |
949 JUMP; | |
950 else | |
951 JUMP_NEXT; | |
952 break; | |
953 | |
954 case Bgotoifnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
955 /* Discard any multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
956 if (NILP (TOP_LVALUE = TOP)) |
428 | 957 JUMP; |
958 else | |
959 { | |
960 DISCARD (1); | |
961 JUMP_NEXT; | |
962 } | |
963 break; | |
964 | |
965 case Bgotoifnonnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
966 /* Discard any multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
967 if (!NILP (TOP_LVALUE = TOP)) |
428 | 968 JUMP; |
969 else | |
970 { | |
971 DISCARD (1); | |
972 JUMP_NEXT; | |
973 } | |
974 break; | |
975 | |
976 | |
977 case BRgoto: | |
978 JUMPR; | |
979 break; | |
980 | |
981 case BRgotoifnil: | |
982 if (NILP (POP)) | |
983 JUMPR; | |
984 else | |
985 JUMPR_NEXT; | |
986 break; | |
987 | |
988 case BRgotoifnonnil: | |
989 if (!NILP (POP)) | |
990 JUMPR; | |
991 else | |
992 JUMPR_NEXT; | |
993 break; | |
994 | |
995 case BRgotoifnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
996 if (NILP (TOP_LVALUE = TOP)) |
428 | 997 JUMPR; |
998 else | |
999 { | |
1000 DISCARD (1); | |
1001 JUMPR_NEXT; | |
1002 } | |
1003 break; | |
1004 | |
1005 case BRgotoifnonnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1006 if (!NILP (TOP_LVALUE = TOP)) |
428 | 1007 JUMPR; |
1008 else | |
1009 { | |
1010 DISCARD (1); | |
1011 JUMPR_NEXT; | |
1012 } | |
1013 break; | |
1014 | |
1015 case Breturn: | |
1016 UNGCPRO; | |
1017 #ifdef ERROR_CHECK_BYTE_CODE | |
1018 /* Binds and unbinds are supposed to be compiled balanced. */ | |
1019 if (specpdl_depth() != speccount) | |
563 | 1020 invalid_byte_code ("unbalanced specbinding stack", Qunbound); |
428 | 1021 #endif |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1022 return TOP_WITH_MULTIPLE_VALUES; |
428 | 1023 |
1024 case Bdiscard: | |
1025 DISCARD (1); | |
1026 break; | |
1027 | |
1028 case Bdup: | |
1029 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1030 Lisp_Object arg = TOP_WITH_MULTIPLE_VALUES; |
428 | 1031 PUSH (arg); |
1032 break; | |
1033 } | |
1034 | |
1035 case Bconstant2: | |
1036 PUSH (constants_data[READ_UINT_2]); | |
1037 break; | |
1038 | |
1039 case Bcar: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1040 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1041 /* Fcar can GC via wrong_type_argument. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1042 /* GCPRO_STACK; */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1043 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1044 TOP_LVALUE = CONSP (arg) ? XCAR (arg) : Fcar (arg); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1045 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1046 } |
428 | 1047 |
1048 case Bcdr: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1049 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1050 /* Fcdr can GC via wrong_type_argument. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1051 /* GCPRO_STACK; */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1052 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1053 TOP_LVALUE = CONSP (arg) ? XCDR (arg) : Fcdr (arg); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1054 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1055 } |
428 | 1056 |
1057 case Bunbind_all: | |
1058 /* To unbind back to the beginning of this frame. Not used yet, | |
1059 but will be needed for tail-recursion elimination. */ | |
771 | 1060 unbind_to (speccount); |
428 | 1061 break; |
1062 | |
1063 case Bnth: | |
1064 { | |
1065 Lisp_Object arg = POP; | |
1920 | 1066 /* Fcar and Fnthcdr can GC via wrong_type_argument. */ |
1067 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1068 TOP_LVALUE = Fcar (Fnthcdr (TOP, arg)); |
428 | 1069 break; |
1070 } | |
1071 | |
1072 case Bsymbolp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1073 TOP_LVALUE = SYMBOLP (TOP) ? Qt : Qnil; |
428 | 1074 break; |
1075 | |
1076 case Bconsp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1077 TOP_LVALUE = CONSP (TOP) ? Qt : Qnil; |
428 | 1078 break; |
1079 | |
1080 case Bstringp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1081 TOP_LVALUE = STRINGP (TOP) ? Qt : Qnil; |
428 | 1082 break; |
1083 | |
1084 case Blistp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1085 TOP_LVALUE = LISTP (TOP) ? Qt : Qnil; |
428 | 1086 break; |
1087 | |
1088 case Bnumberp: | |
1983 | 1089 #ifdef WITH_NUMBER_TYPES |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1090 TOP_LVALUE = NUMBERP (TOP) ? Qt : Qnil; |
1983 | 1091 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1092 TOP_LVALUE = INT_OR_FLOATP (TOP) ? Qt : Qnil; |
1983 | 1093 #endif |
428 | 1094 break; |
1095 | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
1096 case Bfixnump: |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1097 TOP_LVALUE = INTP (TOP) ? Qt : Qnil; |
428 | 1098 break; |
1099 | |
1100 case Beq: | |
1101 { | |
1102 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1103 TOP_LVALUE = EQ_WITH_EBOLA_NOTICE (TOP, arg) ? Qt : Qnil; |
428 | 1104 break; |
1105 } | |
1106 | |
1107 case Bnot: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1108 TOP_LVALUE = NILP (TOP) ? Qt : Qnil; |
428 | 1109 break; |
1110 | |
1111 case Bcons: | |
1112 { | |
1113 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1114 TOP_LVALUE = Fcons (TOP, arg); |
428 | 1115 break; |
1116 } | |
1117 | |
1118 case Blist1: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1119 TOP_LVALUE = Fcons (TOP, Qnil); |
428 | 1120 break; |
1121 | |
1122 | |
1123 case BlistN: | |
1124 n = READ_UINT_1; | |
1125 goto do_list; | |
1126 | |
1127 case Blist2: | |
1128 case Blist3: | |
1129 case Blist4: | |
1130 /* common case */ | |
1131 n = opcode - (Blist1 - 1); | |
1132 do_list: | |
1133 { | |
1134 Lisp_Object list = Qnil; | |
1135 list_loop: | |
1136 list = Fcons (TOP, list); | |
1137 if (--n) | |
1138 { | |
1139 DISCARD (1); | |
1140 goto list_loop; | |
1141 } | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1142 TOP_LVALUE = list; |
428 | 1143 break; |
1144 } | |
1145 | |
1146 | |
1147 case Bconcat2: | |
1148 case Bconcat3: | |
1149 case Bconcat4: | |
1150 n = opcode - (Bconcat2 - 2); | |
1151 goto do_concat; | |
1152 | |
1153 case BconcatN: | |
1154 /* common case */ | |
1155 n = READ_UINT_1; | |
1156 do_concat: | |
1157 DISCARD (n - 1); | |
1920 | 1158 /* Apparently `concat' can GC; Fconcat GCPROs its arguments. */ |
1159 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1160 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1161 TOP_LVALUE = Fconcat (n, TOP_ADDRESS); |
428 | 1162 break; |
1163 | |
1164 | |
1165 case Blength: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1166 TOP_LVALUE = Flength (TOP); |
428 | 1167 break; |
1168 | |
1169 case Baset: | |
1170 { | |
1171 Lisp_Object arg2 = POP; | |
1172 Lisp_Object arg1 = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1173 TOP_LVALUE = Faset (TOP, arg1, arg2); |
428 | 1174 break; |
1175 } | |
1176 | |
1177 case Bsymbol_value: | |
1920 | 1178 /* Why does this need GCPRO_STACK? If not, remove others, too. */ |
1884 | 1179 /* GCPRO_STACK; */ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1180 TOP_LVALUE = Fsymbol_value (TOP); |
428 | 1181 break; |
1182 | |
1183 case Bsymbol_function: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1184 TOP_LVALUE = Fsymbol_function (TOP); |
428 | 1185 break; |
1186 | |
1187 case Bget: | |
1188 { | |
1189 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1190 TOP_LVALUE = Fget (TOP, arg, Qnil); |
428 | 1191 break; |
1192 } | |
1193 | |
1194 case Bsub1: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1195 { |
1983 | 1196 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1197 TOP_LVALUE = Fsub1 (TOP); |
1983 | 1198 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1199 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1200 TOP_LVALUE = INTP (arg) ? INT_MINUS1 (arg) : Fsub1 (arg); |
1983 | 1201 #endif |
428 | 1202 break; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1203 } |
428 | 1204 case Badd1: |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1205 { |
1983 | 1206 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1207 TOP_LVALUE = Fadd1 (TOP); |
1983 | 1208 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1209 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1210 TOP_LVALUE = INTP (arg) ? INT_PLUS1 (arg) : Fadd1 (arg); |
1983 | 1211 #endif |
428 | 1212 break; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1213 } |
428 | 1214 |
1215 case Beqlsign: | |
1216 { | |
1217 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1218 TOP_LVALUE = bytecode_arithcompare (TOP, arg) == 0 ? Qt : Qnil; |
428 | 1219 break; |
1220 } | |
1221 | |
1222 case Bgtr: | |
1223 { | |
1224 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1225 TOP_LVALUE = bytecode_arithcompare (TOP, arg) > 0 ? Qt : Qnil; |
428 | 1226 break; |
1227 } | |
1228 | |
1229 case Blss: | |
1230 { | |
1231 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1232 TOP_LVALUE = bytecode_arithcompare (TOP, arg) < 0 ? Qt : Qnil; |
428 | 1233 break; |
1234 } | |
1235 | |
1236 case Bleq: | |
1237 { | |
1238 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1239 TOP_LVALUE = bytecode_arithcompare (TOP, arg) <= 0 ? Qt : Qnil; |
428 | 1240 break; |
1241 } | |
1242 | |
1243 case Bgeq: | |
1244 { | |
1245 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1246 TOP_LVALUE = bytecode_arithcompare (TOP, arg) >= 0 ? Qt : Qnil; |
428 | 1247 break; |
1248 } | |
1249 | |
1250 | |
1251 case Bnegate: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1252 TOP_LVALUE = bytecode_negate (TOP); |
428 | 1253 break; |
1254 | |
1255 case Bnconc: | |
1256 DISCARD (1); | |
1920 | 1257 /* nconc2 GCPROs before calling this. */ |
1258 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1259 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1260 TOP_LVALUE = bytecode_nconc2 (TOP_ADDRESS); |
428 | 1261 break; |
1262 | |
1263 case Bplus: | |
1264 { | |
1265 Lisp_Object arg2 = POP; | |
1266 Lisp_Object arg1 = TOP; | |
1983 | 1267 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1268 TOP_LVALUE = bytecode_arithop (arg1, arg2, opcode); |
1983 | 1269 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1270 TOP_LVALUE = INTP (arg1) && INTP (arg2) ? |
428 | 1271 INT_PLUS (arg1, arg2) : |
1272 bytecode_arithop (arg1, arg2, opcode); | |
1983 | 1273 #endif |
428 | 1274 break; |
1275 } | |
1276 | |
1277 case Bdiff: | |
1278 { | |
1279 Lisp_Object arg2 = POP; | |
1280 Lisp_Object arg1 = TOP; | |
1983 | 1281 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1282 TOP_LVALUE = bytecode_arithop (arg1, arg2, opcode); |
1983 | 1283 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1284 TOP_LVALUE = INTP (arg1) && INTP (arg2) ? |
428 | 1285 INT_MINUS (arg1, arg2) : |
1286 bytecode_arithop (arg1, arg2, opcode); | |
1983 | 1287 #endif |
428 | 1288 break; |
1289 } | |
1290 | |
1291 case Bmult: | |
1292 case Bquo: | |
1293 case Bmax: | |
1294 case Bmin: | |
1295 { | |
1296 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1297 TOP_LVALUE = bytecode_arithop (TOP, arg, opcode); |
428 | 1298 break; |
1299 } | |
1300 | |
1301 case Bpoint: | |
1302 PUSH (make_int (BUF_PT (current_buffer))); | |
1303 break; | |
1304 | |
1305 case Binsert: | |
1920 | 1306 /* Says it can GC. */ |
1307 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1308 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1309 TOP_LVALUE = Finsert (1, TOP_ADDRESS); |
428 | 1310 break; |
1311 | |
1312 case BinsertN: | |
1313 n = READ_UINT_1; | |
1314 DISCARD (n - 1); | |
1920 | 1315 /* See Binsert. */ |
1316 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1317 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1318 TOP_LVALUE = Finsert (n, TOP_ADDRESS); |
428 | 1319 break; |
1320 | |
1321 case Baref: | |
1322 { | |
1323 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1324 TOP_LVALUE = Faref (TOP, arg); |
428 | 1325 break; |
1326 } | |
1327 | |
1328 case Bmemq: | |
1329 { | |
1330 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1331 TOP_LVALUE = Fmemq (TOP, arg); |
428 | 1332 break; |
1333 } | |
1334 | |
1335 case Bset: | |
1336 { | |
1337 Lisp_Object arg = POP; | |
1884 | 1338 /* Fset may call magic handlers */ |
1339 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1340 TOP_LVALUE = Fset (TOP, arg); |
428 | 1341 break; |
1342 } | |
1343 | |
1344 case Bequal: | |
1345 { | |
1346 Lisp_Object arg = POP; | |
1920 | 1347 /* Can QUIT, so can GC, right? */ |
1348 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1349 TOP_LVALUE = Fequal (TOP, arg); |
428 | 1350 break; |
1351 } | |
1352 | |
1353 case Bnthcdr: | |
1354 { | |
1355 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1356 TOP_LVALUE = Fnthcdr (TOP, arg); |
428 | 1357 break; |
1358 } | |
1359 | |
1360 case Belt: | |
1361 { | |
1362 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1363 TOP_LVALUE = Felt (TOP, arg); |
428 | 1364 break; |
1365 } | |
1366 | |
1367 case Bmember: | |
1368 { | |
1369 Lisp_Object arg = POP; | |
1920 | 1370 /* Can QUIT, so can GC, right? */ |
1371 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1372 TOP_LVALUE = Fmember (TOP, arg); |
428 | 1373 break; |
1374 } | |
1375 | |
1376 case Bgoto_char: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1377 TOP_LVALUE = Fgoto_char (TOP, Qnil); |
428 | 1378 break; |
1379 | |
1380 case Bcurrent_buffer: | |
1381 { | |
793 | 1382 Lisp_Object buffer = wrap_buffer (current_buffer); |
1383 | |
428 | 1384 PUSH (buffer); |
1385 break; | |
1386 } | |
1387 | |
1388 case Bset_buffer: | |
1884 | 1389 /* #### WAG: set-buffer may cause Fset's of buffer locals |
1390 Didn't prevent crash. :-( */ | |
1391 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1392 TOP_LVALUE = Fset_buffer (TOP); |
428 | 1393 break; |
1394 | |
1395 case Bpoint_max: | |
1396 PUSH (make_int (BUF_ZV (current_buffer))); | |
1397 break; | |
1398 | |
1399 case Bpoint_min: | |
1400 PUSH (make_int (BUF_BEGV (current_buffer))); | |
1401 break; | |
1402 | |
1403 case Bskip_chars_forward: | |
1404 { | |
1405 Lisp_Object arg = POP; | |
1920 | 1406 /* Can QUIT, so can GC, right? */ |
1407 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1408 TOP_LVALUE = Fskip_chars_forward (TOP, arg, Qnil); |
428 | 1409 break; |
1410 } | |
1411 | |
1412 case Bassq: | |
1413 { | |
1414 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1415 TOP_LVALUE = Fassq (TOP, arg); |
428 | 1416 break; |
1417 } | |
1418 | |
1419 case Bsetcar: | |
1420 { | |
1421 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1422 TOP_LVALUE = Fsetcar (TOP, arg); |
428 | 1423 break; |
1424 } | |
1425 | |
1426 case Bsetcdr: | |
1427 { | |
1428 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1429 TOP_LVALUE = Fsetcdr (TOP, arg); |
428 | 1430 break; |
1431 } | |
1432 | |
1433 case Bnreverse: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1434 TOP_LVALUE = bytecode_nreverse (TOP); |
428 | 1435 break; |
1436 | |
1437 case Bcar_safe: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1438 TOP_LVALUE = CONSP (TOP) ? XCAR (TOP) : Qnil; |
428 | 1439 break; |
1440 | |
1441 case Bcdr_safe: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1442 TOP_LVALUE = CONSP (TOP) ? XCDR (TOP) : Qnil; |
428 | 1443 break; |
1444 | |
1445 } | |
1446 } | |
1447 } | |
1448 | |
1449 /* It makes a worthwhile performance difference (5%) to shunt | |
1450 lesser-used opcodes off to a subroutine, to keep the switch in | |
1451 execute_optimized_program small. If you REALLY care about | |
1452 performance, you want to keep your heavily executed code away from | |
1453 rarely executed code, to minimize cache misses. | |
1454 | |
1455 Don't make this function static, since then the compiler might inline it. */ | |
1456 Lisp_Object * | |
1457 execute_rare_opcode (Lisp_Object *stack_ptr, | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1458 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1459 Lisp_Object *stack_beg, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1460 Lisp_Object *stack_end, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1461 #endif /* ERROR_CHECK_BYTE_CODE */ |
2286 | 1462 const Opbyte *UNUSED (program_ptr), |
428 | 1463 Opcode opcode) |
1464 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1465 REGISTER int n; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1466 |
428 | 1467 switch (opcode) |
1468 { | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1469 |
428 | 1470 case Bsave_excursion: |
1471 record_unwind_protect (save_excursion_restore, | |
1472 save_excursion_save ()); | |
1473 break; | |
1474 | |
4775
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1475 /* This bytecode will eventually go away, once we no longer encounter |
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1476 byte code from 21.4. In 21.5.10 and newer, save-window-excursion is |
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1477 a macro. */ |
428 | 1478 case Bsave_window_excursion: |
1479 { | |
1480 int count = specpdl_depth (); | |
4775
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1481 record_unwind_protect (Feval, |
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1482 list2 (Qset_window_configuration, |
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4717
diff
changeset
|
1483 call0 (Qcurrent_window_configuration))); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1484 TOP_LVALUE = Fprogn (TOP); |
771 | 1485 unbind_to (count); |
428 | 1486 break; |
1487 } | |
1488 | |
1489 case Bsave_restriction: | |
1490 record_unwind_protect (save_restriction_restore, | |
844 | 1491 save_restriction_save (current_buffer)); |
428 | 1492 break; |
1493 | |
1494 case Bcatch: | |
1495 { | |
1496 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1497 TOP_LVALUE = internal_catch (TOP, Feval, arg, 0, 0, 0); |
428 | 1498 break; |
1499 } | |
1500 | |
1501 case Bskip_chars_backward: | |
1502 { | |
1503 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1504 TOP_LVALUE = Fskip_chars_backward (TOP, arg, Qnil); |
428 | 1505 break; |
1506 } | |
1507 | |
1508 case Bunwind_protect: | |
1509 record_unwind_protect (Fprogn, POP); | |
1510 break; | |
1511 | |
1512 case Bcondition_case: | |
1513 { | |
1514 Lisp_Object arg2 = POP; /* handlers */ | |
1515 Lisp_Object arg1 = POP; /* bodyform */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1516 TOP_LVALUE = condition_case_3 (arg1, TOP, arg2); |
428 | 1517 break; |
1518 } | |
1519 | |
1520 case Bset_marker: | |
1521 { | |
1522 Lisp_Object arg2 = POP; | |
1523 Lisp_Object arg1 = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1524 TOP_LVALUE = Fset_marker (TOP, arg1, arg2); |
428 | 1525 break; |
1526 } | |
1527 | |
1528 case Brem: | |
1529 { | |
1530 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1531 TOP_LVALUE = Frem (TOP, arg); |
428 | 1532 break; |
1533 } | |
1534 | |
1535 case Bmatch_beginning: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1536 TOP_LVALUE = Fmatch_beginning (TOP); |
428 | 1537 break; |
1538 | |
1539 case Bmatch_end: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1540 TOP_LVALUE = Fmatch_end (TOP); |
428 | 1541 break; |
1542 | |
1543 case Bupcase: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1544 TOP_LVALUE = Fupcase (TOP, Qnil); |
428 | 1545 break; |
1546 | |
1547 case Bdowncase: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1548 TOP_LVALUE = Fdowncase (TOP, Qnil); |
428 | 1549 break; |
1550 | |
1551 case Bfset: | |
1552 { | |
1553 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1554 TOP_LVALUE = Ffset (TOP, arg); |
428 | 1555 break; |
1556 } | |
1557 | |
1558 case Bstring_equal: | |
1559 { | |
1560 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1561 TOP_LVALUE = Fstring_equal (TOP, arg); |
428 | 1562 break; |
1563 } | |
1564 | |
1565 case Bstring_lessp: | |
1566 { | |
1567 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1568 TOP_LVALUE = Fstring_lessp (TOP, arg); |
428 | 1569 break; |
1570 } | |
1571 | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4974
diff
changeset
|
1572 case Bsubseq: |
428 | 1573 { |
1574 Lisp_Object arg2 = POP; | |
1575 Lisp_Object arg1 = POP; | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4974
diff
changeset
|
1576 TOP_LVALUE = Fsubseq (TOP, arg1, arg2); |
428 | 1577 break; |
1578 } | |
1579 | |
1580 case Bcurrent_column: | |
1581 PUSH (make_int (current_column (current_buffer))); | |
1582 break; | |
1583 | |
1584 case Bchar_after: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1585 TOP_LVALUE = Fchar_after (TOP, Qnil); |
428 | 1586 break; |
1587 | |
1588 case Bindent_to: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1589 TOP_LVALUE = Findent_to (TOP, Qnil, Qnil); |
428 | 1590 break; |
1591 | |
1592 case Bwiden: | |
1593 PUSH (Fwiden (Qnil)); | |
1594 break; | |
1595 | |
1596 case Bfollowing_char: | |
1597 PUSH (Ffollowing_char (Qnil)); | |
1598 break; | |
1599 | |
1600 case Bpreceding_char: | |
1601 PUSH (Fpreceding_char (Qnil)); | |
1602 break; | |
1603 | |
1604 case Beolp: | |
1605 PUSH (Feolp (Qnil)); | |
1606 break; | |
1607 | |
1608 case Beobp: | |
1609 PUSH (Feobp (Qnil)); | |
1610 break; | |
1611 | |
1612 case Bbolp: | |
1613 PUSH (Fbolp (Qnil)); | |
1614 break; | |
1615 | |
1616 case Bbobp: | |
1617 PUSH (Fbobp (Qnil)); | |
1618 break; | |
1619 | |
1620 case Bsave_current_buffer: | |
1621 record_unwind_protect (save_current_buffer_restore, | |
1622 Fcurrent_buffer ()); | |
1623 break; | |
1624 | |
1625 case Binteractive_p: | |
1626 PUSH (Finteractive_p ()); | |
1627 break; | |
1628 | |
1629 case Bforward_char: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1630 TOP_LVALUE = Fforward_char (TOP, Qnil); |
428 | 1631 break; |
1632 | |
1633 case Bforward_word: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1634 TOP_LVALUE = Fforward_word (TOP, Qnil); |
428 | 1635 break; |
1636 | |
1637 case Bforward_line: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1638 TOP_LVALUE = Fforward_line (TOP, Qnil); |
428 | 1639 break; |
1640 | |
1641 case Bchar_syntax: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1642 TOP_LVALUE = Fchar_syntax (TOP, Qnil); |
428 | 1643 break; |
1644 | |
1645 case Bbuffer_substring: | |
1646 { | |
1647 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1648 TOP_LVALUE = Fbuffer_substring (TOP, arg, Qnil); |
428 | 1649 break; |
1650 } | |
1651 | |
1652 case Bdelete_region: | |
1653 { | |
1654 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1655 TOP_LVALUE = Fdelete_region (TOP, arg, Qnil); |
428 | 1656 break; |
1657 } | |
1658 | |
1659 case Bnarrow_to_region: | |
1660 { | |
1661 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1662 TOP_LVALUE = Fnarrow_to_region (TOP, arg, Qnil); |
428 | 1663 break; |
1664 } | |
1665 | |
1666 case Bend_of_line: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1667 TOP_LVALUE = Fend_of_line (TOP, Qnil); |
428 | 1668 break; |
1669 | |
1670 case Btemp_output_buffer_setup: | |
1671 temp_output_buffer_setup (TOP); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1672 TOP_LVALUE = Vstandard_output; |
428 | 1673 break; |
1674 | |
1675 case Btemp_output_buffer_show: | |
1676 { | |
1677 Lisp_Object arg = POP; | |
1678 temp_output_buffer_show (TOP, Qnil); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1679 TOP_LVALUE = arg; |
428 | 1680 /* GAG ME!! */ |
1681 /* pop binding of standard-output */ | |
771 | 1682 unbind_to (specpdl_depth() - 1); |
428 | 1683 break; |
1684 } | |
1685 | |
1686 case Bold_eq: | |
1687 { | |
1688 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1689 TOP_LVALUE = HACKEQ_UNSAFE (TOP, arg) ? Qt : Qnil; |
428 | 1690 break; |
1691 } | |
1692 | |
1693 case Bold_memq: | |
1694 { | |
1695 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1696 TOP_LVALUE = Fold_memq (TOP, arg); |
428 | 1697 break; |
1698 } | |
1699 | |
1700 case Bold_equal: | |
1701 { | |
1702 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1703 TOP_LVALUE = Fold_equal (TOP, arg); |
428 | 1704 break; |
1705 } | |
1706 | |
1707 case Bold_member: | |
1708 { | |
1709 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1710 TOP_LVALUE = Fold_member (TOP, arg); |
428 | 1711 break; |
1712 } | |
1713 | |
1714 case Bold_assq: | |
1715 { | |
1716 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1717 TOP_LVALUE = Fold_assq (TOP, arg); |
428 | 1718 break; |
1719 } | |
1720 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1721 case Bbind_multiple_value_limits: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1722 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1723 Lisp_Object upper = POP, first = TOP, speccount; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1724 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1725 CHECK_NATNUM (upper); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1726 CHECK_NATNUM (first); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1727 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1728 speccount = make_int (bind_multiple_value_limits (XINT (first), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1729 XINT (upper))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1730 PUSH (upper); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1731 PUSH (speccount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1732 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1733 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1734 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1735 case Bmultiple_value_call: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1736 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1737 n = XINT (POP); |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1738 DISCARD_PRESERVING_MULTIPLE_VALUES_UNSAFE (n - 1); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1739 /* Discard multiple values for the first (function) argument: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1740 TOP_LVALUE = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1741 TOP_LVALUE = multiple_value_call (n, TOP_ADDRESS); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1742 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1743 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1744 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1745 case Bmultiple_value_list_internal: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1746 { |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1747 DISCARD_PRESERVING_MULTIPLE_VALUES_UNSAFE (3); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1748 TOP_LVALUE = multiple_value_list_internal (4, TOP_ADDRESS); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1749 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1750 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1751 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1752 case Bthrow: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1753 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1754 Lisp_Object arg = POP_WITH_MULTIPLE_VALUES; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1755 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1756 /* We never throw to a catch tag that is a multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1757 throw_or_bomb_out (TOP, arg, 0, Qnil, Qnil); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1758 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1759 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1760 |
428 | 1761 default: |
4914
1628e3b9601a
When aborting due to unknown opcode, output more descriptive msg
Ben Wing <ben@xemacs.org>
parents:
4910
diff
changeset
|
1762 { |
1628e3b9601a
When aborting due to unknown opcode, output more descriptive msg
Ben Wing <ben@xemacs.org>
parents:
4910
diff
changeset
|
1763 Ascbyte msg[100]; |
1628e3b9601a
When aborting due to unknown opcode, output more descriptive msg
Ben Wing <ben@xemacs.org>
parents:
4910
diff
changeset
|
1764 sprintf (msg, "Unknown opcode %d", opcode); |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1765 bytecode_abort_with_message (msg); |
4914
1628e3b9601a
When aborting due to unknown opcode, output more descriptive msg
Ben Wing <ben@xemacs.org>
parents:
4910
diff
changeset
|
1766 } |
428 | 1767 break; |
1768 } | |
1769 return stack_ptr; | |
1770 } | |
1771 | |
1772 | |
563 | 1773 DOESNT_RETURN |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4775
diff
changeset
|
1774 invalid_byte_code (const Ascbyte *reason, Lisp_Object frob) |
428 | 1775 { |
563 | 1776 signal_error (Qinvalid_byte_code, reason, frob); |
428 | 1777 } |
1778 | |
1779 /* Check for valid opcodes. Change this when adding new opcodes. */ | |
1780 static void | |
1781 check_opcode (Opcode opcode) | |
1782 { | |
1783 if ((opcode < Bvarref) || | |
1784 (opcode == 0251) || | |
1785 (opcode > Bassq && opcode < Bconstant)) | |
563 | 1786 invalid_byte_code ("invalid opcode in instruction stream", |
1787 make_int (opcode)); | |
428 | 1788 } |
1789 | |
1790 /* Check that IDX is a valid offset into the `constants' vector */ | |
1791 static void | |
1792 check_constants_index (int idx, Lisp_Object constants) | |
1793 { | |
1794 if (idx < 0 || idx >= XVECTOR_LENGTH (constants)) | |
563 | 1795 signal_ferror |
1796 (Qinvalid_byte_code, | |
1797 "reference %d to constants array out of range 0, %ld", | |
428 | 1798 idx, XVECTOR_LENGTH (constants) - 1); |
1799 } | |
1800 | |
1801 /* Get next character from Lisp instructions string. */ | |
563 | 1802 #define READ_INSTRUCTION_CHAR(lvalue) do { \ |
867 | 1803 (lvalue) = itext_ichar (ptr); \ |
1804 INC_IBYTEPTR (ptr); \ | |
563 | 1805 *icounts_ptr++ = program_ptr - program; \ |
1806 if (lvalue > UCHAR_MAX) \ | |
1807 invalid_byte_code \ | |
1808 ("Invalid character in byte code string", make_char (lvalue)); \ | |
428 | 1809 } while (0) |
1810 | |
1811 /* Get opcode from Lisp instructions string. */ | |
1812 #define READ_OPCODE do { \ | |
1813 unsigned int c; \ | |
1814 READ_INSTRUCTION_CHAR (c); \ | |
1815 opcode = (Opcode) c; \ | |
1816 } while (0) | |
1817 | |
1818 /* Get next operand, a uint8, from Lisp instructions string. */ | |
1819 #define READ_OPERAND_1 do { \ | |
1820 READ_INSTRUCTION_CHAR (arg); \ | |
1821 argsize = 1; \ | |
1822 } while (0) | |
1823 | |
1824 /* Get next operand, a uint16, from Lisp instructions string. */ | |
1825 #define READ_OPERAND_2 do { \ | |
1826 unsigned int arg1, arg2; \ | |
1827 READ_INSTRUCTION_CHAR (arg1); \ | |
1828 READ_INSTRUCTION_CHAR (arg2); \ | |
1829 arg = arg1 + (arg2 << 8); \ | |
1830 argsize = 2; \ | |
1831 } while (0) | |
1832 | |
1833 /* Write 1 byte to PTR, incrementing PTR */ | |
1834 #define WRITE_INT8(value, ptr) do { \ | |
1835 *((ptr)++) = (value); \ | |
1836 } while (0) | |
1837 | |
1838 /* Write 2 bytes to PTR, incrementing PTR */ | |
1839 #define WRITE_INT16(value, ptr) do { \ | |
1840 WRITE_INT8 (((unsigned) (value)) & 0x00ff, (ptr)); \ | |
1841 WRITE_INT8 (((unsigned) (value)) >> 8 , (ptr)); \ | |
1842 } while (0) | |
1843 | |
1844 /* We've changed our minds about the opcode we've already written. */ | |
1845 #define REWRITE_OPCODE(new_opcode) ((void) (program_ptr[-1] = new_opcode)) | |
1846 | |
1847 /* Encode an op arg within the opcode, or as a 1 or 2-byte operand. */ | |
1848 #define WRITE_NARGS(base_opcode) do { \ | |
1849 if (arg <= 5) \ | |
1850 { \ | |
1851 REWRITE_OPCODE (base_opcode + arg); \ | |
1852 } \ | |
1853 else if (arg <= UCHAR_MAX) \ | |
1854 { \ | |
1855 REWRITE_OPCODE (base_opcode + 6); \ | |
1856 WRITE_INT8 (arg, program_ptr); \ | |
1857 } \ | |
1858 else \ | |
1859 { \ | |
1860 REWRITE_OPCODE (base_opcode + 7); \ | |
1861 WRITE_INT16 (arg, program_ptr); \ | |
1862 } \ | |
1863 } while (0) | |
1864 | |
1865 /* Encode a constants reference within the opcode, or as a 2-byte operand. */ | |
1866 #define WRITE_CONSTANT do { \ | |
1867 check_constants_index(arg, constants); \ | |
1868 if (arg <= UCHAR_MAX - Bconstant) \ | |
1869 { \ | |
1870 REWRITE_OPCODE (Bconstant + arg); \ | |
1871 } \ | |
1872 else \ | |
1873 { \ | |
1874 REWRITE_OPCODE (Bconstant2); \ | |
1875 WRITE_INT16 (arg, program_ptr); \ | |
1876 } \ | |
1877 } while (0) | |
1878 | |
1879 #define WRITE_OPCODE WRITE_INT8 (opcode, program_ptr) | |
1880 | |
1881 /* Compile byte code instructions into free space provided by caller, with | |
1882 size >= (2 * string_char_length (instructions) + 1) * sizeof (Opbyte). | |
1883 Returns length of compiled code. */ | |
1884 static void | |
1885 optimize_byte_code (/* in */ | |
1886 Lisp_Object instructions, | |
1887 Lisp_Object constants, | |
1888 /* out */ | |
442 | 1889 Opbyte * const program, |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1890 Elemcount * const program_length, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
1891 Elemcount * const varbind_count) |
428 | 1892 { |
647 | 1893 Bytecount instructions_length = XSTRING_LENGTH (instructions); |
665 | 1894 Elemcount comfy_size = (Elemcount) (2 * instructions_length); |
428 | 1895 |
442 | 1896 int * const icounts = alloca_array (int, comfy_size); |
428 | 1897 int * icounts_ptr = icounts; |
1898 | |
1899 /* We maintain a table of jumps in the source code. */ | |
1900 struct jump | |
1901 { | |
1902 int from; | |
1903 int to; | |
1904 }; | |
442 | 1905 struct jump * const jumps = alloca_array (struct jump, comfy_size); |
428 | 1906 struct jump *jumps_ptr = jumps; |
1907 | |
1908 Opbyte *program_ptr = program; | |
1909 | |
867 | 1910 const Ibyte *ptr = XSTRING_DATA (instructions); |
1911 const Ibyte * const end = ptr + instructions_length; | |
428 | 1912 |
1913 *varbind_count = 0; | |
1914 | |
1915 while (ptr < end) | |
1916 { | |
1917 Opcode opcode; | |
1918 int arg; | |
1919 int argsize = 0; | |
1920 READ_OPCODE; | |
1921 WRITE_OPCODE; | |
1922 | |
1923 switch (opcode) | |
1924 { | |
1925 Lisp_Object val; | |
1926 | |
1927 case Bvarref+7: READ_OPERAND_2; goto do_varref; | |
1928 case Bvarref+6: READ_OPERAND_1; goto do_varref; | |
1929 case Bvarref: case Bvarref+1: case Bvarref+2: | |
1930 case Bvarref+3: case Bvarref+4: case Bvarref+5: | |
1931 arg = opcode - Bvarref; | |
1932 do_varref: | |
1933 check_constants_index (arg, constants); | |
1934 val = XVECTOR_DATA (constants) [arg]; | |
1935 if (!SYMBOLP (val)) | |
563 | 1936 invalid_byte_code ("variable reference to non-symbol", val); |
428 | 1937 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val))) |
563 | 1938 invalid_byte_code ("variable reference to constant symbol", val); |
428 | 1939 WRITE_NARGS (Bvarref); |
1940 break; | |
1941 | |
1942 case Bvarset+7: READ_OPERAND_2; goto do_varset; | |
1943 case Bvarset+6: READ_OPERAND_1; goto do_varset; | |
1944 case Bvarset: case Bvarset+1: case Bvarset+2: | |
1945 case Bvarset+3: case Bvarset+4: case Bvarset+5: | |
1946 arg = opcode - Bvarset; | |
1947 do_varset: | |
1948 check_constants_index (arg, constants); | |
1949 val = XVECTOR_DATA (constants) [arg]; | |
1950 if (!SYMBOLP (val)) | |
563 | 1951 wtaerror ("attempt to set non-symbol", val); |
428 | 1952 if (EQ (val, Qnil) || EQ (val, Qt)) |
563 | 1953 signal_error (Qsetting_constant, 0, val); |
428 | 1954 /* Ignore assignments to keywords by converting to Bdiscard. |
1955 For backward compatibility only - we'd like to make this an error. */ | |
1956 if (SYMBOL_IS_KEYWORD (val)) | |
1957 REWRITE_OPCODE (Bdiscard); | |
1958 else | |
1959 WRITE_NARGS (Bvarset); | |
1960 break; | |
1961 | |
1962 case Bvarbind+7: READ_OPERAND_2; goto do_varbind; | |
1963 case Bvarbind+6: READ_OPERAND_1; goto do_varbind; | |
1964 case Bvarbind: case Bvarbind+1: case Bvarbind+2: | |
1965 case Bvarbind+3: case Bvarbind+4: case Bvarbind+5: | |
1966 arg = opcode - Bvarbind; | |
1967 do_varbind: | |
1968 (*varbind_count)++; | |
1969 check_constants_index (arg, constants); | |
1970 val = XVECTOR_DATA (constants) [arg]; | |
1971 if (!SYMBOLP (val)) | |
563 | 1972 wtaerror ("attempt to let-bind non-symbol", val); |
428 | 1973 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val))) |
563 | 1974 signal_error (Qsetting_constant, |
1975 "attempt to let-bind constant symbol", val); | |
428 | 1976 WRITE_NARGS (Bvarbind); |
1977 break; | |
1978 | |
1979 case Bcall+7: READ_OPERAND_2; goto do_call; | |
1980 case Bcall+6: READ_OPERAND_1; goto do_call; | |
1981 case Bcall: case Bcall+1: case Bcall+2: | |
1982 case Bcall+3: case Bcall+4: case Bcall+5: | |
1983 arg = opcode - Bcall; | |
1984 do_call: | |
1985 WRITE_NARGS (Bcall); | |
1986 break; | |
1987 | |
1988 case Bunbind+7: READ_OPERAND_2; goto do_unbind; | |
1989 case Bunbind+6: READ_OPERAND_1; goto do_unbind; | |
1990 case Bunbind: case Bunbind+1: case Bunbind+2: | |
1991 case Bunbind+3: case Bunbind+4: case Bunbind+5: | |
1992 arg = opcode - Bunbind; | |
1993 do_unbind: | |
1994 WRITE_NARGS (Bunbind); | |
1995 break; | |
1996 | |
1997 case Bgoto: | |
1998 case Bgotoifnil: | |
1999 case Bgotoifnonnil: | |
2000 case Bgotoifnilelsepop: | |
2001 case Bgotoifnonnilelsepop: | |
2002 READ_OPERAND_2; | |
2003 /* Make program_ptr-relative */ | |
2004 arg += icounts - (icounts_ptr - argsize); | |
2005 goto do_jump; | |
2006 | |
2007 case BRgoto: | |
2008 case BRgotoifnil: | |
2009 case BRgotoifnonnil: | |
2010 case BRgotoifnilelsepop: | |
2011 case BRgotoifnonnilelsepop: | |
2012 READ_OPERAND_1; | |
2013 /* Make program_ptr-relative */ | |
2014 arg -= 127; | |
2015 do_jump: | |
2016 /* Record program-relative goto addresses in `jumps' table */ | |
2017 jumps_ptr->from = icounts_ptr - icounts - argsize; | |
2018 jumps_ptr->to = jumps_ptr->from + arg; | |
2019 jumps_ptr++; | |
2020 if (arg >= -1 && arg <= argsize) | |
563 | 2021 invalid_byte_code ("goto instruction is its own target", Qunbound); |
428 | 2022 if (arg <= SCHAR_MIN || |
2023 arg > SCHAR_MAX) | |
2024 { | |
2025 if (argsize == 1) | |
2026 REWRITE_OPCODE (opcode + Bgoto - BRgoto); | |
2027 WRITE_INT16 (arg, program_ptr); | |
2028 } | |
2029 else | |
2030 { | |
2031 if (argsize == 2) | |
2032 REWRITE_OPCODE (opcode + BRgoto - Bgoto); | |
2033 WRITE_INT8 (arg, program_ptr); | |
2034 } | |
2035 break; | |
2036 | |
2037 case Bconstant2: | |
2038 READ_OPERAND_2; | |
2039 WRITE_CONSTANT; | |
2040 break; | |
2041 | |
2042 case BlistN: | |
2043 case BconcatN: | |
2044 case BinsertN: | |
2045 READ_OPERAND_1; | |
2046 WRITE_INT8 (arg, program_ptr); | |
2047 break; | |
2048 | |
2049 default: | |
2050 if (opcode < Bconstant) | |
2051 check_opcode (opcode); | |
2052 else | |
2053 { | |
2054 arg = opcode - Bconstant; | |
2055 WRITE_CONSTANT; | |
2056 } | |
2057 break; | |
2058 } | |
2059 } | |
2060 | |
2061 /* Fix up jumps table to refer to NEW offsets. */ | |
2062 { | |
2063 struct jump *j; | |
2064 for (j = jumps; j < jumps_ptr; j++) | |
2065 { | |
2066 #ifdef ERROR_CHECK_BYTE_CODE | |
2067 assert (j->from < icounts_ptr - icounts); | |
2068 assert (j->to < icounts_ptr - icounts); | |
2069 #endif | |
2070 j->from = icounts[j->from]; | |
2071 j->to = icounts[j->to]; | |
2072 #ifdef ERROR_CHECK_BYTE_CODE | |
2073 assert (j->from < program_ptr - program); | |
2074 assert (j->to < program_ptr - program); | |
2075 check_opcode ((Opcode) (program[j->from-1])); | |
2076 #endif | |
2077 check_opcode ((Opcode) (program[j->to])); | |
2078 } | |
2079 } | |
2080 | |
2081 /* Fixup jumps in byte-code until no more fixups needed */ | |
2082 { | |
2083 int more_fixups_needed = 1; | |
2084 | |
2085 while (more_fixups_needed) | |
2086 { | |
2087 struct jump *j; | |
2088 more_fixups_needed = 0; | |
2089 for (j = jumps; j < jumps_ptr; j++) | |
2090 { | |
2091 int from = j->from; | |
2092 int to = j->to; | |
2093 int jump = to - from; | |
2094 Opbyte *p = program + from; | |
2095 Opcode opcode = (Opcode) p[-1]; | |
2096 if (!more_fixups_needed) | |
2097 check_opcode ((Opcode) p[jump]); | |
2098 assert (to >= 0 && program + to < program_ptr); | |
2099 switch (opcode) | |
2100 { | |
2101 case Bgoto: | |
2102 case Bgotoifnil: | |
2103 case Bgotoifnonnil: | |
2104 case Bgotoifnilelsepop: | |
2105 case Bgotoifnonnilelsepop: | |
2106 WRITE_INT16 (jump, p); | |
2107 break; | |
2108 | |
2109 case BRgoto: | |
2110 case BRgotoifnil: | |
2111 case BRgotoifnonnil: | |
2112 case BRgotoifnilelsepop: | |
2113 case BRgotoifnonnilelsepop: | |
2114 if (jump > SCHAR_MIN && | |
2115 jump <= SCHAR_MAX) | |
2116 { | |
2117 WRITE_INT8 (jump, p); | |
2118 } | |
2119 else /* barf */ | |
2120 { | |
2121 struct jump *jj; | |
2122 for (jj = jumps; jj < jumps_ptr; jj++) | |
2123 { | |
2124 assert (jj->from < program_ptr - program); | |
2125 assert (jj->to < program_ptr - program); | |
2126 if (jj->from > from) jj->from++; | |
2127 if (jj->to > from) jj->to++; | |
2128 } | |
2129 p[-1] += Bgoto - BRgoto; | |
2130 more_fixups_needed = 1; | |
2131 memmove (p+1, p, program_ptr++ - p); | |
2132 WRITE_INT16 (jump, p); | |
2133 } | |
2134 break; | |
2135 | |
2136 default: | |
2500 | 2137 ABORT(); |
428 | 2138 break; |
2139 } | |
2140 } | |
2141 } | |
2142 } | |
2143 | |
2144 /* *program_ptr++ = 0; */ | |
2145 *program_length = program_ptr - program; | |
2146 } | |
2147 | |
2148 /* Optimize the byte code and store the optimized program, only | |
2149 understood by bytecode.c, in an opaque object in the | |
2150 instructions slot of the Compiled_Function object. */ | |
2151 void | |
2152 optimize_compiled_function (Lisp_Object compiled_function) | |
2153 { | |
2154 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (compiled_function); | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2155 Elemcount program_length; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2156 Elemcount varbind_count; |
428 | 2157 Opbyte *program; |
2158 | |
1737 | 2159 { |
2160 int minargs = 0, maxargs = 0, totalargs = 0; | |
2161 int optional_p = 0, rest_p = 0, i = 0; | |
2162 { | |
2163 LIST_LOOP_2 (arg, f->arglist) | |
2164 { | |
2165 if (EQ (arg, Qand_optional)) | |
2166 optional_p = 1; | |
2167 else if (EQ (arg, Qand_rest)) | |
2168 rest_p = 1; | |
2169 else | |
2170 { | |
2171 if (rest_p) | |
2172 { | |
2173 maxargs = MANY; | |
2174 totalargs++; | |
2175 break; | |
2176 } | |
2177 if (!optional_p) | |
2178 minargs++; | |
2179 maxargs++; | |
2180 totalargs++; | |
2181 } | |
2182 } | |
2183 } | |
2184 | |
2185 if (totalargs) | |
3092 | 2186 #ifdef NEW_GC |
2187 f->arguments = make_compiled_function_args (totalargs); | |
2188 #else /* not NEW_GC */ | |
1737 | 2189 f->args = xnew_array (Lisp_Object, totalargs); |
3092 | 2190 #endif /* not NEW_GC */ |
1737 | 2191 |
2192 { | |
2193 LIST_LOOP_2 (arg, f->arglist) | |
2194 { | |
2195 if (!EQ (arg, Qand_optional) && !EQ (arg, Qand_rest)) | |
3092 | 2196 #ifdef NEW_GC |
2197 XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i++] = arg; | |
2198 #else /* not NEW_GC */ | |
1737 | 2199 f->args[i++] = arg; |
3092 | 2200 #endif /* not NEW_GC */ |
1737 | 2201 } |
2202 } | |
2203 | |
2204 f->max_args = maxargs; | |
2205 f->min_args = minargs; | |
2206 f->args_in_array = totalargs; | |
2207 } | |
2208 | |
428 | 2209 /* If we have not actually read the bytecode string |
2210 and constants vector yet, fetch them from the file. */ | |
2211 if (CONSP (f->instructions)) | |
2212 Ffetch_bytecode (compiled_function); | |
2213 | |
2214 if (STRINGP (f->instructions)) | |
2215 { | |
826 | 2216 /* XSTRING_LENGTH() is more efficient than string_char_length(), |
428 | 2217 which would be slightly more `proper' */ |
2218 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (f->instructions)); | |
2219 optimize_byte_code (f->instructions, f->constants, | |
2220 program, &program_length, &varbind_count); | |
2500 | 2221 f->specpdl_depth = (unsigned short) (XINT (Flength (f->arglist)) + |
2222 varbind_count); | |
428 | 2223 f->instructions = |
440 | 2224 make_opaque (program, program_length * sizeof (Opbyte)); |
428 | 2225 } |
2226 | |
2227 assert (OPAQUEP (f->instructions)); | |
2228 } | |
2229 | |
2230 /************************************************************************/ | |
2231 /* The compiled-function object type */ | |
2232 /************************************************************************/ | |
3092 | 2233 |
428 | 2234 static void |
2235 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun, | |
2236 int escapeflag) | |
2237 { | |
2238 /* This function can GC */ | |
2239 Lisp_Compiled_Function *f = | |
2240 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */ | |
2241 int docp = f->flags.documentationp; | |
2242 int intp = f->flags.interactivep; | |
2243 struct gcpro gcpro1, gcpro2; | |
2244 GCPRO2 (obj, printcharfun); | |
2245 | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2246 write_ascstring (printcharfun, print_readably ? "#[" : |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2247 "#<compiled-function "); |
428 | 2248 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK |
2249 if (!print_readably) | |
2250 { | |
2251 Lisp_Object ann = compiled_function_annotation (f); | |
2252 if (!NILP (ann)) | |
800 | 2253 write_fmt_string_lisp (printcharfun, "(from %S) ", 1, ann); |
428 | 2254 } |
2255 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ | |
2256 /* COMPILED_ARGLIST = 0 */ | |
2257 print_internal (compiled_function_arglist (f), printcharfun, escapeflag); | |
2258 | |
2259 /* COMPILED_INSTRUCTIONS = 1 */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4775
diff
changeset
|
2260 write_ascstring (printcharfun, " "); |
428 | 2261 { |
2262 struct gcpro ngcpro1; | |
2263 Lisp_Object instructions = compiled_function_instructions (f); | |
2264 NGCPRO1 (instructions); | |
2265 if (STRINGP (instructions) && !print_readably) | |
2266 { | |
2267 /* We don't usually want to see that junk in the bytecode. */ | |
800 | 2268 write_fmt_string (printcharfun, "\"...(%ld)\"", |
826 | 2269 (long) string_char_length (instructions)); |
428 | 2270 } |
2271 else | |
2272 print_internal (instructions, printcharfun, escapeflag); | |
2273 NUNGCPRO; | |
2274 } | |
2275 | |
2276 /* COMPILED_CONSTANTS = 2 */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4775
diff
changeset
|
2277 write_ascstring (printcharfun, " "); |
428 | 2278 print_internal (compiled_function_constants (f), printcharfun, escapeflag); |
2279 | |
2280 /* COMPILED_STACK_DEPTH = 3 */ | |
800 | 2281 write_fmt_string (printcharfun, " %d", compiled_function_stack_depth (f)); |
428 | 2282 |
2283 /* COMPILED_DOC_STRING = 4 */ | |
2284 if (docp || intp) | |
2285 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4775
diff
changeset
|
2286 write_ascstring (printcharfun, " "); |
428 | 2287 print_internal (compiled_function_documentation (f), printcharfun, |
2288 escapeflag); | |
2289 } | |
2290 | |
2291 /* COMPILED_INTERACTIVE = 5 */ | |
2292 if (intp) | |
2293 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4775
diff
changeset
|
2294 write_ascstring (printcharfun, " "); |
428 | 2295 print_internal (compiled_function_interactive (f), printcharfun, |
2296 escapeflag); | |
2297 } | |
2298 | |
2299 UNGCPRO; | |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2300 if (print_readably) |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2301 write_ascstring (printcharfun, "]"); |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2302 else |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
2303 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj)); |
428 | 2304 } |
2305 | |
2306 | |
2307 static Lisp_Object | |
2308 mark_compiled_function (Lisp_Object obj) | |
2309 { | |
2310 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj); | |
814 | 2311 int i; |
428 | 2312 |
2313 mark_object (f->instructions); | |
2314 mark_object (f->arglist); | |
2315 mark_object (f->doc_and_interactive); | |
2316 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2317 mark_object (f->annotated); | |
2318 #endif | |
814 | 2319 for (i = 0; i < f->args_in_array; i++) |
3092 | 2320 #ifdef NEW_GC |
2321 mark_object (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i]); | |
2322 #else /* not NEW_GC */ | |
814 | 2323 mark_object (f->args[i]); |
3092 | 2324 #endif /* not NEW_GC */ |
814 | 2325 |
428 | 2326 /* tail-recurse on constants */ |
2327 return f->constants; | |
2328 } | |
2329 | |
2330 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
2331 compiled_function_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
2332 int UNUSED (foldcase)) |
428 | 2333 { |
2334 Lisp_Compiled_Function *f1 = XCOMPILED_FUNCTION (obj1); | |
2335 Lisp_Compiled_Function *f2 = XCOMPILED_FUNCTION (obj2); | |
2336 return | |
2337 (f1->flags.documentationp == f2->flags.documentationp && | |
2338 f1->flags.interactivep == f2->flags.interactivep && | |
2339 f1->flags.domainp == f2->flags.domainp && /* I18N3 */ | |
2340 internal_equal (compiled_function_instructions (f1), | |
2341 compiled_function_instructions (f2), depth + 1) && | |
2342 internal_equal (f1->constants, f2->constants, depth + 1) && | |
2343 internal_equal (f1->arglist, f2->arglist, depth + 1) && | |
2344 internal_equal (f1->doc_and_interactive, | |
2345 f2->doc_and_interactive, depth + 1)); | |
2346 } | |
2347 | |
665 | 2348 static Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2349 compiled_function_hash (Lisp_Object obj, int depth, Boolint UNUSED (equalp)) |
428 | 2350 { |
2351 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj); | |
2352 return HASH3 ((f->flags.documentationp << 2) + | |
2353 (f->flags.interactivep << 1) + | |
2354 f->flags.domainp, | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2355 internal_hash (f->instructions, depth + 1, 0), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2356 internal_hash (f->constants, depth + 1, 0)); |
428 | 2357 } |
2358 | |
1204 | 2359 static const struct memory_description compiled_function_description[] = { |
814 | 2360 { XD_INT, offsetof (Lisp_Compiled_Function, args_in_array) }, |
3092 | 2361 #ifdef NEW_GC |
2362 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, arguments) }, | |
2363 #else /* not NEW_GC */ | |
2364 { XD_BLOCK_PTR, offsetof (Lisp_Compiled_Function, args), | |
2551 | 2365 XD_INDIRECT (0, 0), { &lisp_object_description } }, |
3092 | 2366 #endif /* not NEW_GC */ |
440 | 2367 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, instructions) }, |
2368 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, constants) }, | |
2369 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, arglist) }, | |
2370 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, doc_and_interactive) }, | |
428 | 2371 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK |
440 | 2372 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, annotated) }, |
428 | 2373 #endif |
2374 { XD_END } | |
2375 }; | |
2376 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2377 DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT ("compiled-function", compiled_function, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2378 mark_compiled_function, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2379 print_compiled_function, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2380 compiled_function_equal, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2381 compiled_function_hash, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2382 compiled_function_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2383 Lisp_Compiled_Function); |
3092 | 2384 |
428 | 2385 |
2386 DEFUN ("compiled-function-p", Fcompiled_function_p, 1, 1, 0, /* | |
2387 Return t if OBJECT is a byte-compiled function object. | |
2388 */ | |
2389 (object)) | |
2390 { | |
2391 return COMPILED_FUNCTIONP (object) ? Qt : Qnil; | |
2392 } | |
2393 | |
2394 /************************************************************************/ | |
2395 /* compiled-function object accessor functions */ | |
2396 /************************************************************************/ | |
2397 | |
2398 Lisp_Object | |
2399 compiled_function_arglist (Lisp_Compiled_Function *f) | |
2400 { | |
2401 return f->arglist; | |
2402 } | |
2403 | |
2404 Lisp_Object | |
2405 compiled_function_instructions (Lisp_Compiled_Function *f) | |
2406 { | |
2407 if (! OPAQUEP (f->instructions)) | |
2408 return f->instructions; | |
2409 | |
2410 { | |
2411 /* Invert action performed by optimize_byte_code() */ | |
2412 Lisp_Opaque *opaque = XOPAQUE (f->instructions); | |
2413 | |
867 | 2414 Ibyte * const buffer = |
2367 | 2415 alloca_ibytes (OPAQUE_SIZE (opaque) * MAX_ICHAR_LEN); |
867 | 2416 Ibyte *bp = buffer; |
428 | 2417 |
442 | 2418 const Opbyte * const program = (const Opbyte *) OPAQUE_DATA (opaque); |
2419 const Opbyte *program_ptr = program; | |
2420 const Opbyte * const program_end = program_ptr + OPAQUE_SIZE (opaque); | |
428 | 2421 |
2422 while (program_ptr < program_end) | |
2423 { | |
2424 Opcode opcode = (Opcode) READ_UINT_1; | |
867 | 2425 bp += set_itext_ichar (bp, opcode); |
428 | 2426 switch (opcode) |
2427 { | |
2428 case Bvarref+7: | |
2429 case Bvarset+7: | |
2430 case Bvarbind+7: | |
2431 case Bcall+7: | |
2432 case Bunbind+7: | |
2433 case Bconstant2: | |
867 | 2434 bp += set_itext_ichar (bp, READ_UINT_1); |
2435 bp += set_itext_ichar (bp, READ_UINT_1); | |
428 | 2436 break; |
2437 | |
2438 case Bvarref+6: | |
2439 case Bvarset+6: | |
2440 case Bvarbind+6: | |
2441 case Bcall+6: | |
2442 case Bunbind+6: | |
2443 case BlistN: | |
2444 case BconcatN: | |
2445 case BinsertN: | |
867 | 2446 bp += set_itext_ichar (bp, READ_UINT_1); |
428 | 2447 break; |
2448 | |
2449 case Bgoto: | |
2450 case Bgotoifnil: | |
2451 case Bgotoifnonnil: | |
2452 case Bgotoifnilelsepop: | |
2453 case Bgotoifnonnilelsepop: | |
2454 { | |
2455 int jump = READ_INT_2; | |
2456 Opbyte buf2[2]; | |
2457 Opbyte *buf2p = buf2; | |
2458 /* Convert back to program-relative address */ | |
2459 WRITE_INT16 (jump + (program_ptr - 2 - program), buf2p); | |
867 | 2460 bp += set_itext_ichar (bp, buf2[0]); |
2461 bp += set_itext_ichar (bp, buf2[1]); | |
428 | 2462 break; |
2463 } | |
2464 | |
2465 case BRgoto: | |
2466 case BRgotoifnil: | |
2467 case BRgotoifnonnil: | |
2468 case BRgotoifnilelsepop: | |
2469 case BRgotoifnonnilelsepop: | |
867 | 2470 bp += set_itext_ichar (bp, READ_INT_1 + 127); |
428 | 2471 break; |
2472 | |
2473 default: | |
2474 break; | |
2475 } | |
2476 } | |
2477 return make_string (buffer, bp - buffer); | |
2478 } | |
2479 } | |
2480 | |
2481 Lisp_Object | |
2482 compiled_function_constants (Lisp_Compiled_Function *f) | |
2483 { | |
2484 return f->constants; | |
2485 } | |
2486 | |
2487 int | |
2488 compiled_function_stack_depth (Lisp_Compiled_Function *f) | |
2489 { | |
2490 return f->stack_depth; | |
2491 } | |
2492 | |
2493 /* The compiled_function->doc_and_interactive slot uses the minimal | |
2494 number of conses, based on compiled_function->flags; it may take | |
2495 any of the following forms: | |
2496 | |
2497 doc | |
2498 interactive | |
2499 domain | |
2500 (doc . interactive) | |
2501 (doc . domain) | |
2502 (interactive . domain) | |
2503 (doc . (interactive . domain)) | |
2504 */ | |
2505 | |
2506 /* Caller must check flags.interactivep first */ | |
2507 Lisp_Object | |
2508 compiled_function_interactive (Lisp_Compiled_Function *f) | |
2509 { | |
2510 assert (f->flags.interactivep); | |
2511 if (f->flags.documentationp && f->flags.domainp) | |
2512 return XCAR (XCDR (f->doc_and_interactive)); | |
2513 else if (f->flags.documentationp) | |
2514 return XCDR (f->doc_and_interactive); | |
2515 else if (f->flags.domainp) | |
2516 return XCAR (f->doc_and_interactive); | |
2517 else | |
2518 return f->doc_and_interactive; | |
2519 } | |
2520 | |
2521 /* Caller need not check flags.documentationp first */ | |
2522 Lisp_Object | |
2523 compiled_function_documentation (Lisp_Compiled_Function *f) | |
2524 { | |
2525 if (! f->flags.documentationp) | |
2526 return Qnil; | |
2527 else if (f->flags.interactivep && f->flags.domainp) | |
2528 return XCAR (f->doc_and_interactive); | |
2529 else if (f->flags.interactivep) | |
2530 return XCAR (f->doc_and_interactive); | |
2531 else if (f->flags.domainp) | |
2532 return XCAR (f->doc_and_interactive); | |
2533 else | |
2534 return f->doc_and_interactive; | |
2535 } | |
2536 | |
2537 /* Caller need not check flags.domainp first */ | |
2538 Lisp_Object | |
2539 compiled_function_domain (Lisp_Compiled_Function *f) | |
2540 { | |
2541 if (! f->flags.domainp) | |
2542 return Qnil; | |
2543 else if (f->flags.documentationp && f->flags.interactivep) | |
2544 return XCDR (XCDR (f->doc_and_interactive)); | |
2545 else if (f->flags.documentationp) | |
2546 return XCDR (f->doc_and_interactive); | |
2547 else if (f->flags.interactivep) | |
2548 return XCDR (f->doc_and_interactive); | |
2549 else | |
2550 return f->doc_and_interactive; | |
2551 } | |
2552 | |
2553 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2554 | |
2555 Lisp_Object | |
2556 compiled_function_annotation (Lisp_Compiled_Function *f) | |
2557 { | |
2558 return f->annotated; | |
2559 } | |
2560 | |
2561 #endif | |
2562 | |
5206
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2563 /* used only by Snarf-documentation. */ |
428 | 2564 void |
2565 set_compiled_function_documentation (Lisp_Compiled_Function *f, | |
2566 Lisp_Object new_doc) | |
2567 { | |
2568 assert (INTP (new_doc) || STRINGP (new_doc)); | |
2569 | |
5206
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2570 if (f->flags.documentationp) |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2571 { |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2572 if (f->flags.interactivep && f->flags.domainp) |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2573 XCAR (f->doc_and_interactive) = new_doc; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2574 else if (f->flags.interactivep) |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2575 XCAR (f->doc_and_interactive) = new_doc; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2576 else if (f->flags.domainp) |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2577 XCAR (f->doc_and_interactive) = new_doc; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2578 else |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2579 f->doc_and_interactive = new_doc; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2580 } |
428 | 2581 else |
5206
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2582 { |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2583 f->flags.documentationp = 1; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2584 if (f->flags.interactivep || f->flags.domainp) |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2585 { |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2586 f->doc_and_interactive = Fcons (new_doc, f->doc_and_interactive); |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2587 } |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2588 else |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2589 { |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2590 f->doc_and_interactive = new_doc; |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2591 } |
39d74978fd32
Keep around file info for dumped functions and variables without docstrings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2592 } |
428 | 2593 } |
2594 | |
2595 | |
2596 DEFUN ("compiled-function-arglist", Fcompiled_function_arglist, 1, 1, 0, /* | |
2597 Return the argument list of the compiled-function object FUNCTION. | |
2598 */ | |
2599 (function)) | |
2600 { | |
2601 CHECK_COMPILED_FUNCTION (function); | |
2602 return compiled_function_arglist (XCOMPILED_FUNCTION (function)); | |
2603 } | |
2604 | |
2605 DEFUN ("compiled-function-instructions", Fcompiled_function_instructions, 1, 1, 0, /* | |
2606 Return the byte-opcode string of the compiled-function object FUNCTION. | |
2607 */ | |
2608 (function)) | |
2609 { | |
2610 CHECK_COMPILED_FUNCTION (function); | |
2611 return compiled_function_instructions (XCOMPILED_FUNCTION (function)); | |
2612 } | |
2613 | |
2614 DEFUN ("compiled-function-constants", Fcompiled_function_constants, 1, 1, 0, /* | |
2615 Return the constants vector of the compiled-function object FUNCTION. | |
2616 */ | |
2617 (function)) | |
2618 { | |
2619 CHECK_COMPILED_FUNCTION (function); | |
2620 return compiled_function_constants (XCOMPILED_FUNCTION (function)); | |
2621 } | |
2622 | |
2623 DEFUN ("compiled-function-stack-depth", Fcompiled_function_stack_depth, 1, 1, 0, /* | |
444 | 2624 Return the maximum stack depth of the compiled-function object FUNCTION. |
428 | 2625 */ |
2626 (function)) | |
2627 { | |
2628 CHECK_COMPILED_FUNCTION (function); | |
2629 return make_int (compiled_function_stack_depth (XCOMPILED_FUNCTION (function))); | |
2630 } | |
2631 | |
2632 DEFUN ("compiled-function-doc-string", Fcompiled_function_doc_string, 1, 1, 0, /* | |
2633 Return the doc string of the compiled-function object FUNCTION, if available. | |
2634 Functions that had their doc strings snarfed into the DOC file will have | |
2635 an integer returned instead of a string. | |
2636 */ | |
2637 (function)) | |
2638 { | |
2639 CHECK_COMPILED_FUNCTION (function); | |
2640 return compiled_function_documentation (XCOMPILED_FUNCTION (function)); | |
2641 } | |
2642 | |
2643 DEFUN ("compiled-function-interactive", Fcompiled_function_interactive, 1, 1, 0, /* | |
2644 Return the interactive spec of the compiled-function object FUNCTION, or nil. | |
2645 If non-nil, the return value will be a list whose first element is | |
2646 `interactive' and whose second element is the interactive spec. | |
2647 */ | |
2648 (function)) | |
2649 { | |
2650 CHECK_COMPILED_FUNCTION (function); | |
2651 return XCOMPILED_FUNCTION (function)->flags.interactivep | |
2652 ? list2 (Qinteractive, | |
2653 compiled_function_interactive (XCOMPILED_FUNCTION (function))) | |
2654 : Qnil; | |
2655 } | |
2656 | |
2657 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2658 | |
826 | 2659 DEFUN ("compiled-function-annotation", Fcompiled_function_annotation, 1, 1, 0, /* |
428 | 2660 Return the annotation of the compiled-function object FUNCTION, or nil. |
2661 The annotation is a piece of information indicating where this | |
2662 compiled-function object came from. Generally this will be | |
2663 a symbol naming a function; or a string naming a file, if the | |
2664 compiled-function object was not defined in a function; or nil, | |
2665 if the compiled-function object was not created as a result of | |
2666 a `load'. | |
2667 */ | |
2668 (function)) | |
2669 { | |
2670 CHECK_COMPILED_FUNCTION (function); | |
2671 return compiled_function_annotation (XCOMPILED_FUNCTION (function)); | |
2672 } | |
2673 | |
2674 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ | |
2675 | |
2676 DEFUN ("compiled-function-domain", Fcompiled_function_domain, 1, 1, 0, /* | |
2677 Return the domain of the compiled-function object FUNCTION, or nil. | |
2678 This is only meaningful if I18N3 was enabled when emacs was compiled. | |
2679 */ | |
2680 (function)) | |
2681 { | |
2682 CHECK_COMPILED_FUNCTION (function); | |
2683 return XCOMPILED_FUNCTION (function)->flags.domainp | |
2684 ? compiled_function_domain (XCOMPILED_FUNCTION (function)) | |
2685 : Qnil; | |
2686 } | |
2687 | |
2688 | |
2689 | |
2690 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /* | |
2691 If the byte code for compiled function FUNCTION is lazy-loaded, fetch it now. | |
2692 */ | |
2693 (function)) | |
2694 { | |
2695 Lisp_Compiled_Function *f; | |
2696 CHECK_COMPILED_FUNCTION (function); | |
2697 f = XCOMPILED_FUNCTION (function); | |
2698 | |
2699 if (OPAQUEP (f->instructions) || STRINGP (f->instructions)) | |
2700 return function; | |
2701 | |
2702 if (CONSP (f->instructions)) | |
2703 { | |
2704 Lisp_Object tem = read_doc_string (f->instructions); | |
2705 if (!CONSP (tem)) | |
563 | 2706 signal_error (Qinvalid_byte_code, |
2707 "Invalid lazy-loaded byte code", tem); | |
428 | 2708 /* v18 or v19 bytecode file. Need to Ebolify. */ |
2709 if (f->flags.ebolified && VECTORP (XCDR (tem))) | |
2710 ebolify_bytecode_constants (XCDR (tem)); | |
2711 f->instructions = XCAR (tem); | |
2712 f->constants = XCDR (tem); | |
2713 return function; | |
2714 } | |
2500 | 2715 ABORT (); |
801 | 2716 return Qnil; /* not (usually) reached */ |
428 | 2717 } |
2718 | |
2719 DEFUN ("optimize-compiled-function", Foptimize_compiled_function, 1, 1, 0, /* | |
2720 Convert compiled function FUNCTION into an optimized internal form. | |
2721 */ | |
2722 (function)) | |
2723 { | |
2724 Lisp_Compiled_Function *f; | |
2725 CHECK_COMPILED_FUNCTION (function); | |
2726 f = XCOMPILED_FUNCTION (function); | |
2727 | |
2728 if (OPAQUEP (f->instructions)) /* Already optimized? */ | |
2729 return Qnil; | |
2730 | |
2731 optimize_compiled_function (function); | |
2732 return Qnil; | |
2733 } | |
2734 | |
2735 DEFUN ("byte-code", Fbyte_code, 3, 3, 0, /* | |
2736 Function used internally in byte-compiled code. | |
2737 First argument INSTRUCTIONS is a string of byte code. | |
2738 Second argument CONSTANTS is a vector of constants. | |
2739 Third argument STACK-DEPTH is the maximum stack depth used in this function. | |
2740 If STACK-DEPTH is incorrect, Emacs may crash. | |
2741 */ | |
2742 (instructions, constants, stack_depth)) | |
2743 { | |
2744 /* This function can GC */ | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2745 Elemcount varbind_count; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2746 Elemcount program_length; |
428 | 2747 Opbyte *program; |
2748 | |
2749 CHECK_STRING (instructions); | |
2750 CHECK_VECTOR (constants); | |
2751 CHECK_NATNUM (stack_depth); | |
2752 | |
2753 /* Optimize the `instructions' string, just like when executing a | |
2754 regular compiled function, but don't save it for later since this is | |
2755 likely to only be executed once. */ | |
2756 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (instructions)); | |
2757 optimize_byte_code (instructions, constants, program, | |
2758 &program_length, &varbind_count); | |
2759 SPECPDL_RESERVE (varbind_count); | |
2760 return execute_optimized_program (program, | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2761 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2762 program_length, |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2763 #endif |
428 | 2764 XINT (stack_depth), |
2765 XVECTOR_DATA (constants)); | |
2766 } | |
2767 | |
2768 | |
2769 void | |
2770 syms_of_bytecode (void) | |
2771 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
2720
diff
changeset
|
2772 INIT_LISP_OBJECT (compiled_function); |
3092 | 2773 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2774 INIT_LISP_OBJECT (compiled_function_args); |
3092 | 2775 #endif /* NEW_GC */ |
442 | 2776 |
2777 DEFERROR_STANDARD (Qinvalid_byte_code, Qinvalid_state); | |
563 | 2778 DEFSYMBOL (Qbyte_code); |
2779 DEFSYMBOL_MULTIWORD_PREDICATE (Qcompiled_functionp); | |
428 | 2780 |
2781 DEFSUBR (Fbyte_code); | |
2782 DEFSUBR (Ffetch_bytecode); | |
2783 DEFSUBR (Foptimize_compiled_function); | |
2784 | |
2785 DEFSUBR (Fcompiled_function_p); | |
2786 DEFSUBR (Fcompiled_function_instructions); | |
2787 DEFSUBR (Fcompiled_function_constants); | |
2788 DEFSUBR (Fcompiled_function_stack_depth); | |
2789 DEFSUBR (Fcompiled_function_arglist); | |
2790 DEFSUBR (Fcompiled_function_interactive); | |
2791 DEFSUBR (Fcompiled_function_doc_string); | |
2792 DEFSUBR (Fcompiled_function_domain); | |
2793 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2794 DEFSUBR (Fcompiled_function_annotation); | |
2795 #endif | |
2796 | |
2797 #ifdef BYTE_CODE_METER | |
563 | 2798 DEFSYMBOL (Qbyte_code_meter); |
428 | 2799 #endif |
2800 } | |
2801 | |
2802 void | |
2803 vars_of_bytecode (void) | |
2804 { | |
2805 #ifdef BYTE_CODE_METER | |
2806 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter /* | |
2807 A vector of vectors which holds a histogram of byte code usage. | |
2808 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte | |
2809 opcode CODE has been executed. | |
2810 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0, | |
2811 indicates how many times the byte opcodes CODE1 and CODE2 have been | |
2812 executed in succession. | |
2813 */ ); | |
2814 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on /* | |
2815 If non-nil, keep profiling information on byte code usage. | |
2816 The variable `byte-code-meter' indicates how often each byte opcode is used. | |
2817 If a symbol has a property named `byte-code-meter' whose value is an | |
2818 integer, it is incremented each time that symbol's function is called. | |
2819 */ ); | |
2820 | |
2821 byte_metering_on = 0; | |
2822 Vbyte_code_meter = make_vector (256, Qzero); | |
2823 { | |
2824 int i = 256; | |
2825 while (i--) | |
2826 XVECTOR_DATA (Vbyte_code_meter)[i] = make_vector (256, Qzero); | |
2827 } | |
2828 #endif /* BYTE_CODE_METER */ | |
2829 } | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2830 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2831 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2832 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2833 /* Initialize the opcodes in the table that correspond to a base opcode |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2834 plus an offset (except for Bconstant). */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2835 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2836 static void |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2837 init_opcode_table_multi_op (Opcode op) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2838 { |
5091 | 2839 const Ascbyte *base = opcode_name_table[op]; |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2840 Ascbyte temp[300]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2841 int i; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2842 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2843 for (i = 1; i < 7; i++) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2844 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2845 assert (!opcode_name_table[op + i]); |
5091 | 2846 sprintf (temp, "%s+%d", base, i); |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2847 opcode_name_table[op + i] = xstrdup (temp); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2848 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2849 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2850 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2851 #endif /* ERROR_CHECK_BYTE_CODE */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2852 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2853 void |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2854 reinit_vars_of_bytecode (void) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2855 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2856 #ifdef ERROR_CHECK_BYTE_CODE |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2857 int i; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2858 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2859 #define OPCODE(sym, val) opcode_name_table[val] = xstrdup (#sym); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2860 #include "bytecode-ops.h" |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2861 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2862 for (i = 0; i < countof (opcode_name_table); i++) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2863 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2864 int j; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2865 Ascbyte *name = opcode_name_table[i]; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2866 if (name) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2867 { |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2868 Bytecount len = strlen (name); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2869 /* Prettify the name by converting underscores to hyphens, similar |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2870 to what happens with DEFSYMBOL. */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2871 for (j = 0; j < len; j++) |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2872 if (name[j] == '_') |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2873 name[j] = '-'; |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2874 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2875 } |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2876 |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2877 init_opcode_table_multi_op (Bvarref); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2878 init_opcode_table_multi_op (Bvarset); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2879 init_opcode_table_multi_op (Bvarbind); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2880 init_opcode_table_multi_op (Bcall); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2881 init_opcode_table_multi_op (Bunbind); |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2882 #endif /* ERROR_CHECK_BYTE_CODE */ |
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4914
diff
changeset
|
2883 } |