feat(types): Huge + Angle + Percent polish numeric types (#55)
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 19s
ci / build-and-test (push) Successful in 1m30s
commit-lint / conventional-commits (push) Successful in 6s
docs / build-and-deploy (push) Successful in 23s

Types phase 5 (polish). A splice-on-demand numeric runtime
(runtime/native/numeric.ludic, built on the inline Math.* trig) behind three
namespaces:

- Huge.* — idle big numbers (normalized mantissa x 10^exponent): from/add/
  sub/mul/neg/cmp/sign/mantissa/exp/str (scientific 1.23e45). Display-scale,
  not lockstep-exact (BigInt/Decimal for exactness).
- Angle.* — auto-wrapping radians: from_degrees/to_degrees/wrap/sin/cos/add/
  diff (shortest signed rotation)/lerp (shortest arc).
- Percent.* — clamped [0,1]: clamp/of/lerp/apply.

Remaining phase-5 items are already covered (duration=Duration.*,
rune=Unicode.*, i64=long) or need a type-checking pass (handle, typed name,
other sized ints) — tracked for later.

Wired: parser splice trigger (g_uses_numeric), emit_call dispatch, reseeded
seed, a self-asserting example (examples/library/numeric.ludic + feat_case),
per-symbol docs + inventory. All suites green incl. golden renders byte-
identical and the bootstrap fixpoint.

NOTE: fixed `const`s lower to raw-int-typed values (emit_call N_CONST), which
breaks fixed comparisons — the runtime uses inline fixed literals instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-31 19:04:37 +03:00
parent 539f258d92
commit 5dc8394f22
33 changed files with 23162 additions and 21092 deletions

View file

@ -389,6 +389,37 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
if (meth == "clear") { bare = "set_clear"; push(labels, "s") }
if (meth == "members") { bare = "set_members"; push(labels, "s") }
}
# Huge.* / Angle.* / Percent.* -> the numeric runtime (runtime/native/numeric.ludic,
# spliced on demand). Ordinary Ludic functions, so the generic call path keeps
# their return types (Huge / fixed / int / bool).
if (ns == "Huge") {
if (meth == "from") { bare = "huge_from"; push(labels, "value") }
if (meth == "add") { bare = "huge_add"; push(labels, "a"); push(labels, "b") }
if (meth == "sub") { bare = "huge_sub"; push(labels, "a"); push(labels, "b") }
if (meth == "mul") { bare = "huge_mul"; push(labels, "a"); push(labels, "b") }
if (meth == "neg") { bare = "huge_neg"; push(labels, "a") }
if (meth == "cmp") { bare = "huge_cmp"; push(labels, "a"); push(labels, "b") }
if (meth == "sign") { bare = "huge_sign"; push(labels, "a") }
if (meth == "mantissa") { bare = "huge_mantissa"; push(labels, "a") }
if (meth == "exp") { bare = "huge_exp"; push(labels, "a") }
if (meth == "str") { bare = "huge_str"; push(labels, "a") }
}
if (ns == "Angle") {
if (meth == "from_degrees") { bare = "angle_from_degrees"; push(labels, "d") }
if (meth == "to_degrees") { bare = "angle_to_degrees"; push(labels, "a") }
if (meth == "wrap") { bare = "angle_wrap"; push(labels, "a") }
if (meth == "sin") { bare = "angle_sin"; push(labels, "a") }
if (meth == "cos") { bare = "angle_cos"; push(labels, "a") }
if (meth == "add") { bare = "angle_add"; push(labels, "a"); push(labels, "b") }
if (meth == "diff") { bare = "angle_diff"; push(labels, "a"); push(labels, "b") }
if (meth == "lerp") { bare = "angle_lerp"; push(labels, "a"); push(labels, "b"); push(labels, "t") }
}
if (ns == "Percent") {
if (meth == "clamp") { bare = "percent_clamp"; push(labels, "v") }
if (meth == "of") { bare = "percent_of"; push(labels, "num"); push(labels, "den") }
if (meth == "lerp") { bare = "percent_lerp"; push(labels, "a"); push(labels, "b"); push(labels, "t") }
if (meth == "apply") { bare = "percent_apply"; push(labels, "value"); push(labels, "p") }
}
if (ns == "Grid") {
if (meth == "line") { bare = "grid_line"; push(labels, "x0"); push(labels, "y0"); push(labels, "x1"); push(labels, "y1") }
if (meth == "blocked") { bare = "grid_blocked"; push(labels, "x"); push(labels, "y"); push(labels, "wall") }

View file

@ -177,6 +177,7 @@ function p_postfix() -> Node {
if e.a.kind == E_ID and e.a.s == "Regex" { g_uses_regex = true } # splice the regex runtime on demand
if e.a.kind == E_ID and (e.a.s == "BigInt" or e.a.s == "Decimal") { g_uses_bignum = true } # splice the bignum runtime on demand
if e.a.kind == E_ID and (e.a.s == "Dict" or e.a.s == "Set") { g_uses_dict = true } # splice the hash-table runtime on demand
if e.a.kind == E_ID and (e.a.s == "Huge" or e.a.s == "Angle" or e.a.s == "Percent") { g_uses_numeric = true } # splice the huge/angle/percent runtime on demand
if e.a.kind == E_ID and e.a.s == "Query" { g_uses_query = true } # splice the ECS spatial-query runtime on demand
if e.a.kind == E_ID and e.a.s == "Reflect" { g_uses_reflect = true } # force-emit the reflection ABI (Reflect.* reads the world schema)
if e.a.kind == E_ID and e.a.s == "Light" { g_uses_light = true } # splice the 2D light-accumulation pass on demand
@ -425,6 +426,7 @@ var cur_dir: pointer
var g_uses_regex: bool = false # a program mentioned Regex.* -> splice the regex runtime
var g_uses_bignum: bool = false # a program mentioned BigInt.*/Decimal.* -> splice the bignum runtime
var g_uses_dict: bool = false # a program mentioned Dict.*/Set.* -> splice the hash-table runtime
var g_uses_numeric: bool = false # a program mentioned Huge.*/Angle.*/Percent.* -> splice the numeric runtime
var g_uses_query: bool = false # a program mentioned Query.* -> splice the query runtime + reflection ABI
var g_uses_reflect: bool = false # a program mentioned Reflect.* -> force-emit the reflection ABI
var g_uses_light: bool = false # a program mentioned Light.* -> splice the 2D light pass
@ -617,6 +619,13 @@ function maybe_splice_runtime() -> void {
do_import("runtime/native/dict.ludic")
cur_dir = saved
}
# any program that uses Huge.*/Angle.*/Percent.* gets the numeric runtime
# spliced in (it builds on Math.*, which lowers inline, so a plain tool works).
if g_uses_numeric {
cur_dir = ""
do_import("runtime/native/numeric.ludic")
cur_dir = saved
}
# any program that uses Query.* gets the ECS spatial-query helpers spliced in;
# they read entity state through the reflection ABI (emit_decl force-emits it
# for a Query program even when it declares no events).
@ -733,6 +742,7 @@ function parse_program() -> void {
g_uses_regex = false
g_uses_bignum = false
g_uses_dict = false
g_uses_numeric = false
g_uses_query = false
g_uses_reflect = false
g_uses_esys = false

File diff suppressed because it is too large Load diff