From a292fd643431d96ff6b1fec090662e207753dfa6 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Tue, 17 Oct 2023 21:23:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B1=E4=BA=8EGitHub-Actions=E7=9A=84Rust?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E9=99=90=E5=88=B6,=20=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=B0=8F=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/syntax/mod.rs | 23 ++++++++++++++++++++++- tools/utils/Cargo.lock | 2 +- tools/utils/Cargo.toml | 2 +- tools/utils/src/counter.rs | 24 +++++++++++++++++++++++- 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73176d6..36b6e23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,7 +288,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.12.5" +version = "0.12.6" dependencies = [ "display_source", "lalrpop", @@ -559,7 +559,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "utils" -version = "0.1.1" +version = "0.1.2" [[package]] name = "var_utils" diff --git a/Cargo.toml b/Cargo.toml index 5bd3216..af28986 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.12.5" +version = "0.12.6" edition = "2021" authors = ["A4-Tacks "] diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index d728977..8aef82d 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -2121,7 +2121,6 @@ pub trait Compile { } } -#[derive(Debug)] pub struct CompileMeta { /// 标记与`id`的映射关系表 tags_map: HashMap, @@ -2142,6 +2141,28 @@ pub struct CompileMeta { const_expand_tag_name_map: Vec>, value_binds: HashMap<(Var, Var), Var>, } +impl Debug for CompileMeta { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // 为适应GitHub Rust Actions的老版本Rust, 暂时将Debug宏手动实现 + struct DotDot; + impl Debug for DotDot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "..") + } + } + f.debug_struct("CompileMeta") + .field("tags_map", &self.tags_map) + .field("tag_count", &self.tag_count) + .field("tag_codes", &self.tag_codes) + .field("tmp_var_count", &self.tmp_var_count.counter()) + .field("const_var_namespace", &self.const_var_namespace) + .field("dexp_result_handles", &self.dexp_result_handles) + .field("tmp_tag_count", &self.tmp_tag_count.counter()) + .field("const_expand_tag_name_map", &self.const_expand_tag_name_map) + .field("value_binds", &self.value_binds) + .finish() + } +} impl Default for CompileMeta { fn default() -> Self { Self::with_tag_codes(TagCodes::new()) diff --git a/tools/utils/Cargo.lock b/tools/utils/Cargo.lock index 1014ef1..df869b4 100644 --- a/tools/utils/Cargo.lock +++ b/tools/utils/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "utils" -version = "0.1.0" +version = "0.1.2" diff --git a/tools/utils/Cargo.toml b/tools/utils/Cargo.toml index 091e37d..3efe751 100644 --- a/tools/utils/Cargo.toml +++ b/tools/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "utils" -version = "0.1.1" +version = "0.1.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/utils/src/counter.rs b/tools/utils/src/counter.rs index dd53586..642b182 100644 --- a/tools/utils/src/counter.rs +++ b/tools/utils/src/counter.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + /// 一个负责获取结果并自增的结构 /// # Examples /// ``` @@ -12,12 +14,26 @@ /// assert_eq!(counter.get(), "__2"); /// assert_eq!(counter.get(), "__3"); /// ``` -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +#[derive(PartialEq, Eq, Hash, Clone, Copy)] pub struct Counter { counter: T, getter: F, } +impl Debug for Counter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + struct DotDot; + impl Debug for DotDot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "..") + } + } + f.debug_struct("Counter") + .field("counter", &self.counter) + .field("getter", &DotDot) + .finish() + } +} impl Counter where F: FnMut(&mut T) -> R @@ -29,9 +45,15 @@ where F: FnMut(&mut T) -> R } } + /// 获取更新函数返回的值 pub fn get(&mut self) -> R { (self.getter)(&mut self.counter) } + + /// 返回内部值 + pub fn counter(&self) -> &T { + &self.counter + } } impl Counter