freelang-v4 4.3.0

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 (261) hide show
  1. package/README.md +548 -0
  2. package/dist/ast.d.ts +367 -0
  3. package/dist/ast.js +4 -0
  4. package/dist/ast.js.map +1 -0
  5. package/dist/async-basic.test.d.ts +1 -0
  6. package/dist/async-basic.test.js +88 -0
  7. package/dist/async-basic.test.js.map +1 -0
  8. package/dist/async-jest.test.d.ts +1 -0
  9. package/dist/async-jest.test.js +99 -0
  10. package/dist/async-jest.test.js.map +1 -0
  11. package/dist/channel-jest.test.d.ts +1 -0
  12. package/dist/channel-jest.test.js +148 -0
  13. package/dist/channel-jest.test.js.map +1 -0
  14. package/dist/checker-jest.test.d.ts +1 -0
  15. package/dist/checker-jest.test.js +160 -0
  16. package/dist/checker-jest.test.js.map +1 -0
  17. package/dist/checker.d.ts +149 -0
  18. package/dist/checker.js +1565 -0
  19. package/dist/checker.js.map +1 -0
  20. package/dist/checker.test.d.ts +1 -0
  21. package/dist/checker.test.js +217 -0
  22. package/dist/checker.test.js.map +1 -0
  23. package/dist/compiler-jest.test.d.ts +1 -0
  24. package/dist/compiler-jest.test.js +233 -0
  25. package/dist/compiler-jest.test.js.map +1 -0
  26. package/dist/compiler.d.ts +127 -0
  27. package/dist/compiler.js +1588 -0
  28. package/dist/compiler.js.map +1 -0
  29. package/dist/compiler.test.d.ts +1 -0
  30. package/dist/compiler.test.js +313 -0
  31. package/dist/compiler.test.js.map +1 -0
  32. package/dist/db-100m-full.d.ts +5 -0
  33. package/dist/db-100m-full.js +78 -0
  34. package/dist/db-100m-full.js.map +1 -0
  35. package/dist/db-100m-no-index.d.ts +12 -0
  36. package/dist/db-100m-no-index.js +119 -0
  37. package/dist/db-100m-no-index.js.map +1 -0
  38. package/dist/db-100m-real.d.ts +5 -0
  39. package/dist/db-100m-real.js +131 -0
  40. package/dist/db-100m-real.js.map +1 -0
  41. package/dist/db-100m-streaming.d.ts +15 -0
  42. package/dist/db-100m-streaming.js +164 -0
  43. package/dist/db-100m-streaming.js.map +1 -0
  44. package/dist/db-100m-test.d.ts +5 -0
  45. package/dist/db-100m-test.js +111 -0
  46. package/dist/db-100m-test.js.map +1 -0
  47. package/dist/db-jest.test.d.ts +1 -0
  48. package/dist/db-jest.test.js +182 -0
  49. package/dist/db-jest.test.js.map +1 -0
  50. package/dist/db-runtime.d.ts +24 -0
  51. package/dist/db-runtime.js +204 -0
  52. package/dist/db-runtime.js.map +1 -0
  53. package/dist/db.d.ts +249 -0
  54. package/dist/db.js +593 -0
  55. package/dist/db.js.map +1 -0
  56. package/dist/file-io-jest.test.d.ts +1 -0
  57. package/dist/file-io-jest.test.js +225 -0
  58. package/dist/file-io-jest.test.js.map +1 -0
  59. package/dist/for-of-jest.test.d.ts +1 -0
  60. package/dist/for-of-jest.test.js +230 -0
  61. package/dist/for-of-jest.test.js.map +1 -0
  62. package/dist/for-of.test.d.ts +1 -0
  63. package/dist/for-of.test.js +305 -0
  64. package/dist/for-of.test.js.map +1 -0
  65. package/dist/function-literal-jest.test.d.ts +1 -0
  66. package/dist/function-literal-jest.test.js +180 -0
  67. package/dist/function-literal-jest.test.js.map +1 -0
  68. package/dist/function-literal.test.d.ts +1 -0
  69. package/dist/function-literal.test.js +245 -0
  70. package/dist/function-literal.test.js.map +1 -0
  71. package/dist/generics-jest.test.d.ts +1 -0
  72. package/dist/generics-jest.test.js +93 -0
  73. package/dist/generics-jest.test.js.map +1 -0
  74. package/dist/ir-gen.d.ts +15 -0
  75. package/dist/ir-gen.js +400 -0
  76. package/dist/ir-gen.js.map +1 -0
  77. package/dist/ir.d.ts +114 -0
  78. package/dist/ir.js +5 -0
  79. package/dist/ir.js.map +1 -0
  80. package/dist/lexer.d.ts +110 -0
  81. package/dist/lexer.js +467 -0
  82. package/dist/lexer.js.map +1 -0
  83. package/dist/lexer.test.d.ts +1 -0
  84. package/dist/lexer.test.js +426 -0
  85. package/dist/lexer.test.js.map +1 -0
  86. package/dist/main.d.ts +2 -0
  87. package/dist/main.js +241 -0
  88. package/dist/main.js.map +1 -0
  89. package/dist/module-jest.test.d.ts +1 -0
  90. package/dist/module-jest.test.js +123 -0
  91. package/dist/module-jest.test.js.map +1 -0
  92. package/dist/parser.d.ts +56 -0
  93. package/dist/parser.js +1060 -0
  94. package/dist/parser.js.map +1 -0
  95. package/dist/parser.test.d.ts +1 -0
  96. package/dist/parser.test.js +461 -0
  97. package/dist/parser.test.js.map +1 -0
  98. package/dist/pattern-matching-jest.test.d.ts +1 -0
  99. package/dist/pattern-matching-jest.test.js +158 -0
  100. package/dist/pattern-matching-jest.test.js.map +1 -0
  101. package/dist/pkg/init.d.ts +1 -0
  102. package/dist/pkg/init.js +118 -0
  103. package/dist/pkg/init.js.map +1 -0
  104. package/dist/pkg/install.d.ts +1 -0
  105. package/dist/pkg/install.js +77 -0
  106. package/dist/pkg/install.js.map +1 -0
  107. package/dist/pkg/registry.d.ts +23 -0
  108. package/dist/pkg/registry.js +106 -0
  109. package/dist/pkg/registry.js.map +1 -0
  110. package/dist/pkg/run.d.ts +1 -0
  111. package/dist/pkg/run.js +76 -0
  112. package/dist/pkg/run.js.map +1 -0
  113. package/dist/pkg/toml.d.ts +5 -0
  114. package/dist/pkg/toml.js +117 -0
  115. package/dist/pkg/toml.js.map +1 -0
  116. package/dist/repl.d.ts +15 -0
  117. package/dist/repl.js +197 -0
  118. package/dist/repl.js.map +1 -0
  119. package/dist/runtime/bytecode.d.ts +92 -0
  120. package/dist/runtime/bytecode.js +253 -0
  121. package/dist/runtime/bytecode.js.map +1 -0
  122. package/dist/runtime/value.d.ts +102 -0
  123. package/dist/runtime/value.js +302 -0
  124. package/dist/runtime/value.js.map +1 -0
  125. package/dist/runtime/vm.d.ts +65 -0
  126. package/dist/runtime/vm.js +293 -0
  127. package/dist/runtime/vm.js.map +1 -0
  128. package/dist/struct-instance-jest.test.d.ts +1 -0
  129. package/dist/struct-instance-jest.test.js +209 -0
  130. package/dist/struct-instance-jest.test.js.map +1 -0
  131. package/dist/struct-instance.test.d.ts +1 -0
  132. package/dist/struct-instance.test.js +291 -0
  133. package/dist/struct-instance.test.js.map +1 -0
  134. package/dist/struct-jest.test.d.ts +1 -0
  135. package/dist/struct-jest.test.js +176 -0
  136. package/dist/struct-jest.test.js.map +1 -0
  137. package/dist/struct.test.d.ts +1 -0
  138. package/dist/struct.test.js +231 -0
  139. package/dist/struct.test.js.map +1 -0
  140. package/dist/trait-jest.test.d.ts +1 -0
  141. package/dist/trait-jest.test.js +120 -0
  142. package/dist/trait-jest.test.js.map +1 -0
  143. package/dist/vm-jest.test.d.ts +1 -0
  144. package/dist/vm-jest.test.js +569 -0
  145. package/dist/vm-jest.test.js.map +1 -0
  146. package/dist/vm.d.ts +81 -0
  147. package/dist/vm.js +1956 -0
  148. package/dist/vm.js.map +1 -0
  149. package/dist/vm.test.d.ts +1 -0
  150. package/dist/vm.test.js +337 -0
  151. package/dist/vm.test.js.map +1 -0
  152. package/dist/web-repl/sandbox.d.ts +11 -0
  153. package/dist/web-repl/sandbox.js +76 -0
  154. package/dist/web-repl/sandbox.js.map +1 -0
  155. package/dist/web-repl/server.d.ts +1 -0
  156. package/dist/web-repl/server.js +111 -0
  157. package/dist/web-repl/server.js.map +1 -0
  158. package/dist/while-loop-jest.test.d.ts +1 -0
  159. package/dist/while-loop-jest.test.js +201 -0
  160. package/dist/while-loop-jest.test.js.map +1 -0
  161. package/dist/while-loop.test.d.ts +1 -0
  162. package/dist/while-loop.test.js +262 -0
  163. package/dist/while-loop.test.js.map +1 -0
  164. package/docs/EXPERIENCE.md +787 -0
  165. package/docs/README.md +175 -0
  166. package/docs/V1_V2_V3_ANALYSIS.md +107 -0
  167. package/docs/_config.yml +36 -0
  168. package/docs/api-reference.md +459 -0
  169. package/docs/architecture.md +470 -0
  170. package/docs/benchmarks.md +295 -0
  171. package/docs/comparison.md +454 -0
  172. package/docs/index.md +335 -0
  173. package/docs/language-completeness.md +228 -0
  174. package/docs/learning-guide.md +651 -0
  175. package/package.json +65 -0
  176. package/src/api/deploy_key.fl +294 -0
  177. package/src/api/issue.fl +302 -0
  178. package/src/api/org.fl +356 -0
  179. package/src/api/repo.fl +394 -0
  180. package/src/api/team.fl +299 -0
  181. package/src/api/user.fl +385 -0
  182. package/src/api/webhook.fl +273 -0
  183. package/src/ast.ts +158 -0
  184. package/src/async-basic.test.ts +94 -0
  185. package/src/async-jest.test.ts +107 -0
  186. package/src/channel-jest.test.ts +158 -0
  187. package/src/checker-jest.test.ts +189 -0
  188. package/src/checker.test.ts +279 -0
  189. package/src/checker.ts +1861 -0
  190. package/src/commands/analyze.fl +227 -0
  191. package/src/commands/auth.fl +315 -0
  192. package/src/commands/batch.fl +349 -0
  193. package/src/commands/config.fl +199 -0
  194. package/src/commands/deploy_key.fl +352 -0
  195. package/src/commands/issue.fl +275 -0
  196. package/src/commands/main.fl +492 -0
  197. package/src/commands/org.fl +425 -0
  198. package/src/commands/repo.fl +581 -0
  199. package/src/commands/team.fl +244 -0
  200. package/src/commands/user.fl +423 -0
  201. package/src/commands/webhook.fl +400 -0
  202. package/src/compiler-jest.test.ts +275 -0
  203. package/src/compiler.test.ts +375 -0
  204. package/src/compiler.ts +1770 -0
  205. package/src/config.fl +175 -0
  206. package/src/core/batch.fl +355 -0
  207. package/src/core/cache.fl +284 -0
  208. package/src/core/ensure.fl +324 -0
  209. package/src/db-100m-full.ts +96 -0
  210. package/src/db-100m-no-index.ts +133 -0
  211. package/src/db-100m-real.ts +152 -0
  212. package/src/db-100m-streaming.ts +154 -0
  213. package/src/db-100m-test.ts +136 -0
  214. package/src/db-jest.test.ts +161 -0
  215. package/src/db-runtime.ts +242 -0
  216. package/src/db.ts +676 -0
  217. package/src/errors.fl +134 -0
  218. package/src/for-of-jest.test.ts +246 -0
  219. package/src/for-of.test.ts +308 -0
  220. package/src/function-literal-jest.test.ts +193 -0
  221. package/src/function-literal.test.ts +248 -0
  222. package/src/generics-jest.test.ts +104 -0
  223. package/src/http/client.fl +327 -0
  224. package/src/ir-gen.ts +459 -0
  225. package/src/ir.ts +80 -0
  226. package/src/lexer.test.ts +499 -0
  227. package/src/lexer.ts +522 -0
  228. package/src/main.ts +223 -0
  229. package/src/models.fl +162 -0
  230. package/src/module-jest.test.ts +145 -0
  231. package/src/parser.test.ts +542 -0
  232. package/src/parser.ts +1211 -0
  233. package/src/pattern-matching-jest.test.ts +170 -0
  234. package/src/pkg/init.ts +91 -0
  235. package/src/pkg/install.ts +56 -0
  236. package/src/pkg/registry.ts +103 -0
  237. package/src/pkg/run.ts +49 -0
  238. package/src/pkg/toml.ts +129 -0
  239. package/src/repl.ts +190 -0
  240. package/src/runtime/bytecode.ts +291 -0
  241. package/src/runtime/value.ts +322 -0
  242. package/src/runtime/vm.ts +354 -0
  243. package/src/self-host/bootstrap.fl +68 -0
  244. package/src/self-host/interpreter.fl +361 -0
  245. package/src/self-host/lexer-simple.fl +22 -0
  246. package/src/self-host/lexer.fl +305 -0
  247. package/src/self-host/parser.fl +580 -0
  248. package/src/struct-instance-jest.test.ts +221 -0
  249. package/src/struct-instance.test.ts +293 -0
  250. package/src/struct-jest.test.ts +187 -0
  251. package/src/struct.test.ts +234 -0
  252. package/src/trait-jest.test.ts +136 -0
  253. package/src/vm-jest.test.ts +754 -0
  254. package/src/vm.ts +1976 -0
  255. package/src/web-repl/public/index.html +50 -0
  256. package/src/web-repl/public/main.js +105 -0
  257. package/src/web-repl/public/style.css +225 -0
  258. package/src/web-repl/sandbox.ts +88 -0
  259. package/src/web-repl/server.ts +97 -0
  260. package/src/while-loop-jest.test.ts +218 -0
  261. package/src/while-loop.test.ts +267 -0
@@ -0,0 +1,754 @@
1
+ // FreeLang v4 — VM 테스트 (E2E: Source → Lexer → Parser → Compiler → VM) - Jest Format
2
+
3
+ import { Lexer } from "./lexer";
4
+ import { Parser } from "./parser";
5
+ import { Compiler } from "./compiler";
6
+ import { VM } from "./vm";
7
+
8
+ async function exec(source: string): Promise<{ output: string[]; error: string | null }> {
9
+ const { tokens, errors: lexErrors } = new Lexer(source).tokenize();
10
+ if (lexErrors.length > 0) throw new Error(`Lex: ${lexErrors[0].message}`);
11
+ const { program, errors: parseErrors } = new Parser(tokens).parse();
12
+ if (parseErrors.length > 0) throw new Error(`Parse: ${parseErrors[0].message}`);
13
+ const chunk = new Compiler().compile(program);
14
+ return await new VM().run(chunk);
15
+ }
16
+
17
+ // ============================================================
18
+ // Jest Tests
19
+ // ============================================================
20
+
21
+ describe("VM E2E Tests", () => {
22
+ describe("println 기본", () => {
23
+ it('println("hello")', async () => {
24
+ const { output } = await exec('println("hello")');
25
+ expect(output).toEqual(["hello"]);
26
+ });
27
+
28
+ it('println("hello world")', async () => {
29
+ const { output } = await exec('println("hello world")');
30
+ expect(output).toEqual(["hello world"]);
31
+ });
32
+ });
33
+
34
+ describe("정수 산술", () => {
35
+ it("1 + 2 = 3", async () => {
36
+ const { output } = await exec('println(str(1 + 2))');
37
+ expect(output).toEqual(["3"]);
38
+ });
39
+
40
+ it("10 - 3 = 7", async () => {
41
+ const { output } = await exec('println(str(10 - 3))');
42
+ expect(output).toEqual(["7"]);
43
+ });
44
+
45
+ it("4 * 5 = 20", async () => {
46
+ const { output } = await exec('println(str(4 * 5))');
47
+ expect(output).toEqual(["20"]);
48
+ });
49
+
50
+ it("10 / 3 = 3 (i32 truncate)", async () => {
51
+ const { output } = await exec('println(str(10 / 3))');
52
+ expect(output).toEqual(["3"]);
53
+ });
54
+
55
+ it("7 % 3 = 1", async () => {
56
+ const { output } = await exec('println(str(7 % 3))');
57
+ expect(output).toEqual(["1"]);
58
+ });
59
+
60
+ it("-42 (negate)", async () => {
61
+ const { output } = await exec('println(str(-42))');
62
+ expect(output).toEqual(["-42"]);
63
+ });
64
+
65
+ it("2 + 3 * 4 = 14 (precedence)", async () => {
66
+ const { output } = await exec('println(str(2 + 3 * 4))');
67
+ expect(output).toEqual(["14"]);
68
+ });
69
+ });
70
+
71
+ describe("문자열 연결", () => {
72
+ it('string concat', async () => {
73
+ const { output } = await exec('println("hello" + " " + "world")');
74
+ expect(output).toEqual(["hello world"]);
75
+ });
76
+ });
77
+
78
+ describe("비교 + 논리", () => {
79
+ it("1 == 1", async () => {
80
+ const { output } = await exec('println(str(1 == 1))');
81
+ expect(output).toEqual(["true"]);
82
+ });
83
+
84
+ it("1 == 2", async () => {
85
+ const { output } = await exec('println(str(1 == 2))');
86
+ expect(output).toEqual(["false"]);
87
+ });
88
+
89
+ it("1 != 2", async () => {
90
+ const { output } = await exec('println(str(1 != 2))');
91
+ expect(output).toEqual(["true"]);
92
+ });
93
+
94
+ it("1 < 2", async () => {
95
+ const { output } = await exec('println(str(1 < 2))');
96
+ expect(output).toEqual(["true"]);
97
+ });
98
+
99
+ it("2 > 1", async () => {
100
+ const { output } = await exec('println(str(2 > 1))');
101
+ expect(output).toEqual(["true"]);
102
+ });
103
+
104
+ it("true && false", async () => {
105
+ const { output } = await exec('println(str(true && false))');
106
+ expect(output).toEqual(["false"]);
107
+ });
108
+
109
+ it("false || true", async () => {
110
+ const { output } = await exec('println(str(false || true))');
111
+ expect(output).toEqual(["true"]);
112
+ });
113
+ });
114
+
115
+ describe("변수", () => {
116
+ it("var x = 42", async () => {
117
+ const { output } = await exec("var x = 42\nprintln(str(x))");
118
+ expect(output).toEqual(["42"]);
119
+ });
120
+
121
+ it("var name = string", async () => {
122
+ const { output } = await exec('var name = "FreeLang"\nprintln(name)');
123
+ expect(output).toEqual(["FreeLang"]);
124
+ });
125
+
126
+ it("var reassign", async () => {
127
+ const { output } = await exec("var x = 1\nx = 2\nprintln(str(x))");
128
+ expect(output).toEqual(["2"]);
129
+ });
130
+
131
+ it("a + b = 30", async () => {
132
+ const { output } = await exec("var a = 10\nvar b = 20\nprintln(str(a + b))");
133
+ expect(output).toEqual(["30"]);
134
+ });
135
+ });
136
+
137
+ describe("함수", () => {
138
+ it("fn add(3,4) = 7", async () => {
139
+ const { output } = await exec(
140
+ `fn add(a: i32, b: i32) -> i32 { return a + b }
141
+ println(str(add(3, 4)))`
142
+ );
143
+ expect(output).toEqual(["7"]);
144
+ });
145
+
146
+ it("fn double(21) = 42", async () => {
147
+ const { output } = await exec(
148
+ `fn double(n: i32) -> i32 { return n * 2 }
149
+ println(str(double(21)))`
150
+ );
151
+ expect(output).toEqual(["42"]);
152
+ });
153
+
154
+ it("fn greet void", async () => {
155
+ const { output } = await exec(
156
+ `fn greet(name: string) -> void { println("Hello " + name) }
157
+ greet("FreeLang")`
158
+ );
159
+ expect(output).toEqual(["Hello FreeLang"]);
160
+ });
161
+
162
+ it("factorial(5) = 120", async () => {
163
+ const { output } = await exec(
164
+ `fn factorial(n: i32) -> i32 {
165
+ if n <= 1 { return 1 }
166
+ return n * factorial(n + -1)
167
+ }
168
+ println(str(factorial(5)))`
169
+ );
170
+ expect(output).toEqual(["120"]);
171
+ });
172
+ });
173
+
174
+ describe("if 문", () => {
175
+ it("if true", async () => {
176
+ const { output } = await exec('if true { println("yes") }');
177
+ expect(output).toEqual(["yes"]);
178
+ });
179
+
180
+ it("if false (skip)", async () => {
181
+ const { output } = await exec('if false { println("yes") }');
182
+ expect(output).toEqual([]);
183
+ });
184
+
185
+ it("if-else true", async () => {
186
+ const { output } = await exec(
187
+ 'if true { println("yes") } else { println("no") }'
188
+ );
189
+ expect(output).toEqual(["yes"]);
190
+ });
191
+
192
+ it("if-else false", async () => {
193
+ const { output } = await exec(
194
+ 'if false { println("yes") } else { println("no") }'
195
+ );
196
+ expect(output).toEqual(["no"]);
197
+ });
198
+
199
+ it("nested if", async () => {
200
+ const { output } = await exec(
201
+ `var x = 10
202
+ if x > 5 {
203
+ if x > 20 {
204
+ println("big")
205
+ } else {
206
+ println("medium")
207
+ }
208
+ } else {
209
+ println("small")
210
+ }`
211
+ );
212
+ expect(output).toEqual(["medium"]);
213
+ });
214
+ });
215
+
216
+ describe("for 문", () => {
217
+ it("for...in [1,2,3]", async () => {
218
+ const { output } = await exec(
219
+ `for x in [1, 2, 3] {
220
+ println(str(x))
221
+ }`
222
+ );
223
+ expect(output).toEqual(["1", "2", "3"]);
224
+ });
225
+
226
+ it("for sum = 60", async () => {
227
+ const { output } = await exec(
228
+ `var total: i32 = 0
229
+ for x in [10, 20, 30] {
230
+ total = total + x
231
+ }
232
+ println(str(total))`
233
+ );
234
+ expect(output).toEqual(["60"]);
235
+ });
236
+
237
+ it("for...in range(0,5)", async () => {
238
+ const { output } = await exec(
239
+ `for i in range(0, 5) {
240
+ println(str(i))
241
+ }`
242
+ );
243
+ expect(output).toEqual(["0", "1", "2", "3", "4"]);
244
+ });
245
+ });
246
+
247
+ describe("while 문", () => {
248
+ it("while 기본", async () => {
249
+ const { output } = await exec(
250
+ `var i: i32 = 0
251
+ while i < 3 {
252
+ println(str(i))
253
+ i = i + 1
254
+ }`
255
+ );
256
+ expect(output).toEqual(["0", "1", "2"]);
257
+ });
258
+
259
+ it("while break", async () => {
260
+ const { output } = await exec(
261
+ `var i: i32 = 0
262
+ while true {
263
+ if i >= 2 { break }
264
+ println(str(i))
265
+ i = i + 1
266
+ }`
267
+ );
268
+ expect(output).toEqual(["0", "1"]);
269
+ });
270
+ });
271
+
272
+ describe("배열", () => {
273
+ it("배열 생성", async () => {
274
+ const { output } = await exec(
275
+ `var arr = [1, 2, 3]
276
+ println(str(length(arr)))`
277
+ );
278
+ expect(output).toEqual(["3"]);
279
+ });
280
+
281
+ it("배열 인덱싱", async () => {
282
+ const { output } = await exec(
283
+ `var arr = ["a", "b", "c"]
284
+ println(arr[1])`
285
+ );
286
+ expect(output).toEqual(["b"]);
287
+ });
288
+ });
289
+
290
+ describe("메모리 관리 - 스택 & 로컬 변수", () => {
291
+ it("여러 지역 변수 동시 관리", async () => {
292
+ const { output } = await exec(
293
+ `var a = 1
294
+ var b = 2
295
+ var c = 3
296
+ var d = 4
297
+ var e = 5
298
+ println(str(a + b + c + d + e))`
299
+ );
300
+ expect(output).toEqual(["15"]);
301
+ });
302
+
303
+ it("변수 재사용 (가비지 X)", async () => {
304
+ const { output } = await exec(
305
+ `var x = 10
306
+ x = 20
307
+ x = 30
308
+ x = 40
309
+ println(str(x))`
310
+ );
311
+ expect(output).toEqual(["40"]);
312
+ });
313
+
314
+ it("깊은 스택 (100+ 푸시)", async () => {
315
+ let code = "var sum: i32 = 0\n";
316
+ for (let i = 0; i < 50; i++) {
317
+ code += `sum = sum + ${i}\n`;
318
+ }
319
+ code += "println(str(sum))";
320
+ const { output } = await exec(code);
321
+ const expected = (49 * 50) / 2; // 0+1+...+49
322
+ expect(output).toEqual([String(expected)]);
323
+ });
324
+
325
+ it("중첩 블록 스코핑", async () => {
326
+ const { output } = await exec(
327
+ `var x = 10
328
+ if true {
329
+ var x = 20
330
+ println(str(x))
331
+ }
332
+ println(str(x))`
333
+ );
334
+ expect(output).toEqual(["20", "10"]);
335
+ });
336
+ });
337
+
338
+ describe("함수 호출 & 콜 스택", () => {
339
+ it("함수 체인 호출", async () => {
340
+ const { output } = await exec(
341
+ `fn f1(x: i32) -> i32 { return x + 1 }
342
+ fn f2(x: i32) -> i32 { return f1(x) + 1 }
343
+ fn f3(x: i32) -> i32 { return f2(x) + 1 }
344
+ println(str(f3(10)))`
345
+ );
346
+ expect(output).toEqual(["13"]);
347
+ });
348
+
349
+ it("함수 깊은 재귀", async () => {
350
+ const { output } = await exec(
351
+ `fn fib(n: i32) -> i32 {
352
+ if n <= 1 { return n }
353
+ return fib(n - 1) + fib(n - 2)
354
+ }
355
+ println(str(fib(6)))`
356
+ );
357
+ expect(output).toEqual(["8"]); // fib(6) = 8
358
+ });
359
+
360
+ it("함수 다중 반환값 타입", async () => {
361
+ const { output } = await exec(
362
+ `fn getInt() -> i32 { return 42 }
363
+ fn getStr() -> string { return "hello" }
364
+ fn getBool() -> bool { return true }
365
+ println(str(getInt()))
366
+ println(getStr())
367
+ println(str(getBool()))`
368
+ );
369
+ expect(output).toEqual(["42", "hello", "true"]);
370
+ });
371
+
372
+ it("상호 재귀 (서로 호출)", async () => {
373
+ const { output } = await exec(
374
+ `fn isEven(n: i32) -> bool {
375
+ if n == 0 { return true }
376
+ return isOdd(n - 1)
377
+ }
378
+ fn isOdd(n: i32) -> bool {
379
+ if n == 0 { return false }
380
+ return isEven(n - 1)
381
+ }
382
+ println(str(isEven(4)))
383
+ println(str(isOdd(3)))`
384
+ );
385
+ expect(output).toEqual(["true", "true"]);
386
+ });
387
+
388
+ it("함수 로컬 변수 격리", async () => {
389
+ const { output } = await exec(
390
+ `fn modify(x: i32) -> i32 {
391
+ var x = x * 2
392
+ x = x + 10
393
+ return x
394
+ }
395
+ var a = 5
396
+ println(str(modify(a)))
397
+ println(str(a))`
398
+ );
399
+ expect(output).toEqual(["20", "5"]);
400
+ });
401
+ });
402
+
403
+ describe("복합 데이터 구조", () => {
404
+ it("struct 필드 수정", async () => {
405
+ const { output } = await exec(
406
+ `struct Point { x: f64, y: f64 }
407
+ var p = Point { x: 1.0, y: 2.0 }
408
+ println(str(p.x))
409
+ println(str(p.y))`
410
+ );
411
+ expect(output).toEqual(["1", "2"]);
412
+ });
413
+
414
+ it("배열 요소 수정", async () => {
415
+ const { output } = await exec(
416
+ `var arr = [1, 2, 3]
417
+ arr[1] = 99
418
+ println(str(arr[0]))
419
+ println(str(arr[1]))
420
+ println(str(arr[2]))`
421
+ );
422
+ expect(output).toEqual(["1", "99", "3"]);
423
+ });
424
+
425
+ it("다중 배열 (배열의 배열)", async () => {
426
+ const { output } = await exec(
427
+ `var matrix = [[1, 2], [3, 4]]
428
+ println(str(length(matrix)))
429
+ println(str(length(matrix[0])))`
430
+ );
431
+ expect(output).toEqual(["2", "2"]);
432
+ });
433
+ });
434
+
435
+ describe("제어흐름 복잡도", () => {
436
+ it("삼중 if-else", async () => {
437
+ const { output } = await exec(
438
+ `var x = 10
439
+ if x < 5 {
440
+ println("small")
441
+ } else if x < 15 {
442
+ println("medium")
443
+ } else {
444
+ println("large")
445
+ }`
446
+ );
447
+ expect(output).toEqual(["medium"]);
448
+ });
449
+
450
+ it("반복문 조기 종료 (break)", async () => {
451
+ const { output } = await exec(
452
+ `for i in [1, 2, 3, 4, 5] {
453
+ if i == 3 { break }
454
+ println(str(i))
455
+ }`
456
+ );
457
+ expect(output).toEqual(["1", "2"]);
458
+ });
459
+
460
+ it("반복문 건너뛰기 (continue)", async () => {
461
+ const { output } = await exec(
462
+ `for i in [1, 2, 3, 4, 5] {
463
+ if i == 3 { continue }
464
+ println(str(i))
465
+ }`
466
+ );
467
+ expect(output).toEqual(["1", "2", "4", "5"]);
468
+ });
469
+
470
+ it("while 루프 상태 변경", async () => {
471
+ const { output } = await exec(
472
+ `var i: i32 = 0
473
+ var sum: i32 = 0
474
+ while i < 5 {
475
+ sum = sum + i
476
+ i = i + 1
477
+ }
478
+ println(str(sum))`
479
+ );
480
+ expect(output).toEqual(["10"]); // 0+1+2+3+4
481
+ });
482
+ });
483
+
484
+ describe("예외 & 에러 처리", () => {
485
+ it("런타임 에러 캐치 - 0으로 나누기", async () => {
486
+ const { output, error } = await exec("println(str(10 / 0))");
487
+ expect(error).toBeDefined();
488
+ // 에러 메시지는 구현에 따라 다를 수 있음
489
+ });
490
+
491
+ it("수행 제한 초과 (무한 루프 감지)", async () => {
492
+ const { output, error } = await exec("while true { var x = 1 }");
493
+ expect(error).toBeDefined();
494
+ expect(error).toContain("limit");
495
+ });
496
+
497
+ it("배열 범위 초과 접근", async () => {
498
+ const { output, error } = await exec(
499
+ `var arr = [1, 2, 3]
500
+ println(str(arr[10]))`
501
+ );
502
+ // 범위 초과 시 에러 또는 undefined 반환 (구현 의존)
503
+ expect(error !== null || output.length > 0).toBe(true);
504
+ });
505
+ });
506
+
507
+ describe("타입 변환 & 문자열화", () => {
508
+ it("모든 타입 str() 변환", async () => {
509
+ const { output } = await exec(
510
+ `println(str(42))
511
+ println(str(3.14))
512
+ println(str(true))
513
+ println(str(false))`
514
+ );
515
+ expect(output).toEqual(["42", "3.14", "true", "false"]);
516
+ });
517
+
518
+ it("복합 표현식 str() 변환", async () => {
519
+ const { output } = await exec(
520
+ `println(str(1 + 2 * 3))
521
+ println(str(10 > 5))
522
+ println(str(true && false))`
523
+ );
524
+ expect(output).toEqual(["7", "true", "false"]);
525
+ });
526
+ });
527
+
528
+ describe("성능 & 확장성", () => {
529
+ it("1000개 요소 배열", async () => {
530
+ let code = "var arr = [";
531
+ for (let i = 0; i < 1000; i++) {
532
+ code += (i > 0 ? ", " : "") + i;
533
+ }
534
+ code += "]\nprintln(str(length(arr)))";
535
+ const { output } = await exec(code);
536
+ expect(output).toEqual(["1000"]);
537
+ });
538
+
539
+ it("깊은 재귀 (50단계)", async () => {
540
+ const { output } = await exec(
541
+ `fn countdown(n: i32) -> void {
542
+ if n <= 0 {
543
+ println("done")
544
+ } else {
545
+ countdown(n - 1)
546
+ }
547
+ }
548
+ countdown(50)`
549
+ );
550
+ expect(output).toEqual(["done"]);
551
+ });
552
+ });
553
+
554
+ describe("빌틴 함수 - 배열 조작", () => {
555
+ it("push: 배열에 요소 추가", async () => {
556
+ const { output } = await exec(
557
+ `var arr = [1, 2]
558
+ push(arr, 3)
559
+ println(str(length(arr)))`
560
+ );
561
+ expect(output).toEqual(["3"]);
562
+ });
563
+
564
+ it("pop: 배열에서 요소 제거", async () => {
565
+ const { output } = await exec(
566
+ `var arr = [10, 20, 30]
567
+ var x = pop(arr)
568
+ println(str(x))
569
+ println(str(length(arr)))`
570
+ );
571
+ expect(output).toEqual(["30", "2"]);
572
+ });
573
+
574
+ it("pop: 빈 배열에서 pop", async () => {
575
+ const { output } = await exec(
576
+ `var arr: [i32] = []
577
+ var x = pop(arr)
578
+ println(str(x))`
579
+ );
580
+ expect(output.length).toBe(1);
581
+ });
582
+ });
583
+
584
+ describe("빌틴 함수 - 수학", () => {
585
+ it("abs: 절댓값", async () => {
586
+ const { output } = await exec(
587
+ `println(str(abs(-42)))
588
+ println(str(abs(3.14)))`
589
+ );
590
+ expect(output).toEqual(["42", "3.14"]);
591
+ });
592
+
593
+ it("min: 최솟값", async () => {
594
+ const { output } = await exec(
595
+ `println(str(min(10, 5)))
596
+ println(str(min(-3, -8)))`
597
+ );
598
+ expect(output).toEqual(["5", "-8"]);
599
+ });
600
+
601
+ it("max: 최댓값", async () => {
602
+ const { output } = await exec(
603
+ `println(str(max(10, 5)))
604
+ println(str(max(-3, -8)))`
605
+ );
606
+ expect(output).toEqual(["10", "-3"]);
607
+ });
608
+
609
+ it("pow: 거듭제곱", async () => {
610
+ const { output } = await exec(
611
+ `println(str(pow(2, 3)))
612
+ println(str(pow(10, 2)))`
613
+ );
614
+ expect(output).toEqual(["8", "100"]);
615
+ });
616
+
617
+ it("sqrt: 제곱근", async () => {
618
+ const { output } = await exec(
619
+ `println(str(sqrt(16)))
620
+ println(str(sqrt(2)))`
621
+ );
622
+ const [r1, r2] = output;
623
+ expect(r1).toBe("4");
624
+ expect(parseFloat(r2)).toBeCloseTo(1.414, 2);
625
+ });
626
+ });
627
+
628
+ describe("빌틴 함수 - 타입 & 검증", () => {
629
+ it("typeof: 타입 검사", async () => {
630
+ const { output } = await exec(
631
+ `println(typeof(42))
632
+ println(typeof(3.14))
633
+ println(typeof("hello"))
634
+ println(typeof(true))
635
+ println(typeof([1, 2, 3]))`
636
+ );
637
+ expect(output).toEqual(["i32", "f64", "str", "bool", "arr"]);
638
+ });
639
+
640
+ it("assert: 조건 검증 (성공)", async () => {
641
+ const { output } = await exec(
642
+ `assert(true)
643
+ assert(1 > 0)
644
+ println("passed")`
645
+ );
646
+ expect(output).toEqual(["passed"]);
647
+ });
648
+
649
+ it("assert: 조건 검증 (실패)", async () => {
650
+ const { output, error } = await exec(`assert(false, "test failed")`);
651
+ expect(error).toBeDefined();
652
+ expect(error).toContain("test failed");
653
+ });
654
+ });
655
+
656
+ describe("빌틴 함수 - 문자열 조작", () => {
657
+ it("contains: 부분 문자열 확인", async () => {
658
+ const { output } = await exec(
659
+ `println(str(contains("hello world", "world")))
660
+ println(str(contains("hello world", "xyz")))`
661
+ );
662
+ expect(output).toEqual(["true", "false"]);
663
+ });
664
+
665
+ it("split: 문자열 분할", async () => {
666
+ const { output } = await exec(
667
+ `var arr = split("a,b,c", ",")
668
+ println(str(length(arr)))
669
+ println(arr[0])
670
+ println(arr[1])
671
+ println(arr[2])`
672
+ );
673
+ expect(output).toEqual(["3", "a", "b", "c"]);
674
+ });
675
+
676
+ it("trim: 공백 제거", async () => {
677
+ const { output } = await exec(
678
+ `println(trim(" hello "))
679
+ println(trim("world"))`
680
+ );
681
+ expect(output).toEqual(["hello", "world"]);
682
+ });
683
+
684
+ it("to_upper: 대문자 변환", async () => {
685
+ const { output } = await exec(
686
+ `println(to_upper("hello"))
687
+ println(to_upper("HeLLo"))`
688
+ );
689
+ expect(output).toEqual(["HELLO", "HELLO"]);
690
+ });
691
+
692
+ it("to_lower: 소문자 변환", async () => {
693
+ const { output } = await exec(
694
+ `println(to_lower("HELLO"))
695
+ println(to_lower("HeLLo"))`
696
+ );
697
+ expect(output).toEqual(["hello", "hello"]);
698
+ });
699
+
700
+ it("char_at: 문자 접근", async () => {
701
+ const { output } = await exec(
702
+ `println(char_at("hello", 0))
703
+ println(char_at("hello", 4))
704
+ println(char_at("hello", 10))`
705
+ );
706
+ expect(output).toEqual(["h", "o", ""]);
707
+ });
708
+
709
+ it("slice: 부분 문자열", async () => {
710
+ const { output } = await exec(
711
+ `println(slice("hello world", 0, 5))
712
+ println(slice("hello world", 6, 11))`
713
+ );
714
+ expect(output).toEqual(["hello", "world"]);
715
+ });
716
+ });
717
+
718
+ describe("빌틴 함수 - 배열 슬라이싱", () => {
719
+ it("slice: 부분 배열", async () => {
720
+ const { output } = await exec(
721
+ `var arr = [10, 20, 30, 40, 50]
722
+ var sliced = slice(arr, 1, 4)
723
+ println(str(length(sliced)))
724
+ println(str(sliced[0]))
725
+ println(str(sliced[1]))
726
+ println(str(sliced[2]))`
727
+ );
728
+ expect(output).toEqual(["3", "20", "30", "40"]);
729
+ });
730
+ });
731
+
732
+ describe("빌틴 함수 - 클론", () => {
733
+ it("clone: 배열 복제", async () => {
734
+ const { output } = await exec(
735
+ `var arr1 = [1, 2, 3]
736
+ var arr2 = clone(arr1)
737
+ arr1[0] = 99
738
+ println(str(arr1[0]))
739
+ println(str(arr2[0]))`
740
+ );
741
+ expect(output).toEqual(["99", "1"]);
742
+ });
743
+
744
+ it("clone: 중첩 배열 복제", async () => {
745
+ const { output } = await exec(
746
+ `var matrix1 = [[1, 2], [3, 4]]
747
+ var matrix2 = clone(matrix1)
748
+ println(str(length(matrix2)))
749
+ println(str(length(matrix2[0])))`
750
+ );
751
+ expect(output).toEqual(["2", "2"]);
752
+ });
753
+ });
754
+ });