Files
hakorune/CURRENT_TASK.md
Selfhosting Dev e114f9bfe3 fix(llvm): Implement handle-based console.log functions for plugin return values
- Add nyash.console.log_handle(i64) -> i64 family functions to nyrt
- Replace invalid int-to-pointer conversion with proper handle-based calls
- Fix bool(i1) -> i64 type conversion in LLVM compiler
- Resolve LLVM function verification errors
- Enable plugin method execution without NYASH_LLVM_ALLOW_BY_NAME
- Merge codex TLV fixes for plugin return value handling (2000+ lines)

Technical Details:
- Root cause: build_int_to_ptr(handle_value, i8*, "arg_i2p") treated
  handle IDs as memory addresses (invalid operation)
- Solution: Direct i64 handle passing to nyrt functions with proper
  handle registry lookup and to_string_box() conversion
- Type safety: Added proper i1/i32/i64 -> i64 conversion handling

Status: Console.log type errors resolved, plugin return value display
still under investigation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-11 00:21:11 +09:00

4.5 KiB
Raw Blame History

Current Task (2025-09-10)

🎉 LLVMプラグイン戻り値表示問題修正進行中2025-09-10

完了した主要成果

  1. プラグイン実装 - nyash.plugin.invoke_*関数はnyrtライブラリに正常実装済み
  2. プラグイン呼び出し - 環境変数なしでメソッド呼び出し成功
  3. 戻り値型推論修正 - MIR builder にプラグインメソッド型推論追加
  4. by-id統一完了 - by-name方式削除、method_id方式に完全統一
  5. 環境変数削減達成 - NYASH_LLVM_ALLOW_BY_NAME=1削除完了
  6. シンプル実行実現 - ./target/release/nyash --backend llvm program.nyash
  7. codex TLV修正マージ完了 - プラグイン戻り値TLVタグ2/6/7対応2000行修正
  8. console.log ハンドル対応 - 不正なi64→i8*変換を修正、ハンドル対応関数に変更
  9. 型変換エラー解消 - bool(i1)→i64拡張処理追加でLLVM検証エラー修正

🔬 現在の動作状況2025-09-10 最新テスト):

  • プラグイン実行 - CounterBox、FileBox正常実行副作用OK
  • 型エラー解消 - LLVM関数検証エラー修正済み
  • コンパイル成功 - 環境変数なしでLLVMバックエンド動作
  • 条件分岐動作 - if f.exists("file") → "TRUE"/"FALSE"表示OK

🔍 根本原因判明

Task先生の詳細技術調査により特定

  • 不正なハンドル→ポインタ変換: build_int_to_ptr(iv, i8p, "arg_i2p") でハンドル値3を直接メモリアドレス0x3として扱う不正変換
  • 修正完了: console.log を nyash.console.log_handle(i64) -> i64 に変更、ハンドルレジストリ活用

🔍 残存課題

1. プラグイン戻り値表示問題 🔶 ←現在調査中

症状(修正後も継続):

  • CounterBox.get() → 数値戻り値がprint()で空白
  • FileBox.read(path) → 文字列戻り値がprint()で空白
  • FileBox.exists(path) → if条件では動作、変数格納で失敗
  • local x = 42; print(x) → 正常(問題はプラグイン戻り値のみ)

残る問題の推定:

  • print()以外のExternCall処理にも同様の問題がある可能性
  • MIR変数代入処理での型情報不整合
  • プラグイン戻り値のハンドル→実値変換が不完全

📊 修正済みファイル

  • src/mir/builder.rs - プラグインメソッド戻り値型推論追加
  • src/backend/llvm/compiler.rs - by-name方式削除、method_id統一
  • CLAUDE.md - 環境変数セクション更新、コマンド簡素化
  • README.md / README.ja.md - 環境変数説明削除
  • tools/llvm_smoke.sh - テストスクリプト環境変数削除

🎯 次期深堀り調査対象

  1. プラグインランタイム戻り値パス詳細調査 - crates/nyrt/src/lib.rs
  2. LLVM BoxCall戻り値処理詳細分析 - src/backend/llvm/compiler.rs 戻り値変換
  3. MIR変数代入メカニズム調査 - BoxCall→変数の代入処理
  4. print()関数とプラグイン値の相性調査 - 型認識処理

🎯 Restart Notes — Ny Syntax Alignment (20250907)

目的

  • SelfHosting 方針Nyのみで工具を回す前段に合わせて、Ny 構文とコーディング規約を明示化し、最小版ツールの完走性を優先。

Ny 構文(実装時の基準)

  • 1行1文セミコロン非使用。
  • break / continue を使わない(関数早期 return、番兵条件、if 包みで置換)。
  • else は直前の閉じ波括弧と同一行(} else {})。
  • 文字列の "\ は確実にエスケープ。
  • 反復は loop(条件) { …; インクリメント } を基本とし、必要に応じて「関数早期 return」型で早期脱出。

短期タスクSyntax 合意前提で最小ゴール)

  1. include のみ依存木Nyのみ・配列/マップ未使用)を完走化
    • apps/selfhost/tools/dep_tree_min_string.nyash
    • FileBox/PathBox + 文字走査のみで JSON 構築(配列/マップに頼らない)
    • make dep-treetmp/deps.json を出力
  2. using/module 対応は次段(構文・優先順位をユーザーと再すり合わせ後)
    • 優先: module > 相対 > using-path、曖昧=エラー、STRICT ゲート(要相談)
  3. ブリッジ Stage 1 は保留
    • NYASH_DEPS_JSON=<path> 読み込みログ出力のみを最小パッチで用意MIR/JIT/AOT は不変)