docs: AOT/ネイティブコンパイル情報をexecution-backends.mdに追加
- 4つ目の実行方式としてAOT(Ahead-of-Time)コンパイルを文書化 - MIR→WASM→.cwasm のコンパイルパイプラインを説明 - wasm-backend featureでのビルド方法を明記 - 現在の実装状況(完全なスタンドアロン実行ファイルはTODO)を記載 - CLAUDE.mdのWASM説明も3種類(Rust→WASM、Nyash→WASM、Nyash→AOT)に更新 - CURRENT_TASK.mdにPhase 10.9/10.10の完了項目を追加 ChatGPT5さんのAOT試行に対応した適切なドキュメント配置を実施 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
57
examples/README.md
Normal file
57
examples/README.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Examples Quick Start (Minimal)
|
||||
|
||||
このページはPhase 10.10の再起動用ミニ手順です。3つだけ確かめればOK。
|
||||
|
||||
- 事前ビルド: `cargo build --release -j32`
|
||||
- 実行は `./target/release/nyash` を使用
|
||||
|
||||
## 1) HH直実行(Map.get_hh)
|
||||
- 目的: 受け手/キーが関数パラメータのとき、JIT HostCallを許可(HH経路)。
|
||||
- 実行:
|
||||
```
|
||||
NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 NYASH_JIT_HOSTCALL=1 NYASH_JIT_EVENTS=1 \
|
||||
./target/release/nyash --backend vm examples/jit_map_get_param_hh.nyash
|
||||
```
|
||||
- 期待: `allow id: nyash.map.get_hh` イベントが出る。戻り値は `value1`。
|
||||
|
||||
## 2) mutating opt-in(JitPolicyBox)
|
||||
- 目的: 既定 read_only。必要最小の書き込みだけホワイトリストで許可。
|
||||
- 実行:
|
||||
```
|
||||
NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 NYASH_JIT_HOSTCALL=1 NYASH_JIT_EVENTS=1 \
|
||||
./target/release/nyash --backend vm examples/jit_policy_optin_mutating.nyash
|
||||
```
|
||||
- 期待: 1回目は `policy_denied_mutating` でfallback、whitelist後の2回目はallow。
|
||||
|
||||
イベントの見やすさ(任意):
|
||||
```
|
||||
# コンパイル時(lower)のみ: phase="lower" が付与(compileは明示opt-in)
|
||||
NYASH_JIT_EVENTS_COMPILE=1 NYASH_JIT_EVENTS_PATH=events.jsonl ...
|
||||
|
||||
# 実行時(runtime)のみ: phase="execute" が付与される
|
||||
NYASH_JIT_EVENTS_RUNTIME=1 NYASH_JIT_EVENTS_PATH=events.jsonl ...
|
||||
```
|
||||
|
||||
## 3) CountingGc デモ
|
||||
- 目的: GCのカウント/トレース/バリア観測の導線確認(VM経路)。
|
||||
- 実行:
|
||||
```
|
||||
./target/release/nyash --backend vm examples/gc_counting_demo.nyash
|
||||
```
|
||||
- Tips: 詳細ログは `NYASH_GC_COUNTING=1 NYASH_GC_TRACE=2` を併用。
|
||||
|
||||
## 4) Policy whitelist(events分離)
|
||||
- 目的: read_only下でのfallback→allow(whitelist)と、compile/runtimeのphase分離をイベントで確認。
|
||||
- 実行(しきい値=1を明示/またはDebugConfigBoxでapply後にRunnerが自動設定):
|
||||
```
|
||||
NYASH_JIT_THRESHOLD=1 NYASH_JIT_HOSTCALL=1 \
|
||||
./target/release/nyash --backend vm examples/jit_policy_whitelist_demo.nyash
|
||||
```
|
||||
- 期待: `policy_events.jsonl` に `phase:"lower"`(計画)と `phase:"execute"`(実績)が出る。
|
||||
|
||||
---
|
||||
|
||||
補足
|
||||
- DebugConfigBox(events/stats/dump/dot)と GcConfigBox は Box から `apply()` で環境へ反映できます。
|
||||
- `--emit-cfg path.dot` または `DebugConfigBox.setPath("jit_dot", path)` でCFGのDOT出力。いずれもdumpを自動有効化。
|
||||
- イベントは `phase` フィールドで区別(lower/execute)。`jit_events_path` でJSONL出力先を指定可能。
|
||||
81
examples/any_helpers_demo.nyash
Normal file
81
examples/any_helpers_demo.nyash
Normal file
@ -0,0 +1,81 @@
|
||||
// ANY Helpers Demo - 型を問わない統一的な操作
|
||||
// ANYヘルパーは Array, String, Map すべてに対応する万能メソッド!
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local console
|
||||
console = new ConsoleBox()
|
||||
|
||||
console.log("=== ANY Helpers Demo ===")
|
||||
console.log("")
|
||||
|
||||
// 1. length() - どんなBoxでも長さ/サイズを取得
|
||||
console.log("1) length() helper:")
|
||||
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
arr.push("cat")
|
||||
arr.push("dog")
|
||||
console.log("Array length: " + arr.length()) // 2
|
||||
|
||||
local str
|
||||
str = new StringBox("Hello")
|
||||
console.log("String length: " + str.length()) // 5
|
||||
|
||||
local map
|
||||
map = new MapBox()
|
||||
map.set("name", "Nyash")
|
||||
map.set("version", "1.0")
|
||||
console.log("Map size: " + map.length()) // 2
|
||||
console.log("")
|
||||
|
||||
// 2. isEmpty() - どんなBoxでも空かチェック
|
||||
console.log("2) isEmpty() helper:")
|
||||
|
||||
local emptyArr
|
||||
emptyArr = new ArrayBox()
|
||||
console.log("Empty array: " + emptyArr.isEmpty()) // true
|
||||
arr.push("fish")
|
||||
console.log("Non-empty array: " + arr.isEmpty()) // false
|
||||
|
||||
local emptyStr
|
||||
emptyStr = new StringBox("")
|
||||
console.log("Empty string: " + emptyStr.isEmpty()) // true
|
||||
local fullStr
|
||||
fullStr = new StringBox("Nyash")
|
||||
console.log("Non-empty string: " + fullStr.isEmpty()) // false
|
||||
|
||||
local emptyMap
|
||||
emptyMap = new MapBox()
|
||||
console.log("Empty map: " + emptyMap.isEmpty()) // true
|
||||
console.log("Non-empty map: " + map.isEmpty()) // false
|
||||
console.log("")
|
||||
|
||||
// 3. 実用例:型を気にせず処理
|
||||
console.log("3) Practical example - type-agnostic processing:")
|
||||
|
||||
local items
|
||||
items = new ArrayBox()
|
||||
items.push(arr) // Array
|
||||
items.push(str) // String
|
||||
items.push(map) // Map
|
||||
|
||||
// どんな型でも統一的に処理できる!
|
||||
local i
|
||||
i = 0
|
||||
loop(i < items.length()) {
|
||||
local item
|
||||
item = items.get(i)
|
||||
console.log("Item " + i + " - length: " + item.length() + ", empty: " + item.isEmpty())
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
console.log("")
|
||||
console.log("=== ANYヘルパーの威力 ===")
|
||||
console.log("- 型固有のメソッドを覚える必要なし")
|
||||
console.log("- Array/String/Mapを統一的に扱える")
|
||||
console.log("- Everything is Box 哲学の体現!")
|
||||
|
||||
return "Demo complete!"
|
||||
}
|
||||
}
|
||||
44
examples/jit_any_helpers_demo.nyash
Normal file
44
examples/jit_any_helpers_demo.nyash
Normal file
@ -0,0 +1,44 @@
|
||||
// JIT ANY Helpers Demo - JIT内部での統一的な型処理
|
||||
// ANYヘルパーは nyash.any.length_h と nyash.any.is_empty_h として
|
||||
// JITのHostCall経由で Array/String/Map を統一的に扱える!
|
||||
|
||||
box Helper {
|
||||
birth() {}
|
||||
|
||||
// このメソッドがJITコンパイルされると、内部的にANYヘルパーが使われる
|
||||
getInfo(obj) {
|
||||
// JIT内部では nyash.any.length_h が呼ばれる
|
||||
local len
|
||||
len = obj.length() // Array/Stringなら動作
|
||||
|
||||
// JIT内部では nyash.any.is_empty_h が呼ばれる
|
||||
local empty
|
||||
empty = obj.isEmpty() // Array/Stringなら動作
|
||||
|
||||
return len
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local H
|
||||
H = new Helper()
|
||||
|
||||
// Array での使用
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
arr.push("cat")
|
||||
arr.push("dog")
|
||||
print("Array info: " + H.getInfo(arr)) // 2
|
||||
|
||||
// String での使用
|
||||
local str
|
||||
str = new StringBox("Hello")
|
||||
print("String info: " + H.getInfo(str)) // 5
|
||||
|
||||
// 注意: MapBoxは現在のインタープリターではlength()未実装
|
||||
// JITでは nyash.any.length_h が Map.size() にマップされる
|
||||
|
||||
return "Done"
|
||||
}
|
||||
}
|
||||
44
examples/jit_policy_whitelist_demo.nyash
Normal file
44
examples/jit_policy_whitelist_demo.nyash
Normal file
@ -0,0 +1,44 @@
|
||||
// JitPolicy whitelist demo with DebugConfigBox event setup.
|
||||
// Goal: show fallback on read_only, then allow after whitelist.
|
||||
// Run (Cranelift enabled recommended):
|
||||
// cargo build --release -j32 --features cranelift-jit
|
||||
// NYASH_JIT_HOSTCALL=1 ./target/release/nyash --backend vm examples/jit_policy_whitelist_demo.nyash
|
||||
// Check events file:
|
||||
// cat policy_events.jsonl # contains phase=lower/execute decisions
|
||||
|
||||
box Helper {
|
||||
birth() {}
|
||||
add(a) {
|
||||
a.push(1)
|
||||
return a.length()
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
// Enable compile-time events and output path via DebugConfigBox
|
||||
local D
|
||||
D = new DebugConfigBox()
|
||||
D = D.setFlag("jit_events_compile", true)
|
||||
D = D.setFlag("jit_events_runtime", true)
|
||||
D = D.setPath("jit_events_path", "policy_events.jsonl")
|
||||
D.apply()
|
||||
|
||||
// Prepare JIT policy: read_only first
|
||||
local P
|
||||
P = new JitPolicyBox()
|
||||
P.set("read_only", true)
|
||||
|
||||
// Prepare data and helper
|
||||
local H, A
|
||||
H = new Helper()
|
||||
A = new ArrayBox()
|
||||
|
||||
// 1st call: should fallback by policy (mutating denied)
|
||||
H.add(A)
|
||||
|
||||
// Whitelist push_h and retry (expect allow)
|
||||
P.addWhitelist("nyash.array.push_h")
|
||||
return H.add(A)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user