🎉 feat: MIRパラメータ解決完全修正 + VM E2Eテスト成功!

Phase 9.78b関連修正:
- MirBuilder::lower_method_as_function でValueIdリセット実装
  - me → %0, 引数 → %1... の正しいマッピング
- build_me_expression() で変数テーブル優先解決
- VM E2Eテスト test_vm_user_box_birth_and_method 成功
  - new Person("Alice").greet() → "Hello, Alice"

ドキュメント:
- mir-unified-reference.md を正式MIRドキュメントとして配置
  - 現在の35命令実装状態を正確に記載
  - RefGet/RefSet仕様含む

ChatGPT5によるMIRビルダー修正で、VMバックエンドでのユーザー定義Box完全動作!
This commit is contained in:
Moe Charm
2025-08-20 19:34:09 +09:00
parent 41832b2c88
commit 8aef29eaef
3 changed files with 329 additions and 8 deletions

View File

@ -80,6 +80,9 @@ impl MirBuilder {
let saved_function = self.current_function.take();
let saved_block = self.current_block.take();
let saved_var_map = std::mem::take(&mut self.variable_map);
let saved_value_gen = self.value_gen.clone();
// Reset value id generator so that params start from %0, %1, ...
self.value_gen.reset();
// Switch context to new function
self.current_function = Some(function);
@ -88,11 +91,11 @@ impl MirBuilder {
// Create parameter value ids and bind variable names
if let Some(ref mut f) = self.current_function {
// 'me' parameter
// 'me' parameter will be %0
let me_id = self.value_gen.next();
f.params.push(me_id);
self.variable_map.insert("me".to_string(), me_id);
// user parameters
// user parameters continue as %1..N
for p in &params {
let pid = self.value_gen.next();
f.params.push(pid);
@ -125,6 +128,7 @@ impl MirBuilder {
self.current_function = saved_function;
self.current_block = saved_block;
self.variable_map = saved_var_map;
self.value_gen = saved_value_gen;
Ok(())
}
@ -905,17 +909,17 @@ impl MirBuilder {
/// Build me expression: me
fn build_me_expression(&mut self) -> Result<ValueId, String> {
// For now, return a reference to the current instance
// In a full implementation, this would resolve to the actual instance reference
// If lowering a method/birth function, "me" should be a parameter
if let Some(id) = self.variable_map.get("me").cloned() {
return Ok(id);
}
// Fallback: use a symbolic constant (legacy behavior)
let me_value = self.value_gen.next();
// For simplicity, emit a constant representing "me"
// In practice, this should resolve to the current instance context
self.emit_instruction(MirInstruction::Const {
dst: me_value,
value: ConstValue::String("__me__".to_string()),
})?;
Ok(me_value)
}