Files
hakorune/examples
Moe Charm 11506cee3b Phase 11-12: LLVM backend initial, semantics layer, plugin unification
Major changes:
- LLVM backend initial implementation (compiler.rs, llvm mode)
- Semantics layer integration in interpreter (operators.rs)
- Phase 12 plugin architecture revision (3-layer system)
- Builtin box removal preparation
- MIR instruction set documentation (26→Core-15 migration)
- Cross-backend testing infrastructure
- Await/nowait syntax support

New features:
- LLVM AOT compilation support (--backend llvm)
- Semantics layer for interpreter→VM flow
- Tri-backend smoke tests
- Plugin-only registry mode

Bug fixes:
- Interpreter plugin box arithmetic operations
- Branch test returns incorrect values

Documentation:
- Phase 12 README.md updated with new plugin architecture
- Removed obsolete NYIR proposals
- Added LLVM test programs documentation

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-01 23:44:34 +09:00
..

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-inJitPolicyBox

  • 目的: 既定 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 whitelistevents分離

  • 目的: read_only下でのfallback→allowwhitelistと、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.jsonlphase:"lower"(計画)と phase:"execute"(実績)が出る。

補足

  • DebugConfigBoxevents/stats/dump/dotと GcConfigBox は Box から apply() で環境へ反映できます。
  • --emit-cfg path.dot または DebugConfigBox.setPath("jit_dot", path) でCFGのDOT出力。いずれもdumpを自動有効化。
  • イベントは phase フィールドで区別lower/executejit_events_path でJSONL出力先を指定可能。

5) AOT最小手順--compile-native

  • 目的: Craneliftでオブジェクトを生成し、libnyrt とリンクしてEXE化。
  • 事前: cargo build --release --features cranelift-jit
  • 実行例String/Integer/Consoleの最小:
./target/release/nyash --compile-native examples/aot_min_string_len.nyash -o app && ./app
# 結果は `Result: <val>` として標準出力に表示
  • Python最小チェーンRO:
./target/release/nyash --compile-native examples/aot_py_min_chain.nyash -o app && ./app
  • スクリプト版(詳細な手順): tools/build_aot.sh <file> -o <out>Windowsは tools/build_aot.ps1

6) SchedulerPhase 10.6b 準備)

  • 目的: 協調スケジューラのSafepoint連携を観測
  • 実行(デモ):
NYASH_SCHED_DEMO=1 NYASH_SCHED_POLL_BUDGET=2 \
  ./target/release/nyash --backend vm examples/scheduler_demo.nyash
  • 期待: [SCHED] immediate task ran at safepoint[SCHED] delayed task ran at safepoint が出力