🎉 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 super::ValueId;
|
|
|
|
|
use crate::ast::ASTNode;
|
|
|
|
|
|
|
|
|
|
impl super::MirBuilder {
|
|
|
|
|
// Lambda lowering to FunctionNew
|
|
|
|
|
pub(super) fn build_lambda_expression(
|
|
|
|
|
&mut self,
|
|
|
|
|
params: Vec<String>,
|
|
|
|
|
body: Vec<ASTNode>,
|
|
|
|
|
) -> Result<ValueId, String> {
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
let mut used: HashSet<String> = HashSet::new();
|
|
|
|
|
let mut locals: HashSet<String> = HashSet::new();
|
2025-09-17 07:43:07 +09:00
|
|
|
for p in ¶ms {
|
|
|
|
|
locals.insert(p.clone());
|
|
|
|
|
}
|
|
|
|
|
fn collect_vars(
|
|
|
|
|
ast: &ASTNode,
|
|
|
|
|
used: &mut std::collections::HashSet<String>,
|
|
|
|
|
locals: &mut std::collections::HashSet<String>,
|
|
|
|
|
) {
|
🎉 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
|
|
|
match ast {
|
2025-09-17 07:43:07 +09:00
|
|
|
ASTNode::Variable { name, .. } => {
|
|
|
|
|
if !locals.contains(name) {
|
|
|
|
|
used.insert(name.clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Assignment { target, value, .. } => {
|
|
|
|
|
collect_vars(target, used, locals);
|
|
|
|
|
collect_vars(value, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::BinaryOp { left, right, .. } => {
|
|
|
|
|
collect_vars(left, used, locals);
|
|
|
|
|
collect_vars(right, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::UnaryOp { operand, .. } => {
|
|
|
|
|
collect_vars(operand, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::MethodCall {
|
|
|
|
|
object, arguments, ..
|
|
|
|
|
} => {
|
|
|
|
|
collect_vars(object, used, locals);
|
|
|
|
|
for a in arguments {
|
|
|
|
|
collect_vars(a, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::FunctionCall { arguments, .. } => {
|
|
|
|
|
for a in arguments {
|
|
|
|
|
collect_vars(a, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Call {
|
|
|
|
|
callee, arguments, ..
|
|
|
|
|
} => {
|
|
|
|
|
collect_vars(callee, used, locals);
|
|
|
|
|
for a in arguments {
|
|
|
|
|
collect_vars(a, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::FieldAccess { object, .. } => {
|
|
|
|
|
collect_vars(object, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::New { arguments, .. } => {
|
|
|
|
|
for a in arguments {
|
|
|
|
|
collect_vars(a, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::If {
|
|
|
|
|
condition,
|
|
|
|
|
then_body,
|
|
|
|
|
else_body,
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
collect_vars(condition, used, locals);
|
|
|
|
|
for st in then_body {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
if let Some(eb) = else_body {
|
|
|
|
|
for st in eb {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Loop {
|
|
|
|
|
condition, body, ..
|
|
|
|
|
} => {
|
🎉 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
|
|
|
collect_vars(condition, used, locals);
|
2025-09-17 07:43:07 +09:00
|
|
|
for st in body {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::TryCatch {
|
|
|
|
|
try_body,
|
|
|
|
|
catch_clauses,
|
|
|
|
|
finally_body,
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
for st in try_body {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
for c in catch_clauses {
|
|
|
|
|
for st in &c.body {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if let Some(fb) = finally_body {
|
|
|
|
|
for st in fb {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Throw { expression, .. } => {
|
|
|
|
|
collect_vars(expression, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Print { expression, .. } => {
|
|
|
|
|
collect_vars(expression, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::Return { value, .. } => {
|
|
|
|
|
if let Some(v) = value {
|
|
|
|
|
collect_vars(v, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ASTNode::AwaitExpression { expression, .. } => {
|
|
|
|
|
collect_vars(expression, used, locals);
|
|
|
|
|
}
|
|
|
|
|
ASTNode::PeekExpr {
|
|
|
|
|
scrutinee,
|
|
|
|
|
arms,
|
|
|
|
|
else_expr,
|
|
|
|
|
..
|
|
|
|
|
} => {
|
🎉 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
|
|
|
collect_vars(scrutinee, used, locals);
|
2025-09-17 07:43:07 +09:00
|
|
|
for (_, e) in arms {
|
|
|
|
|
collect_vars(e, used, locals);
|
|
|
|
|
}
|
🎉 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
|
|
|
collect_vars(else_expr, used, locals);
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
ASTNode::Program { statements, .. } => {
|
|
|
|
|
for st in statements {
|
|
|
|
|
collect_vars(st, used, locals);
|
|
|
|
|
}
|
|
|
|
|
}
|
🎉 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
|
|
|
ASTNode::FunctionDeclaration { params, body, .. } => {
|
|
|
|
|
let mut inner = locals.clone();
|
2025-09-17 07:43:07 +09:00
|
|
|
for p in params {
|
|
|
|
|
inner.insert(p.clone());
|
|
|
|
|
}
|
|
|
|
|
for st in body {
|
|
|
|
|
collect_vars(st, used, &mut inner);
|
|
|
|
|
}
|
🎉 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
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
for st in body.iter() {
|
|
|
|
|
collect_vars(st, &mut used, &mut locals);
|
|
|
|
|
}
|
🎉 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
|
|
|
let mut captures: Vec<(String, ValueId)> = Vec::new();
|
|
|
|
|
for name in used.into_iter() {
|
2025-09-17 07:43:07 +09:00
|
|
|
if let Some(&vid) = self.variable_map.get(&name) {
|
|
|
|
|
captures.push((name, vid));
|
|
|
|
|
}
|
🎉 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
|
|
|
}
|
|
|
|
|
let me = self.variable_map.get("me").copied();
|
|
|
|
|
let dst = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::FunctionNew {
|
|
|
|
|
dst,
|
|
|
|
|
params: params.clone(),
|
|
|
|
|
body: body.clone(),
|
|
|
|
|
captures,
|
|
|
|
|
me,
|
|
|
|
|
})?;
|
|
|
|
|
self.value_types
|
|
|
|
|
.insert(dst, crate::mir::MirType::Box("FunctionBox".to_string()));
|
🎉 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(dst)
|
|
|
|
|
}
|
|
|
|
|
}
|