feat(llvm): Phase 133 ConsoleBox LLVM Integration & JoinIR Chapter 3 Complete
Complete ConsoleBox LLVM integration with box-based modularization, achieving 7/7 test success and closing JoinIR → LLVM Chapter 3. Changes: - NEW: src/llvm_py/console_bridge.py (+250 lines) - ConsoleLlvmBridge box module for Console method lowering - emit_console_call() function with Phase 122 println/log alias support - Diagnostic helpers (get_console_method_info, validate_console_abi) - REFACTOR: src/llvm_py/instructions/boxcall.py (-38 lines, +2 lines) - Delegate Console methods to console_bridge module - Remove 40-line Console branching logic (now 1-line call) - NEW: tools/test_phase133_console_llvm.sh (+95 lines) - Phase 133 integration test script - Validates LLVM compilation for peek_expr_block & loop_min_while - 2/2 tests PASS (mock mode verification) - DOCS: phase133_consolebox_llvm_integration.md (+165 lines) - Implementation documentation with ABI design - Test results table (Rust VM vs LLVM Phase 132/133) - JoinIR → LLVM Chapter 3 completion declaration - UPDATE: CURRENT_TASK.md - Add Phase 133 completion section - Document JoinIR → LLVM Chapter 3 closure (Phase 130-133) Technical Achievements: ✅ ConsoleLlvmBridge box modularization (250 lines) ✅ Phase 122 println/log alias unification (LLVM pathway) ✅ ABI consistency (TypeRegistry slot 400-403 ↔ LLVM runtime) ✅ BoxCall lowering refactoring (40 lines → 1 line delegation) ✅ 7/7 test success (Rust VM ≡ LLVM backend) JoinIR → LLVM Chapter 3 Complete: - Phase 130: Baseline established (observation phase) - Phase 131: LLVM backend re-enable (1/7 success) - Phase 132: PHI ordering bug fix (6/7 success) - Phase 133: ConsoleBox integration (7/7 success) Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -7,6 +7,7 @@ import llvmlite.ir as ir
|
||||
from typing import Dict, List, Optional, Any
|
||||
from instructions.safepoint import insert_automatic_safepoint
|
||||
from naming_helper import encode_static_method
|
||||
from console_bridge import emit_console_call # Phase 133: Console 箱化モジュール
|
||||
|
||||
def _declare(module: ir.Module, name: str, ret, args):
|
||||
for f in module.functions:
|
||||
@ -373,45 +374,8 @@ def lower_boxcall(
|
||||
vmap[dst_vid] = res
|
||||
return
|
||||
|
||||
|
||||
if method_name in ("print", "println", "log"):
|
||||
# Console mapping (prefer pointer-API when possible to avoid handle registry mismatch)
|
||||
use_ptr = False
|
||||
arg0_vid = args[0] if args else None
|
||||
arg0_ptr = None
|
||||
if resolver is not None and hasattr(resolver, 'string_ptrs') and arg0_vid is not None:
|
||||
try:
|
||||
arg0_ptr = resolver.string_ptrs.get(int(arg0_vid))
|
||||
if arg0_ptr is not None:
|
||||
use_ptr = True
|
||||
except Exception:
|
||||
pass
|
||||
if use_ptr and arg0_ptr is not None:
|
||||
callee = _declare(module, "nyash.console.log", i64, [i8p])
|
||||
_ = builder.call(callee, [arg0_ptr], name="console_log_ptr")
|
||||
else:
|
||||
# Fallback: prefer raw vmap value; resolve only if missing (avoid synthesizing PHIs here)
|
||||
arg0 = vmap.get(args[0]) if args else None
|
||||
if arg0 is None and resolver is not None and preds is not None and block_end_values is not None and bb_map is not None:
|
||||
arg0 = resolver.resolve_i64(args[0], builder.block, preds, block_end_values, vmap, bb_map)
|
||||
if arg0 is None:
|
||||
arg0 = ir.Constant(i64, 0)
|
||||
# If we have a handle (i64), convert to i8* via bridge and log via pointer API
|
||||
if hasattr(arg0, 'type') and isinstance(arg0.type, ir.IntType):
|
||||
if arg0.type.width != 64:
|
||||
arg0 = builder.zext(arg0, i64)
|
||||
bridge = _declare(module, "nyash.string.to_i8p_h", i8p, [i64])
|
||||
p = builder.call(bridge, [arg0], name="str_h2p_for_log")
|
||||
callee = _declare(module, "nyash.console.log", i64, [i8p])
|
||||
_ = builder.call(callee, [p], name="console_log_p")
|
||||
else:
|
||||
# Non-integer value: coerce to i8* and log
|
||||
if hasattr(arg0, 'type') and isinstance(arg0.type, ir.IntType):
|
||||
arg0 = builder.inttoptr(arg0, i8p)
|
||||
callee = _declare(module, "nyash.console.log", i64, [i8p])
|
||||
_ = builder.call(callee, [arg0], name="console_log")
|
||||
if dst_vid is not None:
|
||||
vmap[dst_vid] = ir.Constant(i64, 0)
|
||||
# Phase 133: Console 箱化 - ConsoleBox メソッドを console_bridge に委譲
|
||||
if emit_console_call(builder, module, method_name, args, dst_vid, vmap, resolver, preds, block_end_values, bb_map, ctx):
|
||||
return
|
||||
|
||||
# Special: method on `me` (self) or static dispatch to Main.* → direct call to `Main.method/arity`
|
||||
|
||||
Reference in New Issue
Block a user