feat(phase21.5): selfhost CWD fix + loop executable semantics + diagnostics

## Task 1: Selfhost Child Process CWD Fix 
- Fix: try_selfhost_builder() now runs from repo root
- Implementation: (cd "$ROOT" && ... "$NYASH_BIN" ...)
- Benefit: nyash.toml using mappings are reliably loaded
- Location: tools/hakorune_emit_mir.sh:96-108
- Resolves: "using not found: 'hako.mir.builder.internal.*'" errors

## Task 2: Loop JSONFrag Executable Semantics 
- Upgrade: FORCE=1 now generates complete executable while-loop
- Structure: entry(0) → loop(1) → body(2) → exit(3)
- Semantics:
  - PHI node: i = {i0, entry} | {i_next, body}
  - Increment: i_next = i + 1
  - Backedge: body → loop
  - Exit: ret i (final loop variable value)
- Location: lang/src/mir/builder/internal/loop_opts_adapter_box.hako:24-44
- Expected: rc=10 (limit value) instead of structure-only validation

## Task 3: Enhanced Diagnostics 
- Added: HAKO_SELFHOST_TRACE=1 outputs comprehensive diagnostics
- Info: prog_json_len, tokens (Loop/Compare counts), cwd, nyash.toml status
- Example: [builder/selfhost-first:trace] prog_json_len=90 tokens=Loop:0,Compare:0 cwd=... nyash.toml=present
- Location: tools/hakorune_emit_mir.sh:87-100
- Benefit: One-line diagnosis of CWD/nyash.toml/using issues

## Task 4: nyash.toml Missing Entries 
- Added: hako.mir.builder.internal.builder_config mapping
- Added: hako.mir.builder.internal.loop_opts_adapter mapping
- Location: nyash.toml
- Benefit: Selfhost-first can resolve internal builder dependencies

## Implementation Principles
- 既定挙動不変 (Default unchanged, FORCE=1 guarded)
- Dev toggle controlled (TRACE=1, NO_DELEGATE=1)
- Minimal diff with clear rollback path
- CWD fix ensures stable using resolution
- Executable semantics enable proper EXE testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-11 09:09:55 +09:00
parent 0d41970313
commit 2299da7663
3 changed files with 60 additions and 14 deletions

View File

@ -225,6 +225,8 @@ path = "lang/src/shared/common/string_helpers.hako"
"hako.mir.builder.internal.lower_typeop_cast" = "lang/src/mir/builder/internal/lower_typeop_cast_box.hako"
"hako.mir.builder.internal.runner_min" = "lang/src/mir/builder/internal/runner_min_box.hako"
"hako.mir.builder.internal.jsonfrag_normalizer" = "lang/src/mir/builder/internal/jsonfrag_normalizer_box.hako"
"hako.mir.builder.internal.builder_config" = "lang/src/mir/builder/internal/builder_config_box.hako"
"hako.mir.builder.internal.loop_opts_adapter" = "lang/src/mir/builder/internal/loop_opts_adapter_box.hako"
# StageB support modules
"hako.compiler.entry.bundle_resolver" = "lang/src/compiler/entry/bundle_resolver.hako"