refactor: 大規模なモジュールを分割し、コードの構造を改善
runner, mir/builder, backend/llvm の各モジュールが肥大化していたため、責務ごとにファイルを分割し、見通しを改善するリファクタリングを実施。
### `runner`
- `mod.rs` に集中していたロジックを、以下のモジュールに分割:
- `tasks.rs`: `nyash.toml` のタスク実行処理
- `build.rs`: AOTビルドパイプラインの実装
- `pipeline.rs`: `using` の解決など、パイプライン中のユーティリティ
- `demos.rs`: デモの実行処理
### `mir/builder`
- `if/else` 文のPHIノード生成ロジックを `stmts.rs` から `phi.rs` へ切り出し。
- `utils.rs` にあったPHI関連のヘルパーも `phi.rs` に集約。
- ASTから自由変数を収集するロジックを `vars.rs` へ切り出し。
### `backend/llvm/compiler/codegen`
- 巨大だった `lower_one_function` 関数を、`function.rs` モジュールとして分離。
- `sanitize_symbol` などのヘルパー関数を `utils.rs` へ移動。
This commit is contained in:
@ -99,3 +99,35 @@ pub(super) fn suggest_in_base(base: &str, leaf: &str, out: &mut Vec<String>) {
|
||||
let p = std::path::Path::new(base);
|
||||
walk(p, leaf, out, 4);
|
||||
}
|
||||
|
||||
/// Resolve a using target according to priority: modules > relative > using-paths
|
||||
/// Returns Ok(resolved_path_or_token). On strict mode, ambiguous matches cause error.
|
||||
pub(super) fn resolve_using_target(
|
||||
tgt: &str,
|
||||
is_path: bool,
|
||||
modules: &[(String, String)],
|
||||
using_paths: &[String],
|
||||
context_dir: Option<&std::path::Path>,
|
||||
strict: bool,
|
||||
verbose: bool,
|
||||
) -> Result<String, String> {
|
||||
if is_path { return Ok(tgt.to_string()); }
|
||||
// 1) modules mapping
|
||||
if let Some((_, p)) = modules.iter().find(|(n, _)| n == tgt) { return Ok(p.clone()); }
|
||||
// 2) build candidate list: relative then using-paths
|
||||
let rel = tgt.replace('.', "/") + ".nyash";
|
||||
let mut cand: Vec<String> = Vec::new();
|
||||
if let Some(dir) = context_dir { let c = dir.join(&rel); if c.exists() { cand.push(c.to_string_lossy().to_string()); } }
|
||||
for base in using_paths {
|
||||
let c = std::path::Path::new(base).join(&rel);
|
||||
if c.exists() { cand.push(c.to_string_lossy().to_string()); }
|
||||
}
|
||||
if cand.is_empty() {
|
||||
if verbose { eprintln!("[using] unresolved '{}' (searched: rel+paths)", tgt); }
|
||||
return Ok(tgt.to_string());
|
||||
}
|
||||
if cand.len() > 1 && strict {
|
||||
return Err(format!("ambiguous using '{}': {}", tgt, cand.join(", ")));
|
||||
}
|
||||
Ok(cand.remove(0))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user