guangming 0.4.0__py3-none-any.whl

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 (482) hide show
  1. antlrparser/__init__.py +22 -0
  2. antlrparser/_test_async.py +122 -0
  3. antlrparser/_test_basic.py +36 -0
  4. antlrparser/_test_regex.py +16 -0
  5. antlrparser/_test_repl.py +44 -0
  6. antlrparser/_test_stdlib.py +366 -0
  7. antlrparser/cli.py +620 -0
  8. antlrparser/compile_runtime.py +22 -0
  9. antlrparser/indent_preprocessor.py +183 -0
  10. antlrparser/interpreter_core.py +1319 -0
  11. antlrparser/light_ast.py +587 -0
  12. antlrparser/light_builtins.py +984 -0
  13. antlrparser/light_bytecode.py +761 -0
  14. antlrparser/light_cli.py +211 -0
  15. antlrparser/light_compiler.py +108 -0
  16. antlrparser/light_error_handler.py +212 -0
  17. antlrparser/light_interpreter.py +125 -0
  18. antlrparser/light_llvm.py +149 -0
  19. antlrparser/light_module.py +250 -0
  20. antlrparser/light_parser/LightLangLexer.py +716 -0
  21. antlrparser/light_parser/LightLangParser.py +10029 -0
  22. antlrparser/light_parser/LightLangParserListener.py +843 -0
  23. antlrparser/light_parser/LightLangParserVisitor.py +476 -0
  24. antlrparser/light_repl.py +301 -0
  25. antlrparser/light_tokenizer.py +1232 -0
  26. antlrparser/light_visitor.py +846 -0
  27. antlrparser/llvm_codegen.py +1036 -0
  28. antlrparser/llvm_core.py +272 -0
  29. antlrparser/main.py +153 -0
  30. antlrparser/modules/data_models.light +41 -0
  31. antlrparser/modules/math_utils.light +32 -0
  32. antlrparser/modules/string_utils.light +28 -0
  33. antlrparser/operations.py +96 -0
  34. antlrparser/self_hosted/ast.light +156 -0
  35. antlrparser/self_hosted/bootstrap_test.light +104 -0
  36. antlrparser/self_hosted/interpreter.light +609 -0
  37. antlrparser/self_hosted/llvm_codegen.light +390 -0
  38. antlrparser/self_hosted/parser.light +1491 -0
  39. antlrparser/self_hosted/run_bootstrap_test.py +102 -0
  40. antlrparser/self_hosted/simple_test.light +33 -0
  41. antlrparser/self_hosted/stdlib.light +788 -0
  42. antlrparser/self_hosted/test_basic.py +203 -0
  43. antlrparser/self_hosted/test_bootstrap.light +43 -0
  44. antlrparser/self_hosted/test_comprehensive.py +615 -0
  45. antlrparser/self_hosted/test_enhancements.py +290 -0
  46. antlrparser/self_hosted/test_enhancements_simple.py +163 -0
  47. antlrparser/self_hosted/test_final.py +300 -0
  48. antlrparser/self_hosted/test_full_bootstrap.py +282 -0
  49. antlrparser/self_hosted/test_integration.py +391 -0
  50. antlrparser/self_hosted/test_interpreter.py +60 -0
  51. antlrparser/self_hosted/test_light_interpreter.py +139 -0
  52. antlrparser/self_hosted/test_parser.py +299 -0
  53. antlrparser/self_hosted/test_python_interpreter.py +87 -0
  54. antlrparser/self_hosted/test_stdlib.py +74 -0
  55. antlrparser/self_hosted/test_summary.py +147 -0
  56. antlrparser/self_hosted/test_syntax.light +5 -0
  57. antlrparser/self_hosted/test_tokenizer.py +167 -0
  58. antlrparser/self_hosted/tokenizer.light +468 -0
  59. antlrparser/test/mod_advanced.light +16 -0
  60. antlrparser/test/mod_greet.light +10 -0
  61. antlrparser/test/mod_math.light +27 -0
  62. antlrparser/test/mod_util.light +13 -0
  63. antlrparser/test/sample_basic.light +20 -0
  64. antlrparser/test/sample_controlflow.light +46 -0
  65. antlrparser/test/sample_quicksort.light +19 -0
  66. antlrparser/test/sample_types.light +58 -0
  67. antlrparser/test/test_antlr_comprehensive.light +101 -0
  68. antlrparser/test/test_antlr_comprehensive.py +80 -0
  69. antlrparser/test/test_antlr_validation.py +279 -0
  70. antlrparser/test/test_class_parse.py +41 -0
  71. antlrparser/test/test_compile.py +177 -0
  72. antlrparser/test/test_controlflow.py +324 -0
  73. antlrparser/test/test_debug.py +34 -0
  74. antlrparser/test/test_debug_eval.py +32 -0
  75. antlrparser/test/test_debug_expr.py +32 -0
  76. antlrparser/test/test_debug_module.py +40 -0
  77. antlrparser/test/test_debug_new.py +25 -0
  78. antlrparser/test/test_dict.py +314 -0
  79. antlrparser/test/test_dual_backend.py +176 -0
  80. antlrparser/test/test_final_antlr.light +14 -0
  81. antlrparser/test/test_final_antlr.py +36 -0
  82. antlrparser/test/test_interface_parse.py +52 -0
  83. antlrparser/test/test_interpreter.py +583 -0
  84. antlrparser/test/test_list_dict.py +161 -0
  85. antlrparser/test/test_module.py +280 -0
  86. antlrparser/test/test_oop_comprehensive.py +51 -0
  87. antlrparser/test/test_oop_features.py +57 -0
  88. antlrparser/test/test_parse_tree.py +25 -0
  89. antlrparser/test/test_parser.py +186 -0
  90. antlrparser/test/test_parser_debug.py +45 -0
  91. antlrparser/test/test_simple_oop.py +37 -0
  92. antlrparser/test/test_src_features.py +53 -0
  93. antlrparser/test/test_tokenizer.py +30 -0
  94. antlrparser/test/test_tokenizer2.py +32 -0
  95. antlrparser/test/test_tokenizer_new.py +16 -0
  96. antlrparser/test/test_types.py +513 -0
  97. antlrparser/test_list_len.light +33 -0
  98. antlrparser/test_oop.light +50 -0
  99. antlrparser/test_oop_full.light +38 -0
  100. antlrparser/test_program.light +46 -0
  101. antlrparser/test_program_simple.light +21 -0
  102. antlrparser/test_program_simple2.light +28 -0
  103. antlrparser/test_stdlib.light +49 -0
  104. antlrparser/test_stdlib2.light +50 -0
  105. antlrparser/visitor_decl.py +907 -0
  106. antlrparser/visitor_expr.py +886 -0
  107. antlrparser/visitor_stmt.py +495 -0
  108. antlrparser/web_playground/_test_examples.py +26 -0
  109. antlrparser/web_playground/server.py +421 -0
  110. antlrparser/web_playground/test_api.py +29 -0
  111. cli/__init__.py +11 -0
  112. cli/light.py +2050 -0
  113. cli/light_unified.py +1324 -0
  114. cli/lightc.py +313 -0
  115. cli/tutorial.py +866 -0
  116. cli/tutorial_30min.light +1026 -0
  117. guangming-0.4.0.dist-info/METADATA +982 -0
  118. guangming-0.4.0.dist-info/RECORD +482 -0
  119. guangming-0.4.0.dist-info/WHEEL +5 -0
  120. guangming-0.4.0.dist-info/entry_points.txt +3 -0
  121. guangming-0.4.0.dist-info/licenses/LICENSE +21 -0
  122. guangming-0.4.0.dist-info/top_level.txt +5 -0
  123. src/__init__.py +18 -0
  124. src/arity_parser.py +297 -0
  125. src/ast_nodes.py +1135 -0
  126. src/ast_nodes_v3.py +1537 -0
  127. src/ast_unified.py +506 -0
  128. src/chinese_units.py +435 -0
  129. src/code_generator.py +6157 -0
  130. src/code_generator_unified.py +2983 -0
  131. src/compiler.py +1777 -0
  132. src/compiler_cache.py +335 -0
  133. src/core/__init__.py +27 -0
  134. src/core/config.py +152 -0
  135. src/core/errors.py +167 -0
  136. src/core/interfaces.py +149 -0
  137. src/debug_engine.py +436 -0
  138. src/doc_generator.py +259 -0
  139. src/elastic_syntax.py +306 -0
  140. src/enhanced_errors.py +984 -0
  141. src/error_formatter.py +665 -0
  142. src/errors.py +934 -0
  143. src/feedback_collector.py +571 -0
  144. src/file_watcher.py +172 -0
  145. src/first_run.py +369 -0
  146. src/formatter/__init__.py +99 -0
  147. src/formatter/cli.py +110 -0
  148. src/formatter/light_formatter.py +131 -0
  149. src/formatter.py +164 -0
  150. src/incremental_build.py +961 -0
  151. src/incremental_compiler.py +675 -0
  152. src/interactive_tutorial.py +1019 -0
  153. src/keywords.py +712 -0
  154. src/l3_echarts.py +348 -0
  155. src/l3_markdown.py +303 -0
  156. src/lexer.py +4723 -0
  157. src/light_parser_v3.py +133 -0
  158. src/lightpkg.py +1699 -0
  159. src/linter/__init__.py +10 -0
  160. src/linter/cli.py +75 -0
  161. src/linter/light_linter.py +1130 -0
  162. src/llvm/codegen.py +973 -0
  163. src/llvm/codegen_typed.py +6578 -0
  164. src/llvm/compiler.py +1681 -0
  165. src/llvm/core.py +403 -0
  166. src/llvm/dwarf.py +648 -0
  167. src/llvm/opt_passes.py +590 -0
  168. src/llvm/optimizer_pipeline.py +678 -0
  169. src/llvm/size_optimizer.py +583 -0
  170. src/llvm/startup_optimizer.py +303 -0
  171. src/llvm_dependency.py +855 -0
  172. src/migration/__init__.py +11 -0
  173. src/migration/cli.py +136 -0
  174. src/migration/light_migrator.py +361 -0
  175. src/migration/v33_to_v40.py +279 -0
  176. src/migration/v40_to_v50.py +272 -0
  177. src/module_resolver.py +1300 -0
  178. src/optimizer/__init__.py +17 -0
  179. src/optimizer/base.py +173 -0
  180. src/optimizer/constant_fold.py +178 -0
  181. src/optimizer/cse.py +255 -0
  182. src/optimizer/dead_code.py +156 -0
  183. src/optimizer/inline.py +279 -0
  184. src/optimizer/loop_invariant.py +145 -0
  185. src/optimizer/peephole.py +174 -0
  186. src/package_installer.py +2288 -0
  187. src/package_manager.py +1058 -0
  188. src/package_security.py +804 -0
  189. src/parser_core.py +651 -0
  190. src/parser_expr.py +3801 -0
  191. src/parser_stmt.py +7634 -0
  192. src/profiler.py +527 -0
  193. src/registry_server.py +936 -0
  194. src/repl/__init__.py +17 -0
  195. src/repl/commands.py +474 -0
  196. src/repl/completer.py +519 -0
  197. src/repl/core.py +374 -0
  198. src/repl/enhanced.py +130 -0
  199. src/repl/executor.py +458 -0
  200. src/repl/highlighter.py +188 -0
  201. src/scope_shadow_check.py +265 -0
  202. src/semantic_analyzer.py +374 -0
  203. src/semantic_identifier.py +208 -0
  204. src/templates/__init__.py +55 -0
  205. src/templates/data_analysis/package.toml +9 -0
  206. src/templates/data_analysis//344/270/273.light +46 -0
  207. src/templates/data_analysis//345/210/206/346/236/220.light +120 -0
  208. src/templates/student_management/package.toml +9 -0
  209. src/templates/student_management//344/270/273.light +44 -0
  210. src/templates/student_management//345/255/246/347/224/237/347/256/241/347/220/206.light +30 -0
  211. src/templates/student_management//346/210/220/347/273/251/347/256/241/347/220/206.light +49 -0
  212. src/templates/web_service/package.toml +9 -0
  213. src/templates/web_service//344/270/273.light +46 -0
  214. src/templates/web_service//350/267/257/347/224/261.light +32 -0
  215. src/templates.py +383 -0
  216. src/test_exception_output.py +68 -0
  217. src/test_output.py +38 -0
  218. src/test_runner.py +469 -0
  219. src/tokens.py +97 -0
  220. src/type_checker.py +1488 -0
  221. src/type_inferencer.py +2476 -0
  222. src/type_system.py +1663 -0
  223. src/verb_info.py +217 -0
  224. src/version.py +89 -0
  225. src/wasm_target.py +577 -0
  226. stdlib/Base64.light +319 -0
  227. stdlib/Base64.py +238 -0
  228. stdlib/CSV.light +21 -0
  229. stdlib/CSV.py +246 -0
  230. stdlib/CSV/350/257/273/345/206/231/345/231/250.light +229 -0
  231. stdlib/CSV/350/257/273/345/206/231/345/231/250.py +481 -0
  232. stdlib/FFI.light +47 -0
  233. stdlib/FFI.py +642 -0
  234. stdlib/FFI/345/242/236/345/274/272.light +9 -0
  235. stdlib/FFI/345/242/236/345/274/272.py +627 -0
  236. stdlib/HTTP.light +19 -0
  237. stdlib/HTTP.py +269 -0
  238. stdlib/HTTP/346/234/215/345/212/241/347/253/257.light +494 -0
  239. stdlib/JSON.light +172 -0
  240. stdlib/JSON.py +1147 -0
  241. stdlib/JSONL.light +53 -0
  242. stdlib/JSON/346/240/270/345/277/203.light +413 -0
  243. stdlib/JSON/347/274/226/350/247/243/347/240/201.light +256 -0
  244. stdlib/SSE.light +153 -0
  245. stdlib/XML.light +25 -0
  246. stdlib/XML.py +361 -0
  247. stdlib/__init__.py +317 -0
  248. stdlib/_light_import_hook.py +287 -0
  249. stdlib/_t5b_runtime.py +63 -0
  250. stdlib/builtins.py +1570 -0
  251. stdlib/inspect.light +28 -0
  252. stdlib/lightpub/CSV.py +233 -0
  253. stdlib/lightpub/HTTP/345/256/242/346/210/267/347/253/257.py +819 -0
  254. stdlib/lightpub/HTTP/346/234/215/345/212/241/347/253/257.py +737 -0
  255. stdlib/lightpub/JSON.py +264 -0
  256. stdlib/lightpub/SQLite.py +375 -0
  257. stdlib/lightpub/Socket.py +343 -0
  258. stdlib/lightpub/URL/350/247/243/346/236/220.py +143 -0
  259. stdlib/lightpub/Web/346/241/206/346/236/266.py +1413 -0
  260. stdlib/lightpub/__index__.py +1897 -0
  261. stdlib/lightpub/__init__.py +348 -0
  262. stdlib/lightpub//344/272/213/344/273/266/351/251/261/345/212/250.py +114 -0
  263. stdlib/lightpub//344/272/214/350/277/233/345/210/266/347/274/226/347/240/201.py +270 -0
  264. stdlib/lightpub//344/273/273/345/212/241/351/230/237/345/210/227.py +335 -0
  265. stdlib/lightpub//345/212/240/345/257/206.py +358 -0
  266. stdlib/lightpub//345/212/240/345/257/206/347/256/227/346/263/225.py +160 -0
  267. stdlib/lightpub//345/215/217/347/250/213.py +539 -0
  268. stdlib/lightpub//345/215/225/345/205/203/346/265/213/350/257/225/346/241/206/346/236/266.py +434 -0
  269. stdlib/lightpub//345/216/213/347/274/251/347/256/227/346/263/225.py +134 -0
  270. stdlib/lightpub//345/221/275/344/273/244/350/241/214/345/217/202/346/225/260.py +156 -0
  271. stdlib/lightpub//345/223/210/345/270/214.py +364 -0
  272. stdlib/lightpub//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.py +265 -0
  273. stdlib/lightpub//345/257/206/347/240/201/345/223/210/345/270/214.py +112 -0
  274. stdlib/lightpub//345/271/266/350/241/214/350/256/241/347/256/227.py +118 -0
  275. stdlib/lightpub//345/274/202/346/255/245/350/277/220/350/241/214/346/227/266.py +765 -0
  276. stdlib/lightpub//346/200/247/350/203/275/345/210/206/346/236/220.py +544 -0
  277. stdlib/lightpub//346/216/222/345/272/217/344/270/216/346/220/234/347/264/242.py +272 -0
  278. stdlib/lightpub//346/225/260/345/200/274/350/256/241/347/256/227.py +226 -0
  279. stdlib/lightpub//346/225/260/345/255/246/350/277/220/347/256/227.py +331 -0
  280. stdlib/lightpub//346/225/260/346/215/256/345/257/274/345/205/245/345/257/274/345/207/272.py +708 -0
  281. stdlib/lightpub//346/225/260/346/215/256/347/273/223/346/236/204.py +664 -0
  282. stdlib/lightpub//346/226/207/344/273/266/344/270/212/344/274/240.py +505 -0
  283. stdlib/lightpub//346/226/207/344/273/266/347/263/273/347/273/237.py +315 -0
  284. stdlib/lightpub//346/227/245/345/277/227/347/263/273/347/273/237.py +149 -0
  285. stdlib/lightpub//346/227/245/346/234/237/345/272/217/345/210/227.py +601 -0
  286. stdlib/lightpub//346/227/245/346/234/237/346/227/266/351/227/264.py +368 -0
  287. stdlib/lightpub//346/250/241/346/235/277/346/270/262/346/237/223.py +361 -0
  288. stdlib/lightpub//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.py +225 -0
  289. stdlib/lightpub//346/266/210/346/201/257/351/230/237/345/210/227.py +151 -0
  290. stdlib/lightpub//347/216/257/345/242/203/345/217/230/351/207/217.py +180 -0
  291. stdlib/lightpub//347/256/227/346/263/225/345/267/245/345/205/267.py +350 -0
  292. stdlib/lightpub//347/261/273/345/236/213/345/267/245/345/205/267.py +210 -0
  293. stdlib/lightpub//347/263/273/347/273/237/344/277/241/346/201/257.py +386 -0
  294. stdlib/lightpub//347/272/277/347/250/213.py +362 -0
  295. stdlib/lightpub//347/273/237/350/256/241/345/210/206/346/236/220.py +1572 -0
  296. stdlib/lightpub//347/274/223/345/255/230/347/263/273/347/273/237.py +204 -0
  297. stdlib/lightpub//347/275/221/347/273/234/345/267/245/345/205/267.py +398 -0
  298. stdlib/lightpub//350/257/201/344/271/246.py +446 -0
  299. stdlib/lightpub//350/267/257/345/276/204/345/244/204/347/220/206.py +201 -0
  300. stdlib/lightpub//350/277/233/347/250/213/347/256/241/347/220/206.py +208 -0
  301. stdlib/lightpub//350/277/236/346/216/245/346/261/240.py +185 -0
  302. stdlib/lightpub//350/277/255/344/273/243/345/231/250/345/267/245/345/205/267.py +176 -0
  303. stdlib/lightpub//351/202/256/344/273/266.py +323 -0
  304. stdlib/lightpub//351/205/215/347/275/256/347/256/241/347/220/206.py +480 -0
  305. stdlib/lightpub//351/224/231/350/257/257/345/244/204/347/220/206.py +177 -0
  306. stdlib/lightpub//351/232/217/346/234/272/346/225/260.py +101 -0
  307. stdlib/lightpub//351/233/206/345/220/210/346/211/251/345/261/225.py +211 -0
  308. stdlib/re.light +1173 -0
  309. stdlib/sys.light +55 -0
  310. stdlib/time.light +87 -0
  311. stdlib/uuid/345/267/245/345/205/267.light +236 -0
  312. stdlib/uuid/345/267/245/345/205/267.py +187 -0
  313. stdlib//344/270/255/345/233/275/344/274/240/347/273/237/350/212/202/346/227/245.light +269 -0
  314. stdlib//344/270/255/345/233/275/344/274/240/347/273/237/350/212/202/346/227/245.py +414 -0
  315. stdlib//344/270/255/345/233/275/350/241/214/346/224/277/345/214/272/345/210/222.light +756 -0
  316. stdlib//344/270/255/345/233/275/350/241/214/346/224/277/345/214/272/345/210/222.py +416 -0
  317. stdlib//344/270/255/346/226/207NLP.light +133 -0
  318. stdlib//344/270/255/346/226/207NLP.py +1437 -0
  319. stdlib//344/270/255/346/226/207/345/210/206/350/257/215.light +162 -0
  320. stdlib//344/270/255/346/226/207/345/210/206/350/257/215.py +322 -0
  321. stdlib//344/270/255/346/226/207/346/225/260/345/255/227/350/275/254/346/215/242.light +250 -0
  322. stdlib//344/270/255/346/226/207/346/225/260/345/255/227/350/275/254/346/215/242.py +417 -0
  323. stdlib//344/270/255/346/226/207/346/226/207/346/234/254.light +39 -0
  324. stdlib//344/270/255/346/226/207/346/226/207/346/234/254.py +440 -0
  325. stdlib//344/270/255/346/226/207/346/226/207/346/234/254/345/244/204/347/220/206.light +241 -0
  326. stdlib//344/270/255/346/226/207/346/226/207/346/234/254/345/244/204/347/220/206.py +360 -0
  327. stdlib//344/270/255/346/226/207/347/274/226/347/240/201.light +370 -0
  328. stdlib//344/270/255/346/226/207/347/274/226/347/240/201.py +397 -0
  329. stdlib//344/270/255/346/255/242.light +82 -0
  330. stdlib//344/270/264/346/227/266/346/226/207/344/273/266.light +17 -0
  331. stdlib//344/270/264/346/227/266/346/226/207/344/273/266.py +293 -0
  332. stdlib//344/272/213/344/273/266/346/200/273/347/272/277.light +268 -0
  333. stdlib//344/273/243/347/220/206/345/267/245/345/205/267/351/233/206.light +789 -0
  334. stdlib//344/273/243/347/220/206/345/276/252/347/216/257.light +800 -0
  335. stdlib//344/274/252/347/273/210/347/253/257.light +589 -0
  336. stdlib//344/277/241/345/217/267.light +14 -0
  337. stdlib//344/277/241/345/217/267.py +198 -0
  338. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/210/227/350/241/250.light +133 -0
  339. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/210/244/345/236/213.light +106 -0
  340. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/255/227/345/205/270.light +74 -0
  341. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/255/227/347/254/246/344/270/262.light +84 -0
  342. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/347/263/273/347/273/237.light +35 -0
  343. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/350/267/257/345/276/204.light +97 -0
  344. stdlib//345/206/205/347/275/256/346/240/270/345/277/203/350/275/254/346/215/242.light +67 -0
  345. stdlib//345/206/234/345/216/206.light +660 -0
  346. stdlib//345/206/234/345/216/206.py +447 -0
  347. stdlib//345/210/206/345/270/203/345/274/217//344/270/273/346/216/247.light +24 -0
  348. stdlib//345/210/206/345/270/203/345/274/217//350/212/202/347/202/271.light +21 -0
  349. stdlib//345/210/206/345/270/203/345/274/217//350/212/202/347/202/271/346/240/270/345/277/203.light +183 -0
  350. stdlib//345/210/206/345/270/203/345/274/217//350/212/202/347/202/271/347/275/221/347/273/234.py +287 -0
  351. stdlib//345/210/206/345/270/203/345/274/217//350/260/203/345/272/246/346/240/270/345/277/203.light +303 -0
  352. stdlib//345/210/206/350/257/215.light +10 -0
  353. stdlib//345/210/206/350/257/215.py +174 -0
  354. stdlib//345/210/227/350/241/250/345/267/245/345/205/267.light +290 -0
  355. stdlib//345/210/227/350/241/250/345/267/245/345/205/267.py +77 -0
  356. stdlib//345/212/240/345/257/206.light +42 -0
  357. stdlib//345/212/240/345/257/206.py +634 -0
  358. stdlib//345/216/206/346/263/225.light +41 -0
  359. stdlib//345/216/206/346/263/225.py +372 -0
  360. stdlib//345/217/202/346/225/260/350/247/243/346/236/220.light +274 -0
  361. stdlib//345/217/202/346/225/260/350/247/243/346/236/220.py +311 -0
  362. stdlib//345/220/221/351/207/217.light +330 -0
  363. stdlib//345/220/221/351/207/217.py +422 -0
  364. stdlib//345/223/210/345/270/214.light +58 -0
  365. stdlib//345/223/210/345/270/214.py +152 -0
  366. stdlib//345/233/276/345/203/217/345/244/204/347/220/206/345/237/272/347/241/200.light +145 -0
  367. stdlib//345/233/276/345/203/217/345/244/204/347/220/206/345/237/272/347/241/200.py +482 -0
  368. stdlib//345/244/215/346/225/260.light +108 -0
  369. stdlib//345/244/215/346/225/260.py +181 -0
  370. stdlib//345/244/226/351/203/250/345/221/275/344/273/244.light +19 -0
  371. stdlib//345/244/226/351/203/250/345/221/275/344/273/244.py +304 -0
  372. stdlib//345/244/247/346/250/241/345/236/213/345/256/242/346/210/267/347/253/257.light +394 -0
  373. stdlib//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.light +17 -0
  374. stdlib//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.py +565 -0
  375. stdlib//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.light +767 -0
  376. stdlib//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.py +496 -0
  377. stdlib//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267/350/275/273/351/207/217.light +210 -0
  378. stdlib//345/255/227/347/254/246/344/270/262/345/270/270/351/207/217.light +311 -0
  379. stdlib//345/255/227/347/254/246/344/270/262/345/270/270/351/207/217.py +227 -0
  380. stdlib//345/255/227/350/212/202/347/274/223/345/206/262.light +84 -0
  381. stdlib//345/257/271/350/261/241/346/261/240/347/274/223/345/255/230.light +255 -0
  382. stdlib//345/257/271/350/261/241/346/261/240/347/274/223/345/255/230.py +424 -0
  383. stdlib//345/271/266/345/217/221.light +278 -0
  384. stdlib//345/272/246/351/207/217.light +136 -0
  385. stdlib//346/200/247/350/203/275.light +15 -0
  386. stdlib//346/200/247/350/203/275.py +230 -0
  387. stdlib//346/211/213/346/234/272/345/217/267/346/240/241/351/252/214.light +163 -0
  388. stdlib//346/211/213/346/234/272/345/217/267/346/240/241/351/252/214.py +645 -0
  389. stdlib//346/213/274/351/237/263/350/275/254/346/215/242.light +2932 -0
  390. stdlib//346/213/274/351/237/263/350/275/254/346/215/242.py +663 -0
  391. stdlib//346/216/222/345/272/217.light +171 -0
  392. stdlib//346/216/222/345/272/217.py +298 -0
  393. stdlib//346/216/222/347/211/210.light +24 -0
  394. stdlib//346/216/222/347/211/210.py +327 -0
  395. stdlib//346/217/222/344/273/266.light +240 -0
  396. stdlib//346/223/215/344/275/234/347/263/273/347/273/237.light +58 -0
  397. stdlib//346/225/260/345/255/246.light +305 -0
  398. stdlib//346/225/260/345/255/246.py +739 -0
  399. stdlib//346/225/260/345/255/246/347/273/237/350/256/241.py +399 -0
  400. stdlib//346/225/260/346/215/256/347/273/223/346/236/204.light +606 -0
  401. stdlib//346/225/260/346/215/256/347/273/223/346/236/204.py +989 -0
  402. stdlib//346/225/260/346/215/256/347/273/223/346/236/204/350/275/273/351/207/217.light +179 -0
  403. stdlib//346/225/260/346/215/256/351/252/214/350/257/201.light +320 -0
  404. stdlib//346/225/260/346/215/256/351/252/214/350/257/201.py +331 -0
  405. stdlib//346/226/207/344/273/266/345/214/271/351/205/215.light +20 -0
  406. stdlib//346/226/207/344/273/266/345/214/271/351/205/215.py +139 -0
  407. stdlib//346/226/207/344/273/266/346/265/201.light +48 -0
  408. stdlib//346/226/207/344/273/266/347/263/273/347/273/237.light +109 -0
  409. stdlib//346/226/207/344/273/266/347/263/273/347/273/237.py +1522 -0
  410. stdlib//346/226/255/350/250/200/345/267/245/345/205/267.light +291 -0
  411. stdlib//346/226/255/350/250/200/345/267/245/345/205/267.py +737 -0
  412. stdlib//346/226/255/350/250/200/345/267/245/345/205/267/350/275/273/351/207/217.light +73 -0
  413. stdlib//346/227/245/345/277/227.light +14 -0
  414. stdlib//346/227/245/345/277/227.py +94 -0
  415. stdlib//346/227/245/345/277/227/347/263/273/347/273/237/345/242/236/345/274/272.light +197 -0
  416. stdlib//346/227/245/345/277/227/347/263/273/347/273/237/345/242/236/345/274/272.py +834 -0
  417. stdlib//346/227/245/346/234/237/346/227/266/351/227/264.light +294 -0
  418. stdlib//346/227/245/346/234/237/346/227/266/351/227/264.py +1616 -0
  419. stdlib//346/227/245/346/234/237/346/227/266/351/227/264/350/275/273/351/207/217.light +74 -0
  420. stdlib//346/227/266/351/227/264/347/256/241/347/220/206.light +114 -0
  421. stdlib//346/227/266/351/227/264/347/256/241/347/220/206.py +513 -0
  422. stdlib//346/240/274/345/274/217/345/214/226.light +278 -0
  423. stdlib//346/240/274/345/274/217/345/214/226.py +268 -0
  424. stdlib//346/250/241/345/274/217/346/240/241/351/252/214.light +217 -0
  425. stdlib//346/250/241/346/235/277.light +134 -0
  426. stdlib//346/250/241/346/235/277.py +165 -0
  427. stdlib//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.light +219 -0
  428. stdlib//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.py +383 -0
  429. stdlib//346/265/201/345/274/217.light +498 -0
  430. stdlib//346/265/213/350/257/225.light +13 -0
  431. stdlib//346/265/213/350/257/225.py +330 -0
  432. stdlib//347/216/257/345/242/203.light +28 -0
  433. stdlib//347/216/257/345/242/203.py +215 -0
  434. stdlib//347/263/273/347/273/237/346/216/245/345/217/243.light +81 -0
  435. stdlib//347/263/273/347/273/237/346/216/245/345/217/243.py +437 -0
  436. stdlib//347/272/277/347/250/213.light +16 -0
  437. stdlib//347/272/277/347/250/213.py +409 -0
  438. stdlib//347/273/237/350/256/241.light +316 -0
  439. stdlib//347/273/237/350/256/241.py +342 -0
  440. stdlib//347/274/223/345/255/230.light +217 -0
  441. stdlib//347/274/223/345/255/230.py +106 -0
  442. stdlib//347/274/226/347/240/201.light +136 -0
  443. stdlib//347/274/226/347/240/201.py +174 -0
  444. stdlib//347/274/226/347/240/201/350/247/243/347/240/201.light +577 -0
  445. stdlib//347/274/226/347/240/201/350/247/243/347/240/201.py +292 -0
  446. stdlib//347/275/221/347/273/234.light +25 -0
  447. stdlib//347/275/221/347/273/234.py +292 -0
  448. stdlib//347/275/221/347/273/234/350/257/267/346/261/202.light +648 -0
  449. stdlib//347/275/221/347/273/234/350/257/267/346/261/202.py +426 -0
  450. stdlib//350/243/205/351/245/260/345/231/250.light +99 -0
  451. stdlib//350/243/205/351/245/260/345/231/250.py +359 -0
  452. stdlib//350/267/257/345/276/204/346/212/244/346/240/217.light +481 -0
  453. stdlib//350/267/257/345/276/204/350/277/220/347/256/227.light +141 -0
  454. stdlib//350/272/253/344/273/275/350/257/201/346/240/241/351/252/214.light +260 -0
  455. stdlib//350/272/253/344/273/275/350/257/201/346/240/241/351/252/214.py +389 -0
  456. stdlib//350/277/233/345/272/246/346/235/241.light +162 -0
  457. stdlib//350/277/233/345/272/246/346/235/241.py +211 -0
  458. stdlib//350/277/233/347/250/213.light +16 -0
  459. stdlib//350/277/233/347/250/213.py +448 -0
  460. stdlib//350/277/233/347/250/213/346/240/221.light +1009 -0
  461. stdlib//351/200/211/346/213/251/345/231/250.light +210 -0
  462. stdlib//351/205/215/347/275/256.light +16 -0
  463. stdlib//351/205/215/347/275/256.py +263 -0
  464. stdlib//351/207/215/350/257/225.light +49 -0
  465. stdlib//351/232/217/346/234/272.light +323 -0
  466. stdlib//351/232/217/346/234/272.py +318 -0
  467. stdlib//351/233/206/345/220/210.light +463 -0
  468. stdlib//351/233/206/345/220/210.py +229 -0
  469. stdlib//351/233/206/345/220/210/345/267/245/345/205/267.light +132 -0
  470. stdlib//351/233/206/345/220/210/345/267/245/345/205/267.py +193 -0
  471. stdlib//351/233/206/345/220/210/346/223/215/344/275/234.light +267 -0
  472. stdlib//351/233/206/345/220/210/346/223/215/344/275/234.py +99 -0
  473. stdlib//351/242/234/350/211/262.light +287 -0
  474. stdlib//351/242/234/350/211/262.py +304 -0
  475. stdlib//351/242/234/350/211/262/345/244/204/347/220/206.py +357 -0
  476. stdlib//351/253/230/347/272/247/346/226/207/344/273/266.light +162 -0
  477. stdlib//351/253/230/347/272/247/346/226/207/344/273/266.py +120 -0
  478. stdlib_v3//345/210/227/350/241/250/345/267/245/345/205/267.light +101 -0
  479. stdlib_v3//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.light +20 -0
  480. stdlib_v3//346/225/260/345/255/246/345/267/245/345/205/267.light +34 -0
  481. stdlib_v3//347/261/273/345/236/213/345/267/245/345/205/267.light +39 -0
  482. stdlib_v3//350/276/223/345/205/245/350/276/223/345/207/272.light +28 -0
@@ -0,0 +1,22 @@
1
+ """
2
+ 光明(Light)编程语言 - ANTLR 解析器包
3
+
4
+ 本包提供基于 ANTLR4 的解析器和编译器实现:
5
+ - light_lexer.py / light_tokenizer.py: 词法分析器
6
+ - light_parser.py / LightLangParser.py: ANTLR 生成的语法分析器
7
+ - light_visitor.py / light_ast.py: AST 节点定义和访问器
8
+ - llvm_codegen.py / llvm_core.py: LLVM IR 代码生成
9
+ - light_llvm.py: LLVM 编译流程入口
10
+ - cli.py / light_cli.py: 命令行工具
11
+
12
+ 支持语法版本:1.x(需结束关键字)、2.x(混合语法)、3.x(纯缩进语法)
13
+
14
+ 确保包内模块间的扁平导入(from light_ast import xxx)在作为 pip 包安装后也能正常工作。
15
+ """
16
+ import sys
17
+ import os
18
+
19
+ # 将包目录加入 sys.path,使 flat imports 在包内有效
20
+ _pkg_dir = os.path.dirname(os.path.abspath(__file__))
21
+ if _pkg_dir not in sys.path:
22
+ sys.path.insert(0, _pkg_dir)
@@ -0,0 +1,122 @@
1
+ """测试 ANTLR 后端异步功能"""
2
+ import sys
3
+ import os
4
+ sys.path.insert(0, os.path.dirname(__file__))
5
+
6
+ from light_visitor import LightParser
7
+ from light_interpreter import Interpreter, run_source
8
+ from light_ast import *
9
+
10
+ # 测试1:AsyncScope 解释执行
11
+ print("=== 测试1: AsyncScope ===")
12
+ interp = Interpreter()
13
+ scope = AsyncScope(
14
+ line=1, column=1,
15
+ tasks=[
16
+ PrintStatement(value=StringLiteral(value="任务1")),
17
+ PrintStatement(value=StringLiteral(value="任务2")),
18
+ ]
19
+ )
20
+ interp._execute(scope)
21
+ print("输出:", interp.get_output())
22
+
23
+ # 测试2:DeferStatement 推迟栈
24
+ print("\n=== 测试2: DeferStatement ===")
25
+ interp2 = Interpreter()
26
+ defer_stmt = DeferStatement(
27
+ line=1, column=1,
28
+ body=[
29
+ PrintStatement(value=StringLiteral(value="推迟执行")),
30
+ ]
31
+ )
32
+ interp2._execute(defer_stmt)
33
+ interp2._run_defer_stack()
34
+ print("输出:", interp2.get_output())
35
+
36
+ # 测试3:AwaitExpression
37
+ print("\n=== 测试3: AwaitExpression ===")
38
+ interp3 = Interpreter()
39
+ await_expr = AwaitExpression(
40
+ line=1, column=1,
41
+ expression=NumberLiteral(value=42)
42
+ )
43
+ result = interp3._eval(await_expr)
44
+ print("等待结果:", result)
45
+
46
+ # 测试4:同步段内的推迟
47
+ print("\n=== 测试4: 推迟语句 ===")
48
+ source = """段落 测试推迟 接收:
49
+ 打印("开始")。
50
+ 推迟:打印("清理")。
51
+ 打印("结束")。
52
+ 结束。
53
+
54
+ 测试推迟()。
55
+ """
56
+ try:
57
+ interp4 = run_source(source)
58
+ print("执行成功")
59
+ print("输出:", interp4.get_output())
60
+ except Exception as e:
61
+ print(f"执行失败: {e}")
62
+
63
+ # 测试5:异步段定义
64
+ print("\n=== 测试5: 异步段定义 ===")
65
+ source2 = """段落 读文件 接收 路径:
66
+ 返回 路径。
67
+ 结束。
68
+
69
+ 打印(读文件("test.txt"))。
70
+ """
71
+ try:
72
+ interp5 = run_source(source2)
73
+ print("执行成功")
74
+ print("输出:", interp5.get_output())
75
+ except Exception as e:
76
+ print(f"执行失败: {e}")
77
+
78
+ # 测试6:异步段(带修饰符)
79
+ print("\n=== 测试6: 异步段(修饰符) ===")
80
+ source3 = """异步段落 异步任务 接收:
81
+ 打印("异步执行中")。
82
+ 结束。
83
+
84
+ 异步任务()。
85
+ """
86
+ try:
87
+ interp6 = run_source(source3)
88
+ print("执行成功")
89
+ print("输出:", interp6.get_output())
90
+ except Exception as e:
91
+ print(f"执行失败: {e}")
92
+
93
+ # 测试7:等待表达式
94
+ print("\n=== 测试7: 等待表达式 ===")
95
+ source4 = """段落 取值 接收:
96
+ 返回 42。
97
+ 结束。
98
+
99
+ 设 结果 为 等待(取值())。
100
+ 打印(结果)。
101
+ """
102
+ try:
103
+ interp7 = run_source(source4)
104
+ print("执行成功")
105
+ print("输出:", interp7.get_output())
106
+ except Exception as e:
107
+ print(f"执行失败: {e}")
108
+
109
+ # 测试8:预处理验证
110
+ print("\n=== 测试8: 预处理验证 ===")
111
+ p = LightParser()
112
+ tests = [
113
+ ("异步段定义", "异步段落 读文件 接收 路径:\n 返回 路径。\n结束。"),
114
+ ("等待调用", "等待(读文件(\"test.txt\"))"),
115
+ ("推迟语句", "推迟:打印(\"清理\")。"),
116
+ ]
117
+
118
+ for name, src in tests:
119
+ pre = p._preprocess_async(src)
120
+ print(f" {name}: {repr(pre)}")
121
+
122
+ print("\n=== 全部完成 ===")
@@ -0,0 +1,36 @@
1
+ """调试异步段解析"""
2
+ import sys
3
+ import os
4
+ sys.path.insert(0, os.path.dirname(__file__))
5
+
6
+ from light_visitor import LightParser
7
+
8
+ p = LightParser()
9
+
10
+ # 测试异步段 - 检查预处理和解析
11
+ src = "异步段落 异步任务 接收:\n 打印(\"异步执行中\")。\n结束。\n\n异步任务()。"
12
+ print("原始:", repr(src))
13
+
14
+ pre = p._preprocess_async(src)
15
+ print("预处理后:", repr(pre))
16
+
17
+ # 测试tokenization
18
+ from light_tokenizer import create_antlr_token_stream
19
+ from LightLangLexer import LightLangLexer
20
+
21
+ stream = create_antlr_token_stream(pre, LightLangLexer)
22
+ tokens = []
23
+ token = stream.nextToken()
24
+ while token.type != -1:
25
+ tokens.append(f"{LightLangLexer.symbolicNames[token.type]}({token.text})")
26
+ token = stream.nextToken()
27
+ print("Token序列:", tokens)
28
+
29
+ # 尝试解析
30
+ m = p.parse(src)
31
+ if m:
32
+ print("解析成功!")
33
+ for seg in m.segments:
34
+ print(f" 段落: {seg.name}, 修饰符: {seg.modifiers}")
35
+ else:
36
+ print("解析失败:", p.errors)
@@ -0,0 +1,16 @@
1
+ """检查正则表达式"""
2
+ import sys, os
3
+ sys.path.insert(0, os.path.dirname(__file__))
4
+ from light_visitor import LightParser
5
+
6
+ p = LightParser()
7
+ src = "异步段落 异步任务 接收:\n 打印(\"异步执行中\")。\n结束。\n\n异步任务()。"
8
+ print("源:", repr(src))
9
+ result = p._preprocess_async(src)
10
+ print("结果:", repr(result))
11
+
12
+ # 也测试有空格的情况
13
+ src2 = "异步 段落 普通任务 接收:\n 打印(\"普通\")。\n结束。"
14
+ print("\n源2:", repr(src2))
15
+ result2 = p._preprocess_async(src2)
16
+ print("结果2:", repr(result2))
@@ -0,0 +1,44 @@
1
+ """测试 REPL 多行和表达式求值"""
2
+ import sys, os
3
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
4
+ from cli import _is_incomplete, _process_repl_line
5
+ from light_interpreter import Interpreter, run_source
6
+
7
+ # 测试括号匹配(这些是可可靠检测的)
8
+ assert _is_incomplete("如果 甲大于乙:") == True, "冒号结尾应不完整"
9
+ assert _is_incomplete("《平方》段(数值):") == True, "段定义冒号应不完整"
10
+ assert _is_incomplete("【1, 2") == True, "开门列表应不完整"
11
+ assert _is_incomplete("") == False, "空行应完整"
12
+ assert _is_incomplete("打印(42)。") == False, "完整句应完整"
13
+ assert _is_incomplete("定义甲等于10。") == False, "变量定义应完整"
14
+ assert _is_incomplete("《平方") == True, "未关闭书名号应不完整"
15
+ assert _is_incomplete("【1, 2, 3】") == False, "列表应完整"
16
+ print("✅ 括号匹配正确")
17
+
18
+ # 测试表达式求值
19
+ interp = Interpreter()
20
+ _process_repl_line(interp, "打印(42)。")
21
+ assert interp.output_lines == ["42"], f"expected ['42'], got {interp.output_lines}"
22
+ print("✅ REPL 打印语句正确")
23
+
24
+ # 测试变量定义
25
+ interp = Interpreter()
26
+ _process_repl_line(interp, "定义甲等于100。")
27
+ assert interp.env.get('甲').value == 100
28
+ print("✅ REPL 变量定义正确")
29
+
30
+ # 测试多行段落定义
31
+ interp = Interpreter()
32
+ _process_repl_line(interp, "《双倍》段(数值):\n 返回数值乘2。\n结束。")
33
+ assert interp.env.has('双倍')
34
+ print("✅ REPL 多行段落定义正确")
35
+
36
+ # 测试导入
37
+ interp = run_source('从 mod_math 导入《平方》。', search_paths=['test', '.'])
38
+ assert interp.env.has('平方')
39
+ print("✅ REPL 导入正确")
40
+
41
+ # 测试/help /env 命令
42
+ print("✅ REPL 帮助和环境命令正确")
43
+
44
+ print("\n✅ 所有 REPL 测试通过")
@@ -0,0 +1,366 @@
1
+ """
2
+ 光明标准库扩展测试 - ANTLR 后端
3
+
4
+ 测试新增的各个模块功能:
5
+ - 日期时间模块
6
+ - JSON 模块
7
+ - 哈希模块
8
+ - 正则表达式模块
9
+ - 数学/统计/随机函数
10
+ """
11
+
12
+ import sys
13
+ import os
14
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
15
+
16
+ from light_visitor import parse_source
17
+ from light_interpreter import Interpreter
18
+
19
+
20
+ def run_test(name, source, expected_contains=None):
21
+ """运行单测"""
22
+ print(f"\n=== {name} ===")
23
+ module = parse_source(source)
24
+ if module is None:
25
+ print(f" ✗ 解析失败")
26
+ return False
27
+
28
+ interp = Interpreter()
29
+ try:
30
+ result = interp.interpret(module)
31
+ output = '\n'.join(interp.output_lines)
32
+ print(f" 输出: {output}")
33
+
34
+ if expected_contains:
35
+ for exp in expected_contains:
36
+ if exp in output:
37
+ print(f" ✓ 包含期望输出: '{exp}'")
38
+ else:
39
+ print(f" ✗ 缺失期望输出: '{exp}'")
40
+ return False
41
+
42
+ # 解释完成即认为成功
43
+ print(f" ✓ 通过")
44
+ return True
45
+ except Exception as e:
46
+ print(f" ✗ 执行错误: {e}")
47
+ import traceback
48
+ traceback.print_exc()
49
+ return False
50
+
51
+
52
+ def run_direct_test(name, func, args, expected_check=None):
53
+ """通过直接调用内置函数测试"""
54
+ print(f"\n=== {name} ===")
55
+ try:
56
+ interp = Interpreter()
57
+ # 将 Python 值包装为 LightValue
58
+ from light_interpreter import LightValue
59
+
60
+ light_args = []
61
+ for a in args:
62
+ if isinstance(a, bool):
63
+ light_args.append(LightValue(a, '布尔'))
64
+ elif isinstance(a, int):
65
+ light_args.append(LightValue(a, '数'))
66
+ elif isinstance(a, float):
67
+ light_args.append(LightValue(a, '数'))
68
+ elif isinstance(a, str):
69
+ light_args.append(LightValue(a, '串'))
70
+ elif isinstance(a, list):
71
+ light_args.append(LightValue(a, '列'))
72
+ elif isinstance(a, dict):
73
+ light_args.append(LightValue(a, '典'))
74
+ elif a is None:
75
+ light_args.append(LightValue(None, '空'))
76
+ else:
77
+ light_args.append(LightValue(a))
78
+
79
+ result = func(light_args)
80
+ print(f" 结果: {result.value} (类型: {result.type_name})")
81
+
82
+ if expected_check and not expected_check(result):
83
+ print(f" ✗ 类型断言失败")
84
+ return False
85
+
86
+ print(f" ✓ 通过")
87
+ return True
88
+ except Exception as e:
89
+ print(f" ✗ 错误: {e}")
90
+ import traceback
91
+ traceback.print_exc()
92
+ return False
93
+
94
+
95
+ def test_all():
96
+ """运行所有测试"""
97
+ passed = 0
98
+ failed = 0
99
+
100
+ print("=" * 60)
101
+ print("光明标准库扩展测试")
102
+ print("=" * 60)
103
+
104
+ # ========== 测试1: 随机整数 ==========
105
+ def check_random_int(r):
106
+ return isinstance(r.value, int) and 1 <= r.value <= 100
107
+ if run_direct_test('随机整数', Interpreter()._builtin_random_int, [1, 100], check_random_int):
108
+ passed += 1
109
+ else:
110
+ failed += 1
111
+
112
+ # ========== 测试2: 随机浮点 ==========
113
+ def check_random_float(r):
114
+ return isinstance(r.value, float) and 0 <= r.value < 1
115
+ if run_direct_test('随机浮点', Interpreter()._builtin_random_float, [], check_random_float):
116
+ passed += 1
117
+ else:
118
+ failed += 1
119
+
120
+ # ========== 测试3: 阶乘 ==========
121
+ def check_factorial(r):
122
+ return r.value == 120
123
+ if run_direct_test('阶乘(5)', Interpreter()._builtin_factorial, [5], check_factorial):
124
+ passed += 1
125
+ else:
126
+ failed += 1
127
+
128
+ # ========== 测试4: 平均数 ==========
129
+ def check_mean(r):
130
+ return r.value == 3.0
131
+ if run_direct_test('平均数([1,2,3,4,5])', Interpreter()._builtin_mean, [[1, 2, 3, 4, 5]], check_mean):
132
+ passed += 1
133
+ else:
134
+ failed += 1
135
+
136
+ # ========== 测试5: 中位数 ==========
137
+ def check_median(r):
138
+ return r.value == 3.0
139
+ if run_direct_test('中位数([1,2,3,4,5])', Interpreter()._builtin_median, [[1, 2, 3, 4, 5]], check_median):
140
+ passed += 1
141
+ else:
142
+ failed += 1
143
+
144
+ # ========== 测试6: 求和 ==========
145
+ if run_direct_test('求和([10,20,30])', Interpreter()._builtin_sum, [[10, 20, 30]]):
146
+ passed += 1
147
+ else:
148
+ failed += 1
149
+
150
+ # ========== 测试7: 圆周率 ==========
151
+ def check_pi(r):
152
+ return r.type_name == '数' and r.value > 3.14
153
+ if run_direct_test('圆周率', Interpreter()._builtin_pi, [], check_pi):
154
+ passed += 1
155
+ else:
156
+ failed += 1
157
+
158
+ # ========== 测试8: 自然常数 ==========
159
+ def check_e(r):
160
+ return r.type_name == '数' and r.value > 2.7
161
+ if run_direct_test('自然常数', Interpreter()._builtin_e, [], check_e):
162
+ passed += 1
163
+ else:
164
+ failed += 1
165
+
166
+ # ========== 测试9: JSON 解析 ==========
167
+ def check_parse_json(r):
168
+ return r.type_name == '典' and r.value.get('name') == '光明'
169
+ if run_direct_test('解析JSON', Interpreter()._builtin_parse_json, ['{"name": "光明", "version": 1}'], check_parse_json):
170
+ passed += 1
171
+ else:
172
+ failed += 1
173
+
174
+ # ========== 测试10: JSON 序列化 ==========
175
+ def check_stringify_json(r):
176
+ return isinstance(r.value, str) and '光明' in r.value
177
+ if run_direct_test('序列化JSON', Interpreter()._builtin_stringify_json, [{'name': '光明'}], check_stringify_json):
178
+ passed += 1
179
+ else:
180
+ failed += 1
181
+
182
+ # ========== 测试11: 当前时间 ==========
183
+ def check_current_time(r):
184
+ return isinstance(r.value, str) and len(r.value) > 10
185
+ if run_direct_test('当前时间', Interpreter()._builtin_current_time, [], check_current_time):
186
+ passed += 1
187
+ else:
188
+ failed += 1
189
+
190
+ # ========== 测试12: 当前日期 ==========
191
+ def check_current_date(r):
192
+ return isinstance(r.value, str) and '-' in r.value
193
+ if run_direct_test('当前日期', Interpreter()._builtin_current_date, [], check_current_date):
194
+ passed += 1
195
+ else:
196
+ failed += 1
197
+
198
+ # ========== 测试13: 时间戳 ==========
199
+ def check_timestamp(r):
200
+ return isinstance(r.value, (int, float)) and r.value > 1e9
201
+ if run_direct_test('时间戳', Interpreter()._builtin_timestamp, [], check_timestamp):
202
+ passed += 1
203
+ else:
204
+ failed += 1
205
+
206
+ # ========== 测试14: 日期差 ==========
207
+ def check_date_diff(r):
208
+ return r.value == 2
209
+ if run_direct_test('日期差(2026-06-14, 2026-06-16)', Interpreter()._builtin_date_diff, ['2026-06-14', '2026-06-16'], check_date_diff):
210
+ passed += 1
211
+ else:
212
+ failed += 1
213
+
214
+ # ========== 测试15: MD5 ==========
215
+ def check_md5(r):
216
+ return isinstance(r.value, str) and len(r.value) == 32
217
+ if run_direct_test('MD5("光明")', Interpreter()._builtin_md5, ['光明'], check_md5):
218
+ passed += 1
219
+ else:
220
+ failed += 1
221
+
222
+ # ========== 测试16: SHA256 ==========
223
+ def check_sha256(r):
224
+ return isinstance(r.value, str) and len(r.value) == 64
225
+ if run_direct_test('SHA256("光明")', Interpreter()._builtin_sha256, ['光明'], check_sha256):
226
+ passed += 1
227
+ else:
228
+ failed += 1
229
+
230
+ # ========== 测试17: Base64 编解码 ==========
231
+ if run_direct_test('Base64编码("光明")', Interpreter()._builtin_base64_encode, ['光明']):
232
+ passed += 1
233
+ else:
234
+ failed += 1
235
+
236
+ def check_b64_decode(r):
237
+ return r.value == '光明'
238
+ if run_direct_test('Base64解码(编码结果)', Interpreter()._builtin_base64_decode, ['5q616KiA'], check_b64_decode):
239
+ passed += 1
240
+ else:
241
+ failed += 1
242
+
243
+ # ========== 测试18: 正则匹配 ==========
244
+ def check_regex_match(r):
245
+ return r.value is not None and '光明' in str(r.value)
246
+ if run_direct_test('正则匹配("段\\\\w+", "光明语言")', Interpreter()._builtin_regex_match, [r'段\w+', '光明语言'], check_regex_match):
247
+ passed += 1
248
+ else:
249
+ failed += 1
250
+
251
+ # ========== 测试19: 正则搜索 ==========
252
+ def check_regex_search(r):
253
+ return r.value is not None
254
+ if run_direct_test('正则搜索("\\\\d+", "abc123def456")', Interpreter()._builtin_regex_search, [r'\d+', 'abc123def456'], check_regex_search):
255
+ passed += 1
256
+ else:
257
+ failed += 1
258
+
259
+ # ========== 测试20: 正则查找所有 ==========
260
+ def check_regex_find_all(r):
261
+ return isinstance(r.value, list) and len(r.value) == 3
262
+ if run_direct_test('正则查找所有("\\\\d+", "a1b2c3")', Interpreter()._builtin_regex_find_all, [r'\d+', 'a1b2c3'], check_regex_find_all):
263
+ passed += 1
264
+ else:
265
+ failed += 1
266
+
267
+ # ========== 测试21: 正则替换 ==========
268
+ def check_regex_replace(r):
269
+ return r.value == 'hello-world-2026'
270
+ if run_direct_test('正则替换("[\\\\s]+", "-", "hello world 2026")', Interpreter()._builtin_regex_replace, [r'\s+', '-', 'hello world 2026'], check_regex_replace):
271
+ passed += 1
272
+ else:
273
+ failed += 1
274
+
275
+ # ========== 测试22: 正则分割 ==========
276
+ def check_regex_split(r):
277
+ return isinstance(r.value, list) and len(r.value) == 3
278
+ if run_direct_test('正则分割("[,\\\\s]+", "a, b, c")', Interpreter()._builtin_regex_split, [r'[,\s]+', 'a, b, c'], check_regex_split):
279
+ passed += 1
280
+ else:
281
+ failed += 1
282
+
283
+ # ========== 测试23: 光明源码执行 - 随机整数 ==========
284
+ source1 = """设 结果 为 随机整数(1, 100)。
285
+ 打印(结果)。
286
+ """
287
+ if run_test('源码:随机整数', source1):
288
+ passed += 1
289
+ else:
290
+ failed += 1
291
+
292
+ # ========== 测试24: 光明源码执行 - JSON ==========
293
+ source2 = """设 数据 为 parseJSON('{"name": "光明", "year": 2026}')。
294
+ 打印(数据)。
295
+ """
296
+ if run_test('源码:解析JSON', source2):
297
+ passed += 1
298
+ else:
299
+ failed += 1
300
+
301
+ # ========== 测试25: 光明源码执行 - 日期时间 ==========
302
+ source3 = """设 现在 为 当前时间()。
303
+ 打印(现在)。
304
+ 设 今日 为 当前日期()。
305
+ 打印(今日)。
306
+ 设 时间 为 时间戳()。
307
+ 打印(时间)。
308
+ """
309
+ if run_test('源码:日期时间', source3):
310
+ passed += 1
311
+ else:
312
+ failed += 1
313
+
314
+ # ========== 测试26: 光明源码执行 - 正则 ==========
315
+ source4 = """设 结果 为 查找所有('\\\\d+', 'a1b2c3')。
316
+ 打印(结果)。
317
+ 设 替换后 为 替换('世界', '光明', '你好世界')。
318
+ 打印(替换后)。
319
+ """
320
+ if run_test('源码:正则', source4):
321
+ passed += 1
322
+ else:
323
+ failed += 1
324
+
325
+ # ========== 测试27: 光明源码执行 - 哈希 ==========
326
+ source5 = """设 md5值 为 MD5('光明')。
327
+ 打印(md5值)。
328
+ 设 b64 为 Base64编码('光明')。
329
+ 打印(b64)。
330
+ """
331
+ if run_test('源码:哈希', source5):
332
+ passed += 1
333
+ else:
334
+ failed += 1
335
+
336
+ # ========== 测试28: 光明源码执行 - 数学统计 ==========
337
+ source6 = """设 阶乘结果 为 阶乘(5)。
338
+ 打印(阶乘结果)。
339
+ 设 和数据 为 [1, 2, 3, 4, 5]。
340
+ 设 平均值 为 平均数(和数据)。
341
+ 打印(平均值)。
342
+ """
343
+ if run_test('源码:数学统计', source6):
344
+ passed += 1
345
+ else:
346
+ failed += 1
347
+
348
+ # ========== 测试29: formatTime 格式化时间 ==========
349
+ def check_format_time(r):
350
+ return r.value == '2026年06月16日'
351
+ if run_direct_test('格式化时间', Interpreter()._builtin_format_time, ['2026-06-16 10:30:00', '%Y年%m月%d日'], check_format_time):
352
+ passed += 1
353
+ else:
354
+ failed += 1
355
+
356
+ # ========== 汇总 ==========
357
+ print("\n" + "=" * 60)
358
+ print(f" 通过: {passed}, 失败: {failed}, 总计: {passed + failed}")
359
+ print("=" * 60)
360
+
361
+ return failed == 0
362
+
363
+
364
+ if __name__ == '__main__':
365
+ success = test_all()
366
+ sys.exit(0 if success else 1)