From 751bbe623f72cb448e717a416a4d9655333587fe Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Sat, 13 Apr 2024 16:18:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:arrow=5Fup:=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=96=B0=E7=89=88NAVM=20API=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=87=AA=E8=BA=ABNAVM=E5=90=AF=E5=8A=A8=E5=99=A8=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 4 +-- Cargo.toml | 2 +- src/bin/cin_launcher/main.rs | 2 +- src/cin_implements/cxin_js/launcher.rs | 3 ++- src/cin_implements/nars_python/launcher.rs | 3 ++- src/cin_implements/ona/launcher.rs | 3 ++- src/cin_implements/openjunars/launcher.rs | 3 ++- src/cin_implements/openjunars/mod.rs | 27 +++++++++++++++++-- src/cin_implements/opennars/launcher.rs | 3 ++- src/cin_implements/pynars/launcher.rs | 3 ++- .../cin_search/impls_path_builder/mod.rs | 4 +-- src/cli_support/cin_search/path_builder.rs | 2 +- src/lib.rs | 2 +- src/runtimes/command_vm/runtime.rs | 3 ++- 14 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 230196c..b127074 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "babel_nar" -version = "0.20.2" +version = "0.20.3" dependencies = [ "anyhow", "clap", @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "navm" -version = "0.12.0" +version = "0.13.0" dependencies = [ "anyhow", "nar_dev_utils", diff --git a/Cargo.toml b/Cargo.toml index eef2a38..ba761f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "babel_nar" -version = "0.20.2" +version = "0.20.3" edition = "2021" description = """ Implementation and application supports of the NAVM model diff --git a/src/bin/cin_launcher/main.rs b/src/bin/cin_launcher/main.rs index d45516c..b4f74fe 100644 --- a/src/bin/cin_launcher/main.rs +++ b/src/bin/cin_launcher/main.rs @@ -32,7 +32,7 @@ const TEST_PATH_PYNARS: (&str, &str) = (PYNARS_ROOT, "pynars.ConsolePlus"); /// 启动并获取NARS /// * 🚩【2024-03-27 18:55:07】目前就返回一个测试用的运行时 /// * 🎯敏捷开发用 -fn get_nars() -> impl VmLauncher { +fn get_nars() -> impl VmLauncher { // OpenNARS::new(TEST_PATH_OPENNARS) PyNARS::new(TEST_PATH_PYNARS.0, TEST_PATH_PYNARS.1) // ONA::new(TEST_PATH_ONA) diff --git a/src/cin_implements/cxin_js/launcher.rs b/src/cin_implements/cxin_js/launcher.rs index 2957f49..fe86628 100644 --- a/src/cin_implements/cxin_js/launcher.rs +++ b/src/cin_implements/cxin_js/launcher.rs @@ -39,7 +39,8 @@ impl CXinJS { } /// 启动到「命令行运行时」 -impl VmLauncher for CXinJS { +impl VmLauncher for CXinJS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造并启动虚拟机 pipe! { diff --git a/src/cin_implements/nars_python/launcher.rs b/src/cin_implements/nars_python/launcher.rs index a0d9370..0a1d9eb 100644 --- a/src/cin_implements/nars_python/launcher.rs +++ b/src/cin_implements/nars_python/launcher.rs @@ -35,7 +35,8 @@ impl NARSPython { } /// 启动到「命令行运行时」 -impl VmLauncher for NARSPython { +impl VmLauncher for NARSPython { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令,并启动虚拟机 manipulate!( diff --git a/src/cin_implements/ona/launcher.rs b/src/cin_implements/ona/launcher.rs index dd6d87d..f1d500f 100644 --- a/src/cin_implements/ona/launcher.rs +++ b/src/cin_implements/ona/launcher.rs @@ -50,7 +50,8 @@ impl ONA { } /// 启动到「命令行运行时」 -impl VmLauncher for ONA { +impl VmLauncher for ONA { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造并启动虚拟机 let mut runtime = pipe! { diff --git a/src/cin_implements/openjunars/launcher.rs b/src/cin_implements/openjunars/launcher.rs index 3123b4d..6d9595f 100644 --- a/src/cin_implements/openjunars/launcher.rs +++ b/src/cin_implements/openjunars/launcher.rs @@ -37,7 +37,8 @@ impl OpenJunars { } /// 启动到「命令行运行时」 -impl VmLauncher for OpenJunars { +impl VmLauncher for OpenJunars { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 let command = self.command_generator.generate_command(); diff --git a/src/cin_implements/openjunars/mod.rs b/src/cin_implements/openjunars/mod.rs index f9fad07..7804c79 100644 --- a/src/cin_implements/openjunars/mod.rs +++ b/src/cin_implements/openjunars/mod.rs @@ -42,11 +42,34 @@ mod tests { .expect("无法输入指令"); // 等待四秒钟,让Junars启动 - std::thread::sleep(std::time::Duration::from_secs(1)); + std::thread::sleep(std::time::Duration::from_secs(4)); vm.input_cmd(Cmd::NSE(nse_task!( B>.))) .expect("无法输入指令"); - std::thread::sleep(std::time::Duration::from_secs(6)); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::CYC(1)).expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::NSE(nse_task!( B>?))) + .expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(1)); + + vm.input_cmd(Cmd::CYC(1)).expect("无法输入指令"); + + std::thread::sleep(std::time::Duration::from_secs(3)); + + // 尝试截获其所有输出 + // * 🚩【2024-04-13 16:10:27】目前经由Julia侧`flush(stdout)`,仍然无法捕获 + // * 有输出`[ Info: Answer: B>. %1.0;0.9%`,但无法被程序捕获为文本 + while let Ok(Some(output)) = vm.try_fetch_output() { + dbg!(output); + } + + std::thread::sleep(std::time::Duration::from_secs(2)); // 终止虚拟机运行时 vm.terminate().expect("无法终止虚拟机"); diff --git a/src/cin_implements/opennars/launcher.rs b/src/cin_implements/opennars/launcher.rs index 181af44..649dbc4 100644 --- a/src/cin_implements/opennars/launcher.rs +++ b/src/cin_implements/opennars/launcher.rs @@ -43,7 +43,8 @@ impl OpenNARS { } /// 启动到「命令行运行时」 -impl VmLauncher for OpenNARS { +impl VmLauncher for OpenNARS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 // * 🚩细致的Java参数配置,都外包给[`CommandGeneratorJava`] diff --git a/src/cin_implements/pynars/launcher.rs b/src/cin_implements/pynars/launcher.rs index ed04dfc..e585422 100644 --- a/src/cin_implements/pynars/launcher.rs +++ b/src/cin_implements/pynars/launcher.rs @@ -36,7 +36,8 @@ impl PyNARS { } /// 启动到「命令行运行时」 -impl VmLauncher for PyNARS { +impl VmLauncher for PyNARS { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { // 构造指令 let command = self.command_generator.generate_command(); diff --git a/src/cli_support/cin_search/impls_path_builder/mod.rs b/src/cli_support/cin_search/impls_path_builder/mod.rs index 2d47af7..6acc588 100644 --- a/src/cli_support/cin_search/impls_path_builder/mod.rs +++ b/src/cli_support/cin_search/impls_path_builder/mod.rs @@ -29,7 +29,7 @@ pub fn file_name_matches(path: &Path, name: &str) -> bool { /// 从遍历者中找到匹配的所有启动器 /// * 🎯仅搜索出「可能有效,故构建好」的启动器 -pub fn launchers_from_walker>( +pub fn launchers_from_walker( path_walker: impl PathWalker, path_builder: impl CinPathBuilder, ) -> Vec<(L, usize)> { @@ -41,7 +41,7 @@ pub fn launchers_from_walker>( } /// 类似[`launchers_from_walker`],但根据返回的「匹配度」从高到底排序 -pub fn launchers_from_walker_sorted>( +pub fn launchers_from_walker_sorted( path_walker: impl PathWalker, path_builder: impl CinPathBuilder, ) -> Vec { diff --git a/src/cli_support/cin_search/path_builder.rs b/src/cli_support/cin_search/path_builder.rs index 004805f..c32f5b9 100644 --- a/src/cli_support/cin_search/path_builder.rs +++ b/src/cli_support/cin_search/path_builder.rs @@ -17,7 +17,7 @@ use std::path::Path; pub trait CinPathBuilder { /// 搜索结果的启动器类型 /// * 📌启动后变为[`CinSearch::Runtime`]运行时类型 - type Launcher: VmLauncher; + type Launcher: VmLauncher; /// 搜索结果的运行时类型 type Runtime: VmRuntime; diff --git a/src/lib.rs b/src/lib.rs index 6f24266..498173d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,7 @@ pub mod tests { PYNARS_MODULE = "pynars.ConsolePlus" NARS_PYTHON = "./executables/nars-python-main.exe" CXIN_JS = "./executables/cxin-nars-shell.js" - OPENJUNARS = "./executables/OpenJunars/run.jl" + OPENJUNARS = "./executables/OpenJunars/launch.jl" } } diff --git a/src/runtimes/command_vm/runtime.rs b/src/runtimes/command_vm/runtime.rs index 3a5cbf9..17d4574 100644 --- a/src/runtimes/command_vm/runtime.rs +++ b/src/runtimes/command_vm/runtime.rs @@ -96,7 +96,8 @@ impl VmRuntime for CommandVmRuntime { } /// 构建功能:启动命令行虚拟机 -impl VmLauncher for CommandVm { +impl VmLauncher for CommandVm { + type Runtime = CommandVmRuntime; fn launch(self) -> Result { Ok(CommandVmRuntime { // 状态:正在运行