decimal: decimal literals and constants for Decimal #335
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #34, after #332 and the runtime issue #334.
Goal
const price: Decimal = 19.99(andstatic zero: Self = 0.0instd/number) must evaluate in both back ends. Todayquote.trband the IR have no static form for aDecimal: "there is no float literal type, so a float constant is not aLiteralValue" (compiler/src/ir/ir.trb). Give aDecimalconstant a static form (the literal's exact text) that both back ends turn intotorb_decimal_parseof that text at initialisation, so19.99is exact and0.1 + 0.2 == 0.3holds.Acceptance criteria
Decimalkeeps every written digit (no pass throughFloat64); a literal with more digits than the range limit of #332 is a compile error naming the limit.irtext format, bytecode and C back end handle the constant;plain.trb,exhaustive.trbandquote.trbneed no special case left that returns "not supported" forDecimal.Decimalin amatchon a literal pattern behaves as #332 says.decimal-literalsidentical in the VM and natively.Seed impact
Probably none: no compiler source uses a
Decimalliteral. If the change adds a name looked up by string or a new IR form the seed must read, take the two-commit route (CLAUDE.md "Seed and breaking changes").Size
One PR,
feat(ir): .../feat(checker): ....Exactand conformance programs #336Decimalthat computes #34[loop:torbscript] refine: slice 3 of #34, next: waiting (dependency #334)
Exactand conformance programs #336Decimalthat computes #34[loop:torbscript] claim refine by session:loop-torbscript-20261022 until 2026-10-23T01:30:00Z
[loop:torbscript] decided by the loop: refined acceptance criteria, since #332 landed (docs/design/DECIMAL.md section 9 and 14 slice 3):
Int32(section 9), e.g.1e-3000000000. Why: the record is the source of truth, and the runtime stores digits in an arbitrary-size block._dropped) plus anInt32scale, never aFloat64. Both back ends emit it as an immortal static block (TORB_IMMORTAL_COUNT) so a constant allocates nothing at run time; the checker/constant evaluator builds it. Why: record section 9/10. A new IR constant form is added next toLiteralValue-based statics (compiler/src/ir/ir.trb), text format, bytecode and C back end handle it.Decimal.zero/Decimal.oneinstd/numberbecome0and1(scale 0), per section 9, soDecimal.zero + 5keeps the scale of5.-19.99is the negation of19.99, scale 2.matchon a literal pattern compares by numeric value like==(section 3): the pattern1.0matches1.00. A Decimal match is never exhaustive without a wildcard arm. Why: the record defines equality by value and does not special-case patterns; reusing==keeps one rule.Float64/Int64.ir --statistics .shows the compiler reaching a new name or IR form the seed must read, use the two-commit route.[loop:torbscript] refine: ready. Goal and the record point (DECIMAL.md section 9, slice 3) are clear; the acceptance criteria are corrected per the decided-by-the-loop comment above (no digit limit; compile error only for a scale outside Int32; match literal patterns by value; zero/one become scale 0; conformance program
decimal-literalsidentical in VM and native). Seed: no touch expected. Size: one PR,feat(checker): .../feat(ir): .... Tokens used by this refine worker: ~45k. next: implement[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T04:17:00Z
[loop:torbscript] implement: PR #401 is open and CI is green (gates, tier A and B, conformance in native, VM and debugger lowering, bootstrap). Number literals now adapt to
Decimalwith every written digit (only a scale outsideInt32is a compile error); the IR has a newStaticContents.Decimalform emitted as an immortal block by the C back end and the bytecode (new kernel op 86, no native);Decimal.zero/oneare0/1; amatchcompares literals by numeric value. Checker tests plus the conformance programdecimal-literalsare in. Seed: no refresh needed (the "pack the seed" job was skipped). Fix rounds: 3 (pdisc stamp, format and declarations, expected output and allocation budget 124, one commit type). Token usage: not metered inside the subagent; the run spanned two context windows. next: reviewDecimalthat computes #34Decimalthat computes #34Decimalthat computes #34