DEV Community

CharmPic
CharmPic

Posted on

I'm creating the nyash progrum language.

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

  1. 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),
// ...
}
}

  1. 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" },
]

  1. 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

Testing lifecycle...
βœ… Plugin initialization successful
βœ… Method invocation successful
βœ… Plugin shutdown successful

Top comments (0)