Metadata-Version: 2.4
Name: redrope-lang
Version: 0.1.0
Summary: A tiny capability-based language where syntax and power are loaded through binary knouts.
Author: Red Rope Contributors
License: MIT
Keywords: language,interpreter,bytecode,capabilities,modules
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Interpreters
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Red Rope

Red Rope is a tiny capability-based language where syntax and runtime power are loaded explicitly from binary `.kn` modules, also called knouts.

This repository contains a dependency-free Python reference implementation for the `0.1.0 draft` language spec. See [SPEC.md](SPEC.md) for the current behavior.

## Quick Start

Build the example knouts:

```powershell
python -m redrope.tools.build_examples
```

Run the example program:

```powershell
python -m redrope examples/hello.rr
```

After installing the package, the same program can be run with:

```powershell
redrope examples/hello.rr
```

Expected output:

```text
Hello from Red Rope
```

## Example Program

```redrope
load ../modules/printing.kn
load ../modules/pythonstyle.kn

print("Hello from Red Rope")
```

Nothing except `load` exists before modules are loaded. Runtime modules provide capabilities such as `print`; syntax modules provide statement forms such as `print({x})`.

Syntax modules merge when loaded. Newer syntax rules are checked first, so a later module can override a matching shape while earlier non-conflicting rules remain available.

## Writing Knouts

Human-authored modules use `.knsrc` and compile to binary `.kn` with `knc`:

```powershell
python -m redrope.knc module_src/pythonstyle.knsrc -o modules/pythonstyle.kn
```

After installing the package:

```powershell
knc module_src/pythonstyle.knsrc -o modules/pythonstyle.kn
```

Example runtime module:

```text
module printing runtime
metadata version=1.0
export print function
native print rr_print_stdout
```

Example syntax module:

```text
module pythonstyle syntax
metadata version=1.0
rule print({x}) -> call print x
```

Rule actions may use shorthand calls, where identifiers are captures:

```text
rule display {x} -> call print x
```

They may also use explicit VM actions separated by semicolons:

```text
rule banner {x} -> load_const ">>> "; load_capture x; concat; invoke print 1
```

## Project Layout

- `redrope/`: reference interpreter, module loader, tokenizer, VM, and CLI.
- `redrope/knc.py`: compiles `.knsrc` module source files to binary `.kn` knouts.
- `redrope/tools/build_examples.py`: compiles the sample `.knsrc` modules and writes example `.rr` programs.
- `module_src/`: human-readable sample module sources.
- `examples/hello.rr`: minimal Red Rope program.
- `examples/merged.rr`: demonstrates syntax merging.
- `tests/`: unit tests for the core v0.1 behavior.

## Current Scope

Implemented:

- line-oriented `.rr` execution
- core comments and `load`
- local `.kn` module loading
- `.kn` header and section validation
- exports, native bindings, compiled syntax, and bytecode actions
- `.knsrc` to `.kn` compiler
- syntax merging with newest-rule precedence
- stack-based VM opcodes: `LOAD_CONST`, `LOAD_CAPTURE`, `CALL`, `HALT`
- stack/value VM opcodes: `LOAD_NUMBER`, `POP`, `DUP`, `SWAP`, `CONCAT`
- host native binding for `rr_print_stdout`

Not implemented yet:

- remote module loading or remote execution; both are reserved for a future trust-policy design
- signatures/checksums/trust policy
- unload, namespaces, variables, control flow, or user-defined functions
