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.
Files changed (225) hide show
  1. package/.github/workflows/ci.yml +1 -0
  2. package/README.md +119 -313
  3. package/README.zh.md +118 -314
  4. package/ROADMAP.md +5 -5
  5. package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
  6. package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
  7. package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
  8. package/dist/data/impl_test/function/load.mcfunction +1 -0
  9. package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
  10. package/dist/data/minecraft/tags/function/load.json +5 -0
  11. package/dist/data/playground/function/load.mcfunction +1 -0
  12. package/dist/data/playground/function/start.mcfunction +4 -0
  13. package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
  14. package/dist/data/playground/function/stop.mcfunction +5 -0
  15. package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
  16. package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
  17. package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
  18. package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
  19. package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
  20. package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
  21. package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
  22. package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
  23. package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
  24. package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
  25. package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
  26. package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
  27. package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
  28. package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
  29. package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
  30. package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
  31. package/dist/data/test/function/load.mcfunction +1 -0
  32. package/dist/data/test/function/say_at.mcfunction +6 -0
  33. package/dist/data/test/function/test.mcfunction +4 -0
  34. package/dist/pack.mcmeta +6 -0
  35. package/dist/package.json +1 -1
  36. package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
  37. package/dist/src/__tests__/formatter-extra.test.js +123 -0
  38. package/dist/src/__tests__/global-vars.test.d.ts +13 -0
  39. package/dist/src/__tests__/global-vars.test.js +156 -0
  40. package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
  41. package/dist/src/__tests__/lint/new-rules.test.js +402 -0
  42. package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
  43. package/dist/src/__tests__/lsp-rename.test.js +157 -0
  44. package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
  45. package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
  46. package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
  47. package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
  48. package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
  49. package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
  50. package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
  51. package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
  52. package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
  53. package/dist/src/__tests__/mc-syntax.test.js +4 -1
  54. package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
  55. package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
  56. package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
  57. package/dist/src/__tests__/optimizer-cse.test.js +226 -0
  58. package/dist/src/__tests__/parser.test.js +4 -13
  59. package/dist/src/__tests__/repl-server-extra.test.js +6 -7
  60. package/dist/src/__tests__/repl-server.test.js +5 -7
  61. package/dist/src/__tests__/stdlib/queue.test.js +6 -6
  62. package/dist/src/cli.js +0 -0
  63. package/dist/src/lexer/index.js +2 -1
  64. package/dist/src/lint/index.d.ts +12 -5
  65. package/dist/src/lint/index.js +730 -5
  66. package/dist/src/lsp/main.js +0 -0
  67. package/dist/src/mc-test/client.d.ts +21 -0
  68. package/dist/src/mc-test/client.js +34 -0
  69. package/dist/src/mir/lower.js +108 -6
  70. package/dist/src/optimizer/interprocedural.js +37 -2
  71. package/dist/src/parser/decl-parser.d.ts +19 -0
  72. package/dist/src/parser/decl-parser.js +323 -0
  73. package/dist/src/parser/expr-parser.d.ts +46 -0
  74. package/dist/src/parser/expr-parser.js +759 -0
  75. package/dist/src/parser/index.d.ts +8 -129
  76. package/dist/src/parser/index.js +13 -2262
  77. package/dist/src/parser/stmt-parser.d.ts +28 -0
  78. package/dist/src/parser/stmt-parser.js +577 -0
  79. package/dist/src/parser/type-parser.d.ts +20 -0
  80. package/dist/src/parser/type-parser.js +257 -0
  81. package/dist/src/parser/utils.d.ts +34 -0
  82. package/dist/src/parser/utils.js +141 -0
  83. package/docs/dev/README-mc-integration-tests.md +141 -0
  84. package/docs/lint-rules.md +162 -0
  85. package/docs/stdlib/bigint.md +2 -0
  86. package/editors/vscode/README.md +63 -41
  87. package/editors/vscode/out/extension.js +1881 -1776
  88. package/editors/vscode/out/lsp-server.js +4257 -3651
  89. package/editors/vscode/package-lock.json +3 -3
  90. package/editors/vscode/package.json +1 -1
  91. package/examples/loops-demo.mcrs +87 -0
  92. package/package.json +1 -1
  93. package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
  94. package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
  95. package/redscript-docs/docs/en/stdlib/bits.md +292 -0
  96. package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
  97. package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
  98. package/redscript-docs/docs/en/stdlib/color.md +353 -0
  99. package/redscript-docs/docs/en/stdlib/combat.md +88 -0
  100. package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
  101. package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
  102. package/redscript-docs/docs/en/stdlib/easing.md +558 -0
  103. package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
  104. package/redscript-docs/docs/en/stdlib/effects.md +324 -0
  105. package/redscript-docs/docs/en/stdlib/events.md +3 -0
  106. package/redscript-docs/docs/en/stdlib/expr.md +45 -0
  107. package/redscript-docs/docs/en/stdlib/fft.md +141 -0
  108. package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
  109. package/redscript-docs/docs/en/stdlib/graph.md +259 -0
  110. package/redscript-docs/docs/en/stdlib/heap.md +185 -0
  111. package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
  112. package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
  113. package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
  114. package/redscript-docs/docs/en/stdlib/list.md +559 -0
  115. package/redscript-docs/docs/en/stdlib/map.md +140 -0
  116. package/redscript-docs/docs/en/stdlib/math.md +193 -0
  117. package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
  118. package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
  119. package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
  120. package/redscript-docs/docs/en/stdlib/noise.md +244 -0
  121. package/redscript-docs/docs/en/stdlib/ode.md +253 -0
  122. package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
  123. package/redscript-docs/docs/en/stdlib/particles.md +311 -0
  124. package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
  125. package/redscript-docs/docs/en/stdlib/physics.md +493 -0
  126. package/redscript-docs/docs/en/stdlib/player.md +78 -0
  127. package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
  128. package/redscript-docs/docs/en/stdlib/queue.md +134 -0
  129. package/redscript-docs/docs/en/stdlib/random.md +223 -0
  130. package/redscript-docs/docs/en/stdlib/result.md +143 -0
  131. package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
  132. package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
  133. package/redscript-docs/docs/en/stdlib/sets.md +101 -0
  134. package/redscript-docs/docs/en/stdlib/signal.md +400 -0
  135. package/redscript-docs/docs/en/stdlib/sort.md +104 -0
  136. package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
  137. package/redscript-docs/docs/en/stdlib/state.md +142 -0
  138. package/redscript-docs/docs/en/stdlib/strings.md +154 -0
  139. package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
  140. package/redscript-docs/docs/en/stdlib/teams.md +153 -0
  141. package/redscript-docs/docs/en/stdlib/timer.md +246 -0
  142. package/redscript-docs/docs/en/stdlib/vec.md +158 -0
  143. package/redscript-docs/docs/en/stdlib/world.md +298 -0
  144. package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
  145. package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
  146. package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
  147. package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
  148. package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
  149. package/redscript-docs/docs/zh/stdlib/color.md +353 -0
  150. package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
  151. package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
  152. package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
  153. package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
  154. package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
  155. package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
  156. package/redscript-docs/docs/zh/stdlib/events.md +3 -0
  157. package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
  158. package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
  159. package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
  160. package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
  161. package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
  162. package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
  163. package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
  164. package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
  165. package/redscript-docs/docs/zh/stdlib/list.md +561 -0
  166. package/redscript-docs/docs/zh/stdlib/map.md +132 -0
  167. package/redscript-docs/docs/zh/stdlib/math.md +193 -0
  168. package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
  169. package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
  170. package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
  171. package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
  172. package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
  173. package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
  174. package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
  175. package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
  176. package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
  177. package/redscript-docs/docs/zh/stdlib/player.md +78 -0
  178. package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
  179. package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
  180. package/redscript-docs/docs/zh/stdlib/random.md +222 -0
  181. package/redscript-docs/docs/zh/stdlib/result.md +147 -0
  182. package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
  183. package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
  184. package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
  185. package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
  186. package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
  187. package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
  188. package/redscript-docs/docs/zh/stdlib/state.md +134 -0
  189. package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
  190. package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
  191. package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
  192. package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
  193. package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
  194. package/redscript-docs/docs/zh/stdlib/world.md +289 -0
  195. package/src/__tests__/formatter-extra.test.ts +139 -0
  196. package/src/__tests__/global-vars.test.ts +171 -0
  197. package/src/__tests__/lint/new-rules.test.ts +437 -0
  198. package/src/__tests__/lsp-rename.test.ts +171 -0
  199. package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
  200. package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
  201. package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
  202. package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
  203. package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
  204. package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
  205. package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
  206. package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
  207. package/src/__tests__/mc-syntax.test.ts +3 -0
  208. package/src/__tests__/monomorphize-coverage.test.ts +220 -0
  209. package/src/__tests__/optimizer-cse.test.ts +250 -0
  210. package/src/__tests__/parser.test.ts +4 -13
  211. package/src/__tests__/repl-server-extra.test.ts +6 -6
  212. package/src/__tests__/repl-server.test.ts +5 -6
  213. package/src/__tests__/stdlib/queue.test.ts +6 -6
  214. package/src/lexer/index.ts +2 -1
  215. package/src/lint/index.ts +713 -5
  216. package/src/mc-test/client.ts +40 -0
  217. package/src/mir/lower.ts +111 -2
  218. package/src/optimizer/interprocedural.ts +40 -2
  219. package/src/parser/decl-parser.ts +349 -0
  220. package/src/parser/expr-parser.ts +838 -0
  221. package/src/parser/index.ts +17 -2558
  222. package/src/parser/stmt-parser.ts +585 -0
  223. package/src/parser/type-parser.ts +276 -0
  224. package/src/parser/utils.ts +173 -0
  225. 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
@@ -0,0 +1,6 @@
1
+ # Generated from: /tmp/test_macro2.mcrs:1 (fn say_at)
2
+ # Source: fn say_at(target: selector) -> void
3
+ # src: /tmp/test_macro2.mcrs:2
4
+ summon minecraft:zombie ~0 ~1 ~0
5
+ # src: /tmp/test_macro2.mcrs:3
6
+ say hello from macro
@@ -0,0 +1,4 @@
1
+ # Generated from: /tmp/test_macro.mcrs:3 (fn test)
2
+ # Source: fn test() -> void
3
+ # src: /tmp/test_macro.mcrs:5
4
+ tellraw @s {"text":"","extra":[{"text":"Value is "},{"score":{"name":"$counter","objective":"__test"}}]}
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "RedScript datapack: impl_test"
5
+ }
6
+ }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redscript-mc",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "A high-level programming language that compiles to Minecraft datapacks",
5
5
  "main": "dist/src/index.js",
6
6
  "bin": {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Additional coverage for src/formatter/index.ts
3
+ *
4
+ * Targets uncovered branches: string handling, long line wrapping,
5
+ * comment preservation, CRLF normalization, multiple blank line collapsing.
6
+ */
7
+ export {};
@@ -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
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tests for the 5 new redscript lint rules:
3
+ * no-dead-assignment
4
+ * prefer-match-exhaustive
5
+ * no-empty-catch
6
+ * naming-convention
7
+ * no-magic-numbers
8
+ */
9
+ export {};