Files
Moe Charm c13d9c045e 📚 Phase 12: Nyashスクリプトプラグインシステム設計と埋め込みVM構想
## 主な成果
- Nyashスクリプトでプラグイン作成可能という革命的発見
- C ABI制約の分析と埋め込みVMによる解決策
- MIR/VM/JIT層での箱引数サポートの詳細分析

## ドキュメント作成
- Phase 12基本構想(README.md)
- Gemini/Codex先生の技術分析
- C ABIとの整合性問題と解決策
- 埋め込みVM実装ロードマップ
- 箱引数サポートの技術詳細

## 重要な洞察
- 制約は「リンク時にC ABI必要」のみ
- 埋め込みVMでMIRバイトコード実行により解決可能
- Nyashスクリプト→C ABIプラグイン変換が実現可能

Everything is Box → Everything is Plugin → Everything is Possible!
2025-08-30 22:52:16 +09:00

57 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
// FFI関数型定義
typedef int (*plugin_init_fn)(void);
typedef char* (*parse_fn)(const char*);
typedef void (*free_fn)(char*);
int main() {
// プラグインをロード
void* handle = dlopen("./target/release/libnyash_python_parser_plugin.so", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Failed to load plugin: %s\n", dlerror());
return 1;
}
// 関数を取得
plugin_init_fn init_fn = (plugin_init_fn)dlsym(handle, "nyash_plugin_init");
parse_fn parse_func = (parse_fn)dlsym(handle, "nyash_python_parse");
free_fn free_func = (free_fn)dlsym(handle, "nyash_python_free_string");
if (!init_fn || !parse_func || !free_func) {
fprintf(stderr, "Failed to load functions\n");
dlclose(handle);
return 1;
}
// 初期化
if (init_fn() != 0) {
fprintf(stderr, "Plugin init failed\n");
dlclose(handle);
return 1;
}
// 環境変数からコードを取得
const char* code = getenv("NYASH_PY_CODE");
if (!code) {
code = "def main():\n return 0";
printf("Using default code: %s\n", code);
} else {
printf("Parsing code from NYASH_PY_CODE: %s\n", code);
}
// パース実行
char* result = parse_func(code);
if (result) {
printf("\n=== Parse Result ===\n%s\n", result);
free_func(result);
} else {
printf("Parse failed\n");
}
dlclose(handle);
return 0;
}