Skip to content

Arith v0.2.0

Latest

Choose a tag to compare

@yunabe yunabe released this 06 Sep 12:12
· 16 commits to main since this release
5b8c786

The complete implementation of Arith language version 0.2, which adds arrays and string tooling on top of v0.1.0. See LANGUAGE_SPEC.md for the language and docs/compiler-design.md for the architecture; the v0.1 specification is preserved at its own tag.

Language

  • Array types []T for every element type, nesting included ([][]i64 is a jagged array). Arrays are fixed-length reference values with mutable elements; the types are structural.
  • Array creation: the element-list form [1, 2, 3] and the repeat form [value; count] (the one value is shared by every slot — significant when elements are arrays). An expected array type propagates its element type into both forms, recursively; an empty [] requires one. A negative repeat count is a runtime error.
  • Indexing a[i] with i64 indexes, chaining (grid[i][j], rows(3)[0]), and element assignment — plain and compound — through any index expression; out-of-range indexes are runtime errors, for reads and writes alike.
  • The built-in len(array) — the first expression-valued built-in; like print, the name cannot be redeclared.
  • for x in array iterates elements in index order; the loop variable has the element type and, like a range loop's, is body-scoped and read-only.
  • fn main(args: []string) receives all command-line arguments verbatim — any count, no parsing, no usage exit. []string must be main's only parameter, and no other array type may appear on main.
  • Conversions from string to every other primitive type (i64(s), bool(s), …), parsing with exactly the main-argument grammar; failures are runtime errors. Conversions never involve arrays.
  • Interpolated strings f"x = ${x}" — exactly equivalent to the concatenation "x = " + string(x), holes taking any primitive expression, with nesting, block comments inside holes, and the \$ escape (a bare $ is a compile-time error).
  • Assignment targets generalized: the left side is a variable or any index expression (a chain may be rooted at a call result).

Compiler and CLI

  • New diagnostics ARITH1006, ARITH2004, and ARITH3021–ARITH3027, and the ARITH3002 message now names the redeclared built-in; all listed in docs/diagnostics.md.
  • Emitted array code keeps the checked-semantics discipline: repeat counts narrow with conv.ovf.u (negative counts fault before allocation), indexes with conv.ovf.i; bool elements store as bytes and load zero-extended; nested-array allocations name their element type through the TypeSpec metadata table.
  • The entry-point bridge passes the runtime's string[] straight through to a main(args: []string).
  • Five new programs in examples/calc.arith, matmul.arith, sort.arith, sieve.arith, and life.arith — each pinned by an end-to-end test, alongside the ten from v0.1.

Requires the .NET 10 SDK. Full history: CHANGELOG.md.