Skip to main content

uc386

AI — no code written by a primate.

C23 compiler targeting the Intel 386 (i386 / x86-32) processor under a DOS extender — specifically the flat 32-bit Watcom / DOS/4GW-era C that early-to-mid-1990s PC games were written in.

Status: working and released — pip install uc386 (0.2.1 on PyPI). Measured under our DOS emulator (compile → assemble → run → diff): 215 / 220 c-testsuite and, with --kr, 1397 / 1514 gcc-c-torture executable tests pass. docs/status.md lists the remaining failures.

The frontend (parsing, preprocessing, AST-level optimization) lives in uc_core; this repo owns the driver, the x86-32 NASM emitter, and the DOS runtime bindings.

Features

  • Strict C23 by default. --kr rewrites pre-ANSI K&R code and GNU computed goto into standard C before parsing.
  • Self-contained DOS .exe files bound to the DOS/32A extender, boot-tested under DOSBox in CI.
  • Compiles real third-party programs: DOOM, MicroPython, Kernighan's awk, and 17 GNU utilities.
  • Compact code generation: true is 18 bytes as a flat .bin. A DOS .exe carries a ~32.8 KB DOS/32A extender floor (docs/size.md).
  • Target: unmodified Watcom-era DOS games such as Descent and Duke Nukem 3D (docs/design.md).

Install

From PyPI:

pip install uc386

That gets you the uc386 driver, the bundled i386_dos_libc.asm, and the lib/include/ headers, and it pulls the frontend (uc_core, uplox) and the asm-level optimizer (upeep386) automatically. To assemble + run the output you also need nasm (system package) and, for the dos_emu test harness, pip install unicorn.

The driver has no default include path, so #include <stdio.h> fails until you point -I at the installed headers:

UC386_INC=$(python -c "import uc386,os;print(os.path.join(os.path.dirname(uc386.__file__),'lib','include'))")
uc386 hello.c -o hello.asm -I "$UC386_INC"

examples/hello.c declares its one prototype inline specifically so it compiles with no -I at all.

That install compiles C to .asm. Building a bootable DOS .exe additionally needs pip install upyle and the addons/harness/ tree, which ships only in the source checkout — see docs/path-a-mz-le.md.

Source checkout for development:

sudo apt-get install -y python3 python3-venv nasm    # Debian/Ubuntu
git clone https://github.com/avwohl/uc386 && cd uc386
python3 -m venv .venv && . .venv/bin/activate
pip install pytest unicorn upyle -e .
pytest tests/          # 498 passed, 1 skipped

To co-develop the frontend or the optimizer, clone them as siblings and install those editable too — see CLAUDE.md for that layout.

macOS (Homebrew) and Fedora/RHEL (dnf) instructions, plus the optional toolchains for addon builds (bison/flex) and the DJGPP / OpenWatcom comparison columns, are documented in docs/INSTALL.md.

Documentation

  • cpmdroid - Z80/CP/M emulator for Android phones and tablets. It emulates the RomWBW HBIOS interface and a VT100 terminal.
  • cpmemu - Z80/CP/M emulator for Linux and Windows, with Z80 and 8080 CPU cores. It translates the BDOS and BIOS calls of CP/M 2.2 programs to the host file system.
  • dosiz - MS-DOS emulator for Linux. It uses the dosbox-staging CPU core and translates system calls in the manner of cpmemu. It is the intended test host for uc386.
  • pyle - OMF to MZ+LE linker written in pure Python. It builds the DOS .exe files of uc386 and needs no Open Watcom. The repository is pyle but the package is upyle.
  • qxDOS - DOS emulator app for iOS and macOS with a SwiftUI interface. DOSBox Staging supplies the emulated i386 hardware.
  • uc80 - C compiler for the Z80 processor and CP/M. This sibling backend shares the C23 frontend of uc_core.
  • uc_core - Shared C23 frontend and AST optimizer for the uc80 and uc386 compilers.
  • um80_and_friends - Linux toolchain that is compatible with Microsoft MACRO-80. It has an assembler, a linker, a librarian, and a disassembler. It is the Z80 equivalent of what uc386 needs for i386.
  • upeep386 - Peephole optimizer, assembly dead-code eliminator, and libc symbol splitter for i386. uc386 depends on it.
  • upeepz80 - Peephole optimizer for Z80 compilers. It was the template for upeep386.
  • uplox - LR(1) and GLR parser generator. It writes the lexer and parser tables for the C23 frontend of uc_core from examples/c23.uplox.

License

GPL-3.0-or-later.

Metadata

Release files for uc386 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uc386 0.2.6
File Size Uploaded Provenance Actions
uc386-0.2.6.tar.gz 422.1 kB With provenance Details for uc386-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uc386 0.2.6
File Interpreter ABI Platform Actions
uc386-0.2.6-py3-none-any.whl Python 3 none any Details for uc386-0.2.6-py3-none-any.whl

Total release size: 797.5 kB

Release files / uc386-0.2.6.tar.gz

Download URL uc386-0.2.6.tar.gz
Size 422.1 kB
Tags Source
SHA-256 checksum
How to use checksums
603e5ac3949b2fa2ad301ac76e29d5ce1d3b86b85c677ff98e3dc413dfd3a2ed
BLAKE2b-256 checksum
How to use checksums
b8ddbc4cd039b3023c926be11f5ab4c7e087d1803f4279387fb1228da32c7b19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / uc386-0.2.6-py3-none-any.whl

Download URL uc386-0.2.6-py3-none-any.whl
Size 375.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4788dcebe59cb8745321f0cca85b02006a7e2520f5c058bec3495accabeba67f
BLAKE2b-256 checksum
How to use checksums
0779fa80dc400644d753650d779c6d237d866ac38945139d1bbbec89f3fcdf3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for uc386 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for uc386-0.2.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page