feat(phase-21.8): extract using imports in hakorune_emit_mir.sh (Step 7 part 2)
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 <noreply@anthropic.com>
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user