Shared C23 frontend and AST optimizer for the uc80/uc386 family of retro C compilers
Project description
uc_core
Shared C23 frontend and AST-level optimizer for the uc80 (Z80/CP/M) and
uc386 (x86-32/MS-DOS) retro C compilers.
What's in here
- Lexer / parser — C23 source to AST
- Preprocessor — C23 preprocessor with target-configurable predefined macros
- AST — node definitions shared across backends
- AST optimizer — target-independent expression simplification, constant folding, strength reduction, dead-code elimination at the AST level
- Backend protocol — the contract a target backend must implement
Targets using uc_core
Install
pip install uc_core
Or from source:
pip install -e .
Usage from a backend
from uc_core.lexer import Lexer
from uc_core.parser import Parser
from uc_core.preprocessor import Preprocessor
from uc_core.ast_optimizer import ASTOptimizer
from uc_core.backend import CodeGenerator # Protocol
# Target-specific predefined macros
predefines = {
"__UC80__": "1",
"__Z80__": "1",
"__CPM__": "1",
}
pp = Preprocessor(include_paths=["lib/include"], target_predefines=predefines)
source = pp.preprocess(open("hello.c").read(), "hello.c")
tokens = list(Lexer(source, "hello.c").tokenize())
ast = Parser(tokens).parse()
ast = ASTOptimizer(opt_level=3).optimize(ast)
# Backend is provided by the target package (uc80, uc386, ...)
# It must implement uc_core.backend.CodeGenerator
Related Projects
- 80un - Unpacker for CP/M compression and archive formats (LBR, ARC, squeeze, crunch, CrLZH)
- cpmdroid - Z80/CP/M emulator for Android with RomWBW HBIOS compatibility and VT100 terminal
- cpmemu - CP/M 2.2 emulator with Z80/8080 CPU emulation and BDOS/BIOS translation to Unix filesystem
- ioscpm - Z80/CP/M emulator for iOS and macOS with RomWBW HBIOS compatibility
- learn-ada-z80 - Ada programming examples for the uada80 compiler targeting Z80/CP/M
- mbasic - Modern MBASIC 5.21 Interpreter & Compilers
- mbasic2025 - MBASIC 5.21 source code reconstruction - byte-for-byte match with original binary
- mbasicc - C++ implementation of MBASIC 5.21
- mbasicc_web - WebAssembly MBASIC 5.21
- mpm2 - MP/M II multi-user CP/M emulator with SSH terminal access and SFTP file transfer
- romwbw_emu - Hardware-level Z80 emulator for RomWBW with 512KB ROM + 512KB RAM banking and HBIOS support
- scelbal - SCELBAL BASIC interpreter - 8008 to 8080 translation
- uada80 - Ada compiler targeting Z80 processor and CP/M 2.2 operating system
- uc386 - C23 compiler targeting Intel 386 (x86-32) and MS-DOS; consumer of uc_core
- uc80 - C23 compiler targeting Z80 processor and CP/M operating system; consumer of uc_core
- ucow - Unix/Linux Cowgol to Z80 compiler
- um80_and_friends - Microsoft MACRO-80 compatible toolchain for Linux: assembler, linker, librarian, disassembler
- upeepz80 - Z80 peephole optimizer
- uplm80 - PL/M-80 compiler targeting Intel 8080 and Zilog Z80 assembly language
- z80cpmw - Z80 CP/M emulator for Windows (RomWBW)
License
GPL-3.0-or-later. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uc_core-0.2.0.tar.gz.
File metadata
- Download URL: uc_core-0.2.0.tar.gz
- Upload date:
- Size: 79.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51f1ba8db884525e3016eec0181c43f73d01c761839201f654ceb34c26ef23a8
|
|
| MD5 |
bfef277f12ed05aea92f7a4610195b8a
|
|
| BLAKE2b-256 |
791bc6295eaa1b6979022c274f745fe714dbc3fb97f57bcdbc25de1aaaeb3a27
|
Provenance
The following attestation bundles were made for uc_core-0.2.0.tar.gz:
Publisher:
publish.yml on avwohl/uc_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uc_core-0.2.0.tar.gz -
Subject digest:
51f1ba8db884525e3016eec0181c43f73d01c761839201f654ceb34c26ef23a8 - Sigstore transparency entry: 1409452120
- Sigstore integration time:
-
Permalink:
avwohl/uc_core@57f9025395a22ad4b8abc1f459685bec5ca40969 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/avwohl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57f9025395a22ad4b8abc1f459685bec5ca40969 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file uc_core-0.2.0-py3-none-any.whl.
File metadata
- Download URL: uc_core-0.2.0-py3-none-any.whl
- Upload date:
- Size: 76.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15de5978f32091634cf8f8adffe17634db91168579c44e004c2fe69560eaf16e
|
|
| MD5 |
e50434c14b85fdd81381ad2831575b4f
|
|
| BLAKE2b-256 |
afd7d1a375e6882605ea8dda6e414b671c2aefe9415d75e1b395c7a51086e97c
|
Provenance
The following attestation bundles were made for uc_core-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on avwohl/uc_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uc_core-0.2.0-py3-none-any.whl -
Subject digest:
15de5978f32091634cf8f8adffe17634db91168579c44e004c2fe69560eaf16e - Sigstore transparency entry: 1409452128
- Sigstore integration time:
-
Permalink:
avwohl/uc_core@57f9025395a22ad4b8abc1f459685bec5ca40969 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/avwohl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57f9025395a22ad4b8abc1f459685bec5ca40969 -
Trigger Event:
workflow_dispatch
-
Statement type: