Skip to content

Commit

Permalink
稍微修改了一点点示例什么的
Browse files Browse the repository at this point in the history
- 给vim代码片段的take补了一个结束点
- 给一些代码使用了break而不是标记
  • Loading branch information
A4-Tacks committed Dec 1, 2023
1 parent 161621c commit 1899d0c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README-en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ compilation target language is the `LogicLang` in game [`Mindustry`]
# This is an example of the code and compilation output
**BangLang Source Code**:
```
id count = 0 0;
id, count = 0;
while id < @unitCount {
lookup unit unit_type id;
Expand All @@ -125,16 +125,16 @@ while id < @unitCount {
while Bind != first {
# if the first unit dies, restart this type of counting
goto :restart (sensor $ first @dead;);
op icount icount + 1;
icount = icount + 1;
}
# Accumulate the number of units to the total number of units
op count count + icount;
count = count + icount;
# Print units with units count not equal to zero
print unit_type ": " icount "\n";
}
op id id + 1; # add units type id
id = id + 1; # add units type id
}
print "unit total: " count;
Expand All @@ -145,7 +145,7 @@ printflush message1;

```
set id 0
set count 0
set count id
jump 22 greaterThanEq id @unitCount
lookup unit unit_type id
ubind unit_type
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ English README, please click on [**README-en_US.md**](./README-en_US.md)
# 这是一份示例的代码及编译结果
**Bang语言代码**:
```
id count = 0 0;
id, count = 0;
while id < @unitCount {
lookup unit unit_type id;
Expand All @@ -103,15 +103,15 @@ while id < @unitCount {
while Bind != first {
# 若头单位死亡, 则重新统计该类单位
goto :restart (sensor $ first @dead;);
op icount icount + 1;
icount = icount + 1;
}
op count count + icount; # 将该单位数累加到总单位数
count = count + icount; # 将该单位数累加到总单位数
# 打印每种存在的单位
print unit_type ": " icount "\n";
}
op id id + 1; # 推进单位id
id = id + 1; # 推进单位id
}
print "unit total: " count;
Expand All @@ -120,7 +120,7 @@ printflush message1;
**以上代码将被编译为**
```
set id 0
set count 0
set count id
jump 22 greaterThanEq id @unitCount
lookup unit unit_type id
ubind unit_type
Expand Down
2 changes: 1 addition & 1 deletion examples/const.mdtlbl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#* 内联常量
* 这是通过 const Var = Value 来定义
* 当使用Value时将会进行一个内联常量查找
* 而内联常量是块定义的, 也就是仅在当前块内有效
* 而内联常量是块定义的, 也就是仅在当前块内有效, 确切地说是当前的DExp
* 内联常量的值是一个Value, 也就是说你可以往里面塞一个DExp, 这可以有效的提高代码复用
* Value有一个特殊的值 `$`, 这个值为包裹这个Value的DExp的返回句柄
* 例如 `(x: read $ cell1 0;)`, 其中的`$`代表了这个DExp的返回句柄`x`
Expand Down
2 changes: 1 addition & 1 deletion examples/control_plus.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
i = 0;
while i < 64 {
read num cell1 i;
op i i + 1;
i = i + 1;
continue num == 0;
break num > 0xFF;
print i ": " num "\n";
Expand Down
12 changes: 6 additions & 6 deletions examples/insert_sort.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ do { # 按钮弹起时等待按钮被按下
} while (sensor $ switch1 @enabled;);

read length cell1 0; # 被排序的数组长
set i 1;
i = 1;
while i < length {
read num bank1 i;
set j i;
while (j: set c j; op j j - 1;) >= 0 {
j = i;
while (j: c = j; j = j - 1;) >= 0 {
read num_1 bank1 j;
goto :break1 num_1 <= num;
break num_1 <= num;
write num_1 bank1 c;
} :break1 # 跳出循环用的标记
}
write num bank1 c;
op i i + 1;
i = i + 1;
}
control enabled switch1 true 0 0 0;

Expand Down
4 changes: 2 additions & 2 deletions examples/item_transport_beans_extend.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const GetTarget = (
while i < links {
# 链接了一个分类器和多个目标
getlink Return i;
goto :bk1 (sensor $ Return my_item;) < (sensor $ Return @itemCapacity;);
break (sensor $ Return my_item;) < (sensor $ Return @itemCapacity;);
op i i + 1;
} :bk1
}
}
take[Return] BuildXY;
} else ulocate building core false 0 $.x $.y 0 $;
Expand Down
10 changes: 3 additions & 7 deletions examples/switch.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ switch i {
case 1 2:
print "1 or 2\n";
print "foo";
goto :switch_end _;
break;
case 3:
print "3\n";
goto :switch_end _;
break;
case 5:
print "5\n";
case 4:
print "4\n";
print "穿透到5\n";
} :switch_end
}
printflush message1;
# 注意: 不要在最后一行留一个标签, 因为标签是向下标记的.
# 你在最后一个非空语句使用标签会往不存在的语句进行一个标记, 这会造成越界访问
# 虽然有断言阻止, 但是也不好报错.
# 避免这种行为即可
#* 以上代码会生成如下结构:
set i 4
op mul __0 i 3
Expand Down
6 changes: 3 additions & 3 deletions examples/switch_append.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*#

switch 1 {
goto :end _;
break;
case 0: print 0;
case 1: print 1;
case 2: print 2;
} :end
}
end;

#* 以上代码会被编译为
Expand All @@ -27,5 +27,5 @@ jump 8 always 0 0
end
*#

# 从以上代码可以看到, goto到end呗加入到了每一行的后面
# 从以上代码可以看到, break加入到了每一行的后面
# 这是一个实用的功能
8 changes: 4 additions & 4 deletions examples/unit_count.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
一个统计所有单位的小逻辑
*#

id count = 0 0;
id, count = 0;

while id < @unitCount {
lookup unit unit_type id;
Expand All @@ -17,15 +17,15 @@ while id < @unitCount {
while Bind != first {
# 若头单位死亡, 则重新统计该类单位
goto :restart (sensor $ first @dead;);
op icount icount + 1;
icount = icount + 1;
}
op count count + icount; # 将该单位数累加到总单位数
count = count + icount; # 将该单位数累加到总单位数

# 打印每种存在的单位
print unit_type ": " icount "\n";
}

op id id + 1; # 推进单位id
id = id + 1; # 推进单位id
}

print "unit total: " count;
Expand Down
2 changes: 1 addition & 1 deletion syntax/vim/mdtlbl.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ snippet const "const value" w
const ${1:NAME} = ${2:value};$0
endsnippet
snippet take "take" w
take ${1:${2:RES} = ${3:VALUE}};
take ${1:${2:RES} = ${3:VALUE}};$0
endsnippet
snippet argt "take arg" w
take ${1:Arg} = _${2:0};$0
Expand Down

0 comments on commit 1899d0c

Please sign in to comment.