Keeping track of multiple plugins

This commit is contained in:
Brooks J Rady 2021-01-05 13:33:23 +00:00
parent c7db38d0c5
commit 6f1546a5cb
3 changed files with 17 additions and 5 deletions

View file

@ -177,7 +177,6 @@ impl Layout {
// FIXME: I probably shouldn't exist, much less with PathBuf (use &Path) // FIXME: I probably shouldn't exist, much less with PathBuf (use &Path)
#[cfg(feature = "wasm-wip")] #[cfg(feature = "wasm-wip")]
pub fn list_plugins(&self) -> Vec<&PathBuf> { pub fn list_plugins(&self) -> Vec<&PathBuf> {
dbg!(&self);
let mut plugins: Vec<_> = self.parts.iter().flat_map(Layout::list_plugins).collect(); let mut plugins: Vec<_> = self.parts.iter().flat_map(Layout::list_plugins).collect();
if let Some(path) = &self.plugin { if let Some(path) = &self.plugin {
plugins.push(path); plugins.push(path);

View file

@ -418,24 +418,27 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
.spawn(move || { .spawn(move || {
use crate::errors::PluginContext; use crate::errors::PluginContext;
use crate::wasm_vm::{mosaic_imports, wasi_stdout}; use crate::wasm_vm::{mosaic_imports, wasi_stdout};
use std::io; use std::{io, collections::HashMap};
use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value}; use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
use wasmer_wasi::{Pipe, WasiState}; use wasmer_wasi::{Pipe, WasiState};
let store = Store::default(); let store = Store::default();
let mut plugin_id = 0;
let mut plugin_map = HashMap::new();
loop { loop {
let (event, mut err_ctx) = receive_plugin_instructions let (event, mut err_ctx) = receive_plugin_instructions
.recv() .recv()
.expect("failed to receive event on channel"); .expect("failed to receive event on channel");
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event))); err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
// FIXME: Clueless on how many of these lines I need... // FIXME: Add a line for every other thread that this one calls out to
// screen.send_app_instructions.update(err_ctx); // screen.send_app_instructions.update(err_ctx);
// screen.send_pty_instructions.update(err_ctx); // screen.send_pty_instructions.update(err_ctx);
match event { match event {
PluginInstruction::Load(path) => { PluginInstruction::Load(path) => {
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that // FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
let module = Module::from_file(&store, path).unwrap(); let module = Module::from_file(&store, &path).unwrap();
let output = Pipe::new(); let output = Pipe::new();
let input = Pipe::new(); let input = Pipe::new();
@ -456,6 +459,15 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
let mosaic = mosaic_imports(&store, &wasi_env); let mosaic = mosaic_imports(&store, &wasi_env);
let instance = Instance::new(&module, &mosaic.chain_back(wasi)).unwrap(); let instance = Instance::new(&module, &mosaic.chain_back(wasi)).unwrap();
debug_log_to_file(format!("Loaded {}({}) from {}", instance.module().name().unwrap(), plugin_id, path.display())).unwrap();
plugin_map.insert(plugin_id, instance);
plugin_id += 1;
// FIXME: End the loading block here
// FIXME: Yucky line
let instance = plugin_map.get(&(plugin_id - 1)).unwrap();
let start = instance.exports.get_function("_start").unwrap(); let start = instance.exports.get_function("_start").unwrap();
let handle_key = instance.exports.get_function("handle_key").unwrap(); let handle_key = instance.exports.get_function("handle_key").unwrap();
let draw = instance.exports.get_function("draw").unwrap(); let draw = instance.exports.get_function("draw").unwrap();
@ -491,7 +503,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
} */ } */
break; break;
} }
debug_log_to_file("WASM module loaded and exited cleanly :)".to_string()).unwrap();
} }
PluginInstruction::Quit => break, PluginInstruction::Quit => break,
i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i), i => panic!("Yo, dawg, nice job calling the wasm thread!\n {:?} is defo not implemented yet...", i),

View file

@ -12,6 +12,8 @@ parts:
Percent: 80 Percent: 80
split_size: split_size:
Percent: 80 Percent: 80
plugin: strider.wasm
- direction: Vertical - direction: Vertical
split_size: split_size:
Percent: 20 Percent: 20
plugin: strider.wasm