decimal: runtime arithmetic (torb_decimal_*) and ready natives #334

Closed
opened 2026-10-12 13:15:56 +00:00 by orion · 6 comments
Collaborator

Part of #34, after #332 (design record).

Goal

Implement the Decimal runtime in runtime/ (C11, new decimal.c plus declarations in torb.h): a reference-counted value holding sign, base-10^9 limbs and an Int32 scale, with the functions the manifest names: torb_decimal_add/subtract/multiply/divide/remainder/negate/absolute/equals/compare/show/hash and torb_decimal_parse, plus the rounding and scale helpers #332 specifies. Turn the decimalEntries of compiler/src/backend/c/natives.trb from plannedRuntimeOf into ready entries; the VM reaches them through the generated thunk table.

Acceptance criteria

  • No plannedRuntimeOf entry for Decimal is left in natives.trb; torb natives --header output and runtime/machine_natives.c are regenerated and committed.
  • C-level tests under runtime/tests/ cover the table of #332 (add/sub/mul exact, division to the context precision, remainder sign, rounding modes, parse and show round trip, scale and exponent limits, divide by zero panic, overflow panic) and run in tier B.
  • A small TorbScript program using only the Decimal natives gives the same output with torb run and torb run --native; leak gate: live blocks at exit 0.

Seed impact

None expected: the compiler sources never use Decimal, and the natives were already declared in the manifest, so no form is new to the seed. The implementer confirms with grep -rn Decimal compiler/src that nothing the seed compiles reaches a Decimal native; if it does, split into two commits per CLAUDE.md "Seed and breaking changes" (the seed refresh itself stays Torben's).

Size

One PR, feat(runtime): ... plus a feat(natives): ... commit. Back-end change: tier B required (touches runtime/ and backend/).

Part of #34, after #332 (design record). ## Goal Implement the `Decimal` runtime in `runtime/` (C11, new `decimal.c` plus declarations in `torb.h`): a reference-counted value holding sign, base-10^9 limbs and an `Int32` scale, with the functions the manifest names: `torb_decimal_add/subtract/multiply/divide/remainder/negate/absolute/equals/compare/show/hash` and `torb_decimal_parse`, plus the rounding and scale helpers #332 specifies. Turn the `decimalEntries` of `compiler/src/backend/c/natives.trb` from `plannedRuntimeOf` into ready entries; the VM reaches them through the generated thunk table. ## Acceptance criteria - [ ] No `plannedRuntimeOf` entry for `Decimal` is left in `natives.trb`; `torb natives --header` output and `runtime/machine_natives.c` are regenerated and committed. - [ ] C-level tests under `runtime/tests/` cover the table of #332 (add/sub/mul exact, division to the context precision, remainder sign, rounding modes, parse and show round trip, scale and exponent limits, divide by zero panic, overflow panic) and run in tier B. - [ ] A small TorbScript program using only the `Decimal` natives gives the same output with `torb run` and `torb run --native`; leak gate: live blocks at exit 0. ## Seed impact None expected: the compiler sources never use `Decimal`, and the natives were already declared in the manifest, so no form is new to the seed. The implementer confirms with `grep -rn Decimal compiler/src` that nothing the seed compiles reaches a `Decimal` native; if it does, split into two commits per CLAUDE.md "Seed and breaking changes" (the seed refresh itself stays Torben's). ## Size One PR, `feat(runtime): ...` plus a `feat(natives): ...` commit. Back-end change: tier B required (touches `runtime/` and `backend/`).
Author
Collaborator

[loop:torbscript] refine: slice 2 of #34, next: waiting (dependency #332)

[loop:torbscript] refine: slice 2 of #34, next: waiting (dependency #332)
Author
Collaborator

[loop:torbscript] refine: dependency #332 landed (PR #340, DECIMAL.md on main), label ready set, next: implement

[loop:torbscript] refine: dependency #332 landed (PR #340, DECIMAL.md on main), label `ready` set, next: implement
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261012 until 2026-10-13T03:40Z

[loop:torbscript] claim implement by session:loop-torbscript-20261012 until 2026-10-13T03:40Z
Author
Collaborator

[loop:torbscript] implement: the worker ended on a session limit; PR #353 is open but tier A, tier B and gates are red (run 997) and the branch is not mergeable, next: fix round (rebase on main, fix the red jobs)

[loop:torbscript] implement: the worker ended on a session limit; PR https://git.torb.dev/torbscript/language/pulls/353 is open but tier A, tier B and gates are red (run 997) and the branch is not mergeable, next: fix round (rebase on main, fix the red jobs)
Author
Collaborator

[loop:torbscript] claim fix by session:loop-torbscript-20261013 until 2026-10-13T09:42Z

[loop:torbscript] claim fix by session:loop-torbscript-20261013 until 2026-10-13T09:42Z
Author
Collaborator

[loop:torbscript] release fix: the worker ended on a session limit after pushing; PR #353 is now green on every required job (tier A, tier B, gates) and mergeable, merge gate review requested, next: waiting (merge gate review of PR #353)

[loop:torbscript] release fix: the worker ended on a session limit after pushing; PR https://git.torb.dev/torbscript/language/pulls/353 is now green on every required job (tier A, tier B, gates) and mergeable, merge gate review requested, next: waiting (merge gate review of PR #353)
argus closed this issue 2026-10-13 07:05:48 +00:00
Sign in to join this conversation.
No labels
loop
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#334
No description provided.