nyash言語つくってます
↓claudecodeに記事を書いてもらいました
プログラミング言語「Nyash」の開発で、ついに動的プラグインシステムが完成しました🎉
今日はPhase 9.75g-0として進めていた「BID-FFI Plugin System」が完了し、次のフェーズ(VM性能改善)への移行も決まった記念すべき日です。
何を実現したのか
Before(プラグイン導入前)
// ビルトインのBoxのみ使用可能
local console = new ConsoleBox()
local math = new MathBox()
local array = new ArrayBox()
// 新しいBox型を追加するには言語本体の改修が必要...
After(プラグインシステム導入後)
// 🌟 プラグインで提供される新しいBox型
local file = new FileBox() // ← プラグインが提供!
local db = new PostgreSQLBox() // ← 将来: プラグインで拡張
local gpu = new CudaBox() // ← 将来: プラグインで拡張
// ファイル操作がこんなに簡単に
file.open("config.json")
local content = file.read()
file.close()
技術的なポイント
- BID-FFI(Box Interface Definition - Foreign Function Interface)
プラグインとのインターフェースを定義する独自仕様を策定しました。
// プラグイン側の実装例(FileBox)
#[no_mangle]
pub unsafe extern "C" fn nyash_plugin_invoke(
method_id: u32,
args: *const u8,
args_len: usize,
result: *mut u8,
result_len: *mut usize,
) -> u32 {
match method_id {
0 => file_open(args, args_len, result, result_len),
1 => file_read(args, args_len, result, result_len),
// ...
}
}
- 型安全性の確保
Rustの型システムを活かして、プラグインとの境界でも型安全性を保っています。
nyash.toml - プラグインの型情報定義
[plugin.types.FileBox]
id = 6
methods = [
{ name = "birth", id = 0, params = ["String"], returns = "Void" },
{ name = "open", id = 1, params = ["String"], returns = "Bool" },
{ name = "read", id = 2, params = [], returns = "String" },
{ name = "write", id = 3, params = ["String"], returns = "Bool" },
]
- プラグインテスター
開発効率を上げるため、プラグインの診断ツールも作成しました。
$ ./tools/plugin-tester/target/release/plugin-tester libnyash_filebox_plugin.so
Plugin Information:
Box Type: FileBox (ID: 6)
Methods: 6
- birth [ID: 0] (constructor)
- open [ID: 1]
- read [ID: 2]
- write [ID: 3]
- close [ID: 4]
- fini [ID: 4294967295] (destructor)
Testing lifecycle...
✅ Plugin initialization successful
✅ Method invocation successful
✅ Plugin shutdown successful
Discussion