Skip to content

Commit

Permalink
修复比较内联的 DExp 两级假值检测实现错误
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Jan 22, 2025
1 parent 369b20a commit 91c190b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 12 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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mindustry_logic_bang_lang"
version = "0.17.17"
version = "0.17.18"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion tools/parser/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parser-tests"
version = "0.1.43"
version = "0.1.44"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
81 changes: 81 additions & 0 deletions tools/parser/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,87 @@ fn inline_cmp_op_test() {
"#).unwrap()).compile().unwrap(),
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = goto(a < b);
do {} while Cmp != (`false`:);
"#).unwrap()).compile().unwrap(),
CompileMeta::new().compile(parse!(parser, r#"
const Cmp = goto(a < b);
do {} while Cmp != (`false`:);
"#).unwrap()).compile().unwrap(),
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?a < b);
break Cmp != (`false`:);
"#).unwrap()).compile().unwrap(),
vec![
"jump 0 lessThan a b"
]
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?a < b);
break Cmp != (false:);
"#).unwrap()).compile().unwrap(),
vec![
"op lessThan __0 a b",
"jump 0 notEqual __0 2",
]
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?m: a < b);
break Cmp != (`false`:);
"#).unwrap()).compile().unwrap(),
vec![
"op lessThan m a b",
"jump 0 notEqual m false",
]
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?a < b);
break Cmp != (`false`: {});
"#).unwrap()).compile().unwrap(),
vec![
"op lessThan __0 a b",
"jump 0 notEqual __0 false",
]
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?a < b);
break Cmp == (`false`: {});
"#).unwrap()).compile().unwrap(),
vec![
"op lessThan __0 a b",
"jump 0 equal __0 false",
]
);

assert_eq!(
CompileMeta::new().compile(parse!(parser, r#"
const false = 2;
const Cmp = (?a < b);
break Cmp == (`false`:);
"#).unwrap()).compile().unwrap(),
vec![
"jump 0 greaterThanEq a b",
]
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tools/syntax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syntax"
version = "0.2.47"
version = "0.2.48"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
15 changes: 9 additions & 6 deletions tools/syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,10 @@ impl CmpTree {
lines
}),
..
}) => take_result.then_some(&**s)
.or_else(|| lines.is_empty()
.and_then(|| f(meta, s))),
}) if lines.is_empty() => take_result
.and_then(|| f(meta, s))
.unwrap_or(&**s)
.into(),
Some(_) => None,
None => Some(&**s),
}
Expand All @@ -1583,15 +1584,17 @@ impl CmpTree {
take_result,
result: s,
lines,
}) => take_result.then_some(&**s)
.or_else(|| lines.is_empty()
.and_then(|| f(meta, s))),
}) if lines.is_empty() => take_result
.and_then(|| f(meta, s))
.unwrap_or(&**s)
.into(),
| V::ReprVar(s)
=> Some(&**s),
| V::ResultHandle
=> Some(&**meta.dexp_handle()),
| V::Binder
=> Some(meta.get_dexp_expand_binder().map(|s| &**s).unwrap_or("__")),
| V::DExp(_)
| V::ValueBind(_)
| V::ValueBindRef(_)
| V::Cmper(_)
Expand Down

0 comments on commit 91c190b

Please sign in to comment.