Skip to content

Shared builtin registry + stdlib gap fill (math, parse, strings, Rand effect, radix literals)#79

Merged
ecto merged 2 commits into
mainfrom
claude/loving-kapitsa-c6050e
Jul 7, 2026
Merged

Shared builtin registry + stdlib gap fill (math, parse, strings, Rand effect, radix literals)#79
ecto merged 2 commits into
mainfrom
claude/loving-kapitsa-c6050e

Conversation

@ecto

@ecto ecto commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Registry

crates/loon-lang/src/builtins.rs is 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:

  • Checker: register_registry_builtins installs monomorphic/Num-bounded schemes directly from the table (polymorphic entries keep bespoke schemes but must exist).
  • loon card: appends a generated ## Builtins section, so docs can't drift.
  • Conformance suite (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)

Tests

  • cargo test --workspace passes (25 suites, exit 0).
  • 12 new conformance/parity tests; 6 new prior-alignment corpus entries (reduce alias, math, parse-int, string helpers, vector index-of, radix literals).

🤖 Generated with Claude Code

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
loon Ready Ready Preview, Comment Jul 7, 2026 6:12am

Request Review

Comment on lines +1360 to +1382
// 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);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude nice

…-c6050e

# Conflicts:
#	crates/loon-lang/src/eir/mod.rs
#	crates/loon-lang/src/eir/vm.rs
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

@ecto ecto merged commit 4904d71 into main Jul 7, 2026
6 checks passed
@chojiai

chojiai Bot commented Jul 7, 2026

Copy link
Copy Markdown

What shipped

This 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:

  • A full set of math functions (floor, ceil, round, sin, cos, tan, log, exp, pi, e, and others) now work correctly, and functions like sqrt and pow now accept whole numbers as well as decimals — previously passing a whole number to sqrt caused a type error.
  • Parsing strings to numbers (parse-int, parse-float) now returns a success-or-failure result instead of crashing on bad input, and reduce now works as expected as a synonym for fold.
  • New string utilities (capitalize, pad-left, pad-right, repeat), index-of on lists (not just text), hexadecimal/octal/binary number literals (0xFF, 0o17, 0b1010), and a Rand effect for reproducible randomness (seedable for deterministic tests) are all available.

Plain-English summary generated by Choji from this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] No way to parse a string to a number

1 participant