use super::{input_translate, output_translate};
use crate::{
cin_implements::common::CommandGeneratorPython,
runtimes::{CommandGenerator, CommandVm, CommandVmRuntime},
};
use anyhow::Result;
use nar_dev_utils::manipulate;
use navm::vm::VmLauncher;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PyNARS {
command_generator: CommandGeneratorPython,
}
impl PyNARS {
pub fn new(root_path: impl Into<PathBuf>, module_path: &str) -> Self {
Self {
command_generator: CommandGeneratorPython::new(root_path, module_path),
}
}
}
impl VmLauncher for PyNARS {
type Runtime = CommandVmRuntime;
fn launch(self) -> Result<CommandVmRuntime> {
let command = self.command_generator.generate_command();
manipulate!(
CommandVm::from(command)
=> .input_translator(input_translate)
=> .output_translator(output_translate)
)
.launch()
}
}