Repository navigation
v0.4.4: multi-statement constant-literal collection sequences
v0.4.4 — multi-statement constant-literal collection sequences
What's new
Handle module-level bodies consisting of an optional docstring followed by
two or more (or one with docstring) constant-literal collection assignments.
This enables keyword.py-style modules with a docstring, a small list, a large
list, and another small list — all in one pass.
New classification modConstLitSeq fires when:
stmtString+ ≥1stmtConstLitCollstatements, or- ≥2
stmtConstLitCollstatements with no docstring.
Co-consts ordering (matches CPython)
CPython places constants in three phases:
- Atomic strings: docstring (if any), then each large-list (n≥31) element in source order.
- None sentinel.
- Tuples in source order: one
ConstTupleper LIST_EXTEND or tuple statement.
Statements with n≥31 contribute their elements to phase 1; LIST_EXTEND (n=3..30)
and tuple statements contribute their tuple to phase 3. This matches the ordering
CPython produces for keyword.py (co_consts = (docstring, elem0..elemN-1, None, tuple0, tuple1)).
Linetable encoding
Each statement produces entries exactly as in the standalone case, but:
- The docstring covers 2 CUs (LOAD_CONST + STORE_NAME
__doc__) in one entry at[0, docEndCol). - Intermediate STORE_NAME uses SHORT0 n=1.
- The final statement's STORE_NAME uses SHORT0 n=3 (merged with LOAD_CONST None + RETURN_VALUE).
New fixtures (224–226)
- 224
"""doc"""\nx = ['a','b','c']— docstring + 1 LIST_EXTEND - 225
"""doc"""\n__all__ = [...]\nsoftkwlist = [...]— docstring + 2 LIST_EXTEND - 226 keyword.py pattern — docstring + LIST_EXTEND + large list (n=35) + LIST_EXTEND
Files changed
bytecode/assign.go— addedappendValueEntryN(generalisesappendValueEntryto N CUs)bytecode/const_lit_coll.go— addedConstLitSeqStmt,ConstLitSeqLineTablecompiler/classify.go— addedmodConstLitSeq,constLitSeqClassify; updatedstmtsToClassificationcompiler/compiler.go— addedcompileConstLitSeq