Skip to content

Commit 57c7153

Browse files
proggeramlugclaude
andcommitted
Add missing documentation: WASM target, perry run, theming, minification, gc()
- New pages: platforms/wasm.md (WebAssembly target), ui/theming.md (perry-styling) - CLI: document `perry run` command with all flags, device detection, remote build - CLI: add `--target wasm` and `--minify` to compiler flags reference - Language: document `gc()` built-in garbage collection function - Platforms: add WASM to overview table/matrix, update iOS with perry run/keyboard/resources - Web: add minification/obfuscation section - Update SUMMARY.md with new pages, introduction with 7 targets Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6783bc7 commit 57c7153

12 files changed

Lines changed: 367 additions & 12 deletions

File tree

CLAUDE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
88

99
Perry is a native TypeScript compiler written in Rust that compiles TypeScript source code directly to native executables. It uses SWC for TypeScript parsing and Cranelift for code generation.
1010

11-
**Current Version:** 0.2.183
11+
**Current Version:** 0.2.184
1212

1313
## Workflow Requirements
1414

@@ -153,6 +153,9 @@ Projects can list npm packages to compile natively instead of routing to V8. Con
153153

154154
## Recent Changes
155155

156+
### v0.2.184
157+
- **Documentation**: add WebAssembly platform page, perry-styling/theming page, `perry run` command docs, `--minify` flag docs, `gc()` built-in docs; update SUMMARY.md, platform overview, CLI commands/flags
158+
156159
### v0.2.183
157160
- **WebAssembly target (`--target wasm`)**: new `perry-codegen-wasm` crate compiles HIR directly to WASM bytecode using `wasm-encoder`; NaN-boxing scheme matches native perry-runtime (f64 values with STRING_TAG/POINTER_TAG); JS runtime bridge for strings, console, Math, type operations; outputs self-contained HTML (base64-embedded WASM) or raw `.wasm` binary; supports functions, control flow, string literals, numeric ops, console.log
158161

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ opt-level = "s" # Optimize for size in stdlib
6666
opt-level = 3
6767

6868
[workspace.package]
69-
version = "0.2.183"
69+
version = "0.2.184"
7070
edition = "2021"
7171
license = "MIT"
7272
repository = "https://github.com/PerryTS/perry"

docs/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [Table](ui/table.md)
3232
- [Animation](ui/animation.md)
3333
- [Multi-Window](ui/multi-window.md)
34+
- [Theming](ui/theming.md)
3435

3536
# Platforms
3637

@@ -41,6 +42,7 @@
4142
- [Windows](platforms/windows.md)
4243
- [Linux (GTK4)](platforms/linux.md)
4344
- [Web](platforms/web.md)
45+
- [WebAssembly](platforms/wasm.md)
4446

4547
# Standard Library
4648

docs/src/cli/commands.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CLI Commands
22

3-
Perry provides 8 commands for compiling, checking, publishing, and managing your projects.
3+
Perry provides 9 commands for compiling, checking, running, publishing, and managing your projects.
44

55
## compile
66

@@ -22,6 +22,7 @@ perry main.ts -o app
2222
| `--keep-intermediates` | Keep `.o` and `.asm` files |
2323
| `--enable-js-runtime` | Enable V8 JavaScript runtime fallback |
2424
| `--type-check` | Enable type checking via tsgo |
25+
| `--minify` | Minify and obfuscate output (auto-enabled for `--target web`) |
2526
| `--app-bundle-id <ID>` | Bundle ID (required for widget targets) |
2627
| `--bundle-extensions <DIR>` | Bundle TypeScript extensions from directory |
2728

@@ -42,6 +43,54 @@ perry compile app.ts --print-hir
4243
perry compile widget.ts --target ios-widget --app-bundle-id com.myapp.widget
4344
```
4445

46+
## run
47+
48+
Compile and launch your app in one step.
49+
50+
```bash
51+
perry run # Auto-detect entry file
52+
perry run --ios # Run on iOS device/simulator
53+
perry run --android # Run on Android device
54+
perry run -- --port 3000 # Forward args to your program
55+
```
56+
57+
| Flag | Description |
58+
|------|-------------|
59+
| `--ios` | Target iOS (device or simulator) |
60+
| `--macos` | Target macOS (default on macOS host) |
61+
| `--web` | Target web (opens in browser) |
62+
| `--android` | Target Android device |
63+
| `--simulator <UDID>` | Specify iOS simulator by UDID |
64+
| `--device <UDID>` | Specify iOS physical device by UDID |
65+
| `--local` | Force local compilation (no remote fallback) |
66+
| `--remote` | Force remote build via Perry Hub |
67+
| `--enable-js-runtime` | Enable V8 JavaScript runtime |
68+
| `--type-check` | Enable type checking via tsgo |
69+
| `--` | Separator for program arguments |
70+
71+
**Entry file detection** (checked in order):
72+
1. `perry.toml``[project] entry` field
73+
2. `src/main.ts`
74+
3. `main.ts`
75+
76+
**Device detection**: When targeting iOS, Perry auto-discovers available simulators (via `simctl`) and physical devices (via `devicectl`). For Android, it uses `adb`. When multiple targets are found, an interactive prompt lets you choose.
77+
78+
**Remote build fallback**: If cross-compilation toolchains aren't installed locally (e.g., iOS targets on a machine without Xcode), `perry run --ios` automatically falls back to Perry Hub's build server — it packages your project, uploads it, streams build progress via WebSocket, downloads the `.ipa`, and installs it on your device. Use `--local` or `--remote` to force either path.
79+
80+
```bash
81+
# Run a CLI program
82+
perry run
83+
84+
# Run on a specific simulator
85+
perry run --ios --simulator 12345-ABCDE
86+
87+
# Force remote build
88+
perry run --ios --remote
89+
90+
# Run web target
91+
perry run --web
92+
```
93+
4594
## check
4695

4796
Validate TypeScript for Perry compatibility without compiling.

docs/src/cli/flags.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Use `--target` to cross-compile:
2525
| `android` | Android | ARM64/ARMv7 |
2626
| `ios-widget` | iOS Widget | WidgetKit extension (requires `--app-bundle-id`) |
2727
| `ios-widget-simulator` | iOS Widget (Sim) | Widget for simulator |
28+
| `wasm` | WebAssembly | Self-contained HTML with WASM or raw `.wasm` binary |
2829
| `web` | Web | Outputs HTML file with JS |
2930
| `windows` | Windows | Win32 executable |
3031
| `linux` | Linux | GTK4 executable |
@@ -46,6 +47,14 @@ Use `--output-type` to change what's produced:
4647
| `--no-link` | Produce `.o` object file only, skip linking |
4748
| `--keep-intermediates` | Keep `.o` and `.asm` intermediate files |
4849

50+
## Output Optimization
51+
52+
| Flag | Description |
53+
|------|-------------|
54+
| `--minify` | Minify and obfuscate output (auto-enabled for `--target web`) |
55+
56+
Minification strips comments, collapses whitespace, and mangles local variable/parameter/non-exported function names for smaller output.
57+
4958
## Runtime Flags
5059

5160
| Flag | Description |
@@ -140,6 +149,12 @@ perry compile app.ts -o app -vvv
140149

141150
# Type-checked compilation
142151
perry app.ts -o app --type-check
152+
153+
# WebAssembly
154+
perry app.ts -o app --target wasm
155+
156+
# Minified web output
157+
perry app.ts -o app --target web --minify
143158
```
144159

145160
## Next Steps

docs/src/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Hello from Perry!
1818
- **Native performance** — Compiles to machine code via Cranelift. Integer-heavy code like Fibonacci runs 2x faster than Node.js.
1919
- **Small binaries** — A hello world is ~300KB. Perry detects what runtime features you use and only links what's needed.
2020
- **Native UI** — Build desktop and mobile apps with declarative TypeScript that compiles to real AppKit, UIKit, GTK4, Win32, or DOM widgets.
21-
- **6 platforms** — macOS, iOS, Android, Windows, Linux, and Web from the same source code.
21+
- **7 targets** — macOS, iOS, Android, Windows, Linux, Web, and WebAssembly from the same source code.
2222
- **Familiar ecosystem** — Use npm packages like `fastify`, `mysql2`, `redis`, `bcrypt`, `lodash`, and more — compiled natively.
2323
- **Zero config** — Point Perry at a `.ts` file and get a binary. No `tsconfig.json` required.
2424

docs/src/language/supported-features.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ console.time("label");
452452
console.timeEnd("label");
453453
```
454454

455+
## Garbage Collection
456+
457+
Perry includes a mark-sweep garbage collector. It runs automatically when memory pressure is detected (~8MB arena blocks), but you can also trigger it manually:
458+
459+
```typescript
460+
gc(); // Explicit garbage collection
461+
```
462+
463+
The GC uses conservative stack scanning to find roots and supports arena-allocated objects (arrays, objects) and malloc-allocated objects (strings, closures, promises, BigInts, errors).
464+
455465
## JSX/TSX
456466

457467
Perry supports JSX syntax for UI component composition:

docs/src/platforms/ios.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ perry app.ts -o app --target ios
2727

2828
This produces an ARM64 binary for physical iOS devices. You'll need to code sign and package it in an `.app` bundle for deployment.
2929

30+
## Running with `perry run`
31+
32+
The easiest way to build and run on iOS is `perry run`:
33+
34+
```bash
35+
perry run --ios # Auto-detect device/simulator
36+
perry run --ios --console # Stream live stdout/stderr
37+
perry run --ios --remote # Use Perry Hub build server
38+
```
39+
40+
Perry auto-discovers available simulators (via `simctl`) and physical devices (via `devicectl`). When multiple targets are found, an interactive prompt lets you choose.
41+
42+
For physical devices, Perry handles code signing automatically — it reads your signing identity and team ID from `~/.perry/config.toml` (set up via `perry setup ios`), embeds the provisioning profile, and signs the `.app` before installing.
43+
44+
If you don't have the iOS cross-compilation toolchain installed locally, `perry run --ios` automatically falls back to Perry Hub's remote build server.
45+
3046
## UI Toolkit
3147

3248
Perry maps UI widgets to UIKit controls:
@@ -99,6 +115,14 @@ The image is centered at 128x128pt with `scaleAspectFit`. You can provide a cust
99115

100116
See [Project Configuration](../getting-started/project-config.md#splash) for the full config reference.
101117

118+
## Resource Bundling
119+
120+
Perry automatically bundles `logo/` and `assets/` directories from your project root into the `.app` bundle. These resources are available at runtime via standard file APIs relative to the app bundle path.
121+
122+
## Keyboard Avoidance
123+
124+
Perry apps automatically handle keyboard avoidance on iOS. When the keyboard appears, the root view adjusts its bottom constraint with an animated layout transition, and focused TextFields are auto-scrolled into view above the keyboard.
125+
102126
## Differences from macOS
103127

104128
- **No menu bar**: iOS doesn't support menu bars. Use toolbar or navigation patterns.

docs/src/platforms/overview.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Perry compiles TypeScript to native executables for 6 platforms from the same so
1212
| Windows | `--target windows` | Win32 | Full support (112/112) |
1313
| Linux | `--target linux` | GTK4 | Full support (112/112) |
1414
| Web | `--target web` | DOM/CSS | Full support (127/127) |
15+
| WebAssembly | `--target wasm` || Core language (no UI) |
1516

1617
## Cross-Compilation
1718

@@ -25,6 +26,7 @@ perry app.ts -o app --target web
2526
perry app.ts -o app --target windows
2627
perry app.ts -o app --target linux
2728
perry app.ts -o app --target android
29+
perry app.ts -o app --target wasm
2830
```
2931

3032
## Platform Detection
@@ -54,14 +56,14 @@ if (__platform__ === 0) {
5456

5557
## Platform Feature Matrix
5658

57-
| Feature | macOS | iOS | Android | Windows | Linux | Web |
58-
|---------|-------|-----|---------|---------|-------|-----|
59-
| CLI programs | Yes ||| Yes | Yes ||
60-
| Native UI | Yes | Yes | Yes | Yes | Yes | Yes |
61-
| File system | Yes | Sandboxed | Sandboxed | Yes | Yes ||
62-
| Networking | Yes | Yes | Yes | Yes | Yes | Fetch |
63-
| System APIs | Yes | Partial | Partial | Yes | Yes | Partial |
64-
| Widgets (WidgetKit) || Yes |||||
59+
| Feature | macOS | iOS | Android | Windows | Linux | Web | WASM |
60+
|---------|-------|-----|---------|---------|-------|-----|------|
61+
| CLI programs | Yes ||| Yes | Yes || Yes |
62+
| Native UI | Yes | Yes | Yes | Yes | Yes | Yes ||
63+
| File system | Yes | Sandboxed | Sandboxed | Yes | Yes |||
64+
| Networking | Yes | Yes | Yes | Yes | Yes | Fetch ||
65+
| System APIs | Yes | Partial | Partial | Yes | Yes | Partial ||
66+
| Widgets (WidgetKit) || Yes ||||||
6567

6668
## Next Steps
6769

@@ -71,3 +73,4 @@ if (__platform__ === 0) {
7173
- [Windows](windows.md)
7274
- [Linux (GTK4)](linux.md)
7375
- [Web](web.md)
76+
- [WebAssembly](wasm.md)

docs/src/platforms/wasm.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# WebAssembly
2+
3+
Perry can compile TypeScript to WebAssembly using `--target wasm`.
4+
5+
## Building
6+
7+
```bash
8+
# Self-contained HTML (default)
9+
perry app.ts -o app --target wasm
10+
open app.html
11+
12+
# Raw .wasm binary
13+
perry app.ts -o app.wasm --target wasm
14+
```
15+
16+
The default output is a single `.html` file containing a base64-embedded WASM binary and a JavaScript runtime bridge. If the output path ends with `.wasm`, a raw WASM binary is produced instead.
17+
18+
## How It Works
19+
20+
The `perry-codegen-wasm` crate compiles HIR directly to WASM bytecode using `wasm-encoder`. Unlike `--target web` (which emits JavaScript), this target produces real WebAssembly with a thin JS bridge for host APIs like `console.log` and string operations.
21+
22+
The NaN-boxing scheme matches the native perry-runtime — f64 values with STRING_TAG/POINTER_TAG — so the same value representation is used across native and WASM targets.
23+
24+
## Supported Features
25+
26+
- **Functions**: definitions, calls, parameters, return values
27+
- **Control flow**: `if`/`else`, `while`, `for`, `switch`, `break`, `continue`, `try`/`catch`/`finally`
28+
- **Data types**: numbers (f64), strings, booleans, `undefined`, `null`
29+
- **Operators**: arithmetic, comparison, logical, unary, update (`++`/`--`)
30+
- **String operations**: literals, concatenation, `charAt`, `substring`, `indexOf`, `slice`, `toLowerCase`, `toUpperCase`, `trim`, `includes`, `startsWith`, `endsWith`, `replace`, `split`, `.length`
31+
- **Math**: `Math.floor`, `Math.ceil`, `Math.round`, `Math.abs`, `Math.sqrt`, `Math.pow`, `Math.min`, `Math.max`, `Math.log`, `Math.random`
32+
- **Console**: `console.log()`, `console.warn()`, `console.error()`
33+
- **Type operations**: `typeof`, `parseInt`, `parseFloat`
34+
- **Other**: template literals, conditional expressions, `Date.now()`
35+
36+
## JavaScript Runtime Bridge
37+
38+
The WASM binary imports ~25 JavaScript functions for host interop:
39+
40+
- **Strings**: creation, concatenation, comparison, method dispatch
41+
- **Console**: output formatting with NaN-boxed value conversion
42+
- **Math**: delegation to `Math.*` built-ins
43+
- **Memory**: access via `WebAssembly.Memory` buffer
44+
45+
Strings are managed via a global string table in JavaScript, with IDs passed as NaN-boxed values to and from WASM.
46+
47+
## Limitations
48+
49+
The WASM target is newer than native and web targets. Current limitations:
50+
51+
- No object or array support (in progress)
52+
- No closures
53+
- No classes or `instanceof`
54+
- No async/await or Promises
55+
- No UI widgets (`perry/ui` is not available)
56+
- Switch statements use cascading if/else (no WASM table jumps)
57+
58+
## Minification
59+
60+
Use `--minify` to minify the JavaScript runtime bridge in the HTML output:
61+
62+
```bash
63+
perry app.ts -o app --target wasm --minify
64+
```
65+
66+
## Example
67+
68+
```typescript
69+
function fibonacci(n: number): number {
70+
if (n <= 1) return n;
71+
return fibonacci(n - 1) + fibonacci(n - 2);
72+
}
73+
74+
console.log(fibonacci(10)); // 55
75+
```
76+
77+
```bash
78+
perry fib.ts -o fib --target wasm
79+
# Produces fib.html — open in any browser
80+
```
81+
82+
## Next Steps
83+
84+
- [Web](web.md) — JavaScript target (full UI support)
85+
- [Platform Overview](overview.md) — All platforms

0 commit comments

Comments
 (0)