diff options
author | Barry Warsaw <barry@python.org> | 2000-08-21 15:38:56 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2000-08-21 15:38:56 (GMT) |
commit | 29c574e30c9600228e1aadc497f2963b0c5d5ae7 (patch) | |
tree | 2c5a4db113b01d0bb1d32648626665e75cf2eb19 /Python | |
parent | 35fd665981e1eb5a1ba3c88c17e5538178047532 (diff) | |
download | cpython-29c574e30c9600228e1aadc497f2963b0c5d5ae7.zip cpython-29c574e30c9600228e1aadc497f2963b0c5d5ae7.tar.gz cpython-29c574e30c9600228e1aadc497f2963b0c5d5ae7.tar.bz2 |
PEP 214, Extended print Statement, has been accepted by the BDFL.
com_print_stmt(): Implement recognition of, and byte compilation for,
extended print using new byte codes PRINT_ITEM_TO and
PRINT_NEWLINE_TO.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/Python/compile.c b/Python/compile.c index 7316790..b7ce770 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2047,16 +2047,44 @@ com_assert_stmt(struct compiling *c, node *n) static void com_print_stmt(struct compiling *c, node *n) { - int i; + int i = 1; + node* stream = NULL; + REQ(n, print_stmt); /* 'print' (test ',')* [test] */ - for (i = 1; i < NCH(n); i += 2) { - com_node(c, CHILD(n, i)); - com_addbyte(c, PRINT_ITEM); - com_pop(c, 1); + + /* are we using the extended print form? */ + if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) { + stream = CHILD(n, 2); + if (NCH(n) > 3 && TYPE(CHILD(n, 3)) == COMMA) + i = 4; + else + i = 3; + } + for (; i < NCH(n); i += 2) { + if (stream != NULL) { + /* stack: [...] => [... obj stream] */ + com_node(c, CHILD(n, i)); + com_node(c, stream); + com_addbyte(c, PRINT_ITEM_TO); + com_pop(c, 2); + } + else { + /* stack: [...] => [... obj] */ + com_node(c, CHILD(n, i)); + com_addbyte(c, PRINT_ITEM); + com_pop(c, 1); + } + } + /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */ + if (TYPE(CHILD(n, NCH(n)-1)) != COMMA) { + if (stream != NULL) { + com_node(c, stream); + com_addbyte(c, PRINT_NEWLINE_TO); + com_pop(c, 1); + } + else + com_addbyte(c, PRINT_NEWLINE); } - if (TYPE(CHILD(n, NCH(n)-1)) != COMMA) - com_addbyte(c, PRINT_NEWLINE); - /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */ } static void |