Skip to main content

Pebble

An educational compiler and bytecode VM for the Pebble programming language.

Pebble is a small imperative language that compiles to bytecode and runs on a custom stack-based virtual machine. The project is designed for learning how compilers work, built incrementally using TDD.

Language Features

  • Integers, floats, strings, booleans
  • Variables (let declarations, const, reassignment)
  • Arithmetic, comparison, bitwise, and logical operators (and, or, not)
  • Short-circuiting and / or and chained comparisons (1 < x < 10)
  • Control flow: if/else, while, for loops, match
  • Collections: lists, dicts, list comprehensions, slicing, tuple unpacking
  • Functions (fn, return), default arguments, closures, and generators (yield)
  • Async / await (async fn, await)
  • Structs, classes with inheritance, and enums
  • Error handling: try / catch / finally and throw
  • Modules and imports (import, from ... import)
  • String interpolation ("hello {name}")
  • print() built-in
  • Comments (#)
  • Curly-brace blocks, newline-delimited statements (no semicolons)

Example

let count = 0
while count < 5 {
    if count > 0 {
        print(count)
    }
    count = count + 1
}

Pipeline

Source -> Lexer -> Parser -> Analyzer -> Module Resolver -> Type Checker -> Compiler -> Optimizer -> VM

See the documentation for a kid-friendly walk-through of each stage.

Quick Start

# Install dependencies
uv sync --all-extras

# Run tests
uv run pytest

# Lint and type check
uv run ruff check .
uv run pyright src tests

Using Pebble from Python

from pebble import run_source

print(run_source('print("Hello from Pebble!")'), end="")

run_source, compile_source, check and format_source are Pebble's public API; see Using Pebble from Python.

Documentation

Full docs (with kid-friendly explanations of every idea): https://robcox2910.github.io/pebble-lang/

Install

PyPI

pip install fromscratch-pebble

Or get the whole series at once: pip install fromscratch-pystack.

Releasing

Other projects in the series (PyStack and PyLLM) use a released version of this one from PyPI, not whatever is on main. To publish a change for them:

  1. Merge the change to main.
  2. Release it: gh release create vX.Y.Z --target main --generate-notes (or push a vX.Y.Z tag); the release workflow publishes it to PyPI. A change to the public API bumps the minor version (v0.1.0 → v0.2.0); anything else bumps the patch (v0.1.0 → v0.1.1).
  3. In each project that uses it, raise the fromscratch-pebble>=X.Y.Z floor in pyproject.toml, run uv lock --upgrade-package fromscratch-pebble, and open a pull request so CI checks the pair together.

This project is one of a series that builds real systems "from scratch in Python" to teach how they work. See the series home for the full story.

Project What it teaches Repository Docs PyPI
PyOS Operating systems py-os Docs fromscratch-pyos
Pebble Compilers and programming languages pebble-lang Docs fromscratch-pebble
PyDB Relational databases pydb Docs fromscratch-pydb
PyKV Key-value stores pykv Docs fromscratch-pykv
PyDocDB Document databases pydoc-db Docs fromscratch-pydocdb
PyGraphDB Graph databases pygraphdb Docs fromscratch-pygraphdb
PyTSDB Time-series databases pytsdb Docs fromscratch-pytsdb
PyVecDB Vector databases pyvecdb Docs fromscratch-pyvecdb
PyColDB Column-family databases pycoldb Docs fromscratch-pycoldb
PyCrypt Cryptography pycrypt Docs fromscratch-pycrypt
PyNet Computer networking pynet Docs fromscratch-pynet
PyWeb HTTP web servers pyweb Docs fromscratch-pyweb
PyGit Version control pygit Docs fromscratch-pygit
PySearch Search engines pysearch Docs fromscratch-pysearch
PyMQ Message queues pymq Docs fromscratch-pymq
PyLLM Language models (the brain) pyllm Docs fromscratch-pyllm
PyScheduler Job scheduling pyscheduler Docs fromscratch-pyscheduler
PyStack Full-stack integration pystack Docs fromscratch-pystack

License

MIT

Metadata

Release files for fromscratch-pebble 0.4.0

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

Source distribution (sdist)

Source distribution for fromscratch-pebble 0.4.0
File Size Uploaded Provenance Actions
fromscratch_pebble-0.4.0.tar.gz 410.3 kB With provenance Details for fromscratch_pebble-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fromscratch-pebble 0.4.0
File Interpreter ABI Platform Actions
fromscratch_pebble-0.4.0-py3-none-any.whl Python 3 none any Details for fromscratch_pebble-0.4.0-py3-none-any.whl

Total release size: 521.1 kB

Release files / fromscratch_pebble-0.4.0.tar.gz

Download URL fromscratch_pebble-0.4.0.tar.gz
Size 410.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2c9954e22811bf58b25ab5ff4bc988f1924dbed43691459aeac591187f0550ed
BLAKE2b-256 checksum
How to use checksums
c74e311666ed9ff3dfcf3ca02e9bd8aaab446e2066a9b0083b012c0fcfd33a2a
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 3, 2026.

Transparency log

Release files / fromscratch_pebble-0.4.0-py3-none-any.whl

Download URL fromscratch_pebble-0.4.0-py3-none-any.whl
Size 110.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f30f244388f20646abcf84b78f407f1b47096e42b33782a4aa94df66009e14e
BLAKE2b-256 checksum
How to use checksums
ee601f9e04d27fb5676a5977d2d61168385007d19049732601b98449108798bd
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 3, 2026.

Transparency log

Security for fromscratch-pebble 0.4.0

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 fromscratch_pebble-0.4.0.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 3, 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