feat(joinir): Phase 213-2 Step 2-2 & 2-3 Data structure extensions

Extended PatternPipelineContext and CarrierUpdateInfo for Pattern 3 AST-based generalization.

Changes:
1. PatternPipelineContext:
   - Added loop_condition: Option<ASTNode>
   - Added loop_body: Option<Vec<ASTNode>>
   - Added loop_update_summary: Option<LoopUpdateSummary>
   - Updated build_pattern_context() for Pattern 3

2. CarrierUpdateInfo:
   - Added then_expr: Option<ASTNode>
   - Added else_expr: Option<ASTNode>
   - Updated analyze_loop_updates() with None defaults

Status: Phase 213-2 Steps 2-2 & 2-3 complete
Next: Create Pattern3IfAnalyzer to extract if statement and populate update summary
This commit is contained in:
nyash-codex
2025-12-10 00:01:53 +09:00
parent 577b5b01d5
commit d7805e5974
138 changed files with 3529 additions and 378 deletions

View File

@ -19,7 +19,7 @@ Enablement
- Use the provided pre-expander script for dev: `tools/dev/at_local_preexpand.sh`.
- Example:
- `tools/dev/at_local_preexpand.sh apps/tests/dev_sugar/at_local_basic.hako > /tmp/out.hako`
- `NYASH_VM_USE_PY=1 ./target/release/nyash --backend vm /tmp/out.hako`
- `NYASH_VM_USE_PY=1 ./target/release/hakorune --backend vm /tmp/out.hako`
Style
- Shared/committed code: prefer explicit `local` (nyfmt may normalize @ to `local`).

View File

@ -8,7 +8,7 @@ How to run (after full build):
- `copyFrom = { method_id = 7, args = [ { kind = "box", category = "plugin" } ] }`
- `cloneSelf = { method_id = 8 }`
- Build the plugin: `cd plugins/nyash-filebox-plugin && cargo build --release`
- Run the example: `./target/release/nyash docs/guides/examples/plugin_boxref_return.hako`
- Run the example: `./target/release/hakorune docs/guides/examples/plugin_boxref_return.hako`
Expected behavior:
- Creates two FileBox instances (`f`, `g`), writes to `f`, copies content to `g` via `copyFrom`, then closes both.

View File

@ -115,6 +115,6 @@ connect(url)
cleanup { env.console.log("done") }
// Stage3 parser gate quick smoke (direct acceptance)
// NYASH_PARSER_STAGE3=1 ./target/release/nyash --backend vm \
// NYASH_PARSER_STAGE3=1 ./target/release/hakorune --backend vm \
// apps/tests/macro/exception/expr_postfix_direct.hako
```

View File

@ -36,7 +36,7 @@ MIR Builder (optional, EXE)
- Run: `./app_out` (exit `7` expected for `return 1+2*3`).
Runner with EXEFirst Parser
- `NYASH_USE_NY_COMPILER=1 NYASH_USE_NY_COMPILER_EXE=1 ./target/release/nyash --backend vm tmp/sample.hako`
- `NYASH_USE_NY_COMPILER=1 NYASH_USE_NY_COMPILER_EXE=1 ./target/release/hakorune --backend vm tmp/sample.hako`
- Smoke: `./tools/exe_first_runner_smoke.sh`
Troubleshooting

View File

@ -126,7 +126,7 @@ for / foreach の糖衣と正規化(概要)
- 出力一致スモークVM, v2
- `tools/smokes/v2/run.sh --profile quick --filter "loop_two_vars|macro"`
- 自己ホスト前展開PyVM 経由)
- `NYASH_VM_USE_PY=1 NYASH_USE_NY_COMPILER=1 NYASH_MACRO_ENABLE=1 NYASH_MACRO_PATHS=apps/macros/examples/loop_normalize_macro.hako ./target/release/nyash --macro-preexpand --backend vm apps/tests/macro/loopform/simple.hako`
- `NYASH_VM_USE_PY=1 NYASH_USE_NY_COMPILER=1 NYASH_MACRO_ENABLE=1 NYASH_MACRO_PATHS=apps/macros/examples/loop_normalize_macro.hako ./target/release/hakorune --macro-preexpand --backend vm apps/tests/macro/loopform/simple.hako`
Selfhost compiler prepass恒等→最小正規化
- Runner が `NYASH_LOOPFORM_NORMALIZE=1``--loopform` にマップして子に渡し、`apps/lib/loopform_normalize.hako` の前処理を適用(現状は恒等)。

View File

@ -22,7 +22,7 @@ Status: MVP available behind environment gates (default OFF). This page describe
Example
```
NYASH_MACRO_ENABLE=1 ./target/release/nyash --backend vm apps/APP/main.hako
NYASH_MACRO_ENABLE=1 ./target/release/hakorune --backend vm apps/APP/main.hako
```
## Test runner (MVP)
@ -46,17 +46,17 @@ NYASH_MACRO_ENABLE=1 ./target/release/nyash --backend vm apps/APP/main.hako
Examples
```
# run all tests in a file
./target/release/nyash --run-tests apps/tests/my_tests.hako
./target/release/hakorune --run-tests apps/tests/my_tests.hako
# filter + wrap entry + default arg injection
NYASH_MACRO_ENABLE=1 NYASH_TEST_ARGS_DEFAULTS=1 \
./target/release/nyash --run-tests --test-filter http --test-entry wrap apps/tests/my_tests.hako
./target/release/hakorune --run-tests --test-filter http --test-entry wrap apps/tests/my_tests.hako
```
## Expansion dump
```
./target/release/nyash --expand --dump-ast apps/tests/ternary_basic.hako
./target/release/hakorune --expand --dump-ast apps/tests/ternary_basic.hako
```
Shows pre/post expansion AST (debug only).

View File

@ -5,9 +5,9 @@ Overview
- Default remains envgated for safety; CI runs smokes to build confidence.
Recommended Flows
- Runner (pilot): `NYASH_USE_NY_COMPILER=1 ./target/release/nyash --backend vm apps/examples/string_p0.hako`
- Runner (pilot): `NYASH_USE_NY_COMPILER=1 ./target/release/hakorune --backend vm apps/examples/string_p0.hako`
- Emitonly: `NYASH_USE_NY_COMPILER=1 NYASH_NY_COMPILER_EMIT_ONLY=1 ...`
- EXEfirst (parser EXE): `tools/build_compiler_exe.sh && NYASH_USE_NY_COMPILER=1 NYASH_USE_NY_COMPILER_EXE=1 ./target/release/nyash --backend vm apps/examples/string_p0.hako`
- EXEfirst (parser EXE): `tools/build_compiler_exe.sh && NYASH_USE_NY_COMPILER=1 NYASH_USE_NY_COMPILER_EXE=1 ./target/release/hakorune --backend vm apps/examples/string_p0.hako`
- LLVM AOT: `NYASH_LLVM_USE_HARNESS=1 tools/build_llvm.sh apps/... -o app && ./app`
CI Workflows
@ -16,11 +16,11 @@ CI Workflows
- Selfhost EXEfirstoptional
- crate 直結ny-llvmcで JSON→EXE→実行までを最短経路で確認できるよ。
- 手順(ローカル):
1) MIR(JSON) を出力: `./target/release/nyash --emit-mir-json tmp/app.json --backend mir apps/tests/ternary_basic.hako`
1) MIR(JSON) を出力: `./target/release/hakorune --emit-mir-json tmp/app.json --backend mir apps/tests/ternary_basic.hako`
2) EXE 生成: `./target/release/ny-llvmc --in tmp/app.json --emit exe --nyrt target/release --out tmp/app`
3) 実行: `./tmp/app`(戻り値が exit code
- ワンコマンドスモーク: `bash tools/crate_exe_smoke.sh apps/tests/ternary_basic.hako`
- CLI で直接 EXE 出力: `./target/release/nyash --emit-exe tmp/app --backend mir apps/tests/ternary_basic.hako`
- CLI で直接 EXE 出力: `./target/release/hakorune --emit-exe tmp/app --backend mir apps/tests/ternary_basic.hako`
- Installs LLVM 18 + llvmlite, then runs `tools/exe_first_smoke.sh`.
Useful Env Flags

View File

@ -5,12 +5,12 @@
⚠️ **ルートディレクトリの汚染防止ルール** ⚠️
```bash
# ❌ 絶対ダメ:ルートで実行
./target/release/nyash test.hako # ログがルートに散乱!
./target/release/hakorune test.hako # ログがルートに散乱!
cargo test > test_output.txt # 出力ファイルがルートに!
# ✅ 正しい方法:必ずディレクトリを使う
cd local_tests && ../target/release/nyash test.hako
./target/release/nyash local_tests/test.hako
cd local_tests && ../target/release/hakorune test.hako
./target/release/hakorune local_tests/test.hako
```
**必須ルール:**
@ -42,7 +42,7 @@ echo 'print("Hello Nyash!")' > local_tests/test_hello.hako
./target/debug/nyash app_dice_rpg.hako
# JIT 実行フラグCLI
./target/release/nyash --backend vm \
./target/release/hakorune --backend vm \
--jit-exec --jit-stats --jit-dump --jit-threshold 1 \
--jit-phi-min --jit-hostcall --jit-handle-debug \
examples/jit_branch_demo.hako
@ -51,11 +51,11 @@ echo 'print("Hello Nyash!")' > local_tests/test_hello.hako
# NYASH_JIT_PHI_MIN/NYASH_JIT_HOSTCALL/NYASH_JIT_HANDLE_DEBUG
# HostCallハンドルPoCの例
./target/release/nyash --backend vm --jit-exec --jit-hostcall examples/jit_array_param_call.hako
./target/release/nyash --backend vm --jit-exec --jit-hostcall examples/jit_map_param_call.hako
./target/release/nyash --backend vm --jit-exec --jit-hostcall examples/jit_map_int_keys_param_call.hako
./target/release/nyash --backend vm --jit-exec --jit-hostcall examples/jit_string_param_length.hako
./target/release/nyash --backend vm --jit-exec --jit-hostcall examples/jit_string_is_empty.hako
./target/release/hakorune --backend vm --jit-exec --jit-hostcall examples/jit_array_param_call.hako
./target/release/hakorune --backend vm --jit-exec --jit-hostcall examples/jit_map_param_call.hako
./target/release/hakorune --backend vm --jit-exec --jit-hostcall examples/jit_map_int_keys_param_call.hako
./target/release/hakorune --backend vm --jit-exec --jit-hostcall examples/jit_string_param_length.hako
./target/release/hakorune --backend vm --jit-exec --jit-hostcall examples/jit_string_is_empty.hako
```
## PHI ポリシーPhase15と検証トグル
@ -103,11 +103,11 @@ python3 tools/phi_trace_check.py --file tmp/phi_trace.jsonl --summary
### 1. CLI レベルの MIR ダンプ
- ソースから直接 MIR を確認:
- `./target/release/nyash --dump-mir path/to/program.hako`
- `./target/release/hakorune --dump-mir path/to/program.hako`
- VM 実行経路で MIR を一緒に吐く:
- `NYASH_VM_DUMP_MIR=1 ./target/release/nyash path/to/program.hako`
- `NYASH_VM_DUMP_MIR=1 ./target/release/hakorune path/to/program.hako`
- JSON で詳細解析したい場合:
- `./target/release/nyash --emit-mir-json mir.json path/to/program.hako`
- `./target/release/hakorune --emit-mir-json mir.json path/to/program.hako`
- 例: `jq '.functions[0].blocks' mir.json` でブロック構造を確認。
### 2. Scope / Loop ヒントNYASH_MIR_HINTS
@ -137,7 +137,7 @@ python3 tools/phi_trace_check.py --file tmp/phi_trace.jsonl --summary
- 戻り値は Void 定数扱いのため、式コンテキストに書いても型崩れしない。
- 実行時の有効化:
- `NYASH_MIR_DEBUG_LOG=1 ./target/release/nyash path/to/program.hako`
- `NYASH_MIR_DEBUG_LOG=1 ./target/release/hakorune path/to/program.hako`
- VM の MIR interpreter が次のようなログを stderr に出力:
```text
@ -189,9 +189,9 @@ cargo build --release
### パーサー無限ループ対策2025-08-09実装
```bash
# 🔥 デバッグ燃料でパーサー制御
./target/release/nyash --debug-fuel 1000 program.hako # 1000回制限
./target/release/nyash --debug-fuel unlimited program.hako # 無制限
./target/release/nyash program.hako # デフォルト10万回
./target/release/hakorune --debug-fuel 1000 program.hako # 1000回制限
./target/release/hakorune --debug-fuel unlimited program.hako # 無制限
./target/release/hakorune program.hako # デフォルト10万回
# パーサー無限ループが検出されると自動停止+詳細情報表示
🚨 PARSER INFINITE LOOP DETECTED at method call argument parsing

View File

@ -27,7 +27,7 @@
3. **詳細ログで確認**
```bash
NYASH_DEBUG_USING=1 ./target/release/nyash program.hako
NYASH_DEBUG_USING=1 ./target/release/hakorune program.hako
```
4. **"Did you mean?" 提案を確認**
@ -64,7 +64,7 @@ StringUtils = "lang/src/shared/common/string_helpers.hako" # ← 追加
2. **デバッグログで詳細確認**
```bash
NYASH_DEBUG_FUNCTION_LOOKUP=1 ./target/release/nyash program.hako
NYASH_DEBUG_FUNCTION_LOOKUP=1 ./target/release/hakorune program.hako
```
出力例:
@ -101,7 +101,7 @@ StringUtils.starts_with("hello", "he") // arity 2 → "starts_with/2" を探す
1. **Methodization トレースログを確認**
```bash
NYASH_METHODIZE_TRACE=1 ./target/release/nyash program.hako
NYASH_METHODIZE_TRACE=1 ./target/release/hakorune program.hako
```
出力例:
@ -114,7 +114,7 @@ StringUtils.starts_with("hello", "he") // arity 2 → "starts_with/2" を探す
3. **Methodization を無効化して確認**
```bash
HAKO_MIR_BUILDER_METHODIZE=0 ./target/release/nyash program.hako
HAKO_MIR_BUILDER_METHODIZE=0 ./target/release/hakorune program.hako
```
**Phase 21.7++ での修正**:
@ -140,7 +140,7 @@ StringUtils.starts_with("hello", "he") // arity 2 → "starts_with/2" を探す
2. **詳細診断モードで実行**
```bash
NYASH_CLI_VERBOSE=1 ./target/release/nyash program.hako 2>&1 | tee debug.log
NYASH_CLI_VERBOSE=1 ./target/release/hakorune program.hako 2>&1 | tee debug.log
```
3. **すべてのデバッグフラグを有効化**
@ -149,7 +149,7 @@ StringUtils.starts_with("hello", "he") // arity 2 → "starts_with/2" を探す
NYASH_DEBUG_USING=1 \
NYASH_METHODIZE_TRACE=1 \
NYASH_CLI_VERBOSE=1 \
./target/release/nyash program.hako
./target/release/hakorune program.hako
```
**Phase 21.7++ での修正**:

View File

@ -8,7 +8,7 @@ Status: PoC complete; PyVM sandbox route wired. This guide explains how to autho
- `NYASH_MACRO_ENABLE=1`
- `NYASH_MACRO_PATHS=apps/macros/examples/echo_macro.hako`
- Run your program as usual (macro expansion happens once before MIR):
- `./target/release/nyash --backend vm apps/tests/ternary_basic.hako`
- `./target/release/hakorune --backend vm apps/tests/ternary_basic.hako`
Environment overview (recommended minimal set)
- `NYASH_MACRO_ENABLE=1`既定ON
@ -66,7 +66,7 @@ export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS=apps/macros/examples/echo_macro.hako
# Run your program (macro expansion happens before MIR)
./target/release/nyash --backend vm apps/tests/ternary_basic.hako
./target/release/hakorune --backend vm apps/tests/ternary_basic.hako
```
Selfhost pathNYASH_USE_NY_COMPILER=1での前展開開発用
@ -75,7 +75,7 @@ Selfhost pathNYASH_USE_NY_COMPILER=1での前展開開発用
NYASH_USE_NY_COMPILER=1 \
NYASH_MACRO_SELFHOST_PRE_EXPAND=1 \
NYASH_VM_USE_PY=1 \
./target/release/nyash --backend vm apps/tests/ternary_basic.hako
./target/release/hakorune --backend vm apps/tests/ternary_basic.hako
```
Notes: 現状は PyVM ルートのみ対応。`NYASH_VM_USE_PY=1` が必須。
@ -84,7 +84,7 @@ CLI プロファイル(推奨)
- `--profile dev`(既定相当: マクロON/厳格ON
- `--profile lite`マクロOFFの軽量モード
- `--profile ci|strict`マクロON/厳格ON
- 例: `./target/release/nyash --profile dev --backend vm apps/tests/ternary_basic.hako`
- 例: `./target/release/hakorune --profile dev --backend vm apps/tests/ternary_basic.hako`
Notes
- Built-in child route (stdin JSON -> stdout JSON) remains available when `NYASH_MACRO_BOX_CHILD_RUNNER=0`.
@ -113,7 +113,7 @@ Array/Map editing examples
## Inspect Expanded AST
```bash
./target/release/nyash --dump-expanded-ast-json apps/tests/ternary_basic.hako
./target/release/hakorune --dump-expanded-ast-json apps/tests/ternary_basic.hako
```
Outputs AST JSON v0 after expansion; use this for golden comparison.

View File

@ -18,10 +18,10 @@ Nyash WebAssemblyWASM実行に関する包括的ガイド
### WASM コンパイル
```bash
# 基本コンパイル
./target/release/nyash --compile-wasm program.hako
./target/release/hakorune --compile-wasm program.hako
# AOT コンパイル(配布用)
./target/release/nyash --aot program.hako
./target/release/hakorune --aot program.hako
```
### ブラウザー実行

View File

@ -104,7 +104,7 @@ cargo update
cargo build --release
# WASM/AOT テスト
./target/release/nyash --aot test_simple.hako
./target/release/hakorune --aot test_simple.hako
wasmtime --allow-precompiled test_simple.cwasm
```
@ -170,7 +170,7 @@ config.cranelift_opt_level(OptLevel::Speed)?;
### 技術指標
```bash
# ✅ 成功条件
./target/release/nyash --aot test.hako # コンパイル成功
./target/release/hakorune --aot test.hako # コンパイル成功
wasmtime --allow-precompiled test.cwasm # 実行成功
echo $? # 0 (正常終了)
```

View File

@ -154,10 +154,10 @@ wasmtime 35.0.0 # 実行時
### 基本動作テスト
```bash
# BoxCall テスト
./target/release/nyash --compile-wasm test_boxcall.hako
./target/release/hakorune --compile-wasm test_boxcall.hako
# AOT テスト
./target/release/nyash --aot test_simple.hako
./target/release/hakorune --aot test_simple.hako
wasmtime --allow-precompiled test_simple.cwasm
```

View File

@ -208,9 +208,9 @@ console.call("log", "Hello Browser!") # ExternCall実装必要
### 基本機能復旧
```bash
# 以下が全て成功すること
./target/release/nyash --compile-wasm test_basic_boxcall.hako
./target/release/nyash --compile-wasm test_box_operations.hako
./target/release/nyash --compile-wasm test_extern_integration.hako
./target/release/hakorune --compile-wasm test_basic_boxcall.hako
./target/release/hakorune --compile-wasm test_box_operations.hako
./target/release/hakorune --compile-wasm test_extern_integration.hako
# WASM実行成功
wasmtime test_basic_boxcall.wasm