From 8c4d63bfbb3ac2402bc26cac0dfb8fa8b2381fb6 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Fri, 14 Nov 2025 16:39:40 +0900 Subject: [PATCH] feat(phase-21.8): extract using imports in hakorune_emit_mir.sh (Step 7 part 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complete imports pipeline by extracting using statements and passing to MirBuilder: - Extract "using X as Y" from source file using grep/sed - Build JSON map {"Y":"Y"} for all imports - Set HAKO_MIRBUILDER_IMPORTS environment variable - extern_provider reads this and passes to program_json_to_mir_json_with_imports() - MapVars::resolve() recognizes MatI64 as valid static box reference Test result: ✅ /tmp/test_imports.hako (using MatI64) → MIR JSON generated without errors ✅ No "undefined variable: MatI64" error ✅ boxcall with MatI64.new() properly resolved Phase 21.8 Step 7 complete - imports pipeline fully functional! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tools/hakorune_emit_mir.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/hakorune_emit_mir.sh b/tools/hakorune_emit_mir.sh index 5efd3594..5fa04ef2 100644 --- a/tools/hakorune_emit_mir.sh +++ b/tools/hakorune_emit_mir.sh @@ -44,6 +44,26 @@ CODE_TMP=$(mktemp --suffix=.hako) trap 'rm -f "$CODE_TMP" || true' EXIT cp "$IN" "$CODE_TMP" +# Phase 21.8: Extract using imports and build JSON map for MirBuilder +# This enables MirBuilder to recognize static box references like MatI64, IntArrayCore +IMPORTS_JSON="{}" +if [ "${NYASH_ENABLE_USING:-1}" = "1" ] || [ "${HAKO_ENABLE_USING:-1}" = "1" ]; then + # Extract "using X as Y" lines and build JSON map {"Y":"Y"} + # Example: "using nyash.core.numeric.matrix_i64 as MatI64" -> "MatI64":"MatI64" + USING_LINES=$(grep -E '^\s*using\s+.*\s+as\s+' "$CODE_TMP" || true) + if [ -n "$USING_LINES" ]; then + IMPORTS_JSON=$(echo "$USING_LINES" | \ + sed -E 's/^\s*using\s+.*\s+as\s+([A-Za-z0-9_]+).*/"\1":"\1"/' | \ + paste -sd ',' | \ + sed 's/^/{/' | sed 's/$/}/') + fi + # Fallback to empty object if extraction failed or produced invalid JSON + if [ -z "$IMPORTS_JSON" ] || [ "$IMPORTS_JSON" = "{}" ]; then + IMPORTS_JSON="{}" + fi +fi +export HAKO_MIRBUILDER_IMPORTS="$IMPORTS_JSON" + # Check if FORCE jsonfrag mode is requested (bypasses Stage-B entirely) if [ "${HAKO_MIR_BUILDER_LOOP_FORCE_JSONFRAG:-0}" = "1" ]; then # Extract limit from code using grep/awk