The real suport for augmented assignment: new opcodes, new PyNumber and
PySequence methods and functions, new tokens.
This commit is contained in:
parent
e289e0bd0c
commit
dd8dbdb717
|
@ -664,6 +664,108 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
float(o).
|
float(o).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* In-place variants of (some of) the above number protocol functions */
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of adding o2 to o1, possibly in-place, or null
|
||||||
|
on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 += o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of subtracting o2 from o1, possibly in-place or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 -= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of multiplying o1 by o2, possibly in-place, or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 *= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of dividing o1 by o2, possibly in-place, or null
|
||||||
|
on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 /= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the remainder of dividing o1 by o2, possibly in-place, or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 %= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
|
||||||
|
PyObject *o3);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of raising o1 to the power of o2, possibly
|
||||||
|
in-place, or null on failure. This is the equivalent of the Python
|
||||||
|
expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of left shifting o1 by o2, possibly in-place, or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 <<= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of right shifting o1 by o2, possibly in-place or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 >>= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of bitwise and of o1 and o2, possibly in-place,
|
||||||
|
or null on failure. This is the equivalent of the Python
|
||||||
|
expression: o1 &= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
|
||||||
|
null on failure. This is the equivalent of the Python expression:
|
||||||
|
o1 ^= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the result of bitwise or or o1 and o2, possibly in-place,
|
||||||
|
or null on failure. This is the equivalent of the Python
|
||||||
|
expression: o1 |= o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Sequence protocol:*/
|
/* Sequence protocol:*/
|
||||||
|
|
||||||
|
@ -824,6 +926,26 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
expression: o.index(value).
|
expression: o.index(value).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* In-place versions of some of the above Sequence functions. */
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Append o2 to o1, in-place when possible. Return the resulting
|
||||||
|
object, which could be o1, or NULL on failure. This is the
|
||||||
|
equivalent of the Python expression: o1 += o2.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
DL_IMPORT(PyObject *) PySequence_InPlaceRepeat(PyObject *o, int count);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Repeat o1 by count, in-place when possible. Return the resulting
|
||||||
|
object, which could be o1, or NULL on failure. This is the
|
||||||
|
equivalent of the Python expression: o1 *= count.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/* Mapping protocol:*/
|
/* Mapping protocol:*/
|
||||||
|
|
||||||
DL_IMPORT(int) PyMapping_Check(PyObject *o);
|
DL_IMPORT(int) PyMapping_Check(PyObject *o);
|
||||||
|
|
|
@ -73,6 +73,10 @@ extern DL_IMPORT(PyObject *) PyInstance_DoBinOp(PyObject *, PyObject *,
|
||||||
PyObject * (*)(PyObject *,
|
PyObject * (*)(PyObject *,
|
||||||
PyObject *));
|
PyObject *));
|
||||||
|
|
||||||
|
extern DL_IMPORT(int)
|
||||||
|
PyInstance_HalfBinOp(PyObject *, PyObject *, char *, PyObject **,
|
||||||
|
PyObject * (*)(PyObject *, PyObject *), int);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,54 +10,55 @@
|
||||||
#define simple_stmt 265
|
#define simple_stmt 265
|
||||||
#define small_stmt 266
|
#define small_stmt 266
|
||||||
#define expr_stmt 267
|
#define expr_stmt 267
|
||||||
#define print_stmt 268
|
#define augassign 268
|
||||||
#define del_stmt 269
|
#define print_stmt 269
|
||||||
#define pass_stmt 270
|
#define del_stmt 270
|
||||||
#define flow_stmt 271
|
#define pass_stmt 271
|
||||||
#define break_stmt 272
|
#define flow_stmt 272
|
||||||
#define continue_stmt 273
|
#define break_stmt 273
|
||||||
#define return_stmt 274
|
#define continue_stmt 274
|
||||||
#define raise_stmt 275
|
#define return_stmt 275
|
||||||
#define import_stmt 276
|
#define raise_stmt 276
|
||||||
#define import_as_name 277
|
#define import_stmt 277
|
||||||
#define dotted_as_name 278
|
#define import_as_name 278
|
||||||
#define dotted_name 279
|
#define dotted_as_name 279
|
||||||
#define global_stmt 280
|
#define dotted_name 280
|
||||||
#define exec_stmt 281
|
#define global_stmt 281
|
||||||
#define assert_stmt 282
|
#define exec_stmt 282
|
||||||
#define compound_stmt 283
|
#define assert_stmt 283
|
||||||
#define if_stmt 284
|
#define compound_stmt 284
|
||||||
#define while_stmt 285
|
#define if_stmt 285
|
||||||
#define for_stmt 286
|
#define while_stmt 286
|
||||||
#define try_stmt 287
|
#define for_stmt 287
|
||||||
#define except_clause 288
|
#define try_stmt 288
|
||||||
#define suite 289
|
#define except_clause 289
|
||||||
#define test 290
|
#define suite 290
|
||||||
#define and_test 291
|
#define test 291
|
||||||
#define not_test 292
|
#define and_test 292
|
||||||
#define comparison 293
|
#define not_test 293
|
||||||
#define comp_op 294
|
#define comparison 294
|
||||||
#define expr 295
|
#define comp_op 295
|
||||||
#define xor_expr 296
|
#define expr 296
|
||||||
#define and_expr 297
|
#define xor_expr 297
|
||||||
#define shift_expr 298
|
#define and_expr 298
|
||||||
#define arith_expr 299
|
#define shift_expr 299
|
||||||
#define term 300
|
#define arith_expr 300
|
||||||
#define factor 301
|
#define term 301
|
||||||
#define power 302
|
#define factor 302
|
||||||
#define atom 303
|
#define power 303
|
||||||
#define listmaker 304
|
#define atom 304
|
||||||
#define lambdef 305
|
#define listmaker 305
|
||||||
#define trailer 306
|
#define lambdef 306
|
||||||
#define subscriptlist 307
|
#define trailer 307
|
||||||
#define subscript 308
|
#define subscriptlist 308
|
||||||
#define sliceop 309
|
#define subscript 309
|
||||||
#define exprlist 310
|
#define sliceop 310
|
||||||
#define testlist 311
|
#define exprlist 311
|
||||||
#define dictmaker 312
|
#define testlist 312
|
||||||
#define classdef 313
|
#define dictmaker 313
|
||||||
#define arglist 314
|
#define classdef 314
|
||||||
#define argument 315
|
#define arglist 315
|
||||||
#define list_iter 316
|
#define argument 316
|
||||||
#define list_for 317
|
#define list_iter 317
|
||||||
#define list_if 318
|
#define list_for 318
|
||||||
|
#define list_if 319
|
||||||
|
|
|
@ -151,6 +151,17 @@ typedef struct {
|
||||||
unaryfunc nb_float;
|
unaryfunc nb_float;
|
||||||
unaryfunc nb_oct;
|
unaryfunc nb_oct;
|
||||||
unaryfunc nb_hex;
|
unaryfunc nb_hex;
|
||||||
|
binaryfunc nb_inplace_add;
|
||||||
|
binaryfunc nb_inplace_subtract;
|
||||||
|
binaryfunc nb_inplace_multiply;
|
||||||
|
binaryfunc nb_inplace_divide;
|
||||||
|
binaryfunc nb_inplace_remainder;
|
||||||
|
ternaryfunc nb_inplace_power;
|
||||||
|
binaryfunc nb_inplace_lshift;
|
||||||
|
binaryfunc nb_inplace_rshift;
|
||||||
|
binaryfunc nb_inplace_and;
|
||||||
|
binaryfunc nb_inplace_xor;
|
||||||
|
binaryfunc nb_inplace_or;
|
||||||
} PyNumberMethods;
|
} PyNumberMethods;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -162,6 +173,8 @@ typedef struct {
|
||||||
intobjargproc sq_ass_item;
|
intobjargproc sq_ass_item;
|
||||||
intintobjargproc sq_ass_slice;
|
intintobjargproc sq_ass_slice;
|
||||||
objobjproc sq_contains;
|
objobjproc sq_contains;
|
||||||
|
binaryfunc sq_inplace_concat;
|
||||||
|
intargfunc sq_inplace_repeat;
|
||||||
} PySequenceMethods;
|
} PySequenceMethods;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -315,8 +328,12 @@ given type object has a specified feature.
|
||||||
#define Py_TPFLAGS_GC 0
|
#define Py_TPFLAGS_GC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* PySequenceMethods and PyNumberMethods contain in-place operators */
|
||||||
|
#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
|
||||||
|
|
||||||
#define Py_TPFLAGS_DEFAULT (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
|
#define Py_TPFLAGS_DEFAULT (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
|
||||||
Py_TPFLAGS_HAVE_SEQUENCE_IN)
|
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
|
||||||
|
Py_TPFLAGS_HAVE_INPLACEOPS)
|
||||||
|
|
||||||
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
|
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
#define ROT_TWO 2
|
#define ROT_TWO 2
|
||||||
#define ROT_THREE 3
|
#define ROT_THREE 3
|
||||||
#define DUP_TOP 4
|
#define DUP_TOP 4
|
||||||
|
#define ROT_FOUR 5
|
||||||
|
|
||||||
#define UNARY_POSITIVE 10
|
#define UNARY_POSITIVE 10
|
||||||
#define UNARY_NEGATIVE 11
|
#define UNARY_NEGATIVE 11
|
||||||
|
@ -47,6 +48,11 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
#define DELETE_SLICE 50
|
#define DELETE_SLICE 50
|
||||||
/* Also uses 51-53 */
|
/* Also uses 51-53 */
|
||||||
|
|
||||||
|
#define INPLACE_ADD 55
|
||||||
|
#define INPLACE_SUBTRACT 56
|
||||||
|
#define INPLACE_MULTIPLY 57
|
||||||
|
#define INPLACE_DIVIDE 58
|
||||||
|
#define INPLACE_MODULO 59
|
||||||
#define STORE_SUBSCR 60
|
#define STORE_SUBSCR 60
|
||||||
#define DELETE_SUBSCR 61
|
#define DELETE_SUBSCR 61
|
||||||
|
|
||||||
|
@ -55,14 +61,18 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
#define BINARY_AND 64
|
#define BINARY_AND 64
|
||||||
#define BINARY_XOR 65
|
#define BINARY_XOR 65
|
||||||
#define BINARY_OR 66
|
#define BINARY_OR 66
|
||||||
|
#define INPLACE_POWER 67
|
||||||
|
|
||||||
#define PRINT_EXPR 70
|
#define PRINT_EXPR 70
|
||||||
#define PRINT_ITEM 71
|
#define PRINT_ITEM 71
|
||||||
#define PRINT_NEWLINE 72
|
#define PRINT_NEWLINE 72
|
||||||
#define PRINT_ITEM_TO 73
|
#define PRINT_ITEM_TO 73
|
||||||
#define PRINT_NEWLINE_TO 74
|
#define PRINT_NEWLINE_TO 74
|
||||||
|
#define INPLACE_LSHIFT 75
|
||||||
|
#define INPLACE_RSHIFT 76
|
||||||
|
#define INPLACE_AND 77
|
||||||
|
#define INPLACE_XOR 78
|
||||||
|
#define INPLACE_OR 79
|
||||||
#define BREAK_LOOP 80
|
#define BREAK_LOOP 80
|
||||||
|
|
||||||
#define LOAD_LOCALS 82
|
#define LOAD_LOCALS 82
|
||||||
|
@ -84,7 +94,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
#define DELETE_ATTR 96 /* "" */
|
#define DELETE_ATTR 96 /* "" */
|
||||||
#define STORE_GLOBAL 97 /* "" */
|
#define STORE_GLOBAL 97 /* "" */
|
||||||
#define DELETE_GLOBAL 98 /* "" */
|
#define DELETE_GLOBAL 98 /* "" */
|
||||||
|
#define DUP_TOPX 99 /* number of items to duplicate */
|
||||||
#define LOAD_CONST 100 /* Index in const list */
|
#define LOAD_CONST 100 /* Index in const list */
|
||||||
#define LOAD_NAME 101 /* Index in name list */
|
#define LOAD_NAME 101 /* Index in name list */
|
||||||
#define BUILD_TUPLE 102 /* Number of tuple items */
|
#define BUILD_TUPLE 102 /* Number of tuple items */
|
||||||
|
|
|
@ -53,10 +53,21 @@ extern "C" {
|
||||||
#define LEFTSHIFT 34
|
#define LEFTSHIFT 34
|
||||||
#define RIGHTSHIFT 35
|
#define RIGHTSHIFT 35
|
||||||
#define DOUBLESTAR 36
|
#define DOUBLESTAR 36
|
||||||
|
#define PLUSEQUAL 37
|
||||||
|
#define MINEQUAL 38
|
||||||
|
#define STAREQUAL 39
|
||||||
|
#define SLASHEQUAL 40
|
||||||
|
#define PERCENTEQUAL 41
|
||||||
|
#define AMPEREQUAL 42
|
||||||
|
#define VBAREQUAL 43
|
||||||
|
#define CIRCUMFLEXEQUAL 44
|
||||||
|
#define LEFTSHIFTEQUAL 45
|
||||||
|
#define RIGHTSHIFTEQUAL 46
|
||||||
|
#define DOUBLESTAREQUAL 47
|
||||||
/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
|
/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
|
||||||
#define OP 37
|
#define OP 48
|
||||||
#define ERRORTOKEN 38
|
#define ERRORTOKEN 49
|
||||||
#define N_TOKENS 39
|
#define N_TOKENS 50
|
||||||
|
|
||||||
/* Special definitions for cooperation with parser */
|
/* Special definitions for cooperation with parser */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue