diff --git a/Cargo.lock b/Cargo.lock index 6f12d1c..44abf0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,7 +301,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.16.0" +version = "0.16.1" dependencies = [ "display_source", "logic_lint", @@ -535,7 +535,7 @@ dependencies = [ [[package]] name = "syntax" -version = "0.2.20" +version = "0.2.21" dependencies = [ "either", "tag_code", diff --git a/Cargo.toml b/Cargo.toml index f02abe6..51af004 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.16.0" +version = "0.16.1" edition = "2021" authors = ["A4-Tacks "] diff --git a/tools/syntax/Cargo.toml b/tools/syntax/Cargo.toml index c3560a8..ad609d2 100644 --- a/tools/syntax/Cargo.toml +++ b/tools/syntax/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syntax" -version = "0.2.20" +version = "0.2.21" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/syntax/src/lib.rs b/tools/syntax/src/lib.rs index f3b1df4..a93eb6c 100644 --- a/tools/syntax/src/lib.rs +++ b/tools/syntax/src/lib.rs @@ -36,6 +36,25 @@ macro_rules! impl_enum_froms { } )* }; } +macro_rules! impl_enum_try_into { + (impl TryInto for $ty:ty {$( + $variant:ident => $target:ty ; + )*}) => { + $( + impl TryFrom<$ty> for $target { + type Error = $ty; + + fn try_from(value: $ty) -> Result { + use $ty::*; + match value { + $variant(v) => Ok(v), + this => Err(this), + } + } + } + )* + }; +} macro_rules! impl_derefs { (impl $([$($t:tt)*])? for $ty:ty => ($self_:ident : $expr:expr): $res_ty:ty) => { impl $(<$($t)*>)? ::std::ops::Deref for $ty { @@ -562,6 +581,12 @@ impl_enum_froms!(impl From for Value { BuiltinFunc => BuiltinFunc; ValueBindRef => ValueBindRef; }); +impl_enum_try_into!(impl TryInto for Value { + Var => Var; + DExp => DExp; + ValueBind => ValueBind; + ValueBindRef => ValueBindRef; +}); /// 一次性的迭代器格式化包装器 struct IterFmtter { @@ -2830,6 +2855,11 @@ impl Compile for ConstMatch { let args = self.args.into_value_args(meta) .into_iter() .map(|value| { + if let Some(var) = value.as_var() { + if meta.get_const_value(var).is_some() { + return value.try_into().unwrap(); + } + } let handle = meta.get_tmp_var(); Const( handle.clone().into(),