Skip to content

v0.0.11

Choose a tag to compare

@tamnd tamnd released this 26 Apr 14:24
· 111 commits to main since this release
v0.0.11
4f4b71c

v0.0.11

gocopy compile accepts a leading - on the right-hand side of a
name = literal assignment, producing a negative integer or float
constant.

CPython's constant folder treats -N as UNARY_NEGATIVE applied to the
literal N, then folds the result. Both the original un-negated value
and the folded negative end up in the consts tuple:

consts = (N, None, -N)   LOAD_CONST 2 → the negated value
noneIdx = 1

Negative floats follow the same pattern. Integer immortal-range rules
apply to the positive literal: values in [0, 256] get FLAG_REF; the
negative counterparts follow the same immortal rule ([-5, -1] get
FLAG_REF; below -5 do not).

-0 (integer) is excluded from this rung — CPython also keeps both
0 and 0 in the tuple, but the duplicate handling is non-trivial.

Added

  • negLiteral{pos, neg any} type in compiler/classify.go: carries
    both the un-negated and negated values so the compiler can build the
    correct consts tuple.
  • Negative-prefix detection in tryParseAssign: checked before the
    positive-float parser (which accepts a leading -).
  • bytecode.AssignBytecodeAt(valueIdx, noneIdx byte, tailStmts int):
    the general form of AssignBytecode with an explicit value const index.
    AssignBytecode is now a thin wrapper calling AssignBytecodeAt(0, ...).
  • Five new fixtures: 053_assign_neg_one.py through
    057_assign_neg_float_sci.py.

Out of scope (deferred)

  • -0 (integer negative zero).
  • Negative integers below -2^31 (need TYPE_LONG).
  • Complex literal RHS (x = 1j).
  • Multiple sequential assignments (x = 1\ny = 2).
  • Wiring gopapy as the parser.