Files
hakorune/docs/reference/mir-dumper-guide.md
Moe Charm 2200312f09 docs: Add field visibility analysis and MIR BoxCall documentation
## Field Visibility Analysis Results
- Confirmed init{} fields are **public** in current Nyash implementation
- No access modifier (private/public) system currently implemented
- All fields accessible via me.fieldname syntax
- Documented findings for future reference

## MIR Documentation Enhancements
- Created comprehensive mir-dumper-guide.md for reading MIR dumps
- Enhanced mir-26-specification.md with BoxCall vs regular Call examples
- Added clear identification patterns:
  * BoxCall: `call %value.method(args)` (plugins/builtins)
  * Regular Call: `call %func(%me, args)` (user-defined boxes)

## VM Backend BoxRef Handling Improvements
- Fixed BoxRef method dispatch using share_box() instead of clone_box()
- Prevents unintended constructor calls during method resolution
- Maintains proper instance identity throughout VM execution

## MIR Builder User-Defined Box Tracking
- Added user_defined_boxes HashSet to track declared user boxes
- Improved method lowering decisions for user-defined vs builtin boxes
- Enhanced AST→MIR conversion accuracy for method calls

## Plugin Tester Lifecycle Enhancements
- Added comprehensive FileBox lifecycle testing (open/write/close)
- Enhanced cloneSelf() and copyFrom() testing with proper Handle parsing
- Added TLV encoding helpers for strings and bytes
- Improved error reporting and step-by-step validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 01:18:25 +09:00

2.0 KiB
Raw Blame History

MIR Dumper Output Guide

MIRダンプ出力を正しく読み解くためのガイドです。

BoxCall vs 通常のCall の見分け方

BoxCall形式プラグイン/ビルトインBoxのメソッド

%8 = call %7.cloneSelf()
%17 = call %7.open(%14, %16)
%22 = call %7.write(%21)
%23 = call %8.copyFrom(%7)

特徴:

  • call %値.メソッド名(引数) の形式
  • 値(%7, %8などに対して直接メソッドを呼ぶ
  • プラグインBoxやビルトインBoxで使用される

通常のCall形式ユーザー定義Boxのメソッド

%func = const "UserBox.calculate/2"
%result = call %func(%me, %arg1)

特徴:

  • 事前に const "クラス名.メソッド名/引数数" で関数値を取得
  • call %関数値(%me, 引数...) の形式で呼び出し
  • 第1引数は常に %meself相当

実例での比較

plugin_boxref_return.nyashのMIRダンプ

11: %7 = new FileBox()
12: call %7.birth()
13: %8 = call %7.cloneSelf()        ← BoxCallプラグインメソッド
26: %17 = call %7.open(%14, %16)    ← BoxCallプラグインメソッド
33: %22 = call %7.write(%21)        ← BoxCallプラグインメソッド
34: %23 = call %8.copyFrom(%7)      ← BoxCallプラグインメソッド

これらはすべてBoxCall形式で、プラグインのFileBoxメソッドを直接呼び出しています。

ユーザー定義Boxの場合仮想例

; ユーザー定義Box "Calculator" のメソッド呼び出し
%calc_func = const "Calculator.add/2"
%result = call %calc_func(%me, %10, %20)

この場合は、MIR関数として事前にlower済みのメソッドを呼び出しています。

まとめ

  • call %値.メソッド() → BoxCallプラグイン/ビルトイン)
  • call %関数値(%me, ...) → 通常のCallユーザー定義Box

MIRダンプを見る際は、この形式の違いに注目することで、どのタイプのメソッド呼び出しかを判断できます。