Skip to content

Commit

Permalink
feat: ⬆️ 兼容NAVM.rs 0.15,包括「终止」命令 (#5)
Browse files Browse the repository at this point in the history
1. 兼容NAVM.rs 0.15,增加对`EXI`「退出」指令的转换(兼容OpenNARS 1.5.8定制版)
2. 尝试针对Java程序解决「残留进程锁死主进程」的问题(目前尚未完全实现)
3. 更新有关依赖版本
  • Loading branch information
ARCJ137442 authored May 9, 2024
1 parent 2923a8b commit af57913
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "babel_nar"
version = "0.22.0"
version = "0.23.0"
edition = "2021"
description = """
Implementation and application supports of the NAVM model
Expand Down Expand Up @@ -54,7 +54,7 @@ features = [
# ! 本地依赖可以不添加版本
# 载入NAVM API,引入「非公理虚拟机」模型
# path = "../NAVM.rs"
version = "0" # 现已发布于`crates.io`
version = "0.15" # 现已发布于`crates.io`
# git = "https://github.com/ARCJ137442/NAVM.rs"
# ! 【2024-03-23 19:19:01】似乎Rust-Analyzer无法获取私有仓库数据
features = [] # ! 【2024-03-21 09:24:51】暂时没有特性
Expand Down
6 changes: 6 additions & 0 deletions src/cin_implements/opennars/translators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub fn input_translate(cmd: Cmd) -> Result<String> {
Cmd::VOL(n) => format!("*volume={n}"),
// 注释 ⇒ 忽略 | ❓【2024-04-02 22:43:05】可能需要打印,但这样却没法统一IO(到处print的习惯不好)
Cmd::REM { .. } => String::new(),
// 退出码
Cmd::EXI { .. } => "*exit".into(),
// 其它类型
// * 📌【2024-03-24 22:57:18】基本足够支持
// ! 🚩【2024-03-27 22:42:56】不使用[`anyhow!`]:打印时会带上一大堆调用堆栈
Expand Down Expand Up @@ -97,6 +99,10 @@ pub fn output_translate(content_raw: String) -> Result<Output> {
"ERR" | "ERROR" => Output::ERROR {
description: content_raw,
},
// * 🚩【2024-05-09 14:41:11】目前为OpenNARS 1.5.8(定制版)专用
"TERMINATED" | "EXITED" | "QUITTED" => Output::TERMINATED {
description: content_raw,
},
// * 🚩利用OpenNARS常见输出「全大写」的特征,兼容「confirm」与「disappoint」
upper if !head.is_empty() && head == upper => Output::UNCLASSIFIED {
r#type: head.to_string(),
Expand Down
8 changes: 7 additions & 1 deletion src/runtimes/command_vm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ impl VmRuntime for CommandVmRuntime {
}

fn terminate(&mut self) -> Result<()> {
// 给CIN发送「终止」指令:告知CIN内部「需要结束程序」
// * 📌【2024-05-09 14:20:00】目前似乎通过这一手段,仍然无法彻底关闭Java程序
// * 🔬【2024-05-09 14:20:22】目前在程序关闭时,即便杀掉了子进程,也会因此被阻塞(需要kill`java.exe`才能解锁)
self.input_cmd(Cmd::EXI {
reason: "CIN terminated by BabelNAR".into(),
})?;

// 杀死子进程
self.process.kill()?;

Expand Down Expand Up @@ -162,7 +169,6 @@ pub mod tests {
criterion: impl Fn(&Output, &str) -> bool,
) -> Output {
// 不断拉取输出
// TODO: 💭【2024-03-24 18:21:28】后续可以结合「流式处理者列表」做集成测试
loop {
// 拉取输出及其内容 | ⚠️必要时等待(阻塞!)
let output = vm.fetch_output().unwrap();
Expand Down
6 changes: 2 additions & 4 deletions src/test_tools/vm_interact.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! 与NAVM虚拟机的交互逻辑
use std::{ops::ControlFlow, path::Path};

use crate::cli_support::{error_handling_boost::error_anyhow, io::output_print::OutputType};

use super::{NALInput, OutputExpectation, OutputExpectationError};
use crate::cli_support::{error_handling_boost::error_anyhow, io::output_print::OutputType};
use anyhow::Result;
use nar_dev_utils::{if_return, ResultBoost};
use navm::{cmd::Cmd, output::Output, vm::VmRuntime};
use std::{ops::ControlFlow, path::Path};

/// * 🎯统一存放与「Narsese预期识别」有关的代码
/// * 🚩【2024-04-02 22:49:12】从[`crate::runtimes::command_vm::runtime::tests`]中迁移而来
Expand Down

0 comments on commit af57913

Please sign in to comment.