kz80_prolog 0.1.0

Prolog compiler for Z80 - Logic programming on the RetroShield
Documentation
  • Coverage
  • 70.71%
    198 out of 280 items documented0 out of 94 items with examples
  • Size
  • Source code size: 307.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 14.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ajokela/kz80_prolog
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ajokela

kz80_prolog

A Prolog compiler for the Z80 processor, targeting the RetroShield platform.

Features

  • Edinburgh Prolog syntax
  • Facts and rules (Horn clauses)
  • Unification and backtracking
  • Arithmetic evaluation (is, +, -, *, /, mod)
  • Comparisons (<, >, =<, >=, =:=, =\=)
  • Lists with cons cells ([H|T])
  • Cut (!) for control flow
  • Basic I/O (write, nl)

Usage

# Compile a Prolog program to Z80 binary
kz80_prolog program.pl -o program.bin

# Print AST (for debugging)
kz80_prolog --ast program.pl

# Print tokens (for debugging)
kz80_prolog --tokens program.pl

Example

% family.pl
parent(tom, bob).
parent(bob, pat).

ancestor(X, Y) :- parent(X, Y).
ancestor(X, Z) :- parent(X, Y), ancestor(Y, Z).

?- ancestor(tom, pat).

Architecture

The compiler uses a Simplified Prolog Machine (SPM) approach:

  1. Lexer - Tokenizes Prolog source
  2. Parser - Builds AST (recursive descent)
  3. Analyzer - Classifies variables (permanent/temporary)
  4. Compiler - Generates SPM bytecode
  5. Code Generator - Produces 8KB ROM image with interpreter

Memory Layout

ROM (8KB):
  0x0000-0x00FF  Startup
  0x0100-0x0EFF  SPM interpreter
  0x0F00-0x13FF  Runtime library
  0x1400-0x1BFF  Compiled bytecode
  0x1C00-0x1FFF  Atom table

RAM (6KB):
  0x2000-0x27FF  Heap
  0x2800-0x2FFF  Trail
  0x3000-0x35FF  Stack
  0x3600-0x37FF  Registers

Building

cargo build --release

Testing

cargo test

License

BSD-3-Clause