Files
hakorune/lang/src/vm/flow_runner.hako
nyash-codex df9068a555 feat(stage-b): Add FLOW keyword support + fix Stage-3 keyword conflicts
##  Fixed Issues

### 1. `local` keyword tokenization (commit 9aab64f7)
- Added Stage-3 gate for LOCAL/TRY/CATCH/THROW keywords
- LOCAL now only active when NYASH_PARSER_STAGE3=1

### 2. `env.local.get` keyword conflict
- File: `lang/src/compiler/entry/compiler_stageb.hako:21-23`
- Problem: `.local` in member access tokenized as `.LOCAL` keyword
- Fix: Commented out `env.local.get("HAKO_SOURCE")` line
- Fallback: Use `--source` argument (still functional)

### 3. `flow` keyword missing
- Added FLOW to TokenType enum (`src/tokenizer/kinds.rs`)
- Added "flow" → TokenType::FLOW mapping (`src/tokenizer/lex_ident.rs`)
- Added FLOW to Stage-3 gate (requires NYASH_PARSER_STAGE3=1)
- Added FLOW to parser statement dispatch (`src/parser/statements/mod.rs`)
- Added FLOW to declaration handler (`src/parser/statements/declarations.rs`)
- Updated box_declaration parser to accept BOX or FLOW (`src/parser/declarations/box_definition.rs`)
- Treat `flow FooBox {}` as syntactic sugar for `box FooBox {}`

### 4. Module namespace conversion
- Renamed `lang.compiler.builder.ssa.local` → `localvar` (avoid keyword)
- Renamed file `local.hako` → `local_ssa.hako`
- Converted 152 path-based using statements to namespace format
- Added 26+ entries to `nyash.toml` [modules] section

## ⚠️ Remaining Issues

### Stage-B selfhost compiler performance
- Stage-B compiler not producing output (hangs/times out after 10+ seconds)
- Excessive PHI debug output suggests compilation loop issue
- Needs investigation: infinite loop or N² algorithm in hako compiler

### Fallback JSON version mismatch
- Rust fallback (`--emit-mir-json`) emits MIR v1 JSON (schema_version: "1.0")
- Smoke tests expect MIR v0 JSON (`"version":0, "kind":"Program"`)
- stageb_helpers.sh fallback needs adjustment

## Test Status
- Parse errors: FIXED 
- Keyword conflicts: FIXED 
- Stage-B smoke tests: STILL FAILING  (performance issue)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 04:13:17 +09:00

53 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// flow_runner.hako — Selfhost VM runner thin boxexec allowed under selfhost/vm/
using "lang/src/compiler/pipeline_v2/flow_entry.hako" as FlowEntryBox
using hakorune.vm.mir_min as MirVmMin
using selfhost.shared.common.string_ops as StringOps
static box FlowRunner {
_read_digits(text, pos) { local out = "" local i = pos loop(true) { local ch = text.substring(i, i+1) if ch == "" { break } if ch >= "0" && ch <= "9" { out = out + ch i = i + 1 } else { break } } return out }
_parse_return_int(ast_json) {
if ast_json == null { return null }
local rt = StringOps.index_of_from(ast_json, "\"type\":\"Return\"", 0)
if rt < 0 { return null }
local it = StringOps.index_of_from(ast_json, "\"type\":\"Int\"", rt)
if it < 0 { return null }
local vp = StringOps.index_of_from(ast_json, "\"value\":", it)
if vp < 0 { return null }
local ds = me._read_digits(ast_json, vp + 8)
if ds == "" { return null }
local acc = 0
local i = 0
loop(i < ds.length()) { acc = acc * 10 + ("0123456789".indexOf(ds.substring(i,i+1))) i = i + 1 }
return acc
}
// Execute on MiniVM from Stage1 JSON. compat=1 で v1→v0 経路。
run_vm_min_from_ast(ast_json, prefer_cfg, compat) {
// Fast-path Return(Int v)
local fast = me._parse_return_int(ast_json)
if fast != null { return fast }
local j = null
if compat == 1 { j = FlowEntryBox.emit_v1_compat_from_ast(ast_json, prefer_cfg) }
else { j = FlowEntryBox.emit_v0_from_ast(ast_json, prefer_cfg) }
// DEV marker injection is delegated to the CLI (Rust) bridge.
// 将来の切替用トグル: CLI が __cli_dev__ を埋めた場合のみ __dev__ に正規化現状は未使用・既定OFF
j = me._maybe_inject_dev_marker(j, ast_json)
return MirVmMin.run(j)
}
_maybe_inject_dev_marker(j, ast_json) {
if j == null { return j }
if j.indexOf("\"__dev__\":1") >= 0 { return j }
if ast_json != null && ast_json.indexOf("\"__cli_dev__\":1") >= 0 {
if j.substring(0,1) == "{" {
local payload = j.substring(1, j.length())
return "{\"__dev__\":1," + payload
}
}
return j
}
main(args) { return 0 }
}