Skip to content

A statically-typed, quantum-classical hybrid programming language with affine type safety and OpenQASM 2.0 compilation.

License

Notifications You must be signed in to change notification settings

Asmodeus14/qclang

image

⚛️ QCLang

Schrödinger’s Companion — a modern, type-safe quantum systems programming language.

License Version Status

QCLang is a high-level programming language designed to bridge the gap between classical systems programming and quantum circuit execution.
It features a Rust-inspired syntax, a strict affine type system for quantum safety, and compilation to OpenQASM 2.0.


      /\_/\ 
     ( o.o )      Q U A N T U M   C A T
      > ^ <    Schrödinger’s Companion



✨ Features

  • Hybrid Control Flow
    Seamlessly mix classical logic (if, for, while) with quantum operations.

  • Quantum Safety (Affine Types)
    Compile-time enforcement of the No-Cloning Theorem:

    • Prevents quantum variable reassignment
    • Prevents use-after-measurement
  • Modern, Familiar Syntax
    Strong typing, structs, tuples, and type aliases inspired by Rust.

  • QIR & Optimizing Backend
    Generates optimized OpenQASM 2.0 (QIR phase in progress).

  • Detailed Diagnostics
    Helpful compile-time errors with actionable hints.


🚀 Getting Started

Prerequisites

  • Rust (latest stable)
  • Cargo

Installation (from source)

git clone https://github.com/Asmodeus14/qclang.git
cd qclang
cargo install --path .

📦 Releases

Prebuilt binaries and versioned releases are available for download.

👉 Download from GitHub Releases: https://github.com/Asmodeus14/qclang/releases

Each release includes:

  • qclang CLI binary
  • Release notes
  • Supported platform details

This is the recommended way to install QCLang if you don’t want to build from source.


🧪 Usage

Compile a .qc file to OpenQASM:

qclang compile my_circuit.qc --show

Run syntax checks only:

qclang check my_circuit.qc

📖 Syntax Example

Bell State Preparation

fn main() -> int {
    // Initialize quantum register
    qreg q[2] = |00>;

    // Apply gates (affine: no reassignment)
    H(q[0]);
    CNOT(q[0], q[1]);

    // Measurement consumes the qubits
    let r1: cbit = measure(q[0]);
    let r2: cbit = measure(q[1]);

    return 0;
}

See syntax.md for the full language specification.


🛠️ Project Structure

  • src/lexer.rs — Tokenizer (Logos)
  • src/parser.rs — Recursive descent parser
  • src/semantics/ — Type system & ownership checks
  • src/qir/ — Quantum Intermediate Representation
  • src/codegen/ — OpenQASM 2.0 backend

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

This project is especially friendly to:

  • Compiler enthusiasts
  • Quantum computing researchers
  • Systems programmers

📄 License

Licensed under the Apache License 2.0. See the LICENSE file for details.

About

A statically-typed, quantum-classical hybrid programming language with affine type safety and OpenQASM 2.0 compilation.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published