## 🎉 Step 2: peek→match完全統一アーキテクチャクリーンアップ完了 - ✅ 15ファイルで PeekExpr → MatchExpr 一括置換完了 - ✅ lowering/peek.rs → match_expr.rs 完全移行 - ✅ AI理解性・コードベース一貫性・保守性大幅向上 ## 🔍 Step 3: 複数行パース問題調査完了 - ✅ Task先生による根本原因特定完了 - 原因: オブジェクトリテラルパーサーの改行スキップ不足 - 修正: src/parser/expr/primary.rs の skip_newlines() 追加 ## 🚨 重大発見: PHI命令処理バグ - 問題: gemini_test_case.nyash で期待値2→実際0 - 原因: フェーズM+M.2のPHI統一作業でループ後変数マージに回帰バグ - 詳細: PHI命令は正常だが、print時に間違ったPHI参照 - 影響: Phase 15セルフホスティング基盤の重大バグ ## 📝 CLAUDE.md更新 - 全進捗状況の詳細記録 - 次のアクション: ChatGPT相談でMIRビルダー修正戦略立案 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
150 lines
4.5 KiB
Rust
150 lines
4.5 KiB
Rust
use crate::ast::ASTNode;
|
|
use std::collections::HashSet;
|
|
|
|
/// Collect free variables used in `node` into `used`, excluding names present in `locals`.
|
|
/// `locals` is updated as new local declarations are encountered.
|
|
#[allow(dead_code)]
|
|
pub(super) fn collect_free_vars(
|
|
node: &ASTNode,
|
|
used: &mut HashSet<String>,
|
|
locals: &mut HashSet<String>,
|
|
) {
|
|
match node {
|
|
ASTNode::Variable { name, .. } => {
|
|
if name != "me" && name != "this" && !locals.contains(name) {
|
|
used.insert(name.clone());
|
|
}
|
|
}
|
|
ASTNode::Local { variables, .. } => {
|
|
for v in variables {
|
|
locals.insert(v.clone());
|
|
}
|
|
}
|
|
ASTNode::Assignment { target, value, .. } => {
|
|
collect_free_vars(target, used, locals);
|
|
collect_free_vars(value, used, locals);
|
|
}
|
|
ASTNode::BinaryOp { left, right, .. } => {
|
|
collect_free_vars(left, used, locals);
|
|
collect_free_vars(right, used, locals);
|
|
}
|
|
ASTNode::UnaryOp { operand, .. } => {
|
|
collect_free_vars(operand, used, locals);
|
|
}
|
|
ASTNode::MethodCall {
|
|
object, arguments, ..
|
|
} => {
|
|
collect_free_vars(object, used, locals);
|
|
for a in arguments {
|
|
collect_free_vars(a, used, locals);
|
|
}
|
|
}
|
|
ASTNode::FunctionCall { arguments, .. } => {
|
|
for a in arguments {
|
|
collect_free_vars(a, used, locals);
|
|
}
|
|
}
|
|
ASTNode::Call {
|
|
callee, arguments, ..
|
|
} => {
|
|
collect_free_vars(callee, used, locals);
|
|
for a in arguments {
|
|
collect_free_vars(a, used, locals);
|
|
}
|
|
}
|
|
ASTNode::FieldAccess { object, .. } => {
|
|
collect_free_vars(object, used, locals);
|
|
}
|
|
ASTNode::New { arguments, .. } => {
|
|
for a in arguments {
|
|
collect_free_vars(a, used, locals);
|
|
}
|
|
}
|
|
ASTNode::If {
|
|
condition,
|
|
then_body,
|
|
else_body,
|
|
..
|
|
} => {
|
|
collect_free_vars(condition, used, locals);
|
|
for st in then_body {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
if let Some(eb) = else_body {
|
|
for st in eb {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
}
|
|
}
|
|
ASTNode::Loop {
|
|
condition, body, ..
|
|
} => {
|
|
collect_free_vars(condition, used, locals);
|
|
for st in body {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
}
|
|
ASTNode::TryCatch {
|
|
try_body,
|
|
catch_clauses,
|
|
finally_body,
|
|
..
|
|
} => {
|
|
for st in try_body {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
for c in catch_clauses {
|
|
for st in &c.body {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
}
|
|
if let Some(fb) = finally_body {
|
|
for st in fb {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
}
|
|
}
|
|
ASTNode::Throw { expression, .. } => {
|
|
collect_free_vars(expression, used, locals);
|
|
}
|
|
ASTNode::Print { expression, .. } => {
|
|
collect_free_vars(expression, used, locals);
|
|
}
|
|
ASTNode::Return { value, .. } => {
|
|
if let Some(v) = value {
|
|
collect_free_vars(v, used, locals);
|
|
}
|
|
}
|
|
ASTNode::AwaitExpression { expression, .. } => {
|
|
collect_free_vars(expression, used, locals);
|
|
}
|
|
ASTNode::MatchExpr {
|
|
scrutinee,
|
|
arms,
|
|
else_expr,
|
|
..
|
|
} => {
|
|
collect_free_vars(scrutinee, used, locals);
|
|
for (_, e) in arms {
|
|
collect_free_vars(e, used, locals);
|
|
}
|
|
collect_free_vars(else_expr, used, locals);
|
|
}
|
|
ASTNode::Program { statements, .. } => {
|
|
for st in statements {
|
|
collect_free_vars(st, used, locals);
|
|
}
|
|
}
|
|
ASTNode::FunctionDeclaration { params, body, .. } => {
|
|
let mut inner = locals.clone();
|
|
for p in params {
|
|
inner.insert(p.clone());
|
|
}
|
|
for st in body {
|
|
collect_free_vars(st, used, &mut inner);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|