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>
This commit is contained in:
27
examples/jit_plugin_invoke_param_array.nyash
Normal file
27
examples/jit_plugin_invoke_param_array.nyash
Normal file
@ -0,0 +1,27 @@
|
||||
// JIT plugin_invoke smoke: no NewBox in JITed function
|
||||
// Requires: array plugin built + nyash.toml configured
|
||||
// Build plugins:
|
||||
// (cd plugins/nyash-array-plugin && cargo build --release)
|
||||
// Run (JIT helper only):
|
||||
// NYASH_USE_PLUGIN_BUILTINS=1 NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 \
|
||||
// NYASH_JIT_SHIM_TRACE=1 NYASH_CLI_VERBOSE=1 \
|
||||
// ./target/release/nyash --backend vm examples/jit_plugin_invoke_param_array.nyash
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local a
|
||||
// Create ArrayBox in VM (this function stays in VM)
|
||||
a = new ArrayBox()
|
||||
a.push(1)
|
||||
a.push(2)
|
||||
a.push(3)
|
||||
// Call helper (this function should JIT) — only BoxCall on parameter
|
||||
return me.helper(a)
|
||||
}
|
||||
|
||||
helper(arr) {
|
||||
// No allocations/new here; only plugin call on parameter
|
||||
return arr.length()
|
||||
}
|
||||
}
|
||||
|
||||
16
examples/py_eval_autodecode_demo.nyash
Normal file
16
examples/py_eval_autodecode_demo.nyash
Normal file
@ -0,0 +1,16 @@
|
||||
// Auto-decode demo for eval/getattr/call
|
||||
// Run:
|
||||
// NYASH_PY_AUTODECODE=1 NYASH_CLI_VERBOSE=1 ./target/release/nyash --backend vm examples/py_eval_autodecode_demo.nyash
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local py, n, s
|
||||
py = new PyRuntimeBox()
|
||||
n = py.eval("3.14159")
|
||||
s = py.eval("'hello world'")
|
||||
me.console.log("eval num=", n.toString())
|
||||
me.console.log("eval str=", s)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
45
examples/py_result_chain_complete.nyash
Normal file
45
examples/py_result_chain_complete.nyash
Normal file
@ -0,0 +1,45 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
21
examples/py_result_chain_demo.nyash
Normal file
21
examples/py_result_chain_demo.nyash
Normal file
@ -0,0 +1,21 @@
|
||||
// Result-returning variants demo (R methods)
|
||||
// Run:
|
||||
// NYASH_CLI_VERBOSE=1 ./target/release/nyash --backend vm examples/py_result_chain_demo.nyash
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local py, mR, fR, rR, badR
|
||||
py = new PyRuntimeBox()
|
||||
// Use R variants to get Result boxes
|
||||
mR = py.importR("math")
|
||||
fR = mR.getattrR("sqrt")
|
||||
rR = fR.callR(9)
|
||||
me.console.log("sqrt(9) via R=", rR.toString())
|
||||
|
||||
// Error example: getattrR on missing name
|
||||
badR = mR.getattrR("no_such_attr")
|
||||
me.console.log("missing getattrR=", badR.toString())
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
34
examples/py_result_chain_demo_fixed.nyash
Normal file
34
examples/py_result_chain_demo_fixed.nyash
Normal file
@ -0,0 +1,34 @@
|
||||
// Result-returning variants demo (R methods)
|
||||
// Run:
|
||||
// NYASH_CLI_VERBOSE=1 ./target/release/nyash --backend vm examples/py_result_chain_demo_fixed.nyash
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
|
||||
local py, mR, fR, rR, badR
|
||||
py = new PyRuntimeBox()
|
||||
|
||||
// Use R variants to get Result boxes
|
||||
me.console.log("Testing importR...")
|
||||
mR = py.importR("math")
|
||||
me.console.log("importR result=", mR.toString())
|
||||
|
||||
me.console.log("Testing getattrR on sqrt...")
|
||||
fR = mR.getattrR("sqrt")
|
||||
me.console.log("getattrR result=", fR.toString())
|
||||
|
||||
me.console.log("Testing callR with 9...")
|
||||
rR = fR.callR(9)
|
||||
me.console.log("callR result=", rR.toString())
|
||||
|
||||
// Error example: getattrR on missing attribute
|
||||
me.console.log("Testing error case...")
|
||||
badR = mR.getattrR("no_such_attr")
|
||||
me.console.log("missing getattrR=", badR.toString())
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
25
examples/py_result_simple_test.nyash
Normal file
25
examples/py_result_simple_test.nyash
Normal file
@ -0,0 +1,25 @@
|
||||
// Simple test for Result-returning Python APIs
|
||||
static box Main {
|
||||
main() {
|
||||
local py = new PyRuntimeBox()
|
||||
|
||||
// Test importR (Result variant)
|
||||
print("Testing importR...")
|
||||
local mathR = py.importR("math")
|
||||
print("importR returned: " + mathR)
|
||||
|
||||
// Test error case
|
||||
print("Testing import error...")
|
||||
local badR = py.importR("no_such_module_xxxxx")
|
||||
print("importR error returned: " + badR)
|
||||
|
||||
// Normal import for comparison
|
||||
print("Testing normal import...")
|
||||
local math = py.import("math")
|
||||
local sqrt = math.getattr("sqrt")
|
||||
local result = sqrt.call(16)
|
||||
print("sqrt(16) = " + result.str())
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user