-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy pathceval.c
3055 lines (2804 loc) · 62.2 KB
/
ceval.c
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Execute compiled code */
/* XXX TO DO:
XXX how to pass arguments to call_trace?
XXX totally get rid of access stuff
XXX speed up searching for keywords by using a dictionary
XXX document it!
*/
#include "allobjects.h"
#include "compile.h"
#include "frameobject.h"
#include "eval.h"
#include "opcode.h"
#include "graminit.h"
#include <ctype.h>
/* Turn this on if your compiler chokes on the big switch: */
/* #define CASE_TOO_BIG 1 */
#ifdef DEBUG
/* For debugging the interpreter: */
#define LLTRACE 1 /* Low-level trace feature */
#define CHECKEXC 1 /* Double-check exception checking */
#endif
/* Forward declarations */
static object *eval_code2 PROTO((codeobject *,
object *, object *,
object **, int,
object **, int,
object **, int,
object *));
#ifdef LLTRACE
static int prtrace PROTO((object *, char *));
#endif
static void call_exc_trace PROTO((object **, object**, frameobject *));
static int call_trace
PROTO((object **, object **, frameobject *, char *, object *));
static object *add PROTO((object *, object *));
static object *sub PROTO((object *, object *));
static object *powerop PROTO((object *, object *));
static object *mul PROTO((object *, object *));
static object *divide PROTO((object *, object *));
static object *mod PROTO((object *, object *));
static object *neg PROTO((object *));
static object *pos PROTO((object *));
static object *not PROTO((object *));
static object *invert PROTO((object *));
static object *lshift PROTO((object *, object *));
static object *rshift PROTO((object *, object *));
static object *and PROTO((object *, object *));
static object *xor PROTO((object *, object *));
static object *or PROTO((object *, object *));
static object *call_builtin PROTO((object *, object *, object *));
static object *call_function PROTO((object *, object *, object *));
static object *apply_subscript PROTO((object *, object *));
static object *loop_subscript PROTO((object *, object *));
static int slice_index PROTO((object *, int, int *));
static object *apply_slice PROTO((object *, object *, object *));
static object *build_slice PROTO((object *, object *, object *));
static int assign_subscript PROTO((object *, object *, object *));
static int assign_slice PROTO((object *, object *, object *, object *));
static int cmp_exception PROTO((object *, object *));
static int cmp_member PROTO((object *, object *));
static object *cmp_outcome PROTO((int, object *, object *));
static int import_from PROTO((object *, object *, object *));
static object *build_class PROTO((object *, object *, object *));
#ifdef SUPPORT_OBSOLETE_ACCESS
static int access_statement PROTO((object *, object *, frameobject *));
#endif
static int exec_statement PROTO((object *, object *, object *));
static object *find_from_args PROTO((frameobject *, int));
/* Pointer to current frame, used to link new frames to */
static frameobject *current_frame;
#ifdef WITH_THREAD
#include <errno.h>
#include "thread.h"
static type_lock interpreter_lock = 0;
static long main_thread = 0;
void
init_save_thread()
{
if (interpreter_lock)
return;
interpreter_lock = allocate_lock();
acquire_lock(interpreter_lock, 1);
main_thread = get_thread_ident();
}
#endif
/* Functions save_thread and restore_thread are always defined so
dynamically loaded modules needn't be compiled separately for use
with and without threads: */
object *
save_thread()
{
#ifdef WITH_THREAD
if (interpreter_lock) {
object *res;
res = (object *)current_frame;
current_frame = NULL;
release_lock(interpreter_lock);
return res;
}
#endif
return NULL;
}
void
restore_thread(x)
object *x;
{
#ifdef WITH_THREAD
if (interpreter_lock) {
int err;
err = errno;
acquire_lock(interpreter_lock, 1);
errno = err;
current_frame = (frameobject *)x;
}
#endif
}
/* Mechanism whereby asynchronously executing callbacks (e.g. UNIX
signal handlers or Mac I/O completion routines) can schedule calls
to a function to be called synchronously.
The synchronous function is called with one void* argument.
It should return 0 for success or -1 for failure -- failure should
be accompanied by an exception.
If registry succeeds, the registry function returns 0; if it fails
(e.g. due to too many pending calls) it returns -1 (without setting
an exception condition).
Note that because registry may occur from within signal handlers,
or other asynchronous events, calling malloc() is unsafe!
#ifdef WITH_THREAD
Any thread can schedule pending calls, but only the main thread
will execute them.
#endif
XXX WARNING! ASYNCHRONOUSLY EXECUTING CODE!
There are two possible race conditions:
(1) nested asynchronous registry calls;
(2) registry calls made while pending calls are being processed.
While (1) is very unlikely, (2) is a real possibility.
The current code is safe against (2), but not against (1).
The safety against (2) is derived from the fact that only one
thread (the main thread) ever takes things out of the queue.
*/
static int ticker = 0; /* main loop counter to do periodic things */
#define NPENDINGCALLS 32
static struct {
int (*func) PROTO((ANY *));
ANY *arg;
} pendingcalls[NPENDINGCALLS];
static volatile int pendingfirst = 0;
static volatile int pendinglast = 0;
int
Py_AddPendingCall(func, arg)
int (*func) PROTO((ANY *));
ANY *arg;
{
static int busy = 0;
int i, j;
/* XXX Begin critical section */
/* XXX If you want this to be safe against nested
XXX asynchronous calls, you'll have to work harder! */
if (busy)
return -1;
busy = 1;
i = pendinglast;
j = (i + 1) % NPENDINGCALLS;
if (j == pendingfirst)
return -1; /* Queue full */
pendingcalls[i].func = func;
pendingcalls[i].arg = arg;
pendinglast = j;
ticker = 0; /* Signal main loop */
busy = 0;
/* XXX End critical section */
return 0;
}
int
Py_MakePendingCalls()
{
static int busy = 0;
#ifdef WITH_THREAD
if (get_thread_ident() != main_thread) {
ticker = 0; /* We're not done yet */
return 0;
}
#endif
if (busy) {
ticker = 0; /* We're not done yet */
return 0;
}
busy = 1;
for (;;) {
int i;
int (*func) PROTO((ANY *));
ANY *arg;
i = pendingfirst;
if (i == pendinglast)
break; /* Queue empty */
func = pendingcalls[i].func;
arg = pendingcalls[i].arg;
pendingfirst = (i + 1) % NPENDINGCALLS;
if (func(arg) < 0) {
busy = 0;
ticker = 0; /* We're not done yet */
return -1;
}
}
busy = 0;
return 0;
}
/* Status code for main loop (reason for stack unwind) */
enum why_code {
WHY_NOT, /* No error */
WHY_EXCEPTION, /* Exception occurred */
WHY_RERAISE, /* Exception re-raised by 'finally' */
WHY_RETURN, /* 'return' statement */
WHY_BREAK /* 'break' statement */
};
/* Backward compatible interface */
object *
eval_code(co, globals, locals)
codeobject *co;
object *globals;
object *locals;
{
return eval_code2(co,
globals, locals,
(object **)NULL, 0,
(object **)NULL, 0,
(object **)NULL, 0,
(object *)NULL);
}
/* Interpreter main loop */
#ifndef MAX_RECURSION_DEPTH
#define MAX_RECURSION_DEPTH 10000
#endif
static int recursion_depth = 0;
static object *
eval_code2(co, globals, locals,
args, argcount, kws, kwcount, defs, defcount, owner)
codeobject *co;
object *globals;
object *locals;
object **args;
int argcount;
object **kws; /* length: 2*kwcount */
int kwcount;
object **defs;
int defcount;
object *owner;
{
register unsigned char *next_instr;
register int opcode; /* Current opcode */
register int oparg; /* Current opcode argument, if any */
register object **stack_pointer;
register enum why_code why; /* Reason for block stack unwind */
register int err; /* Error status -- nonzero if error */
register object *x; /* Result object -- NULL if error */
register object *v; /* Temporary objects popped off stack */
register object *w;
register object *u;
register object *t;
register frameobject *f; /* Current frame */
register object **fastlocals;
object *retval; /* Return value */
#ifdef SUPPORT_OBSOLETE_ACCESS
int defmode = 0; /* Default access mode for new variables */
#endif
#ifdef LLTRACE
int lltrace;
#endif
#if defined(DEBUG) || defined(LLTRACE)
/* Make it easier to find out where we are with a debugger */
char *filename = getstringvalue(co->co_filename);
#endif
/* Code access macros */
#define GETCONST(i) Getconst(f, i)
#define GETNAME(i) Getname(f, i)
#define GETNAMEV(i) Getnamev(f, i)
#define FIRST_INSTR() (GETUSTRINGVALUE(f->f_code->co_code))
#define INSTR_OFFSET() (next_instr - FIRST_INSTR())
#define NEXTOP() (*next_instr++)
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
#define JUMPTO(x) (next_instr = FIRST_INSTR() + (x))
#define JUMPBY(x) (next_instr += (x))
/* Stack manipulation macros */
#define STACK_LEVEL() (stack_pointer - f->f_valuestack)
#define EMPTY() (STACK_LEVEL() == 0)
#define TOP() (stack_pointer[-1])
#define BASIC_PUSH(v) (*stack_pointer++ = (v))
#define BASIC_POP() (*--stack_pointer)
#define CHECK_STACK(n) (STACK_LEVEL() + (n) < f->f_nvalues || \
(stack_pointer = extend_stack(f, STACK_LEVEL(), n)))
#ifdef LLTRACE
#define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
#define POP() (lltrace && prtrace(TOP(), "pop"), BASIC_POP())
#else
#define PUSH(v) BASIC_PUSH(v)
#define POP() BASIC_POP()
#endif
/* Local variable macros */
#define GETLOCAL(i) (fastlocals[i])
#define SETLOCAL(i, value) do { XDECREF(GETLOCAL(i)); \
GETLOCAL(i) = value; } while (0)
#ifdef USE_STACKCHECK
if (recursion_depth%10 == 0 && PyOS_CheckStack()) {
err_setstr(MemoryError, "Stack overflow");
return NULL;
}
#endif
if (globals == NULL) {
err_setstr(SystemError, "eval_code2: NULL globals");
return NULL;
}
#ifdef LLTRACE
lltrace = dictlookup(globals, "__lltrace__") != NULL;
#endif
f = newframeobject(
current_frame, /*back*/
co, /*code*/
globals, /*globals*/
locals, /*locals*/
owner, /*owner*/
50, /*nvalues*/
20); /*nblocks*/
if (f == NULL)
return NULL;
current_frame = f;
if (co->co_nlocals > 0)
fastlocals = ((listobject *)f->f_fastlocals)->ob_item;
if (co->co_argcount > 0 ||
co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
int i;
int n = argcount;
object *kwdict = NULL;
if (co->co_flags & CO_VARKEYWORDS) {
kwdict = newmappingobject();
if (kwdict == NULL)
goto fail;
}
if (argcount > co->co_argcount) {
if (!(co->co_flags & CO_VARARGS)) {
err_setstr(TypeError, "too many arguments");
goto fail;
}
n = co->co_argcount;
}
for (i = 0; i < n; i++) {
x = args[i];
INCREF(x);
SETLOCAL(i, x);
}
if (co->co_flags & CO_VARARGS) {
u = newtupleobject(argcount - n);
for (i = n; i < argcount; i++) {
x = args[i];
INCREF(x);
SETTUPLEITEM(u, i-n, x);
}
SETLOCAL(co->co_argcount, u);
}
for (i = 0; i < kwcount; i++) {
object *keyword = kws[2*i];
object *value = kws[2*i + 1];
int j;
/* XXX slow -- speed up using dictionary? */
for (j = 0; j < co->co_argcount; j++) {
object *nm = GETTUPLEITEM(co->co_varnames, j);
if (cmpobject(keyword, nm) == 0)
break;
}
if (j >= co->co_argcount) {
if (kwdict == NULL) {
err_setval(TypeError, keyword);
goto fail;
}
mappinginsert(kwdict, keyword, value);
}
else {
if (GETLOCAL(j) != NULL) {
err_setstr(TypeError,
"keyword parameter redefined");
goto fail;
}
INCREF(value);
SETLOCAL(j, value);
}
}
if (argcount < co->co_argcount) {
int m = co->co_argcount - defcount;
for (i = argcount; i < m; i++) {
if (GETLOCAL(i) == NULL) {
err_setstr(TypeError,
"not enough arguments");
goto fail;
}
}
if (n > m)
i = n - m;
else
i = 0;
for (; i < defcount; i++) {
if (GETLOCAL(m+i) == NULL) {
object *def = defs[i];
INCREF(def);
SETLOCAL(m+i, def);
}
}
}
if (kwdict != NULL) {
i = co->co_argcount;
if (co->co_flags & CO_VARARGS)
i++;
SETLOCAL(i, kwdict);
}
if (0) {
fail:
XDECREF(kwdict);
goto fail2;
}
}
else {
if (argcount > 0 || kwcount > 0) {
err_setstr(TypeError, "no arguments expected");
fail2:
current_frame = f->f_back;
DECREF(f);
return NULL;
}
}
if (sys_trace != NULL) {
/* sys_trace, if defined, is a function that will
be called on *every* entry to a code block.
Its return value, if not None, is a function that
will be called at the start of each executed line
of code. (Actually, the function must return
itself in order to continue tracing.)
The trace functions are called with three arguments:
a pointer to the current frame, a string indicating
why the function is called, and an argument which
depends on the situation. The global trace function
(sys.trace) is also called whenever an exception
is detected. */
if (call_trace(&sys_trace, &f->f_trace, f, "call",
None/*XXX how to compute arguments now?*/)) {
/* Trace function raised an error */
current_frame = f->f_back;
DECREF(f);
return NULL;
}
}
if (sys_profile != NULL) {
/* Similar for sys_profile, except it needn't return
itself and isn't called for "line" events */
if (call_trace(&sys_profile, (object**)0, f, "call",
None/*XXX*/)) {
current_frame = f->f_back;
DECREF(f);
return NULL;
}
}
if (++recursion_depth > MAX_RECURSION_DEPTH) {
--recursion_depth;
err_setstr(RuntimeError, "Maximum recursion depth exceeded");
current_frame = f->f_back;
DECREF(f);
return NULL;
}
next_instr = GETUSTRINGVALUE(f->f_code->co_code);
stack_pointer = f->f_valuestack;
why = WHY_NOT;
err = 0;
x = None; /* Not a reference, just anything non-NULL */
for (;;) {
/* Do periodic things.
Doing this every time through the loop would add
too much overhead (a function call per instruction).
So we do it only every Nth instruction.
The ticker is reset to zero if there are pending
calls (see Py_AddPendingCalls() and
Py_MakePendingCalls() above). */
if (--ticker < 0) {
ticker = sys_checkinterval;
if (pendingfirst != pendinglast) {
if (Py_MakePendingCalls() < 0) {
why = WHY_EXCEPTION;
goto on_error;
}
}
if (sigcheck()) {
why = WHY_EXCEPTION;
goto on_error;
}
#ifdef WITH_THREAD
if (interpreter_lock) {
/* Give another thread a chance */
current_frame = NULL;
release_lock(interpreter_lock);
/* Other threads may run now */
acquire_lock(interpreter_lock, 1);
current_frame = f;
}
#endif
}
/* Extract opcode and argument */
#if defined(DEBUG) || defined(LLTRACE)
f->f_lasti = INSTR_OFFSET();
#endif
opcode = NEXTOP();
if (HAS_ARG(opcode))
oparg = NEXTARG();
#ifdef LLTRACE
/* Instruction tracing */
if (lltrace) {
if (HAS_ARG(opcode)) {
printf("%d: %d, %d\n",
(int) (INSTR_OFFSET() - 3),
opcode, oparg);
}
else {
printf("%d: %d\n",
(int) (INSTR_OFFSET() - 1), opcode);
}
}
#endif
if (!CHECK_STACK(3)) {
x = NULL;
break;
}
/* Main switch on opcode */
switch (opcode) {
/* BEWARE!
It is essential that any operation that fails sets either
x to NULL, err to nonzero, or why to anything but WHY_NOT,
and that no operation that succeeds does this! */
/* case STOP_CODE: this is an error! */
case POP_TOP:
v = POP();
DECREF(v);
break;
case ROT_TWO:
v = POP();
w = POP();
PUSH(v);
PUSH(w);
break;
case ROT_THREE:
v = POP();
w = POP();
x = POP();
PUSH(v);
PUSH(x);
PUSH(w);
break;
case DUP_TOP:
v = TOP();
INCREF(v);
PUSH(v);
break;
case UNARY_POSITIVE:
v = POP();
x = pos(v);
DECREF(v);
PUSH(x);
break;
case UNARY_NEGATIVE:
v = POP();
x = neg(v);
DECREF(v);
PUSH(x);
break;
case UNARY_NOT:
v = POP();
x = not(v);
DECREF(v);
PUSH(x);
break;
case UNARY_CONVERT:
v = POP();
x = reprobject(v);
DECREF(v);
PUSH(x);
break;
case UNARY_INVERT:
v = POP();
x = invert(v);
DECREF(v);
PUSH(x);
break;
case BINARY_POWER:
w = POP();
v = POP();
x = powerop(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_MULTIPLY:
w = POP();
v = POP();
x = mul(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_DIVIDE:
w = POP();
v = POP();
x = divide(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_MODULO:
w = POP();
v = POP();
x = mod(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_ADD:
w = POP();
v = POP();
x = add(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_SUBTRACT:
w = POP();
v = POP();
x = sub(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_SUBSCR:
w = POP();
v = POP();
x = apply_subscript(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_LSHIFT:
w = POP();
v = POP();
x = lshift(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_RSHIFT:
w = POP();
v = POP();
x = rshift(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_AND:
w = POP();
v = POP();
x = and(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_XOR:
w = POP();
v = POP();
x = xor(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case BINARY_OR:
w = POP();
v = POP();
x = or(v, w);
DECREF(v);
DECREF(w);
PUSH(x);
break;
case SLICE+0:
case SLICE+1:
case SLICE+2:
case SLICE+3:
if ((opcode-SLICE) & 2)
w = POP();
else
w = NULL;
if ((opcode-SLICE) & 1)
v = POP();
else
v = NULL;
u = POP();
x = apply_slice(u, v, w);
DECREF(u);
XDECREF(v);
XDECREF(w);
PUSH(x);
break;
case STORE_SLICE+0:
case STORE_SLICE+1:
case STORE_SLICE+2:
case STORE_SLICE+3:
if ((opcode-STORE_SLICE) & 2)
w = POP();
else
w = NULL;
if ((opcode-STORE_SLICE) & 1)
v = POP();
else
v = NULL;
u = POP();
t = POP();
err = assign_slice(u, v, w, t); /* u[v:w] = t */
DECREF(t);
DECREF(u);
XDECREF(v);
XDECREF(w);
break;
case DELETE_SLICE+0:
case DELETE_SLICE+1:
case DELETE_SLICE+2:
case DELETE_SLICE+3:
if ((opcode-DELETE_SLICE) & 2)
w = POP();
else
w = NULL;
if ((opcode-DELETE_SLICE) & 1)
v = POP();
else
v = NULL;
u = POP();
err = assign_slice(u, v, w, (object *)NULL);
/* del u[v:w] */
DECREF(u);
XDECREF(v);
XDECREF(w);
break;
case STORE_SUBSCR:
w = POP();
v = POP();
u = POP();
/* v[w] = u */
err = assign_subscript(v, w, u);
DECREF(u);
DECREF(v);
DECREF(w);
break;
case DELETE_SUBSCR:
w = POP();
v = POP();
/* del v[w] */
err = assign_subscript(v, w, (object *)NULL);
DECREF(v);
DECREF(w);
break;
case PRINT_EXPR:
v = POP();
/* Print value except if procedure result */
/* Before printing, also assign to '_' */
if (v != None &&
(err = dictinsert(f->f_builtins, "_", v)) == 0 &&
!suppress_print) {
flushline();
x = sysget("stdout");
err = writeobject(v, x, 0);
softspace(x, 1);
flushline();
}
DECREF(v);
break;
case PRINT_ITEM:
v = POP();
w = sysget("stdout");
if (softspace(w, 1))
writestring(" ", w);
err = writeobject(v, w, PRINT_RAW);
if (err == 0 && is_stringobject(v)) {
/* XXX move into writeobject() ? */
char *s = getstringvalue(v);
int len = getstringsize(v);
if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ')
softspace(w, 0);
}
DECREF(v);
break;
case PRINT_NEWLINE:
x = sysget("stdout");
if (x == NULL)
err_setstr(RuntimeError, "lost sys.stdout");
else {
writestring("\n", x);
softspace(x, 0);
}
break;
case BREAK_LOOP:
why = WHY_BREAK;
break;
case RAISE_VARARGS:
u = v = w = NULL;
switch (oparg) {
case 3:
u = POP(); /* traceback */
if (u == None) {
DECREF(u);
u = NULL;
}
else if (!PyTraceBack_Check(u)) {
err_setstr(TypeError,
"raise 3rd arg must be traceback or None");
goto raise_error;
}
/* Fallthrough */
case 2:
v = POP(); /* value */
/* Fallthrough */
case 1:
w = POP(); /* exc */
break;
default:
err_setstr(SystemError,
"bad RAISE_VARARGS oparg");
goto raise_error;
}
if (v == NULL) {
v = None;
INCREF(v);
}
/* A tuple is equivalent to its first element here */
while (is_tupleobject(w) && gettuplesize(w) > 0) {
t = w;
w = GETTUPLEITEM(w, 0);
INCREF(w);
DECREF(t);
}
if (is_stringobject(w)) {
;
} else if (is_classobject(w)) {
if (!is_instanceobject(v)
|| !issubclass((object*)((instanceobject*)v)->in_class,
w)) {
err_setstr(TypeError,
"a class exception must have a value that is an instance of the class");
goto raise_error;
}
} else if (is_instanceobject(w)) {
if (v != None) {
err_setstr(TypeError,
"an instance exception may not have a separate value");
goto raise_error;
}
else {
DECREF(v);
v = w;
w = (object*) ((instanceobject*)w)->in_class;
INCREF(w);
}
}
else {
err_setstr(TypeError,
"exceptions must be strings, classes, or instances");
goto raise_error;
}