feat(phase285): Complete weak reference implementation (VM + LLVM harness)

Phase 285LLVM-1.1 to 1.4 + weak reference infrastructure:

**LLVM Harness** (Phase 285LLVM-1.x):
- 285LLVM-1.1: User Box registration & debug output
- 285LLVM-1.2: WeakRef basic operations (identity deferred)
- 285LLVM-1.3: InstanceBox field access (getField/setField)
- 285LLVM-1.4: print Handle resolution (type tag propagation)

**VM Runtime** (nyash_kernel):
- FFI functions: nyrt_weak_new, nyrt_weak_to_strong, nyrt_weak_drop
  (crates/nyash_kernel/src/lib.rs: +209 lines)
- WeakRef plugin invoke support
  (crates/nyash_kernel/src/plugin/invoke.rs: +250 lines)
- weak_handles.rs: WeakRef handle registry (NEW)

**LLVM Python Backend**:
- WeakRef instruction lowering (weak.py: NEW)
- Entry point integration (entry.py: +93 lines)
- Instruction lowering (instruction_lower.py: +13 lines)
- LLVM harness runner script (tools/run_llvm_harness.sh: NEW)

**MIR & Runtime**:
- WeakRef emission & validation
- MIR JSON export for weak instructions
- Environment variable support (NYASH_WEAK_*, HAKO_WEAK_*)

**Documentation**:
- CLAUDE.md: Phase 285 completion notes
- LANGUAGE_REFERENCE_2025.md: Weak reference syntax
- 10-Now.md & 30-Backlog.md: Phase 285 status updates

Total: +864 lines, 24 files changed

SSOT: docs/reference/language/lifecycle.md
Related: Phase 285W-Syntax-0, Phase 285W-Syntax-0.1
This commit is contained in:
2025-12-25 00:11:34 +09:00
parent cc05c37ae3
commit f740e6542f
27 changed files with 1176 additions and 41 deletions

View File

@ -82,13 +82,17 @@ impl super::MirBuilder {
}
ASTNode::BoxDeclaration {
name,
fields, // Phase 285LLVM-1.1: Extract fields
methods,
is_static,
..
} => {
if !*is_static {
self.comp_ctx.user_defined_boxes.insert(name.clone());
// Phase 285LLVM-1.1: Register instance box with field information
self.comp_ctx.register_user_box_with_fields(name.clone(), fields.clone());
} else {
// Static box: no fields
self.comp_ctx.register_user_box(name.clone());
for (mname, mast) in methods {
if let ASTNode::FunctionDeclaration { params, .. } = mast {
self.comp_ctx
@ -223,7 +227,8 @@ impl super::MirBuilder {
}
} else {
// Instance box: register type and lower instance methods/ctors as functions
self.comp_ctx.user_defined_boxes.insert(name.clone());
// Phase 285LLVM-1.1: Register with field information for LLVM harness
self.comp_ctx.register_user_box_with_fields(name.clone(), fields.clone());
self.build_box_declaration(
name.clone(),
methods.clone(),
@ -534,6 +539,9 @@ impl super::MirBuilder {
// main 関数スコープの SlotRegistry を解放するよ。
self.comp_ctx.current_slot_registry = None;
// Phase 285LLVM-1.1: Copy user box declarations to module metadata for LLVM harness
module.metadata.user_box_decls = self.comp_ctx.user_defined_boxes.clone();
Ok(module)
}