Skip to content

Commit

Permalink
feat: ✨ 「原生」转译器;新的「原生IL-1」示例CIN
Browse files Browse the repository at this point in the history
增加【以NAVM指令作为输入,输出JSON式NAVM输出】的「原生」CIN转译器支持;基于「原生」转译器,示例性支持NAVM所开发的「原生IL-1」运行时(仅能跑通「简单演绎推理」)
  • Loading branch information
ARCJ137442 committed Apr 9, 2024
1 parent 3c3f3f7 commit 527dd89
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "babel_nar"
version = "0.18.1"
version = "0.19.0"
edition = "2021"
description = """
Implementation and application supports of the NAVM model
Expand Down
3 changes: 2 additions & 1 deletion src/bin/babelnar_cli/config_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use anyhow::{anyhow, Result};
use babel_nar::{
cin_implements::{
common::generate_command, cxin_js, nars_python, ona, openjunars, opennars, pynars,
common::generate_command, cxin_js, nars_python, native, ona, openjunars, opennars, pynars,
},
cli_support::{cin_search::name_match::name_match, io::readline_iter::ReadlineIter},
eprintln_cli, println_cli,
Expand Down Expand Up @@ -199,6 +199,7 @@ pub type TranslatorDict<'a> = &'a [(
/// 输入转译器的索引字典
/// * 🚩静态存储映射,后续遍历可有序可无序
pub const TRANSLATOR_DICT: TranslatorDict = &[
("Native", native::input_translate, native::output_translate),
(
"OpenNARS",
opennars::input_translate,
Expand Down
33 changes: 33 additions & 0 deletions src/bin/babelnar_cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,39 @@ mod tests {
}
}

/// 测试/原生IL-1
mod native_il_1 {
use super::*;

cin_tests! {
NATIVE_IL_1;

/// 简单演绎
/// * 📝✅【2024-04-09 21:12:10】成功
nal_de => NAL_SIMPLE_DEDUCTION

/// 高阶演绎
/// * 📝❌【2024-04-09 21:12:32】失败:尚不支持
nal_hi => NAL_HIGHER_DEDUCTION

/// 自变量消除
/// * 📝❌【2024-04-09 21:12:32】失败:尚不支持
nal_ie => NAL_I_VAR_ELIMINATION

/// 时间归纳
/// * 📝❌【2024-04-09 21:12:32】失败:尚不支持
nal_te => NAL_TEMPORAL_INDUCTION

/// 简单操作
/// * 📝❌【2024-04-09 21:12:32】失败:尚不支持
nal_so => NAL_SIMPLE_OPERATION

/// 操作
/// * 📝❌【2024-04-09 21:12:32】失败:尚不支持
nal_op => NAL_OPERATION
}
}

// ! ❌【2024-04-07 14:39:20】接口完成度不高的NARS-Python、OpenJunars暂不进行测试

/// 测试入口/带Websocket Shell
Expand Down
5 changes: 4 additions & 1 deletion src/cin_implements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! * ❌【2024-03-25 13:36:30】集成测试`cargo t --all-features`中未能解决
//! * ❗// ! ↑【少用乃至不用这条命令】
//!
//! ? 【2024-03-25 12:48:08】如何兼顾「复用」「性能」与「简洁」
//! * 🚩【2024-04-09 20:47:04】基本完成对「复用」「性能」与「简洁」的兼顾
//! * 📌复用:将OpenNARS、ONA抽象成「基于jar的启动逻辑」「基于exe的启动逻辑」等方式,以便后续重复使用
//! * 📄case:目前ONA、NARS-Python都是基于exe的启动方式
//! * 📌性能:避免过多的封装、粗暴复合导致的空间浪费
Expand All @@ -22,6 +22,9 @@ util::mods! {
// 共用代码
pub common;

// 原生
pub native;

// OpenNARS
pub opennars;

Expand Down
9 changes: 9 additions & 0 deletions src/cin_implements/native/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! NAVM原生的虚拟机(转译器)
//! * ✨Cmd输入转译:直接将[`Cmd`]转换为字符串形式
//! * ✨NAVM_JSON输出转译:基于[`serde_json`]直接从JSON字符串读取[`Output`]
//! * 📌没有固定的启动器:仅通过「命令行启动器」即可启动
util::mods! {
// 输入输出转译
pub pub translators;
}
27 changes: 27 additions & 0 deletions src/cin_implements/native/translators.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! 输入输出转译
//! * ✨Cmd输入转译:直接将[`Cmd`]转换为字符串形式
//! * ✨NAVM_JSON输出转译:基于[`serde_json`]直接从JSON字符串读取[`Output`]
use anyhow::Result;
use navm::{cmd::Cmd, output::Output};
extern crate serde_json;

/// Cmd输入转译
/// * 🚩直接将[`Cmd`]转换为字符串形式
/// * 📌总是成功
pub fn input_translate(cmd: Cmd) -> Result<String> {
Ok(cmd.to_string())
}

/// NAVM_JSON输出转译
/// * 🚩基于[`serde_json`]直接从JSON字符串读取[`Output`]
pub fn output_translate(content_raw: String) -> Result<Output> {
match serde_json::from_str(&content_raw) {
// 解析成功⇒返回
Ok(output) => Ok(output),
// 解析失败⇒转为`OTHER`
Err(..) => Ok(Output::OTHER {
content: content_raw,
}),
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub mod tests {
PYNARS = "./src/tests/cli/config/cin_pynars.hjson"
/// CXinJS
CXIN_JS = "./src/tests/cli/config/cin_cxin_js.hjson"
/// 原生IL-1
NATIVE_IL_1 = "./src/tests/cli/config/cin_native_il_1.hjson"

/// 预引入/NAL测试环境
PRELUDE_TEST = "./src/tests/cli/config/prelude_test.hjson"
Expand Down
16 changes: 16 additions & 0 deletions src/tests/cli/config/cin_native_il_1.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#hjson
// * 🎯用于测试原生「IL-1」运行时
// * ✨基于NAVM,纯Rust编写
{
// 使用「原生」输入输出转译器
translators: native
command: {
// * ⚠️必须前缀`./`以指定是「启动当前工作目录下的exe文件」
cmd: ./native-IL-1.exe
cmdArgs: []
// * 🚩现在基于「固定位置的CIN程序包」运行测试
// * 回溯路径:config(`./`) => cli => tests => src => BabelNAR.rs / executables
currentDir: ./../../../../executables
}
autoRestart: true
}

0 comments on commit 527dd89

Please sign in to comment.