Nyar Assembler
A modern, high-performance assembler and binary format manipulation library for the Nyar Virtual Machine. It provides a fluent API for building Nyar programs, managing constant pools, and generating optimized bytecode in the .nyarc (Nyar Archive) format.
🏛️ Architecture
graph TB
subgraph "Nyar Assembler Pipeline"
A[High-level Instructions] --> B[Nyar Builder]
B --> C[Constant Pool Management]
C --> D[Bytecode Encoder]
D --> E[Nyarc Binary Output]
subgraph "Core Modules"
F[program::builder]
G[program::instructions]
H[program::pool]
I[formats::nyarc]
end
B --> F
D --> G
C --> H
E --> I
end
🚀 Features
Core Capabilities
- Fluent Builder API: Chainable methods to construct modules, functions (chunks), and control flow.
- Instruction Set Support: Comprehensive coverage of the Nyar VM instruction set, including stack manipulation, upvalues, and closure creation.
- Constant Pool Deduplication: Automatically manages and deduplicates constants (integers, floats, strings, etc.) to minimize binary size.
- Metadata Management: Handles imports, exports, and module-level metadata for dynamic linking and execution.
Advanced Features
- Flexible Binary Encoding: Leverages
gaia-binarywith Leb128 variable-length encoding for compact instruction streams. - Closure Support: Built-in support for capturing upvalues and creating closures at runtime.
- Type Safety: Strongly-typed instruction operands and program structures enforced by Rust's type system.
- Zero-Dependency Core: Designed to be lightweight and portable, with minimal external dependencies.
💻 Usage
Generating a "Hello Nyar" Module
The following example demonstrates how to use NyarBuilder to create a simple program that pushes a string and returns.
use ;
use NyarcWriter;
use Cursor;
🛠️ Support Status
| Feature | Status |
|---|---|
| Core Instructions | ✅ |
| Upvalues / Closures | ✅ |
| Constant Pool | ✅ |
| Import / Export | ✅ |
| Binary (.nyarc) | ✅ |
| Disassembler | 🚧 |