🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
// Declarations lowering: static boxes and box declarations
|
2025-09-17 07:43:07 +09:00
|
|
|
use super::{ConstValue, MirInstruction, ValueId};
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
use crate::ast::ASTNode;
|
|
|
|
|
use crate::mir::slot_registry::{get_or_assign_type_id, reserve_method_slot};
|
2025-09-17 07:43:07 +09:00
|
|
|
use std::collections::HashSet;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
|
|
|
|
impl super::MirBuilder {
|
|
|
|
|
/// Build static box (e.g., Main) - extracts main() method body and converts to Program
|
|
|
|
|
/// Also lowers other static methods into standalone MIR functions: BoxName.method/N
|
|
|
|
|
pub(super) fn build_static_main_box(
|
|
|
|
|
&mut self,
|
|
|
|
|
box_name: String,
|
|
|
|
|
methods: std::collections::HashMap<String, ASTNode>,
|
|
|
|
|
) -> Result<ValueId, String> {
|
|
|
|
|
// Lower other static methods (except main) to standalone MIR functions so JIT can see them
|
|
|
|
|
for (mname, mast) in methods.iter() {
|
2025-09-17 07:43:07 +09:00
|
|
|
if mname == "main" {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
if let ASTNode::FunctionDeclaration { params, body, .. } = mast {
|
|
|
|
|
let func_name = format!("{}.{}{}", box_name, mname, format!("/{}", params.len()));
|
|
|
|
|
self.lower_static_method_as_function(func_name, params.clone(), body.clone())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Within this lowering, treat `me` receiver as this static box
|
|
|
|
|
let saved_static = self.current_static_box.clone();
|
|
|
|
|
self.current_static_box = Some(box_name.clone());
|
|
|
|
|
// Look for the main() method
|
|
|
|
|
let out = if let Some(main_method) = methods.get("main") {
|
|
|
|
|
if let ASTNode::FunctionDeclaration { params, body, .. } = main_method {
|
|
|
|
|
// Convert the method body to a Program AST node and lower it
|
2025-09-17 07:43:07 +09:00
|
|
|
let program_ast = ASTNode::Program {
|
|
|
|
|
statements: body.clone(),
|
|
|
|
|
span: crate::ast::Span::unknown(),
|
|
|
|
|
};
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
// Bind default parameters if present (e.g., args=[])
|
|
|
|
|
let saved_var_map = std::mem::take(&mut self.variable_map);
|
|
|
|
|
for p in params.iter() {
|
|
|
|
|
let pid = self.value_gen.next();
|
|
|
|
|
if p == "args" {
|
|
|
|
|
// new ArrayBox() with no args
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(MirInstruction::NewBox {
|
|
|
|
|
dst: pid,
|
|
|
|
|
box_type: "ArrayBox".to_string(),
|
|
|
|
|
args: vec![],
|
|
|
|
|
})?;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst: pid,
|
|
|
|
|
value: ConstValue::Void,
|
|
|
|
|
})?;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
}
|
|
|
|
|
self.variable_map.insert(p.clone(), pid);
|
|
|
|
|
}
|
|
|
|
|
let lowered = self.build_expression(program_ast);
|
|
|
|
|
self.variable_map = saved_var_map;
|
|
|
|
|
lowered
|
|
|
|
|
} else {
|
|
|
|
|
Err("main method in static box is not a FunctionDeclaration".to_string())
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Err("static box must contain a main() method".to_string())
|
|
|
|
|
};
|
|
|
|
|
// Restore static box context
|
|
|
|
|
self.current_static_box = saved_static;
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Build box declaration: box Name { fields... methods... }
|
|
|
|
|
pub(super) fn build_box_declaration(
|
|
|
|
|
&mut self,
|
|
|
|
|
name: String,
|
|
|
|
|
methods: std::collections::HashMap<String, ASTNode>,
|
|
|
|
|
fields: Vec<String>,
|
|
|
|
|
weak_fields: Vec<String>,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
// Create a type registration constant (marker)
|
|
|
|
|
let type_id = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst: type_id,
|
|
|
|
|
value: ConstValue::String(format!("__box_type_{}", name)),
|
|
|
|
|
})?;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
|
|
|
|
// Emit field metadata markers
|
|
|
|
|
for field in fields {
|
|
|
|
|
let field_id = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst: field_id,
|
|
|
|
|
value: ConstValue::String(format!("__field_{}_{}", name, field)),
|
|
|
|
|
})?;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Record weak fields for this box
|
|
|
|
|
if !weak_fields.is_empty() {
|
|
|
|
|
let set: HashSet<String> = weak_fields.into_iter().collect();
|
|
|
|
|
self.weak_fields_by_box.insert(name.clone(), set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reserve method slots for user-defined instance methods (deterministic, starts at 4)
|
|
|
|
|
let mut instance_methods: Vec<String> = Vec::new();
|
|
|
|
|
for (mname, mast) in &methods {
|
|
|
|
|
if let ASTNode::FunctionDeclaration { is_static, .. } = mast {
|
2025-09-17 07:43:07 +09:00
|
|
|
if !*is_static {
|
|
|
|
|
instance_methods.push(mname.clone());
|
|
|
|
|
}
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
instance_methods.sort();
|
|
|
|
|
if !instance_methods.is_empty() {
|
|
|
|
|
let tyid = get_or_assign_type_id(&name);
|
|
|
|
|
for (i, m) in instance_methods.iter().enumerate() {
|
|
|
|
|
let slot = 4u16.saturating_add(i as u16);
|
|
|
|
|
reserve_method_slot(tyid, m, slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Emit markers for declared methods (kept as metadata hints)
|
|
|
|
|
for (method_name, method_ast) in methods {
|
|
|
|
|
if let ASTNode::FunctionDeclaration { .. } = method_ast {
|
|
|
|
|
let method_id = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst: method_id,
|
|
|
|
|
value: ConstValue::String(format!("__method_{}_{}", name, method_name)),
|
|
|
|
|
})?;
|
2025-09-19 08:34:29 +09:00
|
|
|
// Track unified member getters: __get_<prop> | __get_once_<prop> | __get_birth_<prop>
|
|
|
|
|
let kind_and_prop: Option<(super::PropertyKind, String)> = if let Some(rest) = method_name.strip_prefix("__get_once_") {
|
|
|
|
|
Some((super::PropertyKind::Once, rest.to_string()))
|
|
|
|
|
} else if let Some(rest) = method_name.strip_prefix("__get_birth_") {
|
|
|
|
|
Some((super::PropertyKind::BirthOnce, rest.to_string()))
|
|
|
|
|
} else if let Some(rest) = method_name.strip_prefix("__get_") {
|
|
|
|
|
Some((super::PropertyKind::Computed, rest.to_string()))
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
if let Some((k, prop)) = kind_and_prop {
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
let entry: &mut HashMap<String, super::PropertyKind> = self
|
|
|
|
|
.property_getters_by_box
|
|
|
|
|
.entry(name.clone())
|
|
|
|
|
.or_insert_with(HashMap::new);
|
|
|
|
|
entry.insert(prop, k);
|
|
|
|
|
}
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|