circuitpython/tests/cmdline/cmd_parsetree.py.exp
Damien George 5255255fb9 py: Create str/bytes objects in the parser, not the compiler.
Previous to this patch any non-interned str/bytes objects would create a
special parse node that held a copy of the str/bytes data.  Then in the
compiler this data would be turned into a str/bytes object.  This actually
lead to 2 copies of the data, one in the parse node and one in the object.
The parse node's copy of the data would be freed at the end of the compile
stage but nevertheless it meant that the peak memory usage of the
parse/compile stage was higher than it needed to be (by an amount equal to
the number of bytes in all the non-interned str/bytes objects).

This patch changes the behaviour so that str/bytes objects are created
directly in the parser and the object stored in a const-object parse node
(which already exists for bignum, float and complex const objects).  This
reduces peak RAM usage of the parse/compile stage, simplifies the parser
and compiler, and reduces code size by about 170 bytes on Thumb2 archs,
and by about 300 bytes on Xtensa archs.
2017-02-24 13:43:43 +11:00

68 lines
1.4 KiB
Plaintext

----------------
[ 4] rule(1) (n=8)
tok(4)
[ 4] rule(22) (n=4)
id(i)
[ 4] rule(45) (n=1)
NULL
[ 5] rule(8) (n=0)
NULL
[ 6] rule(5) (n=2)
id(a)
tok(14)
[ 7] rule(5) (n=2)
id(b)
str(str)
[ 8] rule(5) (n=2)
id(c)
[ 8] literal \.\+
[ 9] rule(5) (n=2)
id(d)
bytes(bytes)
[ 10] rule(5) (n=2)
id(e)
[ 10] literal \.\+
[ 11] rule(5) (n=2)
id(f)
[ 11] literal \.\+
----------------
File cmdline/cmd_parsetree.py, code block '<module>' (descriptor: \.\+, bytecode @\.\+ bytes)
Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
########
\.\+5b
arg names:
(N_STATE 5)
(N_EXC_STACK 0)
bc=-1 line=1
bc=0 line=4
bc=9 line=5
bc=12 line=6
bc=16 line=7
bc=22 line=8
bc=27 line=9
bc=32 line=10
bc=37 line=11
00 BUILD_TUPLE 0
02 GET_ITER_STACK
03 FOR_ITER 12
06 STORE_NAME i
09 JUMP 3
12 LOAD_CONST_NONE
13 STORE_NAME a
16 LOAD_CONST_STRING 'str'
19 STORE_NAME b
22 LOAD_CONST_OBJ \.\+
24 STORE_NAME c
27 LOAD_CONST_OBJ \.\+
29 STORE_NAME d
32 LOAD_CONST_OBJ \.\+
34 STORE_NAME e
37 LOAD_CONST_OBJ \.\+
39 STORE_NAME f
42 LOAD_CONST_NONE
43 RETURN_VALUE
mem: total=\\d\+, current=\\d\+, peak=\\d\+
stack: \\d\+ out of \\d\+
GC: total: \\d\+, used: \\d\+, free: \\d\+
No. of 1-blocks: \\d\+, 2-blocks: \\d\+, max blk sz: \\d\+, max free sz: \\d\+