aython

Documentation9 min read

Get started

Write a program, run it as a native executable, and check it against CPython.

You write an ordinary Python file, inside the subset. aython run turns it into a Linux executable and runs it; aython check runs it under CPython as well and says whether the two agree. This page is the whole workflow, every command with its real options, and a one-screen summary of what the subset admits.

Requirements #

To You need
Build and run programs, check pass, error and abort cases, fuzz, benchmark Linux on x86-64, with GNU as, a C compiler driver cc (gcc or clang) that links against libc and libm, python3 on PATH (the oracle), and uv
Check reject cases, dump tokens and S-expressions, run the stdlib census, build this site Any machine with uv. Nothing is assembled, so macOS and ARM work too

The project needs Python 3.14 or later; uv fetches it if it is missing. The executables are x86-64 Linux programs: under emulation they run, but their timings mean nothing, so never quote them.

Set up #

git clone https://github.com/sofeikov/aython && cd aython
uv sync

Run every command from the repository root, so that runtime.s is found, or pass --runtime path/to/runtime.s.

Write and run a program #

A program is a .py file. This one is in the test corpus:

tests/mvp/pass_fn_fib.pylines 1–6# mvp: pass
def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)
print(fib(10))

The first line is the judge’s expectation marker, a comment that CPython ignores. Run it:

uv run aython run tests/mvp/pass_fn_fib.py

run writes four files next to the source and then executes the last one:

File What it is
pass_fn_fib.s.gen The assembly the frontend and code generator wrote, one comment per line saying what the line is for. Open it: it is the best way into the code
pass_fn_fib.o That assembly, assembled by as
runtime.o runtime.s, assembled by as; shared by every program in the directory
pass_fn_fib.elf The executable: the program linked with runtime.s, libc and libm by cc

The executable’s standard output and exit status are the program’s. CPython prints this, and the judge requires the executable to print the same bytes:

55

Arguments after the file name reach the program’s argv(): uv run aython run prog.py one two. The executable gets the same 5-second limit the judge uses; past it, run prints aython: timeout and exits 1.

When a program is refused, or fails #

Anything outside the subset is refused before anything is assembled, with the feature named. This needs no assembler, so it works on any machine:

uv run aython run tests/mvp/rej_genexp.py
# ERROR aython: build failed: aython: unsupported: generator expression (lazy iterator out of scope; use a list/set/dict comprehension)

A program that fails while running prints one line naming the error kind on standard error and exits with status 1, unless a try catches it. There is no traceback:

uv run aython run oops.py     # oops.py: x = 9223372036854775807; print(x + 1)
# aython: OverflowError

That one is a documented difference: integers stop at 64 bits, where CPython would print 9223372036854775808.

Check it against CPython #

aython check judges corpus files against their markers:

uv run aython check tests/mvp/*.py
uv run aython check tests/mvp/pass_fn_fib.py tests/mvp/rej_assert.py
uv run aython check --leak tests/mvp/pass_leakflat.py

It prints one line per file and exits 0 only when all of them pass:

INFO aython: ok rej_assert.py [reject] refused: aython: unsupported: assert statement
INFO aython: 1/1 checks passed

The marker on a file’s first # mvp: line says what must happen:

Marker What the judge requires Files in the corpus
# mvp: pass The executable’s standard output equals CPython’s, byte for byte, and both exit 0 106
# mvp: error:ZeroDivisionError Both fail, and both name that kind on standard error. Standard output is not compared 71
# mvp: abort:OverflowError The executable fails naming that kind; CPython also runs, but its result is not compared. For the documented differences, and for failures CPython cannot reproduce, such as exhausting the arena 22
# mvp: reject:assert statement The frontend refuses the file with a message containing that text. Nothing is assembled 71
# mvp: skip A helper module that other corpus files import. Not run on its own 20

A # mvp-argv: one two line passes extra arguments to both sides. --leak also runs the program’s body twice in one process and fails if the second run allocates any fresh arena memory, which is how a forgotten release shows up. Proving it right explains each check and why it is built the way it is.

To add a test, put a file in tests/mvp/ with its marker and run check on it. CI runs check over the whole corpus on every push.

Every command #

These tables are read from the command-line programs themselves when the site is built. Every command also takes --verbose (-v for docsite) for debug logging.

Command What it does Options
uv run aython run SOURCE [ARGS...] Compile source to an ELF and execute it, inheriting stdio.
SOURCE: Program .py file to compile and execute.
ARGS: Arguments forwarded to the program (seen via argv()).
--runtime: Path to runtime.s (default: beside program or cwd).
uv run aython check FILES... Differential-check corpus files against their # mvp: markers.
FILES: Corpus .py files to check.
--runtime: Path to runtime.s (default: beside program or cwd).
--leak: Also run the arena-flatness probe on each file (header-only programs only).
uv run aython fuzz Fuzz the subset against CPython with generated programs. --count (default 100): How many seeded programs to generate and check.
--seed (default 7): Base seed; program i uses seed + i.
--out (default build/fuzz): Directory for generated sources (emptied first).
--runtime: Path to runtime.s (default: cwd).
uv run aython tokdump SOURCE Print the reference token lines for source, one per line.
SOURCE: Program .py file to tokenize.
none
uv run aython sexpdump SOURCE Print the canonical sexp for source, one line per statement.
SOURCE: Program .py file to parse.
none
uv run aython bench [FILES...] Time benchmark programs, ELF vs CPython, best of N alternating rounds.
FILES: Benchmark .py files (default: bench/programs/*.py).
--repeat (default 7): Alternating rounds per program; best of N wins.
--out: Write the Markdown report here (default: bench/results/<machine>.md).
--quick: Smoke mode for CI: 1 round over the first two programs by file name, no report.
--runtime: Path to runtime.s (default: cwd).
uv run aython stdlib-census Measure how much of a stdlib tree the frontend accepts. --stdlib: Stdlib root to measure (default: running interpreter’s).
--out: Write the Markdown report here (default: build/stdlib-census.md).
--min-accepted (default 0): Fail when fewer than this many files are accepted (regression floor).
uv run docsite build Build the site into a directory of static files. --out (default build/site): Directory to build into. It is replaced when the build succeeds.
uv run docsite serve Build the site and serve it locally, rebuilding when a source changes. --out (default build/site): Directory to build into and serve from.
--port (default 8000): Port to listen on.

In practice:

uv run aython fuzz --count 150 --seed 7          # 150 generated programs, judged against CPython
uv run aython bench                               # time bench/programs/*.py, write bench/results/<machine>.md
uv run aython bench --quick                       # build and run two programs once; checks nothing numeric
uv run aython stdlib-census --min-accepted 31   # the census, failing below CI's floor
uv run aython tokdump tests/mvp/pass_arith.py     # the reference tokens parser/tok.s must reproduce
uv run aython sexpdump tests/mvp/pass_arith.py    # the reference S-expressions parser/parse.s must reproduce
uv run docsite serve                              # this site at http://127.0.0.1:8000/aython/, rebuilt on change

On every push CI runs the fuzzer with --count 150 --seed 7 and --count 100 --seed 4242, 250 programs in all. Benchmark numbers are only worth recording on a quiet native machine; How fast, and why explains how to read them.

What the subset admits #

The exact contract, with every edge case, is the Program contract in docs/core-design.md. In outline:

Area Admitted Refused, among others
Values int (signed 64-bit), float, bool, None, str (ASCII), list, tuple, dict, set, range Non-ASCII strings, bytes, integers past 64 bits (abort OverflowError), int(), float(), str()
Assignment x = v, a, b = v, a = b = v, x[i] = v, a[lo:hi] = v, c.x = v, x: T = v, every augmented operator on a name Stepped slice stores, augmented assignment to x[i] or c.x, global, nonlocal
Control flow if/elif/else, while, for over lists, tuples, strings, dicts, sets and ranges (targets may unpack), return, del x[i], del a[lo:hi] while-else, for-else, assert, with, pass outside a class, yield
Functions Top-level def with defaults, *args, keyword-only parameters and **kwargs; calls with keywords, * and ** Nested def, lambda, decorators, functions as values, reading a module-level name inside a function
Exceptions try/except/else/finally; except with a kind, a tuple of kinds, Exception or nothing; raise Kind; bare raise inside except except ... as, raise ... from, raise Exception
Expressions Arithmetic with Python’s floor division, bitwise operators and shifts on ints, set operators, chained comparisons, is, in, and, or, not, displays, list/dict/set comprehensions, f"{x}", indexing and slicing with a step Conditional expressions (a if c else b), generator expressions, lambda, f-string conversions and format specs
Imports Sibling files only, flattened at compile time: import m, import a.b, from m import f as g, from . import m, from .m import f, also inside functions The standard library, from m import *, circular imports, a module as a value
Classes Top-level class with methods, __init__, several bases in C3 order, class-level constants; an instance is a plain dict Decorators, overriding an inherited method, super(), a class as a value

The vocabulary below is read from the frontend’s own tables (BUILTIN_CALLABLES, METHOD_ARITIES, EXC_KINDS and ISINSTANCE_BITS in src/aython/frontend.py) when the site is built:

Builtins print, len, range, repr, isinstance, chr, ord, abs, sum, min, max, sorted, reversed, enumerate, zip, set, read_file, write_file, append_file, argv, exit
str methods split, join, find, replace, strip, lstrip, rstrip, upper, lower, startswith, endswith, splitlines, count
list methods append, extend, pop, remove
set methods add, remove, discard, pop, update, intersection, union, difference, symmetric_difference, issubset, issuperset, clear, copy, isdisjoint, difference_update, intersection_update, symmetric_difference_update
dict methods get, pop, keys, values, items, update, setdefault
Exception kinds TypeError, IndexError, KeyError, ValueError, RuntimeError, ZeroDivisionError, OverflowError, MemoryError, RecursionError, FileNotFoundError, NotImplementedError
isinstance types int, bool, float, str, list, tuple, set

min, max and sorted take one iterable, zip exactly two, and builtins take no keyword arguments. A method name is accepted on any value, and the runtime aborts TypeError when the receiver has no such method, where CPython raises AttributeError. Every such difference is listed in Where it differs from CPython.

Where next #

  • How aython works is the technical report, starting from what a register is.
  • The assembly reader shows a program, its generated assembly and the runtime helpers it calls side by side.
  • The glossary defines every term the site uses.