| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* Execute compiled code */ | 2 /* Execute compiled code */ |
| 3 | 3 |
| 4 /* XXX TO DO: | 4 /* XXX TO DO: |
| 5 XXX speed up searching for keywords by using a dictionary | 5 XXX speed up searching for keywords by using a dictionary |
| 6 XXX document it! | 6 XXX document it! |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /* enable more aggressive intra-module optimizations, where available */ | 9 /* enable more aggressive intra-module optimizations, where available */ |
| 10 #define PY_LOCAL_AGGRESSIVE | 10 #define PY_LOCAL_AGGRESSIVE |
| 11 | 11 |
| 12 #include "Python.h" | 12 #include "Python.h" |
| 13 | 13 |
| 14 #include "code.h" | 14 #include "code.h" |
| 15 #include "frameobject.h" | 15 #include "frameobject.h" |
| 16 #include "eval.h" | 16 #include "eval.h" |
| 17 #include "opcode.h" | 17 #include "opcode.h" |
| 18 #include "structmember.h" | 18 #include "structmember.h" |
| 19 | 19 |
| 20 #include <ctype.h> | 20 #include <ctype.h> |
| 21 | 21 |
| 22 #ifndef WITH_TSC | 22 #ifndef WITH_TSC |
| 23 | 23 |
| 24 #define READ_TIMESTAMP(var) | 24 #define READ_TIMESTAMP(var) |
| 25 | 25 |
| 26 #else | 26 #else |
| 27 | 27 |
| 28 typedef unsigned long long uint64; | 28 typedef unsigned long long uint64; |
| 29 | 29 |
| 30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this | 30 #if defined(__ppc__) /* <- Don't know if this is the correct symbol; this |
| 31 section should work for GCC on any PowerPC | 31 section should work for GCC on any PowerPC |
| 32 platform, irrespective of OS. | 32 platform, irrespective of OS. |
| 33 POWER? Who knows :-) */ | 33 POWER? Who knows :-) */ |
| 34 | 34 |
| 35 #define READ_TIMESTAMP(var) ppc_getcounter(&var) | 35 #define READ_TIMESTAMP(var) ppc_getcounter(&var) |
| 36 | 36 |
| 37 static void | 37 static void |
| 38 ppc_getcounter(uint64 *v) | 38 ppc_getcounter(uint64 *v) |
| 39 { | 39 { |
| 40 register unsigned long tbu, tb, tbu2; | 40 register unsigned long tbu, tb, tbu2; |
| 41 | 41 |
| 42 loop: | 42 loop: |
| 43 asm volatile ("mftbu %0" : "=r" (tbu) ); | 43 asm volatile ("mftbu %0" : "=r" (tbu) ); |
| 44 asm volatile ("mftb %0" : "=r" (tb) ); | 44 asm volatile ("mftb %0" : "=r" (tb) ); |
| 45 asm volatile ("mftbu %0" : "=r" (tbu2)); | 45 asm volatile ("mftbu %0" : "=r" (tbu2)); |
| 46 if (__builtin_expect(tbu != tbu2, 0)) goto loop; | 46 if (__builtin_expect(tbu != tbu2, 0)) goto loop; |
| 47 | 47 |
| 48 /* The slightly peculiar way of writing the next lines is | 48 /* The slightly peculiar way of writing the next lines is |
| 49 compiled better by GCC than any other way I tried. */ | 49 compiled better by GCC than any other way I tried. */ |
| 50 ((long*)(v))[0] = tbu; | 50 ((long*)(v))[0] = tbu; |
| (...skipping 1378 matching lines...) Show 10 above Show 10 below | |
| 1429 | 1429 |
| 1430 case STORE_LOCALS: | 1430 case STORE_LOCALS: |
| 1431 x = POP(); | 1431 x = POP(); |
| 1432 v = f->f_locals; | 1432 v = f->f_locals; |
| 1433 Py_XDECREF(v); | 1433 Py_XDECREF(v); |
| 1434 f->f_locals = x; | 1434 f->f_locals = x; |
| 1435 continue; | 1435 continue; |
| 1436 | 1436 |
| 1437 case RETURN_VALUE: | 1437 case RETURN_VALUE: |
| 1438 retval = POP(); | 1438 retval = POP(); |
| 1439 why = WHY_RETURN; | 1439 why = WHY_RETURN; |
| 1440 goto fast_block_end; | 1440 goto fast_block_end; |
| 1441 | 1441 |
| 1442 case YIELD_VALUE: | 1442 case YIELD_VALUE: |
| 1443 retval = POP(); | 1443 retval = POP(); |
| 1444 f->f_stacktop = stack_pointer; | 1444 f->f_stacktop = stack_pointer; |
| 1445 why = WHY_YIELD; | 1445 why = WHY_YIELD; |
| 1446 goto fast_yield; | 1446 goto fast_yield; |
| 1447 | 1447 |
| 1448 case POP_BLOCK: | 1448 case POP_BLOCK: |
| 1449 { | 1449 { |
| 1450 PyTryBlock *b = PyFrame_BlockPop(f); | 1450 PyTryBlock *b = PyFrame_BlockPop(f); |
| 1451 while (STACK_LEVEL() > b->b_level) { | 1451 while (STACK_LEVEL() > b->b_level) { |
| 1452 v = POP(); | 1452 v = POP(); |
| 1453 Py_DECREF(v); | 1453 Py_DECREF(v); |
| 1454 } | 1454 } |
| 1455 } | 1455 } |
| 1456 continue; | 1456 continue; |
| 1457 | 1457 |
| 1458 PREDICTED(END_FINALLY); | 1458 PREDICTED(END_FINALLY); |
| 1459 case END_FINALLY: | 1459 case END_FINALLY: |
| 1460 v = POP(); | 1460 v = POP(); |
| 1461 if (PyLong_Check(v)) { | 1461 if (PyLong_Check(v)) { |
| 1462 why = (enum why_code) PyLong_AS_LONG(v); | 1462 why = (enum why_code) PyLong_AS_LONG(v); |
| 1463 assert(why != WHY_YIELD); | 1463 assert(why != WHY_YIELD); |
| 1464 if (why == WHY_RETURN || | 1464 if (why == WHY_RETURN || |
| 1465 why == WHY_CONTINUE) | 1465 why == WHY_CONTINUE) |
| 1466 retval = POP(); | 1466 retval = POP(); |
| 1467 } | 1467 } |
| 1468 else if (PyExceptionClass_Check(v)) { | 1468 else if (PyExceptionClass_Check(v)) { |
| 1469 w = POP(); | 1469 w = POP(); |
| 1470 u = POP(); | 1470 u = POP(); |
| 1471 PyErr_Restore(v, w, u); | 1471 PyErr_Restore(v, w, u); |
| 1472 why = WHY_RERAISE; | 1472 why = WHY_RERAISE; |
| 1473 break; | 1473 break; |
| 1474 } | 1474 } |
| 1475 else if (v != Py_None) { | 1475 else if (v != Py_None) { |
| 1476 PyErr_SetString(PyExc_SystemError, | 1476 PyErr_SetString(PyExc_SystemError, |
| 1477 "'finally' pops bad exception"); | 1477 "'finally' pops bad exception"); |
| 1478 why = WHY_EXCEPTION; | 1478 why = WHY_EXCEPTION; |
| 1479 } | |
| 1480 /* | |
| 1481 Make sure the exception state is cleaned up befo re | |
| 1482 the end of an except block. This ensures objects | |
| 1483 referenced by the exception state are not kept | |
| 1484 alive too long. | |
| 1485 See #2507. | |
|
jhylton
2008/05/06 12:59:48
We don't have a lot of comments that refer to spec
Antoine Pitrou
2008/05/06 15:19:41
On 2008/05/06 12:59:48, jhylton wrote:
> We don't
| |
| 1486 */ | |
|
Antoine Pitrou
2008/05/02 22:17:07
Hmm, it looks like I have gone past the 79-column
| |
| 1487 if (tstate->frame->f_exc_type != NULL) | |
| 1488 reset_exc_info(tstate); | |
| 1489 else { | |
| 1490 assert(tstate->frame->f_exc_value == NULL); | |
| 1491 assert(tstate->frame->f_exc_traceback == NULL); | |
|
jhylton
2008/05/06 12:59:48
I'd move the asserts outside of the else. They sh
Antoine Pitrou
2008/05/06 15:19:41
On 2008/05/06 12:59:48, jhylton wrote:
> I'd move
| |
| 1479 } | 1492 } |
| 1480 Py_DECREF(v); | 1493 Py_DECREF(v); |
| 1481 break; | 1494 break; |
| 1482 | 1495 |
| 1483 case LOAD_BUILD_CLASS: | 1496 case LOAD_BUILD_CLASS: |
| 1484 x = PyDict_GetItemString(f->f_builtins, | 1497 x = PyDict_GetItemString(f->f_builtins, |
| 1485 "__build_class__"); | 1498 "__build_class__"); |
| 1486 if (x == NULL) { | 1499 if (x == NULL) { |
| 1487 PyErr_SetString(PyExc_ImportError, | 1500 PyErr_SetString(PyExc_ImportError, |
| 1488 "__build_class__ not found"); | 1501 "__build_class__ not found"); |
| 1489 break; | 1502 break; |
| 1490 } | 1503 } |
| 1491 Py_INCREF(x); | 1504 Py_INCREF(x); |
| 1492 PUSH(x); | 1505 PUSH(x); |
| 1493 break; | 1506 break; |
| 1494 | 1507 |
| 1495 case STORE_NAME: | 1508 case STORE_NAME: |
| 1496 w = GETITEM(names, oparg); | 1509 w = GETITEM(names, oparg); |
| 1497 v = POP(); | 1510 v = POP(); |
| 1498 if ((x = f->f_locals) != NULL) { | 1511 if ((x = f->f_locals) != NULL) { |
| 1499 if (PyDict_CheckExact(x)) | 1512 if (PyDict_CheckExact(x)) |
| 1500 err = PyDict_SetItem(x, w, v); | 1513 err = PyDict_SetItem(x, w, v); |
| 1501 else | 1514 else |
| 1502 err = PyObject_SetItem(x, w, v); | 1515 err = PyObject_SetItem(x, w, v); |
| 1503 Py_DECREF(v); | 1516 Py_DECREF(v); |
| 1504 if (err == 0) continue; | 1517 if (err == 0) continue; |
| 1505 break; | 1518 break; |
| 1506 } | 1519 } |
| 1507 PyErr_Format(PyExc_SystemError, | 1520 PyErr_Format(PyExc_SystemError, |
| 1508 "no locals found when storing %R", w); | 1521 "no locals found when storing %R", w); |
| 1509 break; | 1522 break; |
| 1510 | 1523 |
| 1511 case DELETE_NAME: | 1524 case DELETE_NAME: |
| 1512 w = GETITEM(names, oparg); | 1525 w = GETITEM(names, oparg); |
| 1513 if ((x = f->f_locals) != NULL) { | 1526 if ((x = f->f_locals) != NULL) { |
| 1514 if ((err = PyObject_DelItem(x, w)) != 0) | 1527 if ((err = PyObject_DelItem(x, w)) != 0) |
| 1515 format_exc_check_arg(PyExc_NameError, | 1528 format_exc_check_arg(PyExc_NameError, |
| 1516 NAME_ERROR_MSG, | 1529 NAME_ERROR_MSG, |
| 1517 w); | 1530 w); |
| 1518 break; | 1531 break; |
| 1519 } | 1532 } |
| 1520 PyErr_Format(PyExc_SystemError, | 1533 PyErr_Format(PyExc_SystemError, |
| 1521 "no locals when deleting %R", w); | 1534 "no locals when deleting %R", w); |
| 1522 break; | 1535 break; |
| 1523 | 1536 |
| 1524 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); | 1537 PREDICTED_WITH_ARG(UNPACK_SEQUENCE); |
| 1525 case UNPACK_SEQUENCE: | 1538 case UNPACK_SEQUENCE: |
| 1526 v = POP(); | 1539 v = POP(); |
| 1527 if (PyTuple_CheckExact(v) && | 1540 if (PyTuple_CheckExact(v) && |
| 1528 PyTuple_GET_SIZE(v) == oparg) { | 1541 PyTuple_GET_SIZE(v) == oparg) { |
| (...skipping 2462 matching lines...) Show 10 above Show 10 below | |
| 3991 /* When in-place resizing is not an option. */ | 4004 /* When in-place resizing is not an option. */ |
| 3992 w = PyUnicode_Concat(v, w); | 4005 w = PyUnicode_Concat(v, w); |
| 3993 Py_DECREF(v); | 4006 Py_DECREF(v); |
| 3994 return w; | 4007 return w; |
| 3995 } | 4008 } |
| 3996 } | 4009 } |
| 3997 | 4010 |
| 3998 #ifdef DYNAMIC_EXECUTION_PROFILE | 4011 #ifdef DYNAMIC_EXECUTION_PROFILE |
| 3999 | 4012 |
| 4000 static PyObject * | 4013 static PyObject * |
| 4001 getarray(long a[256]) | 4014 getarray(long a[256]) |
| 4002 { | 4015 { |
| 4003 int i; | 4016 int i; |
| 4004 PyObject *l = PyList_New(256); | 4017 PyObject *l = PyList_New(256); |
| 4005 if (l == NULL) return NULL; | 4018 if (l == NULL) return NULL; |
| 4006 for (i = 0; i < 256; i++) { | 4019 for (i = 0; i < 256; i++) { |
| 4007 PyObject *x = PyLong_FromLong(a[i]); | 4020 PyObject *x = PyLong_FromLong(a[i]); |
| 4008 if (x == NULL) { | 4021 if (x == NULL) { |
| 4009 Py_DECREF(l); | 4022 Py_DECREF(l); |
| 4010 return NULL; | 4023 return NULL; |
| 4011 } | 4024 } |
| 4012 PyList_SetItem(l, i, x); | 4025 PyList_SetItem(l, i, x); |
| 4013 } | 4026 } |
| 4014 for (i = 0; i < 256; i++) | 4027 for (i = 0; i < 256; i++) |
| 4015 a[i] = 0; | 4028 a[i] = 0; |
| 4016 return l; | 4029 return l; |
| 4017 } | 4030 } |
| 4018 | 4031 |
| 4019 PyObject * | 4032 PyObject * |
| 4020 _Py_GetDXProfile(PyObject *self, PyObject *args) | 4033 _Py_GetDXProfile(PyObject *self, PyObject *args) |
| 4021 { | 4034 { |
| 4022 #ifndef DXPAIRS | 4035 #ifndef DXPAIRS |
| 4023 return getarray(dxp); | 4036 return getarray(dxp); |
| 4024 #else | 4037 #else |
| 4025 int i; | 4038 int i; |
| 4026 PyObject *l = PyList_New(257); | 4039 PyObject *l = PyList_New(257); |
| 4027 if (l == NULL) return NULL; | 4040 if (l == NULL) return NULL; |
| 4028 for (i = 0; i < 257; i++) { | 4041 for (i = 0; i < 257; i++) { |
| 4029 PyObject *x = getarray(dxpairs[i]); | 4042 PyObject *x = getarray(dxpairs[i]); |
| 4030 if (x == NULL) { | 4043 if (x == NULL) { |
| 4031 Py_DECREF(l); | 4044 Py_DECREF(l); |
| 4032 return NULL; | 4045 return NULL; |
| 4033 } | 4046 } |
| 4034 PyList_SetItem(l, i, x); | 4047 PyList_SetItem(l, i, x); |
| 4035 } | 4048 } |
| 4036 return l; | 4049 return l; |
| 4037 #endif | 4050 #endif |
| 4038 } | 4051 } |
| 4039 | 4052 |
| 4040 #endif | 4053 #endif |
| OLD | NEW |