forked from parrot/parrot
/
experimental.ops
359 lines (270 loc) · 9.98 KB
/
experimental.ops
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
* $Id$
** experimental.ops
*/
=head1 NAME
experimental.ops - Experimental Opcodes
=cut
=head1 DESCRIPTION
This file contains experimental opcodes.
These opcodes should be considered implicitly deprecated - that is, they
may be removed in any release.
If you rely on any of these opcodes, please open a
Trac ticket at L<https://trac.parrot.org/>.
=cut
###############################################################################
=head2 More Experimental Ops
=over 4
=item B<trap>()
Break into debugger. Implementation notes:
- x86/gcc ... works with gdb
- ppc/gcc ... works with gdb, to proceed: gdb> p $pc = $pc + 4
- TODO
For other architectures, this is a C<noop>.
=back
=cut
op trap() :deprecated {
#if defined(__GNUC__) && defined(i386)
__asm__("int3"); /* opcode 0xcc */
#endif
#if defined(__GNUC__) && defined(PPC)
__asm__("trap"); /* opcode tr 31, 0, 0 */
#endif
}
=over 4
=item B<set_label>(invar PMC, inconst LABEL)
Sets the opcode_t* label value for the given PMC. This is basically only
useful for PMCs such as Sub, Continuation, ExceptionHandler and derivatives
=item B<get_label>(out INT, invar PMC)
Gets the opcode_t* label value from the given PMC. This is basically only
useful for PMCs such as Sub, Continuation, ExceptionHandler and derivatives
=back
=cut
inline op set_label(invar PMC, inconst LABEL) {
VTABLE_set_pointer(interp, $1, (CUR_OPCODE + $2));
}
inline op get_label(out INT, invar PMC) {
void * const ptr = VTABLE_get_pointer(interp, $2);
$1 = PTR2INTVAL(ptr);
}
=over 4
=item B<fetch>(out PMC, in PMC, in PMC, in PMC)
Fetches a value from $2, keyed by $3 into $1. If the resulting PMC is PMCNULL,
uses the type in $4 to create and return a new PMC.
=item B<fetch>(out PMC, in PMC, in INT, in PMC)
=item B<fetch>(out PMC, in PMC, in STR, in PMC)
=back
=cut
inline op fetch(out PMC, in PMC, in PMC, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
}
}
inline op fetch(out PMC, in PMC, in INT, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed_int(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
}
}
inline op fetch(out PMC, in PMC, in STR, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed_str(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
}
}
=over 4
=item B<vivify>(out PMC, in PMC, in PMC, in PMC)
Fetches a value from $2, keyed by $3 into $1. If the resulting PMC is PMCNULL,
uses the type in $4 to create and return a new PMC.
=item B<vivify>(out PMC, in PMC, in INT, in PMC)
=item B<vivify>(out PMC, in PMC, in STR, in PMC)
=back
=cut
inline op vivify(out PMC, in PMC, in PMC, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
VTABLE_set_pmc_keyed(interp, $2, $3, $1);
}
}
inline op vivify(out PMC, in PMC, in INT, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed_int(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
VTABLE_set_pmc_keyed_int(interp, $2, $3, $1);
}
}
inline op vivify(out PMC, in PMC, in STR, in PMC) :base_core {
$1 = VTABLE_get_pmc_keyed_str(interp, $2, $3);
if (PMC_IS_NULL($1)) {
PMC * const classobj = Parrot_oo_get_class(interp, $4);
if (!PMC_IS_NULL(classobj))
$1 = VTABLE_instantiate(interp, classobj, PMCNULL);
else {
const INTVAL type = Parrot_pmc_get_type(interp, $4);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(
interp, expr NEXT(), EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, $4));
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new(interp, type);
}
VTABLE_set_pmc_keyed_str(interp, $2, $3, $1);
}
}
=over 4
=item B<new>(out PMC, in STR, in INT)
=item B<new>(out PMC, in PMC, in INT)
=back
=cut
op new(out PMC, in STR, in INT) {
STRING * const name = $2;
PMC * const _class = Parrot_pcc_get_HLL(interp, CURRENT_CONTEXT(interp))
? Parrot_oo_get_class_str(interp, name)
: PMCNULL;
if (!PMC_IS_NULL(_class)) {
PMC *initial = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Integer));
VTABLE_set_integer_native(interp, initial, $3);
$1 = VTABLE_instantiate(interp, _class, initial);
}
else {
const INTVAL type = Parrot_pmc_get_type_str(interp, name);
if (type <= 0) {
opcode_t *dest = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
EXCEPTION_NO_CLASS,
"Class '%Ss' not found", name);
goto ADDRESS(dest);
}
$1 = Parrot_pmc_new_init_int(interp, type, $3);
}
}
op new(out PMC, in PMC, in INT) {
PMC * const name_key = $2;
/* get_class() returns a PMCProxy for core types, so check for core PMCs */
const INTVAL type = Parrot_pmc_get_type(interp, name_key);
/* if it's clearly a PIR-level PMC */
if (type > enum_class_core_max) {
PMC * const _class = Parrot_oo_get_class(interp, name_key);
if (!PMC_IS_NULL(_class)) {
PMC *initial = Parrot_pmc_new(interp,
Parrot_get_ctx_HLL_type(interp, enum_class_Integer));
VTABLE_set_integer_native(interp, initial, $3);
$1 = VTABLE_instantiate(interp, _class, initial);
}
}
/* if it's a core PMC */
else if (type > enum_class_default)
$1 = Parrot_pmc_new_init_int(interp, type, $3);
/* it's a typo */
else {
opcode_t *dest = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, name_key));
goto ADDRESS(dest);
}
}
=over 4
=item B<root_new>(out PMC, in PMC, in INT)
=back
=cut
op root_new(out PMC, in PMC, in INT) {
PMC * const name_key = $2;
/* get_class() returns a PMCProxy for core types, so check for core PMCs */
const INTVAL type = Parrot_pmc_get_type(interp, name_key);
/* if it's clearly a PIR-level PMC */
if (type > enum_class_core_max) {
PMC * const root_ns = interp->root_namespace;
PMC * const ns = Parrot_get_namespace_keyed(interp, root_ns, name_key);
PMC * const _class = Parrot_oo_get_class(interp, ns);
if (!PMC_IS_NULL(_class)) {
PMC *initial = Parrot_pmc_new(interp,
Parrot_get_ctx_HLL_type(interp, enum_class_Integer));
VTABLE_set_integer_native(interp, initial, $3);
$1 = VTABLE_instantiate(interp, _class, initial);
}
}
/* if it's a core PMC */
else if (type > enum_class_default)
$1 = Parrot_pmc_new_init_int(interp, type, $3);
/* it's a typo */
else {
opcode_t *dest = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
EXCEPTION_NO_CLASS,
"Class '%Ss' not found", VTABLE_get_repr(interp, name_key));
goto ADDRESS(dest);
}
}
=head1 COPYRIGHT
Copyright (C) 2001-2010, Parrot Foundation.
=head1 LICENSE
This program is free software. It is subject to the same license
as the Parrot interp itself.
=cut
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/