Skip to main content

Ada compiler targeting Z80 processor

Project description

uada80 - Ada Compiler for Z80/CP/M

Tests Pylint

An Ada compiler targeting the Z80 processor and CP/M 2.2 operating system, aiming for ACATS (Ada Conformity Assessment Test Suite) compliance.

Project Status

🔧 Alpha - Core compiler functionality implemented

Overview

uada80 is a compiler for the Ada programming language that generates code for the Z80 8-bit microprocessor running CP/M 2.2. The project aims to support a substantial subset of Ada 2012 and pass the ACATS conformance tests.

Target Platform: CP/M 2.2 on Z80

  • Programs load at 0x0100
  • Access to CP/M BDOS for file I/O and console operations
  • Approximately 57K TPA on typical 64K system

Goals

  1. Compile Ada source code to Z80 assembly/machine code
  2. Generate CP/M .COM executables
  3. Pass ACATS test suite (or as many tests as feasible for Z80/CP/M)
  4. Generate efficient code suitable for CP/M systems
  5. Provide clear error messages and diagnostics

Inspiration

This project builds on experience from uplm80, a PL/M-80 compiler for Z80, reusing proven optimization techniques.

Features

Phase 1 (MVP) ✅

  • Project structure
  • Lexer and parser
  • Basic types: Integer, Boolean, Character
  • Procedures and functions
  • Control flow: if, case, loop, for
  • Arrays and records
  • Z80 code generation

Phase 2 (Expanded) ✅

  • Packages
  • Enumeration types
  • Access types (pointers)
  • Derived types
  • Unconstrained arrays
  • AST optimization

Phase 3 (ACATS Compliance) 🔧

  • Generics
  • Exception handling
  • Full attribute support
  • Representation clauses
  • Standard library (adapted for Z80)
  • ACATS test validation

Architecture

Ada Source → Lexer → Parser → AST → Semantic Analysis → Optimizer → Code Gen → Z80 Assembly

See ARCHITECTURE.md for detailed design documentation.

Building

Requirements

  • Python 3.10 or later
  • Optional: Z80 assembler (z80asm, sjasmplus, or similar)
  • Optional: Z80 emulator for testing (e.g., MAME, z80emu)

Installation

# Clone the repository
git clone https://github.com/yourusername/uada80.git
cd uada80

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Running Tests

pytest

Usage

# Compile an Ada source file
uada80 hello.ada -o hello.asm

# With optimization
uada80 hello.ada -o hello.asm -O2

# Generate listing
uada80 hello.ada -o hello.asm --listing

Example Programs

Hello World

with Ada.Text_IO;

procedure Hello is
begin
   Ada.Text_IO.Put_Line("Hello from Ada on Z80!");
end Hello;

Fibonacci

procedure Fibonacci is
   A, B, Temp : Integer;
   N : Integer := 10;
begin
   A := 0;
   B := 1;

   for I in 1 .. N loop
      Temp := A + B;
      A := B;
      B := Temp;
   end loop;
end Fibonacci;

See examples/ for more examples.

Documentation

Compiler Documentation

CP/M Target Platform

Ada Language Specifications

  • specs/ - Ada language specifications and ACATS tests

ACATS Testing

The Ada Conformity Assessment Test Suite is included in acats/.

# Run ACATS tests (when implemented)
python tests/run_acats.py

Limitations

Due to the Z80's 8-bit architecture and limited resources:

  • No floating-point arithmetic (unless software implementation)
  • Integer sizes limited to 8-bit and 16-bit
  • Reduced standard library
  • Tasking support limited or unavailable
  • Limited heap (small memory space)

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run the test suite
  5. Submit a pull request

License

This project is licensed under the GNU General Public License v2.0 - see LICENSE for details.

References

Related Projects

  • GNAT - Production Ada compiler
  • AVR-Ada - Ada for AVR microcontrollers
  • cc65 - C compiler for 6502

Acknowledgments

  • The Ada programming language community
  • The Z80 retrocomputing community
  • ANTLR parser generator team
  • uplm80 optimization techniques

Status Updates

See CHANGELOG.md for development progress.


Note: This is an educational and hobbyist project. For production Ada development, please use GNAT or other mature Ada compilers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uada80-0.3.0.tar.gz (397.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uada80-0.3.0-py3-none-any.whl (304.4 kB view details)

Uploaded Python 3

File details

Details for the file uada80-0.3.0.tar.gz.

File metadata

  • Download URL: uada80-0.3.0.tar.gz
  • Upload date:
  • Size: 397.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for uada80-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b1c370f3f262eda224db5cfbc24284c8e2f8c1b41db2286c83145d94883cfe50
MD5 5b9c7de8778a0eff23f5fa68c0b0395c
BLAKE2b-256 985f5c317d84555093f048e4ae833b30321d2579eb4270eb1c1b4a69309da12a

See more details on using hashes here.

File details

Details for the file uada80-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: uada80-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 304.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for uada80-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef89cd81ff8dcdb0f4d9cec6085180fb8722fab5bf1eb4992e003ad7b65dea7a
MD5 84d420561e728dbba2e4b376fb703546
BLAKE2b-256 1d2b6b74c6a7f11db2dd3b2fafdbcc2d02b9e04463f252f6fad3ff31e56b18f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page