Shared builtin registry + stdlib gap fill (math, parse, strings, Rand effect, radix literals)#79
Conversation
Registry (crates/loon-lang/src/builtins.rs): one table of (name, signature, doc, arity, typing) that the checker's initial environment, loon card, and the conformance suite derive from. tests/builtin_registry.rs asserts every entry is wired in the checker, the legacy interpreter, and EIR lowering, plus differential output-parity tests between the two backends. Gap fills (issues #18 #19 #23 #24 #25 #26): - math: sqrt/pow now typecheck on Int via a Num trait bound; floor, ceil, round, sin/cos/tan/asin/acos/atan/atan2, log, log10, exp, pi, e on both backends - parse-int / parse-float returning Option - capitalize, pad-left, pad-right, repeat - index-of on vectors (interp was strings-only; VM too) - reduce as a true alias of fold (VM previously mis-lowered reduce into the 2-arg map/filter group and returned unit); vals/values aliased both ways - interp gains slice/concat; VM gains map?, vec?, name, type-of, remove - Rand effect (rand, rand-int, seed): nondeterminism via effects, recorded for record/replay, shared SplitMix64 so seeded runs match across backends - hex/octal/binary integer literals (0xFF, 0o17, 0b1010, _ separators) loon card now appends a Builtins section generated from the registry. New prior-alignment corpus entries cover reduce, math, parse-int, string helpers, vector index-of, and radix literals. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| // Core math (issue #19). | ||
| macro_rules! math_to_float { | ||
| ($name:expr, $f:expr) => { | ||
| builtin!(env, $name, |_, args: &[Value]| { | ||
| let x = match &args[0] { | ||
| Value::Float(f) => *f, | ||
| Value::Int(n) => *n as f64, | ||
| _ => return Err(err(concat!($name, " requires a number"))), | ||
| }; | ||
| let g: fn(f64) -> f64 = $f; | ||
| Ok(Value::Float(g(x))) | ||
| }); | ||
| }; | ||
| } | ||
| math_to_float!("sin", f64::sin); | ||
| math_to_float!("cos", f64::cos); | ||
| math_to_float!("tan", f64::tan); | ||
| math_to_float!("asin", f64::asin); | ||
| math_to_float!("acos", f64::acos); | ||
| math_to_float!("atan", f64::atan); | ||
| math_to_float!("log", f64::ln); | ||
| math_to_float!("log10", f64::log10); | ||
| math_to_float!("exp", f64::exp); |
…-c6050e # Conflicts: # crates/loon-lang/src/eir/mod.rs # crates/loon-lang/src/eir/vm.rs
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
What shippedThis is a purely internal change with no user-visible effect — it reorganizes how the language runtime is structured internally and adds automated tests to keep different parts of the system in sync. Wait — reviewing more carefully, this PR does introduce user-facing changes. Several things that previously didn't work now do:
Plain-English summary generated by Choji from this pull request. |
Registry
crates/loon-lang/src/builtins.rsis now the single source of truth for the builtin surface: one table of (name, human-readable signature, doc line, arity forms, typing). Derived from it:register_registry_builtinsinstalls monomorphic/Num-bounded schemes directly from the table (polymorphic entries keep bespoke schemes but must exist).loon card: appends a generated## Builtinssection, so docs can't drift.crates/loon-lang/tests/builtin_registry.rs): asserts every registry entry is wired in the checker env, the legacy interpreter, and EIR lowering, plus differential parity tests running the same programs on both backends and comparing output.Gap fill (closes #18, #19, #23, #24, #25, #26)
floor ceil round sin cos tan asin acos atan atan2 log log10 exp pi eon both backends;sqrt/pow(legacy-only before) now on the VM. NewNumtrait bound (impls: Int, Float) fixes[sqrt 4]→ previously "cannot unify Float with Int".parse-int/parse-floatreturnOption.capitalize,pad-left,pad-right(explicit pad string, arity 3),repeat.index-ofon vectors — was strings-only on both backends.Randeffect (Rand.rand,Rand.rand-int lo hi,Rand.seed n) — randomness flows through the effect system, is recorded for record/replay (is_recorded_op), and both backends share one SplitMix64 so seeded runs are byte-identical across backends. Handlers can override it for tests.0xFF/0o17/0b1010literals with_separators (lexer + parser; bare0b-style unit-suffix literals still parse as[unit 0 :b]).reduceis a true alias offold— the VM previously loweredreduceinto the 2-arg map/filter group, so[reduce init f coll]silently returned unit.vals/valuesaliased both ways; interp gainsslice/concat; VM gainsmap?,vec?,name,type-of,remove.Tests
cargo test --workspacepasses (25 suites, exit 0).🤖 Generated with Claude Code