tape refactor
Usage
bash
tape refactor <file.tape> [options]Purpose
Materializes refactor("path") { ... } blocks into separate .tape files. The compiler validates these blocks on every build — by the time this command runs, the extraction is already proven correct.
bash
tape refactor app.tape
# Wrote ./store.tape
# Rewrote app.tapeWhat it does
- Run analysis pass (scan, parse, lower, typecheck) to validate refactor boundaries
- For each
refactor("path") { ... }block in the source:- Generate the target file with only the imports the moved code uses
- Wrap all declarations in
pub {} - Inherit
@profilefrom the source file
- Rewrite the source file:
- Remove the refactor block(s)
- Add selective imports for symbols that the remaining code references
Examples
bash
# Materialize all refactor blocks:
tape refactor app.tape
# Preview without writing:
tape refactor app.tape --dry-run
# Overwrite existing target files:
tape refactor app.tape --force—dry-run output
plaintext
Virtual module "./store.tape":
Imports: (none)
Exports: items, count, add_item, sum
Host "app.tape" after extraction:
New import: import { items, count, add_item, sum } from "./store.tape";
Removed: refactor block (lines 12-31)
Would write: ./store.tape (new file)
Would rewrite: app.tapeOptions
| Flag | Description |
|---|---|
--dry-run | Show computed file contents without writing to disk |
--force | Overwrite existing target files (default: error if target exists) |
--human | Human-readable output with color |
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success — files written |
| 1 | Compile error in refactor boundary (same errors as tape check) |
| 3 | I/O error (target file exists without --force, permission denied) |
Relationship to other commands
tape refactor uses the same frontend pipeline as tape check — it stops after type checking and does not generate native code. The refactor boundaries are validated during normal tape build and tape check runs too, so errors appear immediately during development.
plaintext
tape check app.tape # validates refactor boundaries (among everything else)
tape build app.tape # also validates them, then builds
tape refactor app.tape # materializes them into filesGenerated file format
Target files are generated with:
- Only the imports the moved code actually uses
- All declarations inside a
pub {}block - The source file’s
@profilepragma (if present) - No other boilerplate
tape
// store.tape (generated by tape refactor)
pub {
var items: [64]i64;
var count: i64 = 0;
fn add_item(val: i64) { ... }
fn sum() -> i64 { ... }
}Error conditions
| Condition | Result |
|---|---|
Target file already exists (no --force) | Exit 3: “file already exists” |
| Refactor block references host-local symbol | Exit 1: compile error (caught during any build) |
| Circular dependency between blocks | Exit 1: compile error (caught during any build) |
| No refactor blocks found in source | Exit 0: no-op, prints “no refactor blocks” |
Last modified: