The story of my hobby language "Nyash," built with AI
I'm creating a language called Nyash based on the "Everything is Box" philosophy.
https://github.com/moe-charm/nyash
The dynamic plugin system is finally complete! π
Today is a momentous day, as we've finished Phase 9.75g-0, the "BID-FFI Plugin System," and have decided to move on to the next phase (VM performance improvements).
What We've Accomplished
Before (Without the plugin system)
// Only built-in Box types are usable
local console = new ConsoleBox()
local math = new MathBox()
local array = new ArrayBox()
// Adding a new Box type required modifying the language core...
After (With the plugin system)
// π New Box types provided by plugins
local file = new FileBox() // β Provided by a plugin!
local db = new PostgreSQLBox() // β Future: extensible via plugins
local gpu = new CudaBox() // β Future: extensible via plugins
// File operations become this simple
file.open("config.json")
local content = file.read()
file.close()
Technical Highlights
- BID-FFI (Box Interface Definition - Foreign Function Interface)
We've established a unique specification for defining the interface with plugins.
Rust
// Example plugin implementation (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),
// ...
}
}
- Ensuring Type Safety
We're leveraging Rust's type system to maintain type safety even at the plugin boundary.
Ini, TOML
nyash.toml - Defining plugin type information
[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" },
]
- Plugin Tester
To boost development efficiency, we also created a diagnostic tool for plugins.
Bash
$ ./tools/plugin-tester/target/release/plugin-tester libnyash_filebox_plugin.so
Plugin Information:
Box Type: FileBox (ID: 6)
Methods: 6
- birth ID: 0
- open [ID: 1]
- read [ID: 2]
- write [ID: 3]
- close [ID: 4]
- fini ID: 4294967295
Testing lifecycle...
β
Plugin initialization successful
β
Method invocation successful
β
Plugin shutdown successful
Top comments (0)