E5D4 GitHub - pain-lng/pain: Pain language
[go: up one dir, main page]

Skip to content

pain-lng/pain

Repository files navigation

Pain Programming Language

A modern, high-performance programming language designed for scientific computing and data science workloads.

Features

Core Language

  • Indentation-based syntax - Clean, Python-like syntax with proper block parsing
  • Static type system - Type inference and type checking
  • Functions and classes - Support for functions, classes, and methods
  • Rich type system - Integers, floats, strings, booleans, lists, arrays, maps, and user-defined types
  • Doc comments - Python-style doc comments with automatic documentation generation

Compiler

  • Lexer and Parser - Complete lexer and parser with indentation-based block parsing
  • Type Checker - Full type checking with type inference
  • IR Generation - Intermediate representation (IR) builder
  • Code Generation - LLVM IR (stable) and MLIR (experimental IR dump) generation
  • Optimizations - SSA transformation, constant folding, dead code elimination
  • Interpreter - Runtime interpreter for testing and development
  • JIT Compilation - Runtime code generation with LLVM ORC (optional, requires LLVM 21+)
  • REPL - Interactive shell with command history and debug commands

Developer Tools

  • LSP Server - Language Server Protocol implementation with:
    • Diagnostics and error reporting
    • Code completion with context-aware suggestions
    • Hover tooltips with doc comments
    • Function location finding
  • VS Code Extension - Full VS Code integration with syntax highlighting and LSP support
  • Code Formatter - Automatic code formatting
  • Documentation Generator - Generate documentation from source code

Package Management

  • painpkg - Package manager with:
    • Dependency resolution (semver)
    • Package installation from local sources (file://) and experimental Git sources (git://, git+ clones only)
    • pain.toml dependency management
    • Local file-based registry with indexing

Runtime

  • Memory Management - Bump allocator and garbage collector
  • Object Model - Runtime object representation for lists, arrays, and user-defined types

Standard Library

  • Math functions: abs, min, max, sqrt, pow, sin, cos, floor, ceil
  • String functions: len, concat, substring, contains, starts_with, ends_with, trim, to_int, to_float, to_string
  • List/Array functions: len (indexing and literals supported)
  • I/O functions: print
  • PML (Pain Markup Language): pml_load_file, pml_parse - Load and parse PML configuration files

Installation

Prerequisites

  • Rust toolchain (install from rustup.rs)
  • LLVM (optional, for LLVM backend)

Build from Source

# Clone the repository
git clone --recursive https://github.com/pain-lng/pain.git
cd pain

# Build all components
cargo build --release

# Build specific components
cargo build --release --package pain-compiler
cargo build --release --package pain-lsp
cargo build --release --package painpkg

Quick Start

Running a Pain Program

# Run a Pain source file
cargo run --package pain-compiler -- run --input example.pain

# Or use the installed binary
pain run example.pain

Building a Pain Program

# Generate LLVM IR
pain build --input example.pain --output example.ll

# Build executable
pain build --input example.pain --executable

# Use MLIR backend (experimental IR dump)
pain build --input example.pain --backend mlir --output example.mlir

Usage Examples

  • Check: pain check --input path/to/file.pain — parse + type-check without running.
  • Format: pain format --input src/main.pain --stdout — pretty-print to stdout or overwrite file.
  • Run via interpreter: pain run --input examples/loop.pain.
  • REPL: pain repl — interactive shell with history and debug commands (:vars, :funcs, :classes).
  • Build optimized binary: pain build --input examples/app.pain --executable --backend llvm.
  • Generate docs: pain doc --input src/lib.pain --output docs/lib.md or pain doc --stdlib.
  • Package manager: painpkg init demo && painpkg install && painpkg run.

Example Program

fn main():
    print("I love Pain!")
    
    let x = 10
    let y = 20
    let sum = x + y
    print(sum)

PML (Pain Markup Language) Example

9B10 PML is a minimalistic declarative data format for configurations and UI structures:

config.pml:

app:
	name: "My App"
	version: "1.0.0"
	debug: false

main.pain:

fn main():
    let config = pml_load_file("config.pml")
    let app_name = config.app.name
    print("Starting " + app_name)

See docs/PML_SPEC.md for complete PML documentation.

Project Structure

This is a workspace containing multiple crates:

  • pain-compiler - Main compiler implementation
  • pain-lsp - Language Server Protocol server
  • pain-runtime - Runtime library (allocator, GC, object model)
  • painpkg - Package manager

Documentation

cargo run -p pain-compiler -- doc --stdlib
cargo run -p pain-compiler -- doc --input source.pain

Benchmarks

Run benchmarks to compare performance:

# Run all benchmarks
cargo bench

# Compare with Python/Rust/C++
cd benches
python compare.py all

License

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

Contributing

Contributions are welcome! Please see the project structure and submit pull requests to the appropriate submodule repositories.

Links

See docs/DEVELOPMENT.md for the branch/CI workflow (main/develop/feature).

Repository Topics & Branding

  • GitHub topics (add to pain, pain-compiler, pain-runtime):
    programming-language, compiler, llvm, mlir, rust, ai, hpc
    Example using GitHub CLI:
    gh repo edit pain-lng/pain --add-topic programming-language --add-topic compiler ...
  • Logo guidance
    • Org avatar: square SVG/PNG at least 512×512 px (transparent background preferred).
    • README hero image: reuse the same asset at ~200 px width near the top (store in assets/logo.svg or assets/logo.png).
    • Keep a monochrome variant handy for dark/light backgrounds if we publish on other portals.
0