Skip to content
drewdestarPublic

About

newr, a new language for a new era. One readable source, seven readable outputs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

newr, a general-purpose programming language. One readable source. Seven readable outputs.

version 0.2.0 python 3.10+ license MIT

newr is a general-purpose programming language. You write one readable source file, and the compiler produces readable code in eight target languages. It takes the best ideas from the languages that came before it and puts them in one place, so the same language works for AI code, IT tools, security work, and anything else you build. A Discord bot is one use of newr, through the discord module. The language itself is not bot-specific.

Try it

git clone https://github.com/drewdestar/newr.git
cd newr
./newr check examples/hello.newr
./newr build --target py -o /tmp/hello.py examples/hello.newr
python3 /tmp/hello.py
examples/hello.newr: ok
examples/hello.newr: ok, wrote /tmp/hello.py
Hello, world!

An example

examples/hello.newr:

print "Hello, world!"

The Python emitter produces readable code, not a blob. This is the whole emitted file:

# Generated by newr from examples/hello.newr. Do not edit by hand.
# Edit the .newr file and rebuild with: newr build examples/hello.newr

print("Hello, world!")

The same file builds for all eight targets today. examples/showcase.newr shows the other side of the language: a small Discord bot with four commands and two events, written in the same syntax.

How it works

How a .newr file becomes seven programs

One front end serves every target. The lexer, parser, resolver, and checker run once, then one emitter per language writes readable code. The conformance corpus decides what correct means: each program in it carries an expected verdict, and every emitter has to produce it. A target that cannot pass does not ship.

Targets

Target Library Status
Python discord.py 2.7.1 Done in M2
JavaScript discord.js 14.28.1, Node 24 LTS Done in M3
Java JDA 6.7.0 Done in M4
C# Discord.Net 3.20.2 Done in M4
Rust serenity 0.12.5, poise 0.7.1 Done in M5
Kotlin Kord 0.18.1 Done in M5
Dart nyxx 6.9.1 Done in M5
Swift — Core emitter done (PR #11); no runtime yet, emit-only; bot programs not yet supported

The language, briefly

  • Types: int (signed 64-bit, checked overflow is a runtime error), float (IEEE-754 binary64), str, bool, list[T], dict[K, V], and more. Nullability is spelled T? (for example str?); the null value is none.
  • No implicit numeric coercion: int does not convert to float implicitly, use float(x). On ints, / truncates toward zero, % takes the sign of the dividend, and division by zero is a runtime error.
  • while, recursion, closures and lambdas, ternary cond ? a : b, ?. / ??, pipeline |> (the piped value becomes the first argument: a |> f(b) is f(a, b)), typed enums, a core match statement, runtime-only requires / ensures contracts, statement-level ? propagation, try blocks returning Result[T, error], try / catch / finally, pub visibility, and qualified imports (import "shop_items.newr" binds the module under its file stem; call it as shop_items.price_of(...)).
  • The discord module holds the bot surface: bot / command / event declarations, store / economy operations, strings blocks + t(), task, and embeds. Bot blocks implicitly import it. General programs persist with the db module (SQLite), file I/O, or the http module (server + fetch); json encode/decode and the ui module round out full-stack programs (M8).

See SPEC.md for the full specification.

Verification

Numbers from the M9 verification (suite, conformance):

  • Full suite: 1576 tests, passing in system Python.
  • Conformance: 101/101 on each of the seven targets that execute programs (py, js, java, cs, rs, kt, dart). Swift is emit-only for now: all 101 programs emit, but none run yet, because the Swift runtime (compiler/newr_rt.swift) is not built.

Usage

New to newr? Start with the usage guide.

./newr check <file.newr>                                # parse, resolve, check; writes nothing
./newr build --check <file.newr>                         # same checks; writes nothing
./newr build --target py|js|java|cs|rs|kt|dart|swift <file.newr> # emit readable code for the target
./newr build --target py -o <out.py> <file.newr>         # emit to a file of your choice
./newr fmt <file.newr>                                   # rewrite in canonical form (see `newr help fmt`)
./newr fix <file.newr>                                   # apply safe fixes for errors that have one (see `newr help fix`)
./newr test <file.newr>                                  # run the file's tests (see `newr help test`)
./newr docs                                              # generate docs/api.md and docs/examples.md (see `newr help docs`)
./newr explain <code>                                    # explain a diagnostic code

Exit codes: 0 success, 1 usage, 2 environment, 4 build error. There is no exit code 3 in v1, the spec reserves 3 for network errors, which no current command can produce.

Documenting your code

A /// line at the start of a logical line documents the declaration directly below it:

/// Doubles a number.
fn double(x: int) -> int:
  return x * 2

A /// block at the top of a file, followed by a blank line, is the file header. newr docs renders the comments into docs/api.md (the stdlib reference) and docs/examples.md (one section per example program). See docs/guide.md.

Install

newr-lang is not on PyPI yet. Until it is, run newr from a checkout, or build a single-file zipapp:

python3 -m zipapp . -o newr.pyz
python3 newr.pyz check examples/hello.newr

Planned alongside the PyPI release: a pipx install, GitHub Releases, and a PowerShell installer. The release workflow is ready (.github/workflows/release.yml, PyPI trusted publishing, no token); the one-time PyPI trusted-publisher setup is still pending.

Status

  • M0: spec frozen (see SPEC.md).
  • M1: front end complete, lexer, parser, AST, resolver, checker, and the discord checker. newr check verifies programs; newr build --check runs the same checks.
  • M2: Python emitter complete.
  • M3: JavaScript emitter complete.
  • M4: Java and C# emitters complete - suite 902/902, conformance 74/74 on all four targets (py, js, java, cs), cold re-evaluation CLEAN.
  • M5: Rust, Kotlin, and Dart emitters complete, suite 963/963, conformance 74/74 on all seven targets (py, js, java, cs, rs, kt, dart), cold re-evaluation CLEAN.
  • M6: the toolchain, newr fmt (canonical formatting), newr init (project scaffold + newr.json), newr test (test functions and test blocks), newr fix (safe E3001 renames), newr docs (generated docs from /// comments). Suite 1209/1209, conformance 79/79 on all seven targets. Version 0.2.0.
  • M7: run anywhere — standalone one-file binary (PyInstaller, built by CI on Linux, macOS and Windows), single-file zipapp, and the browser playground proven with the real compiler. Design and proof in docs/run-anywhere.md.
  • M8: full-stack — db (SQLite), http (server + fetch), json, and ui modules on all seven targets; newr.json manifest keys and newr build --app packaging; the five-file shop app (shared types, view, backend, js frontend, py frontend). Suite 1536/1536, conformance 101/101 on all seven targets.
  • M9: fix round — emitter bugs (rs, cs, kt, dart), imported pub const, qualified types (module.Type), per-thread SQLite connections on py; the CI workflow fix that turned the matrix green. Swift lands as the eighth target (PR #11, core emitter; no runtime yet, so Swift programs emit but don't run; bot programs not yet supported).

Verification runs in CI on every pull request.

Project layout

SPEC.md            the language specification (v0.2.0)
compiler/          the compiler front end and emitters
tests/             front-end test suite (python3 -m unittest discover -s tests)
examples/          .newr examples, plus the v0 golden outputs (hello.py, showcase.py)
conformance/       the conformance corpus: ok/err programs with expected verdicts,
                   the single definition of correct behavior
docs/              error index and diagrams
.github/workflows/ CI

Unverified

  • Windows and macOS execution is proven by the CI matrix (ubuntu-latest, macos-latest, windows-latest), which runs green on all three OSes.
  • Performance numbers are measured on Linux only, per milestone (benchmarks B1-B7, see benchmarks/). Nothing is claimed for other OSes.

License

MIT. See LICENSE.

About

newr, a new language for a new era. One readable source, seven readable outputs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages