magpie-lang/magpie/magpie
Claude Code and agent skill by magpie-lang/magpie
- community
Checking that the SKILL.md file is still in the repository.
Comprehensive guide for writing Magpie (.mp) programs, debugging compiler errors, and using the Magpie CLI. Designed for agents who have never seen Magpie before.
Install
npx vskill@latest install magpie-lang/magpie/magpieSKILL.md
Magpie Language Programming Guide
Use this skill whenever you write, debug, or review Magpie .mp programs.
0) Non-negotiable Rules
- Binary-first: treat compiler diagnostics as ground truth.
- Run
magpie explain <CODE>for any error code you don't recognize. - Use
--output jsonfor machine-readable diagnostics.
- Diagnose by error code first, then apply the smallest fix.
- Smallest reproducer first -- one tiny
.mpfile, then grow. - Change one dimension at a time (syntax, then types, then ownership, then backend).
- Prove fixes with commands and exit codes.
1) What is Magpie
Magpie is a compiled, SSA-based language with explicit ownership, ARC memory management, and first-class GPU support. Programs are written in a low-level IR-like textual format (CSNF).
Key characteristics:
- SSA form -- every value is defined once, used by name (
%x,%y) - Explicit ownership -- you manually
borrow.shared,borrow.mut,share,clone.shared - ARC-managed heap -- the compiler inserts reference counting; you manage ownership transitions
- Block-structured -- functions contain labeled basic blocks (
bb0:,bb1:) with explicit terminators - No implicit conversions -- types must match exactly;
constsuffixes must match declared types - 5 GPU backends -- SPIR-V, Metal (MSL), PTX (CUDA), HIP (AMD), WGSL (WebGPU)
How Magpie differs from familiar languages:
- There are no expressions or statements -- only SSA instructions and terminators
- Control flow uses
br,cbr,switch-- notif/else/for/while - Variables are SSA locals (
%name) -- assigned exactly once - Functions are
@name-- always prefixed with@ - Types are
TName-- user-defined types start withT - Comments use
;(not//or#); doc comments use;;
2) Module Structure
Every .mp file must have a strict header in exactly this order:
The order is mandatory. Swapping any header line causes a parse error (MPP0002).
Minimal template (copy-paste this to start any program)
Exports
List functions (@name) and types (TName) the module makes visible:
Imports
Group imports by source module:
Use imported functions with their full qualified path in calls:
Digest
A hex string for content hashing. Use "0000000000000000" as a placeholder during development.
3) Functions
Function kinds
Parameters and return types
Parameters are SSA names (%name: Type). Return type follows ->.
Meta blocks (optional)
Basic blocks and terminators
Every function body contains one or more blocks. Each block has a label (bbN:) and ends with exactly one terminator.
Terminators
| Terminator | Syntax | Description | |
|---|---|---|---|
ret | ret %value or ret const.i32 0 | Return a value | |
ret (void) | ret | Return unit (for -> unit functions) | |
br | br bb1 | Unconditional branch | |
cbr | cbr %cond bb_true bb_false | Conditional branch (%cond must be bool) | |
switch | switch %val { case 0 -> bb1 case 1 -> bb2 } else bb3 | Multi-way branch | |
unreachable | unreachable | Mark unreachable code path |
Branching example
Phi nodes (merging values from multiple predecessors)
phi selects a value based on which predecessor block was taken. Borrow values cannot appear in phi nodes (MPO0102).
4) Type System
4.1 Primitive types
| Category | Types | |
|---|---|---|
| Signed integers | i1 i8 i16 i32 i64 i128 | |
| Unsigned integers | u1 u8 u16 u32 u64 u128 | |
| Floats | f16 f32 f64 bf16 | |
| Boolean | bool | |
| Unit | unit |
4.2 Builtin heap types
| Type | Description | |
|---|---|---|
Str | UTF-8 string (built-in hash, eq, ord -- no impl needed) | |
Array<T> | Dynamic array | |
Map<K, V> | Hash map (K must have hash + eq impls) | |
TOption<T> | Optional value -- variants: Some { v: T }, None { } | |
TResult<Ok, Err> | Result value -- variants: Ok { v: Ok }, Err { e: Err } | |
TStrBuilder | Mutable string builder | |
TMutex<T> | Mutual exclusion lock | |
TRwLock<T> | Reader-writer lock | |
TCell<T> | Interior mutability cell | |
TFuture<T> | Async future | |
TChannelSend<T> | Channel send endpoint | |
TChannelRecv<T> | Channel receive endpoint | |
TCallable<TSigName> | First-class callable (closure/function pointer) |
4.3 Ownership modifiers
Place these before a type to change ownership mode:
| Modifier | Meaning | Example | |
|---|---|---|---|
| (none) | Unique owner (default) | %p: TPoint | |
shared | Reference-counted shared | %s: shared TPoint | |
borrow | Shared read-only borrow | %b: borrow TPoint | |
mutborrow | Exclusive mutable borrow | %m: mutborrow TPoint | |
weak | Weak reference (non-owning) | %w: weak TPoint |
Important restrictions:
TOptionandTResultrejectsharedandweakprefixes (MPT0002,MPT0003)- Borrows cannot cross block boundaries, appear in phi, or be returned from functions
4.4 User-defined types
Heap struct (reference-counted, can contain any types)
Value struct (stack-allocated, cannot contain heap handles)
If a value struct field contains a heap type (like Str), you get MPT1005. Use heap struct instead.
Heap enum
Value enum (deferred in v0.1 -- use heap enum instead)
value enum will produce MPT1020. Use heap enum for now.
4.5 Signatures and callables
Then use TCallable<TBinaryOp> as the type for first-class function values.
4.6 Raw pointers
Raw pointer ops require unsafe context.
4.7 Type hierarchy diagram
4.8 Trait requirements for collections
| Type | hash | eq | ord | Notes | |
|---|---|---|---|---|---|
| All primitives | yes | yes | yes | Built-in | |
bool | yes | yes | yes | Built-in | |
Str | yes | yes | yes | Built-in -- no explicit `impl` needed | |
User heap struct | no | no | no | Must provide explicit impl declarations | |
User heap enum | no | no | no | Must provide explicit impl declarations |
Map<Str, V> works with no extra code. Map<TMyStruct, V> requires:
Trait impl signature requirements:
hash:(%v: borrow T) -> u64eq:(%a: borrow T, %b: borrow T) -> boolord:(%a: borrow T, %b: borrow T) -> i32
4.9 Extern declarations (FFI)
Extern functions returning rawptr must have attrs { returns="owned" } or attrs { returns="borrowed" } (MPF0001).
4.10 Globals
5) Ownership & Borrowing Model
5.1 Ownership state machine
5.2 Key rules
| Rule | Consequence | |
|---|---|---|
share { v=%x } | Consumes %x. %x is dead after this. | |
borrow.mut { v=%x } | Creates exclusive mutable access, scoped to current block only | |
borrow.shared { v=%x } | Creates shared read access, scoped to current block only | |
clone.shared { v=%x } | Creates a new shared ref. Original survives. | |
| Borrows cannot cross block boundaries | MPO0101 | |
| Borrows cannot appear in phi nodes | MPO0102 | |
| Borrows cannot be returned from functions | MPHIR03 | |
| Cannot use a value after it has been moved/consumed | MPO0007 | |
| Cannot move a value while a borrow is active | MPO0011 |
5.3 Borrow lifecycle per block
5.4 Correct multi-block borrow pattern
Wrong -- borrow crosses block boundary (MPO0101):
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingSKILL.md
Popularity
- Repository stars
- 49
- Repository forks
- 3
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/magpie-lang/magpie/magpie)