Skip to content

Commit

Permalink
优化Debug的labels显示, 并且使gswitch没有控制标记时不增加块
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed May 9, 2024
1 parent c712ab8 commit 4dcfc5b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 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.16.5"
version = "0.16.6"
edition = "2021"

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
10 changes: 7 additions & 3 deletions tools/parser/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,11 @@ ControlWithoutOptionalEnd: LogicLine = {
let mut lines = vec![GSwitch { value, extra, cases }.into()];
meta.push_some_label_to(&mut lines, break_lab);
meta.push_some_label_to(&mut lines, continue_lab);
Expand(lines).into()
<[_; 1]>::try_from(lines)
.map(|[line]| line)
.unwrap_or_else(|lines| {
InlineBlock(lines).into()
})
},

"switch" <value:Value>
Expand Down Expand Up @@ -1104,7 +1108,7 @@ ControlWithoutOptionalEnd: LogicLine = {
if flag.is_misses() {
// 是一个未命中捕获
let tag = meta.get_tag();
out_block.push(LogicLine::Label(tag.clone()));
out_block.push(LogicLine::new_label(tag.clone(), meta));
fill_line = Goto(tag, JumpCmp::Always.into()).into();
false // 已处理, 过滤掉
} else {
Expand All @@ -1130,7 +1134,7 @@ ControlWithoutOptionalEnd: LogicLine = {
)
}
out_block.push(lines.into());
out_block.push(LogicLine::Label(skip_tag));
out_block.push(LogicLine::new_label(skip_tag, meta));

catch_lines.push(Expand(out_block).into())
}
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.24"
version = "0.2.25"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
7 changes: 5 additions & 2 deletions tools/syntax/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,18 @@ pub fn build_builtins() -> Vec<BuiltinFunc> {
/// 以Debug形式显示一个值
fn debug:Debug(meta) [v:value] {
if let Some(ref ext) = meta.extender {
let mut sep = None;
meta.log_info(format!(
"Value Debug:\n\
binder: ..{}\n\
labels: {}\n\
labels: [{}]\n\
value: {}\
",
value.binder.as_ref().map(|s| s.as_str()).unwrap_or(""),
value.labels().iter()
.flat_map(|s| [s.as_str(), ", "])
.flat_map(|v| sep.replace(", ")
.into_iter()
.chain(once(v.as_str())))
.into_iter_fmtter(),
ext.display_value(value.value()),
));
Expand Down

0 comments on commit 4dcfc5b

Please sign in to comment.