Files
hakorune/examples/py_result_chain_complete.nyash
Moe Charm 3d8ba3f3ec fix(jit): NewBoxのJIT安全化とDebugBox Phase 1実装
- NewBoxのJIT扱いを安全化(src/jit/lower/core.rs)
  - NYASH_USE_PLUGIN_BUILTINS=1 && args.is_empty() かつ StringBox/IntegerBox のみJIT許可
  - ArrayBox/MapBox等のプラグインBoxまたは引数ありはunsupportedとしてカウント
  - unsupported>0の関数はJIT対象外となりVM実行にフォールバック(Segfault回避)

- DebugBox Phase 1実装(JITトレース機能)
  - tracePluginCalls(bool)でJITシムトレースON/OFF
  - getJitEvents()で直近のJITイベント取得
  - src/jit/shim_trace.rs追加でトレース基盤実装

- Printのサポート
  - PrintはJIT非対応に戻しVM経路で確実に出力(出力消失解消)

- テストとサンプル追加
  - examples/jit_plugin_invoke_param_array.nyash: 最小JITスモークテスト
  - examples/py_result_*.nyash: Python plugin結果チェーン処理デモ

- PyRuntimeBox拡張
  - str()メソッドでPyObjectのstring表現を取得可能に
  - エラーハンドリング改善とResultチェーンサポート

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 13:46:18 +09:00

45 lines
1.3 KiB
Plaintext

// Complete Result chain test (importR → getattrR → callR)
static box Main {
main() {
local py = new PyRuntimeBox()
// Success chain: math.sqrt(25)
print("=== Success chain test ===")
local mathR = py.importR("math")
print("1. importR('math') = " + mathR)
if mathR.isOk() {
local math = mathR.unwrap()
local sqrtR = math.getattrR("sqrt")
print("2. getattrR('sqrt') = " + sqrtR)
if sqrtR.isOk() {
local sqrt = sqrtR.unwrap()
local resultR = sqrt.callR(25)
print("3. callR(25) = " + resultR)
if resultR.isOk() {
local result = resultR.unwrap()
print("4. Final value = " + result.str())
}
}
}
// Error chain: test error handling
print("\n=== Error chain test ===")
local badModR = py.importR("nonexistent_module")
print("importR('nonexistent_module') = " + badModR)
// Test getattrR error
local mathNormal = py.import("math")
local badAttrR = mathNormal.getattrR("nonexistent_attr")
print("getattrR('nonexistent_attr') = " + badAttrR)
// Test callR with invalid args
local sqrtNormal = mathNormal.getattr("sqrt")
local badCallR = sqrtNormal.callR("invalid_arg")
print("callR('invalid_arg') = " + badCallR)
return 0
}
}