redscript-mc 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +1 -0
- package/README.md +119 -313
- package/README.zh.md +118 -314
- package/ROADMAP.md +5 -5
- package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
- package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
- package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
- package/dist/data/impl_test/function/load.mcfunction +1 -0
- package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/playground/function/load.mcfunction +1 -0
- package/dist/data/playground/function/start.mcfunction +4 -0
- package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
- package/dist/data/playground/function/stop.mcfunction +5 -0
- package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
- package/dist/data/test/function/load.mcfunction +1 -0
- package/dist/data/test/function/say_at.mcfunction +6 -0
- package/dist/data/test/function/test.mcfunction +4 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/package.json +1 -1
- package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
- package/dist/src/__tests__/formatter-extra.test.js +123 -0
- package/dist/src/__tests__/global-vars.test.d.ts +13 -0
- package/dist/src/__tests__/global-vars.test.js +156 -0
- package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
- package/dist/src/__tests__/lint/new-rules.test.js +402 -0
- package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
- package/dist/src/__tests__/lsp-rename.test.js +157 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
- package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
- package/dist/src/__tests__/mc-syntax.test.js +4 -1
- package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
- package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
- package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
- package/dist/src/__tests__/optimizer-cse.test.js +226 -0
- package/dist/src/__tests__/parser.test.js +4 -13
- package/dist/src/__tests__/repl-server-extra.test.js +6 -7
- package/dist/src/__tests__/repl-server.test.js +5 -7
- package/dist/src/__tests__/stdlib/queue.test.js +6 -6
- package/dist/src/cli.js +0 -0
- package/dist/src/lexer/index.js +2 -1
- package/dist/src/lint/index.d.ts +12 -5
- package/dist/src/lint/index.js +730 -5
- package/dist/src/lsp/main.js +0 -0
- package/dist/src/mc-test/client.d.ts +21 -0
- package/dist/src/mc-test/client.js +34 -0
- package/dist/src/mir/lower.js +108 -6
- package/dist/src/optimizer/interprocedural.js +37 -2
- package/dist/src/parser/decl-parser.d.ts +19 -0
- package/dist/src/parser/decl-parser.js +323 -0
- package/dist/src/parser/expr-parser.d.ts +46 -0
- package/dist/src/parser/expr-parser.js +759 -0
- package/dist/src/parser/index.d.ts +8 -129
- package/dist/src/parser/index.js +13 -2262
- package/dist/src/parser/stmt-parser.d.ts +28 -0
- package/dist/src/parser/stmt-parser.js +577 -0
- package/dist/src/parser/type-parser.d.ts +20 -0
- package/dist/src/parser/type-parser.js +257 -0
- package/dist/src/parser/utils.d.ts +34 -0
- package/dist/src/parser/utils.js +141 -0
- package/docs/dev/README-mc-integration-tests.md +141 -0
- package/docs/lint-rules.md +162 -0
- package/docs/stdlib/bigint.md +2 -0
- package/editors/vscode/README.md +63 -41
- package/editors/vscode/out/extension.js +1881 -1776
- package/editors/vscode/out/lsp-server.js +4257 -3651
- package/editors/vscode/package-lock.json +3 -3
- package/editors/vscode/package.json +1 -1
- package/examples/loops-demo.mcrs +87 -0
- package/package.json +1 -1
- package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
- package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/en/stdlib/bits.md +292 -0
- package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
- package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
- package/redscript-docs/docs/en/stdlib/color.md +353 -0
- package/redscript-docs/docs/en/stdlib/combat.md +88 -0
- package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
- package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
- package/redscript-docs/docs/en/stdlib/easing.md +558 -0
- package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
- package/redscript-docs/docs/en/stdlib/effects.md +324 -0
- package/redscript-docs/docs/en/stdlib/events.md +3 -0
- package/redscript-docs/docs/en/stdlib/expr.md +45 -0
- package/redscript-docs/docs/en/stdlib/fft.md +141 -0
- package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/en/stdlib/graph.md +259 -0
- package/redscript-docs/docs/en/stdlib/heap.md +185 -0
- package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
- package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
- package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
- package/redscript-docs/docs/en/stdlib/list.md +559 -0
- package/redscript-docs/docs/en/stdlib/map.md +140 -0
- package/redscript-docs/docs/en/stdlib/math.md +193 -0
- package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
- package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
- package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/en/stdlib/noise.md +244 -0
- package/redscript-docs/docs/en/stdlib/ode.md +253 -0
- package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
- package/redscript-docs/docs/en/stdlib/particles.md +311 -0
- package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/en/stdlib/physics.md +493 -0
- package/redscript-docs/docs/en/stdlib/player.md +78 -0
- package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
- package/redscript-docs/docs/en/stdlib/queue.md +134 -0
- package/redscript-docs/docs/en/stdlib/random.md +223 -0
- package/redscript-docs/docs/en/stdlib/result.md +143 -0
- package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
- package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
- package/redscript-docs/docs/en/stdlib/sets.md +101 -0
- package/redscript-docs/docs/en/stdlib/signal.md +400 -0
- package/redscript-docs/docs/en/stdlib/sort.md +104 -0
- package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
- package/redscript-docs/docs/en/stdlib/state.md +142 -0
- package/redscript-docs/docs/en/stdlib/strings.md +154 -0
- package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/en/stdlib/teams.md +153 -0
- package/redscript-docs/docs/en/stdlib/timer.md +246 -0
- package/redscript-docs/docs/en/stdlib/vec.md +158 -0
- package/redscript-docs/docs/en/stdlib/world.md +298 -0
- package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
- package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
- package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
- package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
- package/redscript-docs/docs/zh/stdlib/color.md +353 -0
- package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
- package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
- package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
- package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
- package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
- package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
- package/redscript-docs/docs/zh/stdlib/events.md +3 -0
- package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
- package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
- package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
- package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
- package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
- package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
- package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
- package/redscript-docs/docs/zh/stdlib/list.md +561 -0
- package/redscript-docs/docs/zh/stdlib/map.md +132 -0
- package/redscript-docs/docs/zh/stdlib/math.md +193 -0
- package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
- package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
- package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
- package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
- package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
- package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
- package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
- package/redscript-docs/docs/zh/stdlib/player.md +78 -0
- package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
- package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
- package/redscript-docs/docs/zh/stdlib/random.md +222 -0
- package/redscript-docs/docs/zh/stdlib/result.md +147 -0
- package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
- package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
- package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
- package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
- package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
- package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
- package/redscript-docs/docs/zh/stdlib/state.md +134 -0
- package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
- package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
- package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
- package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
- package/redscript-docs/docs/zh/stdlib/world.md +289 -0
- package/src/__tests__/formatter-extra.test.ts +139 -0
- package/src/__tests__/global-vars.test.ts +171 -0
- package/src/__tests__/lint/new-rules.test.ts +437 -0
- package/src/__tests__/lsp-rename.test.ts +171 -0
- package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
- package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
- package/src/__tests__/mc-syntax.test.ts +3 -0
- package/src/__tests__/monomorphize-coverage.test.ts +220 -0
- package/src/__tests__/optimizer-cse.test.ts +250 -0
- package/src/__tests__/parser.test.ts +4 -13
- package/src/__tests__/repl-server-extra.test.ts +6 -6
- package/src/__tests__/repl-server.test.ts +5 -6
- package/src/__tests__/stdlib/queue.test.ts +6 -6
- package/src/lexer/index.ts +2 -1
- package/src/lint/index.ts +713 -5
- package/src/mc-test/client.ts +40 -0
- package/src/mir/lower.ts +111 -2
- package/src/optimizer/interprocedural.ts +40 -2
- package/src/parser/decl-parser.ts +349 -0
- package/src/parser/expr-parser.ts +838 -0
- package/src/parser/index.ts +17 -2558
- package/src/parser/stmt-parser.ts +585 -0
- package/src/parser/type-parser.ts +276 -0
- package/src/parser/utils.ts +173 -0
- package/src/stdlib/queue.mcrs +19 -6
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:107 (fn queue_empty)
|
|
2
|
+
# Source: fn queue_empty() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:109
|
|
4
|
+
scoreboard players set $__const_1 __stdlib_queue8_test 1
|
|
5
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_1 __stdlib_queue8_test
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:74 (fn queue_peek)
|
|
2
|
+
# Source: fn queue_peek() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:78
|
|
4
|
+
scoreboard players set $ret __stdlib_queue8_test 0
|
|
5
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:79
|
|
6
|
+
execute store result storage rs:macro_args idx int 1 run scoreboard players get rs.q_head __RS__
|
|
7
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:80
|
|
8
|
+
function stdlib_queue8_test:__queue_peek_apply with storage rs:macro_args
|
|
9
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:81
|
|
10
|
+
return 1
|
|
11
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:82
|
|
12
|
+
scoreboard players set $__const_0 __stdlib_queue8_test 0
|
|
13
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_0 __stdlib_queue8_test
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:74 (fn queue_peek)
|
|
2
|
+
# Source: fn queue_peek() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:76
|
|
4
|
+
scoreboard players set $__const_-1 __stdlib_queue8_test -1
|
|
5
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_-1 __stdlib_queue8_test
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:51 (fn queue_pop)
|
|
2
|
+
# Source: fn queue_pop() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:57
|
|
4
|
+
scoreboard players set $ret __stdlib_queue8_test 0
|
|
5
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:58
|
|
6
|
+
execute store result storage rs:macro_args idx int 1 run scoreboard players get rs.q_head __RS__
|
|
7
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:59
|
|
8
|
+
function stdlib_queue8_test:__queue_peek_apply with storage rs:macro_args
|
|
9
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:61
|
|
10
|
+
scoreboard players add rs.q_head __RS__ 1
|
|
11
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:62
|
|
12
|
+
return 1
|
|
13
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:63
|
|
14
|
+
scoreboard players set $__const_0 __stdlib_queue8_test 0
|
|
15
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_0 __stdlib_queue8_test
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:51 (fn queue_pop)
|
|
2
|
+
# Source: fn queue_pop() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:54
|
|
4
|
+
scoreboard players set $__const_-1 __stdlib_queue8_test -1
|
|
5
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_-1 __stdlib_queue8_test
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:38 (fn queue_push)
|
|
2
|
+
# Source: fn queue_push(val: int) -> void
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:39
|
|
4
|
+
execute store result storage rs:macro_args val int 1 run scoreboard players get $p0 __stdlib_queue8_test
|
|
5
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:40
|
|
6
|
+
function stdlib_queue8_test:__queue_append_apply with storage rs:macro_args
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:38 (fn queue_push)
|
|
2
|
+
# Source: fn queue_push(val: int) -> void
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:39
|
|
4
|
+
execute store result storage rs:macro_args val int 1 run scoreboard players get $p0 __stdlib_queue8_test
|
|
5
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:40
|
|
6
|
+
function stdlib_queue8_test:__queue_append_apply with storage rs:macro_args
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Generated from: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:93 (fn queue_size)
|
|
2
|
+
# Source: fn queue_size() -> int
|
|
3
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:94
|
|
4
|
+
scoreboard players set $ret __stdlib_queue8_test 0
|
|
5
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:95
|
|
6
|
+
function stdlib_queue8_test:__queue_size_raw_apply with storage rs:macro_args
|
|
7
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:96
|
|
8
|
+
scoreboard players operation $ret __stdlib_queue8_test -= rs.q_head __RS__
|
|
9
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:97
|
|
10
|
+
return 1
|
|
11
|
+
# src: /Users/yuzhe/projects/redscript/src/stdlib/queue.mcrs:98
|
|
12
|
+
scoreboard players set $__const_0 __stdlib_queue8_test 0
|
|
13
|
+
scoreboard players operation $ret __stdlib_queue8_test = $__const_0 __stdlib_queue8_test
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Generated from: /tmp/queue_test.mcrs:2 (fn test_queue_push_and_size)
|
|
2
|
+
# Source: fn test_queue_push_and_size() -> void
|
|
3
|
+
# src: /tmp/queue_test.mcrs:3
|
|
4
|
+
function stdlib_queue8_test:queue_clear
|
|
5
|
+
# src: /tmp/queue_test.mcrs:4
|
|
6
|
+
function stdlib_queue8_test:queue_push__const_11
|
|
7
|
+
# src: /tmp/queue_test.mcrs:5
|
|
8
|
+
function stdlib_queue8_test:queue_push__const_22
|
|
9
|
+
# src: /tmp/queue_test.mcrs:6
|
|
10
|
+
function stdlib_queue8_test:queue_size
|
|
11
|
+
scoreboard players operation $test_queue_push_and_size_t3 __stdlib_queue8_test = $ret __stdlib_queue8_test
|
|
12
|
+
# src: /tmp/queue_test.mcrs:7
|
|
13
|
+
execute store result score #queue_size sc8_result run scoreboard players get $test_queue_push_and_size_t3 __stdlib_queue8_test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
scoreboard objectives add __test dummy
|
package/dist/pack.mcmeta
ADDED
package/dist/package.json
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Additional coverage for src/formatter/index.ts
|
|
4
|
+
*
|
|
5
|
+
* Targets uncovered branches: string handling, long line wrapping,
|
|
6
|
+
* comment preservation, CRLF normalization, multiple blank line collapsing.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const formatter_1 = require("../formatter");
|
|
10
|
+
describe('formatter — string literal preservation', () => {
|
|
11
|
+
it('does not reindent content inside string literals', () => {
|
|
12
|
+
const input = 'fn test(): void {\nlet s: string = "{ not a block }";\n}';
|
|
13
|
+
const result = (0, formatter_1.format)(input);
|
|
14
|
+
expect(result).toContain('"{ not a block }"');
|
|
15
|
+
});
|
|
16
|
+
it('handles multiline strings spanning multiple lines', () => {
|
|
17
|
+
// A string that contains a newline escape
|
|
18
|
+
const input = 'fn test(): void {\nlet s: string = "line1\\nline2";\n}';
|
|
19
|
+
const result = (0, formatter_1.format)(input);
|
|
20
|
+
expect(result).toContain('"line1\\nline2"');
|
|
21
|
+
});
|
|
22
|
+
it('handles escaped quotes inside strings', () => {
|
|
23
|
+
const input = 'fn test(): void {\nlet s: string = "say \\"hello\\"";\n}';
|
|
24
|
+
const result = (0, formatter_1.format)(input);
|
|
25
|
+
expect(result).toContain('"say \\"hello\\""');
|
|
26
|
+
});
|
|
27
|
+
it('handles string with braces that should not affect indentation', () => {
|
|
28
|
+
const input = 'fn test(): void {\nlet s: string = "{{{}}} more";\nlet x: int = 1;\n}';
|
|
29
|
+
const result = (0, formatter_1.format)(input);
|
|
30
|
+
// x should be indented at 1 level (inside fn), not affected by string braces
|
|
31
|
+
expect(result).toMatch(/^ {2}let x: int = 1;$/m);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('formatter — comment handling', () => {
|
|
35
|
+
it('preserves inline comments', () => {
|
|
36
|
+
const input = 'fn test(): void {\nlet x: int = 1; // important\n}';
|
|
37
|
+
const result = (0, formatter_1.format)(input);
|
|
38
|
+
expect(result).toContain('// important');
|
|
39
|
+
});
|
|
40
|
+
it('does not treat braces in comments as code', () => {
|
|
41
|
+
const input = 'fn test(): void {\n// { this is a comment\nlet x: int = 1;\n}';
|
|
42
|
+
const result = (0, formatter_1.format)(input);
|
|
43
|
+
expect(result).toMatch(/^ {2}let x: int = 1;$/m);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('formatter — CRLF normalization', () => {
|
|
47
|
+
it('normalizes CRLF to LF', () => {
|
|
48
|
+
const input = 'fn test(): void {\r\nlet x: int = 1;\r\n}';
|
|
49
|
+
const result = (0, formatter_1.format)(input);
|
|
50
|
+
expect(result).not.toContain('\r');
|
|
51
|
+
expect(result).toBe('fn test(): void {\n let x: int = 1;\n}\n');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('formatter — blank line collapsing', () => {
|
|
55
|
+
it('collapses more than 2 consecutive blank lines', () => {
|
|
56
|
+
const input = 'fn a(): void {\n}\n\n\n\n\nfn b(): void {\n}';
|
|
57
|
+
const result = (0, formatter_1.format)(input);
|
|
58
|
+
// Should have at most 2 blank lines between functions
|
|
59
|
+
expect(result).not.toMatch(/\n\n\n\n/);
|
|
60
|
+
});
|
|
61
|
+
it('strips leading blank lines', () => {
|
|
62
|
+
const input = '\n\n\nfn test(): void {\n}';
|
|
63
|
+
const result = (0, formatter_1.format)(input);
|
|
64
|
+
expect(result).toMatch(/^fn test/);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('formatter — long line wrapping', () => {
|
|
68
|
+
it('wraps function calls longer than 80 characters', () => {
|
|
69
|
+
const inner = 'fn test(): void {\n some_function(argument_one, argument_two, argument_three, argument_four, argument_five);\n}';
|
|
70
|
+
const result = (0, formatter_1.format)(inner);
|
|
71
|
+
// Should be wrapped since the line is > 80 chars
|
|
72
|
+
const lines = result.split('\n');
|
|
73
|
+
// After wrapping, should produce more lines than original 3
|
|
74
|
+
expect(lines.length).toBeGreaterThan(3);
|
|
75
|
+
});
|
|
76
|
+
it('does not wrap short function calls', () => {
|
|
77
|
+
const input = 'fn test(): void {\n foo(a, b);\n}';
|
|
78
|
+
const result = (0, formatter_1.format)(input);
|
|
79
|
+
expect(result).toContain('foo(a, b)');
|
|
80
|
+
});
|
|
81
|
+
it('does not wrap lines with comments even if long', () => {
|
|
82
|
+
const longComment = 'fn test(): void {\n let x: int = 1; // this is a very long comment that makes the line exceed 80 characters easily\n}';
|
|
83
|
+
const result = (0, formatter_1.format)(longComment);
|
|
84
|
+
// Should keep comment line as-is (no wrapping)
|
|
85
|
+
expect(result).toContain('// this is a very long comment');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe('formatter — brace collapsing', () => {
|
|
89
|
+
it('puts opening brace on same line as preceding statement', () => {
|
|
90
|
+
const input = 'if true\n{\nlet x: int = 1;\n}';
|
|
91
|
+
const result = (0, formatter_1.format)(input);
|
|
92
|
+
expect(result).toContain('if true {');
|
|
93
|
+
});
|
|
94
|
+
it('handles else brace normalization', () => {
|
|
95
|
+
const input = 'fn test(): void {\nif true {\nlet x: int = 1;\n}else{\nlet y: int = 2;\n}\n}';
|
|
96
|
+
const result = (0, formatter_1.format)(input);
|
|
97
|
+
expect(result).toContain('} else {');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('formatter — deeply nested code', () => {
|
|
101
|
+
it('indents 3 levels deep correctly', () => {
|
|
102
|
+
const input = 'fn test(): void {\nif true {\nif false {\nlet x: int = 1;\n}\n}\n}';
|
|
103
|
+
const result = (0, formatter_1.format)(input);
|
|
104
|
+
expect(result).toMatch(/^ {6}let x: int = 1;$/m);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('formatter — edge cases', () => {
|
|
108
|
+
it('handles single line code', () => {
|
|
109
|
+
const result = (0, formatter_1.format)('let x: int = 1;');
|
|
110
|
+
expect(result).toBe('let x: int = 1;\n');
|
|
111
|
+
});
|
|
112
|
+
it('handles code with only braces', () => {
|
|
113
|
+
const result = (0, formatter_1.format)('{}');
|
|
114
|
+
expect(result).toContain('{');
|
|
115
|
+
expect(result).toContain('}');
|
|
116
|
+
});
|
|
117
|
+
it('handles closing brace followed by opening brace', () => {
|
|
118
|
+
const input = 'fn a(): void {\n}\nfn b(): void {\n}';
|
|
119
|
+
const result = (0, formatter_1.format)(input);
|
|
120
|
+
expect(result).toContain('fn a(): void {\n}\nfn b(): void {\n}\n');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=formatter-extra.test.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for module-level global variables.
|
|
3
|
+
*
|
|
4
|
+
* Covers:
|
|
5
|
+
* - Global variable assignment and read (score_write / score_read)
|
|
6
|
+
* - Global variable increment in a loop
|
|
7
|
+
* - Global variable visible across functions
|
|
8
|
+
* - Global variable in f-string interpolation (no stray "~")
|
|
9
|
+
*
|
|
10
|
+
* These tests compile RedScript source and inspect the generated .mcfunction
|
|
11
|
+
* content to verify correct scoreboard-based code generation.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Integration tests for module-level global variables.
|
|
4
|
+
*
|
|
5
|
+
* Covers:
|
|
6
|
+
* - Global variable assignment and read (score_write / score_read)
|
|
7
|
+
* - Global variable increment in a loop
|
|
8
|
+
* - Global variable visible across functions
|
|
9
|
+
* - Global variable in f-string interpolation (no stray "~")
|
|
10
|
+
*
|
|
11
|
+
* These tests compile RedScript source and inspect the generated .mcfunction
|
|
12
|
+
* content to verify correct scoreboard-based code generation.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const compile_1 = require("../emit/compile");
|
|
16
|
+
// Helper: find a function's body by name
|
|
17
|
+
function getFunctionBody(files, fnName, ns = 'test') {
|
|
18
|
+
const target = `data/${ns}/function/${fnName}.mcfunction`;
|
|
19
|
+
const f = files.find(f => f.path === target || f.path.endsWith(`/${fnName}.mcfunction`));
|
|
20
|
+
if (!f) {
|
|
21
|
+
const paths = files.map(f => f.path).join('\n');
|
|
22
|
+
throw new Error(`Function '${fnName}' not found in output. Files:\n${paths}`);
|
|
23
|
+
}
|
|
24
|
+
return f.content;
|
|
25
|
+
}
|
|
26
|
+
// ──────────────────────────────────────────────────────────────
|
|
27
|
+
// Test 1: global variable assignment and read
|
|
28
|
+
// ──────────────────────────────────────────────────────────────
|
|
29
|
+
describe('Global variable: assignment and read', () => {
|
|
30
|
+
const src = `
|
|
31
|
+
let counter: int = 0;
|
|
32
|
+
|
|
33
|
+
@keep
|
|
34
|
+
fn set_counter() {
|
|
35
|
+
counter = 42;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@keep
|
|
39
|
+
fn get_counter() {
|
|
40
|
+
scoreboard_set("#result", "rs", counter);
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
it('set_counter uses scoreboard players set to write global', () => {
|
|
44
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
45
|
+
const body = getFunctionBody(files, 'set_counter');
|
|
46
|
+
// Should write 42 to the scoreboard for the global variable
|
|
47
|
+
expect(body).toContain('scoreboard players set');
|
|
48
|
+
expect(body).toContain('42');
|
|
49
|
+
});
|
|
50
|
+
it('get_counter reads global via score_read (not hardcoded 0)', () => {
|
|
51
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
52
|
+
const body = getFunctionBody(files, 'get_counter');
|
|
53
|
+
// Should contain a scoreboard read for the counter variable,
|
|
54
|
+
// not a hardcoded literal "0" assignment
|
|
55
|
+
expect(body).toContain('scoreboard players');
|
|
56
|
+
// The result should not be a constant "0" — it must read the scoreboard
|
|
57
|
+
// (hardcoded copy t = 0 was the old bug)
|
|
58
|
+
expect(body).not.toMatch(/scoreboard players set #result rs 0\s*$/);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
// ──────────────────────────────────────────────────────────────
|
|
62
|
+
// Test 2: global variable increment in a loop
|
|
63
|
+
// ──────────────────────────────────────────────────────────────
|
|
64
|
+
describe('Global variable: increment in a loop', () => {
|
|
65
|
+
const src = `
|
|
66
|
+
let running: int = 0;
|
|
67
|
+
|
|
68
|
+
@keep
|
|
69
|
+
fn count_up() {
|
|
70
|
+
let i: int = 0;
|
|
71
|
+
while i < 5 {
|
|
72
|
+
running = running + 1;
|
|
73
|
+
i = i + 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
it('count_up reads and writes running (not a no-op)', () => {
|
|
78
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
79
|
+
const body = getFunctionBody(files, 'count_up');
|
|
80
|
+
// Should contain scoreboard operations (not an empty function)
|
|
81
|
+
expect(body.trim().length).toBeGreaterThan(0);
|
|
82
|
+
expect(body).toContain('scoreboard players');
|
|
83
|
+
});
|
|
84
|
+
it('DCE does not eliminate running = running + 1', () => {
|
|
85
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
86
|
+
// The while loop generates sub-functions; check all files
|
|
87
|
+
const allContent = files.map(f => f.content).join('\n');
|
|
88
|
+
// There must be a scoreboard add or operation for running
|
|
89
|
+
const hasAdd = allContent.includes('scoreboard players add') ||
|
|
90
|
+
allContent.includes('scoreboard players operation');
|
|
91
|
+
expect(hasAdd).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
// ──────────────────────────────────────────────────────────────
|
|
95
|
+
// Test 3: global variable visible across functions
|
|
96
|
+
// ──────────────────────────────────────────────────────────────
|
|
97
|
+
describe('Global variable: cross-function visibility', () => {
|
|
98
|
+
const src = `
|
|
99
|
+
let x: int = 0;
|
|
100
|
+
|
|
101
|
+
@keep
|
|
102
|
+
fn set_x() {
|
|
103
|
+
x = 42;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@keep
|
|
107
|
+
fn get_x() {
|
|
108
|
+
scoreboard_set("#out", "rs", x);
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
it('set_x writes to x (not just a local temp)', () => {
|
|
112
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
113
|
+
const body = getFunctionBody(files, 'set_x');
|
|
114
|
+
expect(body).toContain('scoreboard players set');
|
|
115
|
+
expect(body).toContain('42');
|
|
116
|
+
// The write must target the persistent scoreboard name for x, not a temp
|
|
117
|
+
expect(body).toContain('x');
|
|
118
|
+
});
|
|
119
|
+
it('get_x reads x from scoreboard', () => {
|
|
120
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
121
|
+
const body = getFunctionBody(files, 'get_x');
|
|
122
|
+
// Must contain a scoreboard get / operation to read x
|
|
123
|
+
expect(body).toContain('scoreboard players');
|
|
124
|
+
expect(body).toContain('x');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
// ──────────────────────────────────────────────────────────────
|
|
128
|
+
// Test 4: global variable in f-string interpolation
|
|
129
|
+
// ──────────────────────────────────────────────────────────────
|
|
130
|
+
describe('Global variable: f-string interpolation', () => {
|
|
131
|
+
const src = `
|
|
132
|
+
let score_val: int = 0;
|
|
133
|
+
|
|
134
|
+
@keep
|
|
135
|
+
fn announce() {
|
|
136
|
+
say(f"Score: {score_val}");
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
it('announce does not contain stray ~ in tellraw', () => {
|
|
140
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
141
|
+
const body = getFunctionBody(files, 'announce');
|
|
142
|
+
// The generated tellraw must not fall back to "~" (the old default bug)
|
|
143
|
+
expect(body).not.toContain('"text":"~"');
|
|
144
|
+
expect(body).not.toContain('"~"');
|
|
145
|
+
});
|
|
146
|
+
it('announce reads score_val from scoreboard (not hardcoded)', () => {
|
|
147
|
+
const { files } = (0, compile_1.compile)(src, { namespace: 'test' });
|
|
148
|
+
const body = getFunctionBody(files, 'announce');
|
|
149
|
+
// f-string int interpolation uses macro pattern:
|
|
150
|
+
// execute store result storage ... run scoreboard players get score_val __test
|
|
151
|
+
expect(body).toContain('score_val');
|
|
152
|
+
// Must be a dynamic read, not a constant
|
|
153
|
+
expect(body).not.toMatch(/say Score: \d+/);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=global-vars.test.js.map
|