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,190 @@
1
+ # Set_int
2
+
3
+ > Auto-generated from `src/stdlib/set_int.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [set_add](#set-add)
8
+ - [set_has](#set-has)
9
+ - [set_remove](#set-remove)
10
+ - [set_size](#set-size)
11
+ - [set_clear](#set-clear)
12
+ - [set_union](#set-union)
13
+ - [set_intersect](#set-intersect)
14
+
15
+ ---
16
+
17
+ ## `set_add` <Badge type="info" text="v3.0.0" />
18
+
19
+ Adds an integer to `storage rs:set_int.{set_name}` if it is not already present.
20
+
21
+ Missing sets are created automatically as empty lists before insertion.
22
+
23
+ ```redscript
24
+ fn set_add(set_name: string, value: int)
25
+ ```
26
+
27
+ **Parameters**
28
+
29
+ | Parameter | Description |
30
+ |-----------|-------------|
31
+ | `set_name` | Set name under `storage rs:set_int` |
32
+ | `value` | Integer value to insert |
33
+
34
+ **Example**
35
+
36
+ ```redscript
37
+ set_add("Visited", 42)
38
+ ```
39
+
40
+ ---
41
+
42
+ ## `set_has` <Badge type="info" text="v3.0.0" />
43
+
44
+ Checks whether an integer exists in `storage rs:set_int.{set_name}`.
45
+
46
+ ```redscript
47
+ fn set_has(set_name: string, value: int): int
48
+ ```
49
+
50
+ **Parameters**
51
+
52
+ | Parameter | Description |
53
+ |-----------|-------------|
54
+ | `set_name` | Set name under `storage rs:set_int` |
55
+ | `value` | Integer value to test |
56
+
57
+ **Returns:** 1 if the value exists, otherwise 0
58
+
59
+ **Example**
60
+
61
+ ```redscript
62
+ if (set_has("Visited", 42) == 1) { }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## `set_remove` <Badge type="info" text="v3.0.0" />
68
+
69
+ Removes an integer from `storage rs:set_int.{set_name}`.
70
+
71
+ Removing a missing value is a no-op.
72
+
73
+ ```redscript
74
+ fn set_remove(set_name: string, value: int)
75
+ ```
76
+
77
+ **Parameters**
78
+
79
+ | Parameter | Description |
80
+ |-----------|-------------|
81
+ | `set_name` | Set name under `storage rs:set_int` |
82
+ | `value` | Integer value to remove |
83
+
84
+ **Example**
85
+
86
+ ```redscript
87
+ set_remove("Visited", 42)
88
+ ```
89
+
90
+ ---
91
+
92
+ ## `set_size` <Badge type="info" text="v3.0.0" />
93
+
94
+ Returns the number of elements in `storage rs:set_int.{set_name}`.
95
+
96
+ Missing sets return `0`.
97
+
98
+ ```redscript
99
+ fn set_size(set_name: string): int
100
+ ```
101
+
102
+ **Parameters**
103
+
104
+ | Parameter | Description |
105
+ |-----------|-------------|
106
+ | `set_name` | Set name under `storage rs:set_int` |
107
+
108
+ **Returns:** Current element count
109
+
110
+ **Example**
111
+
112
+ ```redscript
113
+ let count: int = set_size("Visited")
114
+ ```
115
+
116
+ ---
117
+
118
+ ## `set_clear` <Badge type="info" text="v3.0.0" />
119
+
120
+ Clears all elements from `storage rs:set_int.{set_name}`.
121
+
122
+ ```redscript
123
+ fn set_clear(set_name: string)
124
+ ```
125
+
126
+ **Parameters**
127
+
128
+ | Parameter | Description |
129
+ |-----------|-------------|
130
+ | `set_name` | Set name under `storage rs:set_int` |
131
+
132
+ **Example**
133
+
134
+ ```redscript
135
+ set_clear("Visited")
136
+ ```
137
+
138
+ ---
139
+
140
+ ## `set_union` <Badge type="info" text="v3.0.0" />
141
+
142
+ Computes `result = a ∪ b`.
143
+
144
+ The destination set is overwritten with a deduplicated list.
145
+
146
+ ```redscript
147
+ fn set_union(a: string, b: string, result: string)
148
+ ```
149
+
150
+ **Parameters**
151
+
152
+ | Parameter | Description |
153
+ |-----------|-------------|
154
+ | `a` | Left-hand input set name |
155
+ | `b` | Right-hand input set name |
156
+ | `result` | Destination set name |
157
+
158
+ **Example**
159
+
160
+ ```redscript
161
+ set_union("SeenA", "SeenB", "SeenAll")
162
+ ```
163
+
164
+ ---
165
+
166
+ ## `set_intersect` <Badge type="info" text="v3.0.0" />
167
+
168
+ Computes `result = a ∩ b`.
169
+
170
+ The destination set is overwritten with a deduplicated list.
171
+
172
+ ```redscript
173
+ fn set_intersect(a: string, b: string, result: string)
174
+ ```
175
+
176
+ **Parameters**
177
+
178
+ | Parameter | Description |
179
+ |-----------|-------------|
180
+ | `a` | Left-hand input set name |
181
+ | `b` | Right-hand input set name |
182
+ | `result` | Destination set name |
183
+
184
+ **Example**
185
+
186
+ ```redscript
187
+ set_intersect("SeenA", "SeenB", "SeenBoth")
188
+ ```
189
+
190
+ ---
@@ -0,0 +1,101 @@
1
+ # Sets
2
+
3
+ > Auto-generated from `src/stdlib/sets.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [set_new](#set-new)
8
+ - [set_add](#set-add)
9
+ - [set_contains](#set-contains)
10
+ - [set_remove](#set-remove)
11
+ - [set_clear](#set-clear)
12
+
13
+ ---
14
+
15
+ ## `set_new` <Badge type="info" text="v1.1.0" />
16
+
17
+ Create a new empty set and return its unique set ID (string handle).
18
+
19
+ ```redscript
20
+ fn set_new(): string
21
+ ```
22
+
23
+ **Returns:** A unique set ID used by all other set operations
24
+
25
+ **Example**
26
+
27
+ ```redscript
28
+ let s: string = set_new();
29
+ set_add(s, "apple");
30
+ ```
31
+
32
+ ---
33
+
34
+ ## `set_add` <Badge type="info" text="v1.1.0" />
35
+
36
+ Add a value to the set if it is not already present (no-op if already contained).
37
+
38
+ ```redscript
39
+ fn set_add(set: string, value: string)
40
+ ```
41
+
42
+ **Parameters**
43
+
44
+ | Parameter | Description |
45
+ |-----------|-------------|
46
+ | `set` | Set ID returned by `set_new` |
47
+ | `value` | Value to add |
48
+
49
+ ---
50
+
51
+ ## `set_contains` <Badge type="info" text="v1.1.0" />
52
+
53
+ Test whether a value exists in the set.
54
+
55
+ ```redscript
56
+ fn set_contains(set: string, value: string): int
57
+ ```
58
+
59
+ **Parameters**
60
+
61
+ | Parameter | Description |
62
+ |-----------|-------------|
63
+ | `set` | Set ID returned by `set_new` |
64
+ | `value` | Value to look up |
65
+
66
+ **Returns:** 1 if the value is in the set, 0 otherwise
67
+
68
+ ---
69
+
70
+ ## `set_remove` <Badge type="info" text="v1.1.0" />
71
+
72
+ Remove a value from the set (no-op if not present).
73
+
74
+ ```redscript
75
+ fn set_remove(set: string, value: string)
76
+ ```
77
+
78
+ **Parameters**
79
+
80
+ | Parameter | Description |
81
+ |-----------|-------------|
82
+ | `set` | Set ID returned by `set_new` |
83
+ | `value` | Value to remove |
84
+
85
+ ---
86
+
87
+ ## `set_clear` <Badge type="info" text="v1.1.0" />
88
+
89
+ Remove all values from the set, leaving it empty.
90
+
91
+ ```redscript
92
+ fn set_clear(set: string)
93
+ ```
94
+
95
+ **Parameters**
96
+
97
+ | Parameter | Description |
98
+ |-----------|-------------|
99
+ | `set` | Set ID returned by `set_new` |
100
+
101
+ ---
@@ -0,0 +1,400 @@
1
+ # Signal
2
+
3
+ > Auto-generated from `src/stdlib/signal.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [uniform_int](#uniform-int)
8
+ - [uniform_frac](#uniform-frac)
9
+ - [normal_approx12](#normal-approx12)
10
+ - [exp_dist_approx](#exp-dist-approx)
11
+ - [bernoulli](#bernoulli)
12
+ - [weighted2](#weighted2)
13
+ - [weighted3](#weighted3)
14
+ - [gamma_sample](#gamma-sample)
15
+ - [poisson_sample](#poisson-sample)
16
+ - [geometric_sample](#geometric-sample)
17
+ - [negative_binomial_sample](#negative-binomial-sample)
18
+ - [dft_real](#dft-real)
19
+ - [dft_imag](#dft-imag)
20
+ - [dft_magnitude](#dft-magnitude)
21
+
22
+ ---
23
+
24
+ ## `uniform_int` <Badge type="info" text="v2.0.0" />
25
+
26
+ Return a uniform integer in `[lo, hi]` inclusive.
27
+
28
+ Uses LCG RNG. Pass the result as the seed for the next call to chain samples.
29
+
30
+ ```redscript
31
+ fn uniform_int(seed: int, lo: int, hi: int): int
32
+ ```
33
+
34
+ **Parameters**
35
+
36
+ | Parameter | Description |
37
+ |-----------|-------------|
38
+ | `seed` | Any integer seed value |
39
+ | `lo` | Inclusive lower bound |
40
+ | `hi` | Inclusive upper bound |
41
+
42
+ **Returns:** Pseudo-random integer in [lo, hi]
43
+
44
+ **Example**
45
+
46
+ ```redscript
47
+ let dmg: int = uniform_int(seed, 5, 15)
48
+ ```
49
+
50
+ ---
51
+
52
+ ## `uniform_frac` <Badge type="info" text="v2.0.0" />
53
+
54
+ Return a uniform fraction in [0, 10000] (×10000 scale).
55
+
56
+ ```redscript
57
+ fn uniform_frac(seed: int): int
58
+ ```
59
+
60
+ **Parameters**
61
+
62
+ | Parameter | Description |
63
+ |-----------|-------------|
64
+ | `seed` | Any integer seed value |
65
+
66
+ **Returns:** Pseudo-random integer in [0, 10000]
67
+
68
+ **Example**
69
+
70
+ ```redscript
71
+ let frac: int = uniform_frac(seed)
72
+ ```
73
+
74
+ ---
75
+
76
+ ## `normal_approx12` <Badge type="info" text="v2.0.0" />
77
+
78
+ Approximate N(0, 1) variate using the Irwin–Hall method (sum of 12 uniform samples).
79
+
80
+ Result is in ×10000 scale, range approximately [−60000, 60000].
81
+ Each call chains the seed 12 times internally.
82
+
83
+ ```redscript
84
+ fn normal_approx12(seed: int): int
85
+ ```
86
+
87
+ **Parameters**
88
+
89
+ | Parameter | Description |
90
+ |-----------|-------------|
91
+ | `seed` | Any integer seed value |
92
+
93
+ **Returns:** Approximate N(0,1) sample ×10000
94
+
95
+ **Example**
96
+
97
+ ```redscript
98
+ let z: int = normal_approx12(seed)
99
+ ```
100
+
101
+ ---
102
+
103
+ ## `exp_dist_approx` <Badge type="info" text="v2.0.0" />
104
+
105
+ Sample from an exponential distribution with rate `lambda_fx`.
106
+
107
+ Method: `-ln(U) / λ` where `U ~ Uniform(0.01, 1)`. Result is capped at
108
+ `100000` (= 10.0 × 10000) for Minecraft sanity.
109
+
110
+ Requires `import "stdlib/math"` for the `ln` function.
111
+
112
+ ```redscript
113
+ fn exp_dist_approx(seed: int, lambda_fx: int): int
114
+ ```
115
+
116
+ **Parameters**
117
+
118
+ | Parameter | Description |
119
+ |-----------|-------------|
120
+ | `seed` | Any integer seed value |
121
+ | `lambda_fx` | Rate parameter ×10000 (e.g. `10000` = rate 1.0) |
122
+
123
+ **Returns:** Exponential variate ×10000, capped at 100000
124
+
125
+ **Example**
126
+
127
+ ```redscript
128
+ let wait: int = exp_dist_approx(seed, 10000)
129
+ ```
130
+
131
+ ---
132
+
133
+ ## `bernoulli` <Badge type="info" text="v2.0.0" />
134
+
135
+ Return `1` with probability `p_fx / 10000`, otherwise `0`.
136
+
137
+ ```redscript
138
+ fn bernoulli(seed: int, p_fx: int): int
139
+ ```
140
+
141
+ **Parameters**
142
+
143
+ | Parameter | Description |
144
+ |-----------|-------------|
145
+ | `seed` | Any integer seed value |
146
+ | `p_fx` | Probability ×10000 (e.g. `5000` = 50%, `1000` = 10%) |
147
+
148
+ **Returns:** `1` with the given probability, `0` otherwise
149
+
150
+ **Example**
151
+
152
+ ```redscript
153
+ if (bernoulli(seed, 3000) == 1) { /* 30% chance */ }
154
+ ```
155
+
156
+ ---
157
+
158
+ ## `weighted2` <Badge type="info" text="v2.0.0" />
159
+
160
+ Choose `0` or `1` with the given integer weights.
161
+
162
+ ```redscript
163
+ fn weighted2(seed: int, w0: int, w1: int): int
164
+ ```
165
+
166
+ **Parameters**
167
+
168
+ | Parameter | Description |
169
+ |-----------|-------------|
170
+ | `seed` | Any integer seed value |
171
+ | `w0` | Weight for outcome `0` |
172
+ | `w1` | Weight for outcome `1` |
173
+
174
+ **Returns:** `0` or `1` sampled proportionally to the weights
175
+
176
+ **Example**
177
+
178
+ ```redscript
179
+ let side: int = weighted2(seed, 3, 7)
180
+ ```
181
+
182
+ ---
183
+
184
+ ## `weighted3` <Badge type="info" text="v2.0.0" />
185
+
186
+ Choose `0`, `1`, or `2` with the given integer weights.
187
+
188
+ ```redscript
189
+ fn weighted3(seed: int, w0: int, w1: int, w2: int): int
190
+ ```
191
+
192
+ **Parameters**
193
+
194
+ | Parameter | Description |
195
+ |-----------|-------------|
196
+ | `seed` | Any integer seed value |
197
+ | `w0` | Weight for outcome `0` |
198
+ | `w1` | Weight for outcome `1` |
199
+ | `w2` | Weight for outcome `2` |
200
+
201
+ **Returns:** `0`, `1`, or `2` sampled proportionally to the weights
202
+
203
+ **Example**
204
+
205
+ ```redscript
206
+ let tier: int = weighted3(seed, 50, 30, 20)
207
+ ```
208
+
209
+ ---
210
+
211
+ ## `gamma_sample` <Badge type="info" text="v2.0.0" />
212
+
213
+ Sample from a Gamma(k, θ) distribution via summing k exponential samples.
214
+
215
+ Handles integer shape `k = 1..5` (pass `shape_k × 10000`).
216
+ Requires `ln` from `stdlib/math`.
217
+
218
+ ```redscript
219
+ fn gamma_sample(shape_k: int, scale_theta: int, seed: int): int
220
+ ```
221
+
222
+ **Parameters**
223
+
224
+ | Parameter | Description |
225
+ |-----------|-------------|
226
+ | `shape_k` | Shape parameter k ×10000 (e.g. `20000` = k=2) |
227
+ | `scale_theta` | Scale parameter θ ×10000 (e.g. `10000` = θ=1.0) |
228
+ | `seed` | Any integer seed value |
229
+
230
+ **Returns:** Gamma variate ×10000
231
+
232
+ **Example**
233
+
234
+ ```redscript
235
+ let g: int = gamma_sample(20000, 10000, seed)
236
+ ```
237
+
238
+ ---
239
+
240
+ ## `poisson_sample` <Badge type="info" text="v2.0.0" />
241
+
242
+ Sample from a Poisson(λ) distribution using the Knuth algorithm.
243
+
244
+ Works well for `lambda ≤ 20` (200000 in ×10000). Hard cap at 100 iterations.
245
+ Requires `exp_fx` from `stdlib/math`.
246
+
247
+ ```redscript
248
+ fn poisson_sample(lambda: int, seed: int): int
249
+ ```
250
+
251
+ **Parameters**
252
+
253
+ | Parameter | Description |
254
+ |-----------|-------------|
255
+ | `lambda` | Rate parameter ×10000 (e.g. `30000` = λ=3.0) |
256
+ | `seed` | Any integer seed value |
257
+
258
+ **Returns:** Poisson count (plain integer, not ×10000)
259
+
260
+ **Example**
261
+
262
+ ```redscript
263
+ let n: int = poisson_sample(30000, seed)
264
+ ```
265
+
266
+ ---
267
+
268
+ ## `geometric_sample` <Badge type="info" text="v2.0.0" />
269
+
270
+ Sample from a Geometric(p) distribution (number of failures before first success).
271
+
272
+ Method: `floor(ln(U) / ln(1 - p))`. Requires `ln` from `stdlib/math`.
273
+
274
+ ```redscript
275
+ fn geometric_sample(p_success: int, seed: int): int
276
+ ```
277
+
278
+ **Parameters**
279
+
280
+ | Parameter | Description |
281
+ |-----------|-------------|
282
+ | `p_success` | Success probability ×10000 (e.g. `5000` = p=0.5) |
283
+ | `seed` | Any integer seed value |
284
+
285
+ **Returns:** Non-negative integer count of failures
286
+
287
+ **Example**
288
+
289
+ ```redscript
290
+ let fails: int = geometric_sample(5000, seed)
291
+ ```
292
+
293
+ ---
294
+
295
+ ## `negative_binomial_sample` <Badge type="info" text="v2.0.0" />
296
+
297
+ Sample from a Negative Binomial NegBin(r, p) distribution.
298
+
299
+ Method: sum `r` independent Geometric(p) samples.
300
+
301
+ ```redscript
302
+ fn negative_binomial_sample(r: int, p_success: int, seed: int): int
303
+ ```
304
+
305
+ **Parameters**
306
+
307
+ | Parameter | Description |
308
+ |-----------|-------------|
309
+ | `r` | Number of successes (plain integer, e.g. 1, 2, 3) |
310
+ | `p_success` | Success probability ×10000 (e.g. `5000` = p=0.5) |
311
+ | `seed` | Any integer seed value |
312
+
313
+ **Returns:** Total number of failures before `r` successes
314
+
315
+ **Example**
316
+
317
+ ```redscript
318
+ let n: int = negative_binomial_sample(3, 5000, seed)
319
+ ```
320
+
321
+ ---
322
+
323
+ ## `dft_real` <Badge type="info" text="v2.0.0" />
324
+
325
+ Real part of DFT bin `k` for a real-valued signal with up to 8 samples.
326
+
327
+ All values use ×10000 scale. Angle convention: multiples of 45°.
328
+ Unused sample arguments (beyond `n`) are ignored.
329
+
330
+ Formula: `real[k] = (1/n) Σ samples[j] × cos(2πkj/n)`
331
+
332
+ ```redscript
333
+ fn dft_real(s0: int, s1: int, s2: int, s3: int, s4: int, s5: int, s6: int, s7: int, n: int, k: int): int
334
+ ```
335
+
336
+ **Parameters**
337
+
338
+ | Parameter | Description |
339
+ |-----------|-------------|
340
+ | `s0` | Sample 0 ×10000 … @param s7 Sample 7 ×10000 |
341
+ | `n` | Number of samples (1–8) |
342
+ | `k` | Bin index (0 to n−1) |
343
+
344
+ **Returns:** Real part of DFT bin k, ×10000
345
+
346
+ **Example**
347
+
348
+ ```redscript
349
+ let re0: int = dft_real(10000, 0, -10000, 0, 0, 0, 0, 0, 4, 0)
350
+ ```
351
+
352
+ ---
353
+
354
+ ## `dft_imag` <Badge type="info" text="v2.0.0" />
355
+
356
+ Imaginary part of DFT bin `k` for a real-valued signal with up to 8 samples.
357
+
358
+ Uses the negative-sine convention: `imag[k] = -(1/n) Σ samples[j] × sin(2πkj/n)`
359
+
360
+ ```redscript
361
+ fn dft_imag(s0: int, s1: int, s2: int, s3: int, s4: int, s5: int, s6: int, s7: int, n: int, k: int): int
362
+ ```
363
+
364
+ **Parameters**
365
+
366
+ | Parameter | Description |
367
+ |-----------|-------------|
368
+ | `s0` | Sample 0 ×10000 … @param s7 Sample 7 ×10000 |
369
+ | `n` | Number of samples (1–8) |
370
+ | `k` | Bin index (0 to n−1) |
371
+
372
+ **Returns:** Imaginary part of DFT bin k, ×10000
373
+
374
+ ---
375
+
376
+ ## `dft_magnitude` <Badge type="info" text="v2.0.0" />
377
+
378
+ Magnitude of DFT bin `k`: `sqrt(real² + imag²)` in ×10000.
379
+
380
+ ```redscript
381
+ fn dft_magnitude(s0: int, s1: int, s2: int, s3: int, s4: int, s5: int, s6: int, s7: int, n: int, k: int): int
382
+ ```
383
+
384
+ **Parameters**
385
+
386
+ | Parameter | Description |
387
+ |-----------|-------------|
388
+ | `s0` | Sample 0 ×10000 … @param s7 Sample 7 ×10000 |
389
+ | `n` | Number of samples (1–8) |
390
+ | `k` | Bin index (0 to n−1) |
391
+
392
+ **Returns:** Magnitude of DFT bin k in ×10000
393
+
394
+ **Example**
395
+
396
+ ```redscript
397
+ let mag: int = dft_magnitude(10000, 0, -10000, 0, 0, 0, 0, 0, 4, 1)
398
+ ```
399
+
400
+ ---