diff --git a/README-en_US.md b/README-en_US.md index f27d692..b44272d 100644 --- a/README-en_US.md +++ b/README-en_US.md @@ -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; @@ -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; @@ -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 diff --git a/README.md b/README.md index 7288581..2074cc1 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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; @@ -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 diff --git a/examples/const.mdtlbl b/examples/const.mdtlbl index 860f5e8..9895ec3 100644 --- a/examples/const.mdtlbl +++ b/examples/const.mdtlbl @@ -1,7 +1,7 @@ #* 内联常量 * 这是通过 const Var = Value 来定义 * 当使用Value时将会进行一个内联常量查找 - * 而内联常量是块定义的, 也就是仅在当前块内有效 + * 而内联常量是块定义的, 也就是仅在当前块内有效, 确切地说是当前的DExp * 内联常量的值是一个Value, 也就是说你可以往里面塞一个DExp, 这可以有效的提高代码复用 * Value有一个特殊的值 `$`, 这个值为包裹这个Value的DExp的返回句柄 * 例如 `(x: read $ cell1 0;)`, 其中的`$`代表了这个DExp的返回句柄`x` diff --git a/examples/control_plus.mdtlbl b/examples/control_plus.mdtlbl index 9a49947..521994b 100644 --- a/examples/control_plus.mdtlbl +++ b/examples/control_plus.mdtlbl @@ -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"; diff --git a/examples/insert_sort.mdtlbl b/examples/insert_sort.mdtlbl index c847194..bde6881 100644 --- a/examples/insert_sort.mdtlbl +++ b/examples/insert_sort.mdtlbl @@ -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; diff --git a/examples/item_transport_beans_extend.mdtlbl b/examples/item_transport_beans_extend.mdtlbl index 8505f5a..b9305f1 100644 --- a/examples/item_transport_beans_extend.mdtlbl +++ b/examples/item_transport_beans_extend.mdtlbl @@ -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 $; diff --git a/examples/switch.mdtlbl b/examples/switch.mdtlbl index da4d0a1..4fe8110 100644 --- a/examples/switch.mdtlbl +++ b/examples/switch.mdtlbl @@ -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 diff --git a/examples/switch_append.mdtlbl b/examples/switch_append.mdtlbl index 3c6fa09..3c7cf62 100644 --- a/examples/switch_append.mdtlbl +++ b/examples/switch_append.mdtlbl @@ -8,11 +8,11 @@ *# switch 1 { - goto :end _; + break; case 0: print 0; case 1: print 1; case 2: print 2; -} :end +} end; #* 以上代码会被编译为 @@ -27,5 +27,5 @@ jump 8 always 0 0 end *# -# 从以上代码可以看到, goto到end呗加入到了每一行的后面 +# 从以上代码可以看到, break加入到了每一行的后面 # 这是一个实用的功能 diff --git a/examples/unit_count.mdtlbl b/examples/unit_count.mdtlbl index 06c6877..03c2ba0 100644 --- a/examples/unit_count.mdtlbl +++ b/examples/unit_count.mdtlbl @@ -2,7 +2,7 @@ 一个统计所有单位的小逻辑 *# -id count = 0 0; +id, count = 0; while id < @unitCount { lookup unit unit_type id; @@ -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; diff --git a/syntax/vim/mdtlbl.snippets b/syntax/vim/mdtlbl.snippets index f404702..097c252 100644 --- a/syntax/vim/mdtlbl.snippets +++ b/syntax/vim/mdtlbl.snippets @@ -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