Skip to content

Commit

Permalink
添加 angleDiff 的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Sep 21, 2024
1 parent 974bd6b commit d852a06
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 11 deletions.
8 changes: 4 additions & 4 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.4"
version = "0.17.5"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
25 changes: 25 additions & 0 deletions examples/dexp.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ set x __0

# 可以看到, 此处__0就是一个自动分配的变量,
# 不用管它的变量名, 只要好好用`$`就行


# 简而言之, 就是可以在 DExp 中放一些逻辑语句,
# 然后使用这个 DExp 时这些语句总是会在使用之前执行,
# 并且如果需要传递值, DExp 中的语句给 $ 赋值就行,
# 表示了当前这一层 DExp 代表的句柄

print "core: ";
print (
ulocate building core false @copper outx outy found $;
print "pos: " outx ", " outy;
);
printflush message1;

# 以下为上述代码编译的结果
#* >>>
print "core: "
ulocate building core false @copper outx outy found __0
print "pos: "
print outx
print ", "
print outy
print __0
printflush message1
*#
2 changes: 1 addition & 1 deletion syntax/MT-Manager/MindustryLogicBangLang.mtsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}
{ // operator
match: keywordsToRegex(
"abs acos add always and angle asin atan ceil"
"abs acos add always and angle angleDiff asin atan ceil"
"cos div equal floor greaterThan greaterThanEq"
"idiv land len lessThan lessThanEq lnot log"
"max min mod mul noise not notEqual or"
Expand Down
2 changes: 1 addition & 1 deletion syntax/vim/mdtlbl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ syn keyword mdtlblOpFunKeyword
\ equal notEqual land lessThan lessThanEq greaterThan greaterThanEq
\ strictEqual strictNotEqual always _
\ shl shr or and xor max
\ min angle len noise not abs log log10
\ min angle angleDiff len noise not abs log log10
\ floor ceil sqrt rand sin cos tan
\ asin acos atan lnot

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion tools/display_source/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl DisplaySource for Op {
Shl, Shr, Or, And, Xor,
]
op2l: [
Max, Min, Angle, Len, Noise,
Max, Min, Angle, AngleDiff, Len, Noise,
]
};
meta.push(";");
Expand Down
6 changes: 6 additions & 0 deletions tools/parser/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ pub Op: Op = {
<OrSwap<"max", <Value>>> <Value> <Value> => Op::Max(<>),
<OrSwap<"min", <Value>>> <Value> <Value> => Op::Min(<>),
<OrSwap<"angle", <Value>>> <Value> <Value> => Op::Angle(<>),
<OrSwap<"angleDiff", <Value>>> <Value> <Value> => Op::AngleDiff(<>),
<OrSwap<"len", <Value>>> <Value> <Value> => Op::Len(<>),
<OrSwap<"noise", <Value>>> <Value> <Value> => Op::Noise(<>),

Expand Down Expand Up @@ -773,6 +774,11 @@ OpExprCallOp: OpExprInfo = {
op_expr_build_op(
|| Op::Angle(ResultHandle, a.into_value(meta), b.into_value(meta)))
},
OpExprFun2<"angleDiff"> => {
let (a, b) = <>;
op_expr_build_op(
|| Op::AngleDiff(ResultHandle, a.into_value(meta), b.into_value(meta)))
},
OpExprFun2<"len"> => {
let (a, b) = <>;
op_expr_build_op(
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.35"
version = "0.1.36"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 4 additions & 0 deletions tools/parser/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ fn op_generate_test() {
Op::Add("x".into(), "y".into(), "z".into()).generate_args(&mut Default::default()),
args!["op", "add", "x", "y", "z"],
);
assert_eq!(
Op::AngleDiff("x".into(), "y".into(), "z".into()).generate_args(&mut Default::default()),
args!["op", "angleDiff", "x", "y", "z"],
);
}

#[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.41"
version = "0.2.42"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 4 additions & 0 deletions tools/syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,7 @@ pub enum Op {
Max(Value, Value, Value),
Min(Value, Value, Value),
Angle(Value, Value, Value),
AngleDiff(Value, Value, Value),
Len(Value, Value, Value),
Noise(Value, Value, Value),

Expand Down Expand Up @@ -1889,6 +1890,7 @@ impl Op {
Max => "max",
Min => "min",
Angle => "angle",
AngleDiff => "angleDiff",
Len => "len",
Noise => "noise",
]
Expand Down Expand Up @@ -2024,6 +2026,7 @@ impl Op {
// Not Impl
| Op::StrictEqual(..)
| Op::Angle(..)
| Op::AngleDiff(..)
| Op::Len(..)
| Op::Noise(..)
| Op::Rand(..) => None?,
Expand Down Expand Up @@ -2108,6 +2111,7 @@ impl FromMdtArgs<'_> for Op {
Max "max",
Min "min",
Angle "angle",
AngleDiff "angleDiff",
Len "len",
Noise "noise",
],
Expand Down

0 comments on commit d852a06

Please sign in to comment.