hv1: early-exit at main (no plugin init); tokenizer: Stage-3 single-quote + full escapes (\/ \b \f \' \r fix); builder: route BinOp via SSOT emit_binop_to_dst; hv1 verify canary route (builder→Core); docs: phase-20.39 updates
This commit is contained in:
@ -362,6 +362,90 @@ HCODE
|
||||
fi
|
||||
}
|
||||
|
||||
# New function: verify_program_via_builder_to_core
|
||||
# Purpose: Program(JSON v0) → MirBuilder(Hako) → MIR(JSON v0) → Core execution
|
||||
# This is dev-only for testing builder output quality
|
||||
verify_program_via_builder_to_core() {
|
||||
local prog_json_path="$1"
|
||||
|
||||
# Step 1: Use MirBuilderBox to convert Program → MIR(env経由でJSONを渡す)
|
||||
local mir_json_path="/tmp/builder_output_$$.json"
|
||||
|
||||
local builder_code=$(cat <<'HCODE'
|
||||
using "hako.mir.builder" as MirBuilderBox
|
||||
static box Main { method main(args) {
|
||||
local prog_json = env.get("NYASH_VERIFY_JSON")
|
||||
if prog_json == null { print("Builder failed"); return 1 }
|
||||
local mir_out = MirBuilderBox.emit_from_program_json_v0(prog_json, null)
|
||||
if mir_out == null { print("Builder failed"); return 1 }
|
||||
print("" + mir_out)
|
||||
return 0
|
||||
} }
|
||||
HCODE
|
||||
)
|
||||
|
||||
# Read program JSON to env (avoid embedding/escaping)
|
||||
local prog_json_raw
|
||||
prog_json_raw="$(cat "$prog_json_path")"
|
||||
|
||||
# Run builder with internal lowers enabled using v1 dispatcher
|
||||
local mir_json
|
||||
local builder_stderr="/tmp/builder_stderr_$$.log"
|
||||
mir_json=$(HAKO_MIR_BUILDER_INTERNAL=1 \
|
||||
HAKO_FAIL_FAST_ON_HAKO_IN_NYASH_VM=0 \
|
||||
HAKO_ROUTE_HAKOVM=1 \
|
||||
NYASH_USING_AST=1 \
|
||||
NYASH_RESOLVE_FIX_BRACES=1 \
|
||||
NYASH_DISABLE_NY_COMPILER=1 \
|
||||
NYASH_PARSER_STAGE3=1 \
|
||||
HAKO_PARSER_STAGE3=1 \
|
||||
NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 \
|
||||
NYASH_VERIFY_JSON="$prog_json_raw" \
|
||||
run_nyash_vm -c "$builder_code" 2>"$builder_stderr" | tail -n 1)
|
||||
|
||||
# Fallback Option A: use Rust CLI builder when Hako builder fails
|
||||
if [ "$mir_json" = "Builder failed" ] || [ -z "$mir_json" ]; then
|
||||
if [ "${HAKO_MIR_BUILDER_DEBUG:-0}" = "1" ] && [ -f "$builder_stderr" ]; then
|
||||
echo "[builder debug] Hako builder failed, falling back to Rust CLI" >&2
|
||||
cat "$builder_stderr" >&2
|
||||
cp "$builder_stderr" /tmp/builder_last_error.log
|
||||
fi
|
||||
rm -f "$builder_stderr"
|
||||
local tmp_mir="/tmp/ny_builder_conv_$$.json"
|
||||
if "$NYASH_BIN" --program-json-to-mir "$tmp_mir" --json-file "$prog_json_path" >/dev/null 2>&1; then
|
||||
"$NYASH_BIN" --mir-json-file "$tmp_mir" >/dev/null 2>&1
|
||||
local rc=$?
|
||||
rm -f "$tmp_mir"
|
||||
return $rc
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
rm -f "$builder_stderr"
|
||||
|
||||
# Validate builder output looks like MIR JSON; otherwise fallback to Rust CLI
|
||||
if ! echo "$mir_json" | grep -q '"functions"' || ! echo "$mir_json" | grep -q '"blocks"'; then
|
||||
# fallback: Rust CLI builder
|
||||
local tmp_mir="/tmp/ny_builder_conv_$$.json"
|
||||
if "$NYASH_BIN" --program-json-to-mir "$tmp_mir" --json-file "$prog_json_path" >/dev/null 2>&1; then
|
||||
"$NYASH_BIN" --mir-json-file "$tmp_mir" >/dev/null 2>&1
|
||||
local rc=$?
|
||||
rm -f "$tmp_mir"
|
||||
return $rc
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Write MIR JSON to temp file and execute
|
||||
echo "$mir_json" > "$mir_json_path"
|
||||
"$NYASH_BIN" --mir-json-file "$mir_json_path" >/dev/null 2>&1
|
||||
local rc=$?
|
||||
|
||||
rm -f "$mir_json_path"
|
||||
return $rc
|
||||
}
|
||||
|
||||
# Nyash実行ヘルパー(LLVM)
|
||||
run_nyash_llvm() {
|
||||
local program="$1"
|
||||
|
||||
Reference in New Issue
Block a user