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.
- antlrparser/__init__.py +22 -0
- antlrparser/_test_async.py +122 -0
- antlrparser/_test_basic.py +36 -0
- antlrparser/_test_regex.py +16 -0
- antlrparser/_test_repl.py +44 -0
- antlrparser/_test_stdlib.py +366 -0
- antlrparser/cli.py +620 -0
- antlrparser/compile_runtime.py +22 -0
- antlrparser/indent_preprocessor.py +183 -0
- antlrparser/interpreter_core.py +1319 -0
- antlrparser/light_ast.py +587 -0
- antlrparser/light_builtins.py +984 -0
- antlrparser/light_bytecode.py +761 -0
- antlrparser/light_cli.py +211 -0
- antlrparser/light_compiler.py +108 -0
- antlrparser/light_error_handler.py +212 -0
- antlrparser/light_interpreter.py +125 -0
- antlrparser/light_llvm.py +149 -0
- antlrparser/light_module.py +250 -0
- antlrparser/light_parser/LightLangLexer.py +716 -0
- antlrparser/light_parser/LightLangParser.py +10029 -0
- antlrparser/light_parser/LightLangParserListener.py +843 -0
- antlrparser/light_parser/LightLangParserVisitor.py +476 -0
- antlrparser/light_repl.py +301 -0
- antlrparser/light_tokenizer.py +1232 -0
- antlrparser/light_visitor.py +846 -0
- antlrparser/llvm_codegen.py +1036 -0
- antlrparser/llvm_core.py +272 -0
- antlrparser/main.py +153 -0
- antlrparser/modules/data_models.light +41 -0
- antlrparser/modules/math_utils.light +32 -0
- antlrparser/modules/string_utils.light +28 -0
- antlrparser/operations.py +96 -0
- antlrparser/self_hosted/ast.light +156 -0
- antlrparser/self_hosted/bootstrap_test.light +104 -0
- antlrparser/self_hosted/interpreter.light +609 -0
- antlrparser/self_hosted/llvm_codegen.light +390 -0
- antlrparser/self_hosted/parser.light +1491 -0
- antlrparser/self_hosted/run_bootstrap_test.py +102 -0
- antlrparser/self_hosted/simple_test.light +33 -0
- antlrparser/self_hosted/stdlib.light +788 -0
- antlrparser/self_hosted/test_basic.py +203 -0
- antlrparser/self_hosted/test_bootstrap.light +43 -0
- antlrparser/self_hosted/test_comprehensive.py +615 -0
- antlrparser/self_hosted/test_enhancements.py +290 -0
- antlrparser/self_hosted/test_enhancements_simple.py +163 -0
- antlrparser/self_hosted/test_final.py +300 -0
- antlrparser/self_hosted/test_full_bootstrap.py +282 -0
- antlrparser/self_hosted/test_integration.py +391 -0
- antlrparser/self_hosted/test_interpreter.py +60 -0
- antlrparser/self_hosted/test_light_interpreter.py +139 -0
- antlrparser/self_hosted/test_parser.py +299 -0
- antlrparser/self_hosted/test_python_interpreter.py +87 -0
- antlrparser/self_hosted/test_stdlib.py +74 -0
- antlrparser/self_hosted/test_summary.py +147 -0
- antlrparser/self_hosted/test_syntax.light +5 -0
- antlrparser/self_hosted/test_tokenizer.py +167 -0
- antlrparser/self_hosted/tokenizer.light +468 -0
- antlrparser/test/mod_advanced.light +16 -0
- antlrparser/test/mod_greet.light +10 -0
- antlrparser/test/mod_math.light +27 -0
- antlrparser/test/mod_util.light +13 -0
- antlrparser/test/sample_basic.light +20 -0
- antlrparser/test/sample_controlflow.light +46 -0
- antlrparser/test/sample_quicksort.light +19 -0
- antlrparser/test/sample_types.light +58 -0
- antlrparser/test/test_antlr_comprehensive.light +101 -0
- antlrparser/test/test_antlr_comprehensive.py +80 -0
- antlrparser/test/test_antlr_validation.py +279 -0
- antlrparser/test/test_class_parse.py +41 -0
- antlrparser/test/test_compile.py +177 -0
- antlrparser/test/test_controlflow.py +324 -0
- antlrparser/test/test_debug.py +34 -0
- antlrparser/test/test_debug_eval.py +32 -0
- antlrparser/test/test_debug_expr.py +32 -0
- antlrparser/test/test_debug_module.py +40 -0
- antlrparser/test/test_debug_new.py +25 -0
- antlrparser/test/test_dict.py +314 -0
- antlrparser/test/test_dual_backend.py +176 -0
- antlrparser/test/test_final_antlr.light +14 -0
- antlrparser/test/test_final_antlr.py +36 -0
- antlrparser/test/test_interface_parse.py +52 -0
- antlrparser/test/test_interpreter.py +583 -0
- antlrparser/test/test_list_dict.py +161 -0
- antlrparser/test/test_module.py +280 -0
- antlrparser/test/test_oop_comprehensive.py +51 -0
- antlrparser/test/test_oop_features.py +57 -0
- antlrparser/test/test_parse_tree.py +25 -0
- antlrparser/test/test_parser.py +186 -0
- antlrparser/test/test_parser_debug.py +45 -0
- antlrparser/test/test_simple_oop.py +37 -0
- antlrparser/test/test_src_features.py +53 -0
- antlrparser/test/test_tokenizer.py +30 -0
- antlrparser/test/test_tokenizer2.py +32 -0
- antlrparser/test/test_tokenizer_new.py +16 -0
- antlrparser/test/test_types.py +513 -0
- antlrparser/test_list_len.light +33 -0
- antlrparser/test_oop.light +50 -0
- antlrparser/test_oop_full.light +38 -0
- antlrparser/test_program.light +46 -0
- antlrparser/test_program_simple.light +21 -0
- antlrparser/test_program_simple2.light +28 -0
- antlrparser/test_stdlib.light +49 -0
- antlrparser/test_stdlib2.light +50 -0
- antlrparser/visitor_decl.py +907 -0
- antlrparser/visitor_expr.py +886 -0
- antlrparser/visitor_stmt.py +495 -0
- antlrparser/web_playground/_test_examples.py +26 -0
- antlrparser/web_playground/server.py +421 -0
- antlrparser/web_playground/test_api.py +29 -0
- cli/__init__.py +11 -0
- cli/light.py +2050 -0
- cli/light_unified.py +1324 -0
- cli/lightc.py +313 -0
- cli/tutorial.py +866 -0
- cli/tutorial_30min.light +1026 -0
- guangming-0.4.0.dist-info/METADATA +982 -0
- guangming-0.4.0.dist-info/RECORD +482 -0
- guangming-0.4.0.dist-info/WHEEL +5 -0
- guangming-0.4.0.dist-info/entry_points.txt +3 -0
- guangming-0.4.0.dist-info/licenses/LICENSE +21 -0
- guangming-0.4.0.dist-info/top_level.txt +5 -0
- src/__init__.py +18 -0
- src/arity_parser.py +297 -0
- src/ast_nodes.py +1135 -0
- src/ast_nodes_v3.py +1537 -0
- src/ast_unified.py +506 -0
- src/chinese_units.py +435 -0
- src/code_generator.py +6157 -0
- src/code_generator_unified.py +2983 -0
- src/compiler.py +1777 -0
- src/compiler_cache.py +335 -0
- src/core/__init__.py +27 -0
- src/core/config.py +152 -0
- src/core/errors.py +167 -0
- src/core/interfaces.py +149 -0
- src/debug_engine.py +436 -0
- src/doc_generator.py +259 -0
- src/elastic_syntax.py +306 -0
- src/enhanced_errors.py +984 -0
- src/error_formatter.py +665 -0
- src/errors.py +934 -0
- src/feedback_collector.py +571 -0
- src/file_watcher.py +172 -0
- src/first_run.py +369 -0
- src/formatter/__init__.py +99 -0
- src/formatter/cli.py +110 -0
- src/formatter/light_formatter.py +131 -0
- src/formatter.py +164 -0
- src/incremental_build.py +961 -0
- src/incremental_compiler.py +675 -0
- src/interactive_tutorial.py +1019 -0
- src/keywords.py +712 -0
- src/l3_echarts.py +348 -0
- src/l3_markdown.py +303 -0
- src/lexer.py +4723 -0
- src/light_parser_v3.py +133 -0
- src/lightpkg.py +1699 -0
- src/linter/__init__.py +10 -0
- src/linter/cli.py +75 -0
- src/linter/light_linter.py +1130 -0
- src/llvm/codegen.py +973 -0
- src/llvm/codegen_typed.py +6578 -0
- src/llvm/compiler.py +1681 -0
- src/llvm/core.py +403 -0
- src/llvm/dwarf.py +648 -0
- src/llvm/opt_passes.py +590 -0
- src/llvm/optimizer_pipeline.py +678 -0
- src/llvm/size_optimizer.py +583 -0
- src/llvm/startup_optimizer.py +303 -0
- src/llvm_dependency.py +855 -0
- src/migration/__init__.py +11 -0
- src/migration/cli.py +136 -0
- src/migration/light_migrator.py +361 -0
- src/migration/v33_to_v40.py +279 -0
- src/migration/v40_to_v50.py +272 -0
- src/module_resolver.py +1300 -0
- src/optimizer/__init__.py +17 -0
- src/optimizer/base.py +173 -0
- src/optimizer/constant_fold.py +178 -0
- src/optimizer/cse.py +255 -0
- src/optimizer/dead_code.py +156 -0
- src/optimizer/inline.py +279 -0
- src/optimizer/loop_invariant.py +145 -0
- src/optimizer/peephole.py +174 -0
- src/package_installer.py +2288 -0
- src/package_manager.py +1058 -0
- src/package_security.py +804 -0
- src/parser_core.py +651 -0
- src/parser_expr.py +3801 -0
- src/parser_stmt.py +7634 -0
- src/profiler.py +527 -0
- src/registry_server.py +936 -0
- src/repl/__init__.py +17 -0
- src/repl/commands.py +474 -0
- src/repl/completer.py +519 -0
- src/repl/core.py +374 -0
- src/repl/enhanced.py +130 -0
- src/repl/executor.py +458 -0
- src/repl/highlighter.py +188 -0
- src/scope_shadow_check.py +265 -0
- src/semantic_analyzer.py +374 -0
- src/semantic_identifier.py +208 -0
- src/templates/__init__.py +55 -0
- src/templates/data_analysis/package.toml +9 -0
- src/templates/data_analysis//344/270/273.light +46 -0
- src/templates/data_analysis//345/210/206/346/236/220.light +120 -0
- src/templates/student_management/package.toml +9 -0
- src/templates/student_management//344/270/273.light +44 -0
- src/templates/student_management//345/255/246/347/224/237/347/256/241/347/220/206.light +30 -0
- src/templates/student_management//346/210/220/347/273/251/347/256/241/347/220/206.light +49 -0
- src/templates/web_service/package.toml +9 -0
- src/templates/web_service//344/270/273.light +46 -0
- src/templates/web_service//350/267/257/347/224/261.light +32 -0
- src/templates.py +383 -0
- src/test_exception_output.py +68 -0
- src/test_output.py +38 -0
- src/test_runner.py +469 -0
- src/tokens.py +97 -0
- src/type_checker.py +1488 -0
- src/type_inferencer.py +2476 -0
- src/type_system.py +1663 -0
- src/verb_info.py +217 -0
- src/version.py +89 -0
- src/wasm_target.py +577 -0
- stdlib/Base64.light +319 -0
- stdlib/Base64.py +238 -0
- stdlib/CSV.light +21 -0
- stdlib/CSV.py +246 -0
- stdlib/CSV/350/257/273/345/206/231/345/231/250.light +229 -0
- stdlib/CSV/350/257/273/345/206/231/345/231/250.py +481 -0
- stdlib/FFI.light +47 -0
- stdlib/FFI.py +642 -0
- stdlib/FFI/345/242/236/345/274/272.light +9 -0
- stdlib/FFI/345/242/236/345/274/272.py +627 -0
- stdlib/HTTP.light +19 -0
- stdlib/HTTP.py +269 -0
- stdlib/HTTP/346/234/215/345/212/241/347/253/257.light +494 -0
- stdlib/JSON.light +172 -0
- stdlib/JSON.py +1147 -0
- stdlib/JSONL.light +53 -0
- stdlib/JSON/346/240/270/345/277/203.light +413 -0
- stdlib/JSON/347/274/226/350/247/243/347/240/201.light +256 -0
- stdlib/SSE.light +153 -0
- stdlib/XML.light +25 -0
- stdlib/XML.py +361 -0
- stdlib/__init__.py +317 -0
- stdlib/_light_import_hook.py +287 -0
- stdlib/_t5b_runtime.py +63 -0
- stdlib/builtins.py +1570 -0
- stdlib/inspect.light +28 -0
- stdlib/lightpub/CSV.py +233 -0
- stdlib/lightpub/HTTP/345/256/242/346/210/267/347/253/257.py +819 -0
- stdlib/lightpub/HTTP/346/234/215/345/212/241/347/253/257.py +737 -0
- stdlib/lightpub/JSON.py +264 -0
- stdlib/lightpub/SQLite.py +375 -0
- stdlib/lightpub/Socket.py +343 -0
- stdlib/lightpub/URL/350/247/243/346/236/220.py +143 -0
- stdlib/lightpub/Web/346/241/206/346/236/266.py +1413 -0
- stdlib/lightpub/__index__.py +1897 -0
- stdlib/lightpub/__init__.py +348 -0
- stdlib/lightpub//344/272/213/344/273/266/351/251/261/345/212/250.py +114 -0
- stdlib/lightpub//344/272/214/350/277/233/345/210/266/347/274/226/347/240/201.py +270 -0
- stdlib/lightpub//344/273/273/345/212/241/351/230/237/345/210/227.py +335 -0
- stdlib/lightpub//345/212/240/345/257/206.py +358 -0
- stdlib/lightpub//345/212/240/345/257/206/347/256/227/346/263/225.py +160 -0
- stdlib/lightpub//345/215/217/347/250/213.py +539 -0
- stdlib/lightpub//345/215/225/345/205/203/346/265/213/350/257/225/346/241/206/346/236/266.py +434 -0
- stdlib/lightpub//345/216/213/347/274/251/347/256/227/346/263/225.py +134 -0
- stdlib/lightpub//345/221/275/344/273/244/350/241/214/345/217/202/346/225/260.py +156 -0
- stdlib/lightpub//345/223/210/345/270/214.py +364 -0
- stdlib/lightpub//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.py +265 -0
- stdlib/lightpub//345/257/206/347/240/201/345/223/210/345/270/214.py +112 -0
- stdlib/lightpub//345/271/266/350/241/214/350/256/241/347/256/227.py +118 -0
- stdlib/lightpub//345/274/202/346/255/245/350/277/220/350/241/214/346/227/266.py +765 -0
- stdlib/lightpub//346/200/247/350/203/275/345/210/206/346/236/220.py +544 -0
- stdlib/lightpub//346/216/222/345/272/217/344/270/216/346/220/234/347/264/242.py +272 -0
- stdlib/lightpub//346/225/260/345/200/274/350/256/241/347/256/227.py +226 -0
- stdlib/lightpub//346/225/260/345/255/246/350/277/220/347/256/227.py +331 -0
- stdlib/lightpub//346/225/260/346/215/256/345/257/274/345/205/245/345/257/274/345/207/272.py +708 -0
- stdlib/lightpub//346/225/260/346/215/256/347/273/223/346/236/204.py +664 -0
- stdlib/lightpub//346/226/207/344/273/266/344/270/212/344/274/240.py +505 -0
- stdlib/lightpub//346/226/207/344/273/266/347/263/273/347/273/237.py +315 -0
- stdlib/lightpub//346/227/245/345/277/227/347/263/273/347/273/237.py +149 -0
- stdlib/lightpub//346/227/245/346/234/237/345/272/217/345/210/227.py +601 -0
- stdlib/lightpub//346/227/245/346/234/237/346/227/266/351/227/264.py +368 -0
- stdlib/lightpub//346/250/241/346/235/277/346/270/262/346/237/223.py +361 -0
- stdlib/lightpub//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.py +225 -0
- stdlib/lightpub//346/266/210/346/201/257/351/230/237/345/210/227.py +151 -0
- stdlib/lightpub//347/216/257/345/242/203/345/217/230/351/207/217.py +180 -0
- stdlib/lightpub//347/256/227/346/263/225/345/267/245/345/205/267.py +350 -0
- stdlib/lightpub//347/261/273/345/236/213/345/267/245/345/205/267.py +210 -0
- stdlib/lightpub//347/263/273/347/273/237/344/277/241/346/201/257.py +386 -0
- stdlib/lightpub//347/272/277/347/250/213.py +362 -0
- stdlib/lightpub//347/273/237/350/256/241/345/210/206/346/236/220.py +1572 -0
- stdlib/lightpub//347/274/223/345/255/230/347/263/273/347/273/237.py +204 -0
- stdlib/lightpub//347/275/221/347/273/234/345/267/245/345/205/267.py +398 -0
- stdlib/lightpub//350/257/201/344/271/246.py +446 -0
- stdlib/lightpub//350/267/257/345/276/204/345/244/204/347/220/206.py +201 -0
- stdlib/lightpub//350/277/233/347/250/213/347/256/241/347/220/206.py +208 -0
- stdlib/lightpub//350/277/236/346/216/245/346/261/240.py +185 -0
- stdlib/lightpub//350/277/255/344/273/243/345/231/250/345/267/245/345/205/267.py +176 -0
- stdlib/lightpub//351/202/256/344/273/266.py +323 -0
- stdlib/lightpub//351/205/215/347/275/256/347/256/241/347/220/206.py +480 -0
- stdlib/lightpub//351/224/231/350/257/257/345/244/204/347/220/206.py +177 -0
- stdlib/lightpub//351/232/217/346/234/272/346/225/260.py +101 -0
- stdlib/lightpub//351/233/206/345/220/210/346/211/251/345/261/225.py +211 -0
- stdlib/re.light +1173 -0
- stdlib/sys.light +55 -0
- stdlib/time.light +87 -0
- stdlib/uuid/345/267/245/345/205/267.light +236 -0
- stdlib/uuid/345/267/245/345/205/267.py +187 -0
- stdlib//344/270/255/345/233/275/344/274/240/347/273/237/350/212/202/346/227/245.light +269 -0
- stdlib//344/270/255/345/233/275/344/274/240/347/273/237/350/212/202/346/227/245.py +414 -0
- stdlib//344/270/255/345/233/275/350/241/214/346/224/277/345/214/272/345/210/222.light +756 -0
- stdlib//344/270/255/345/233/275/350/241/214/346/224/277/345/214/272/345/210/222.py +416 -0
- stdlib//344/270/255/346/226/207NLP.light +133 -0
- stdlib//344/270/255/346/226/207NLP.py +1437 -0
- stdlib//344/270/255/346/226/207/345/210/206/350/257/215.light +162 -0
- stdlib//344/270/255/346/226/207/345/210/206/350/257/215.py +322 -0
- stdlib//344/270/255/346/226/207/346/225/260/345/255/227/350/275/254/346/215/242.light +250 -0
- stdlib//344/270/255/346/226/207/346/225/260/345/255/227/350/275/254/346/215/242.py +417 -0
- stdlib//344/270/255/346/226/207/346/226/207/346/234/254.light +39 -0
- stdlib//344/270/255/346/226/207/346/226/207/346/234/254.py +440 -0
- stdlib//344/270/255/346/226/207/346/226/207/346/234/254/345/244/204/347/220/206.light +241 -0
- stdlib//344/270/255/346/226/207/346/226/207/346/234/254/345/244/204/347/220/206.py +360 -0
- stdlib//344/270/255/346/226/207/347/274/226/347/240/201.light +370 -0
- stdlib//344/270/255/346/226/207/347/274/226/347/240/201.py +397 -0
- stdlib//344/270/255/346/255/242.light +82 -0
- stdlib//344/270/264/346/227/266/346/226/207/344/273/266.light +17 -0
- stdlib//344/270/264/346/227/266/346/226/207/344/273/266.py +293 -0
- stdlib//344/272/213/344/273/266/346/200/273/347/272/277.light +268 -0
- stdlib//344/273/243/347/220/206/345/267/245/345/205/267/351/233/206.light +789 -0
- stdlib//344/273/243/347/220/206/345/276/252/347/216/257.light +800 -0
- stdlib//344/274/252/347/273/210/347/253/257.light +589 -0
- stdlib//344/277/241/345/217/267.light +14 -0
- stdlib//344/277/241/345/217/267.py +198 -0
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/210/227/350/241/250.light +133 -0
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/210/244/345/236/213.light +106 -0
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/345/255/227/345/205/270.light +74 -0
- 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
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/347/263/273/347/273/237.light +35 -0
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/350/267/257/345/276/204.light +97 -0
- stdlib//345/206/205/347/275/256/346/240/270/345/277/203/350/275/254/346/215/242.light +67 -0
- stdlib//345/206/234/345/216/206.light +660 -0
- stdlib//345/206/234/345/216/206.py +447 -0
- stdlib//345/210/206/345/270/203/345/274/217//344/270/273/346/216/247.light +24 -0
- stdlib//345/210/206/345/270/203/345/274/217//350/212/202/347/202/271.light +21 -0
- 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
- 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
- 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
- stdlib//345/210/206/350/257/215.light +10 -0
- stdlib//345/210/206/350/257/215.py +174 -0
- stdlib//345/210/227/350/241/250/345/267/245/345/205/267.light +290 -0
- stdlib//345/210/227/350/241/250/345/267/245/345/205/267.py +77 -0
- stdlib//345/212/240/345/257/206.light +42 -0
- stdlib//345/212/240/345/257/206.py +634 -0
- stdlib//345/216/206/346/263/225.light +41 -0
- stdlib//345/216/206/346/263/225.py +372 -0
- stdlib//345/217/202/346/225/260/350/247/243/346/236/220.light +274 -0
- stdlib//345/217/202/346/225/260/350/247/243/346/236/220.py +311 -0
- stdlib//345/220/221/351/207/217.light +330 -0
- stdlib//345/220/221/351/207/217.py +422 -0
- stdlib//345/223/210/345/270/214.light +58 -0
- stdlib//345/223/210/345/270/214.py +152 -0
- stdlib//345/233/276/345/203/217/345/244/204/347/220/206/345/237/272/347/241/200.light +145 -0
- stdlib//345/233/276/345/203/217/345/244/204/347/220/206/345/237/272/347/241/200.py +482 -0
- stdlib//345/244/215/346/225/260.light +108 -0
- stdlib//345/244/215/346/225/260.py +181 -0
- stdlib//345/244/226/351/203/250/345/221/275/344/273/244.light +19 -0
- stdlib//345/244/226/351/203/250/345/221/275/344/273/244.py +304 -0
- stdlib//345/244/247/346/250/241/345/236/213/345/256/242/346/210/267/347/253/257.light +394 -0
- stdlib//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.light +17 -0
- stdlib//345/255/227/347/254/246/344/270/262/345/244/204/347/220/206.py +565 -0
- stdlib//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.light +767 -0
- stdlib//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.py +496 -0
- 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
- stdlib//345/255/227/347/254/246/344/270/262/345/270/270/351/207/217.light +311 -0
- stdlib//345/255/227/347/254/246/344/270/262/345/270/270/351/207/217.py +227 -0
- stdlib//345/255/227/350/212/202/347/274/223/345/206/262.light +84 -0
- stdlib//345/257/271/350/261/241/346/261/240/347/274/223/345/255/230.light +255 -0
- stdlib//345/257/271/350/261/241/346/261/240/347/274/223/345/255/230.py +424 -0
- stdlib//345/271/266/345/217/221.light +278 -0
- stdlib//345/272/246/351/207/217.light +136 -0
- stdlib//346/200/247/350/203/275.light +15 -0
- stdlib//346/200/247/350/203/275.py +230 -0
- stdlib//346/211/213/346/234/272/345/217/267/346/240/241/351/252/214.light +163 -0
- stdlib//346/211/213/346/234/272/345/217/267/346/240/241/351/252/214.py +645 -0
- stdlib//346/213/274/351/237/263/350/275/254/346/215/242.light +2932 -0
- stdlib//346/213/274/351/237/263/350/275/254/346/215/242.py +663 -0
- stdlib//346/216/222/345/272/217.light +171 -0
- stdlib//346/216/222/345/272/217.py +298 -0
- stdlib//346/216/222/347/211/210.light +24 -0
- stdlib//346/216/222/347/211/210.py +327 -0
- stdlib//346/217/222/344/273/266.light +240 -0
- stdlib//346/223/215/344/275/234/347/263/273/347/273/237.light +58 -0
- stdlib//346/225/260/345/255/246.light +305 -0
- stdlib//346/225/260/345/255/246.py +739 -0
- stdlib//346/225/260/345/255/246/347/273/237/350/256/241.py +399 -0
- stdlib//346/225/260/346/215/256/347/273/223/346/236/204.light +606 -0
- stdlib//346/225/260/346/215/256/347/273/223/346/236/204.py +989 -0
- stdlib//346/225/260/346/215/256/347/273/223/346/236/204/350/275/273/351/207/217.light +179 -0
- stdlib//346/225/260/346/215/256/351/252/214/350/257/201.light +320 -0
- stdlib//346/225/260/346/215/256/351/252/214/350/257/201.py +331 -0
- stdlib//346/226/207/344/273/266/345/214/271/351/205/215.light +20 -0
- stdlib//346/226/207/344/273/266/345/214/271/351/205/215.py +139 -0
- stdlib//346/226/207/344/273/266/346/265/201.light +48 -0
- stdlib//346/226/207/344/273/266/347/263/273/347/273/237.light +109 -0
- stdlib//346/226/207/344/273/266/347/263/273/347/273/237.py +1522 -0
- stdlib//346/226/255/350/250/200/345/267/245/345/205/267.light +291 -0
- stdlib//346/226/255/350/250/200/345/267/245/345/205/267.py +737 -0
- stdlib//346/226/255/350/250/200/345/267/245/345/205/267/350/275/273/351/207/217.light +73 -0
- stdlib//346/227/245/345/277/227.light +14 -0
- stdlib//346/227/245/345/277/227.py +94 -0
- stdlib//346/227/245/345/277/227/347/263/273/347/273/237/345/242/236/345/274/272.light +197 -0
- stdlib//346/227/245/345/277/227/347/263/273/347/273/237/345/242/236/345/274/272.py +834 -0
- stdlib//346/227/245/346/234/237/346/227/266/351/227/264.light +294 -0
- stdlib//346/227/245/346/234/237/346/227/266/351/227/264.py +1616 -0
- stdlib//346/227/245/346/234/237/346/227/266/351/227/264/350/275/273/351/207/217.light +74 -0
- stdlib//346/227/266/351/227/264/347/256/241/347/220/206.light +114 -0
- stdlib//346/227/266/351/227/264/347/256/241/347/220/206.py +513 -0
- stdlib//346/240/274/345/274/217/345/214/226.light +278 -0
- stdlib//346/240/274/345/274/217/345/214/226.py +268 -0
- stdlib//346/250/241/345/274/217/346/240/241/351/252/214.light +217 -0
- stdlib//346/250/241/346/235/277.light +134 -0
- stdlib//346/250/241/346/235/277.py +165 -0
- stdlib//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.light +219 -0
- stdlib//346/255/243/345/210/231/350/241/250/350/276/276/345/274/217.py +383 -0
- stdlib//346/265/201/345/274/217.light +498 -0
- stdlib//346/265/213/350/257/225.light +13 -0
- stdlib//346/265/213/350/257/225.py +330 -0
- stdlib//347/216/257/345/242/203.light +28 -0
- stdlib//347/216/257/345/242/203.py +215 -0
- stdlib//347/263/273/347/273/237/346/216/245/345/217/243.light +81 -0
- stdlib//347/263/273/347/273/237/346/216/245/345/217/243.py +437 -0
- stdlib//347/272/277/347/250/213.light +16 -0
- stdlib//347/272/277/347/250/213.py +409 -0
- stdlib//347/273/237/350/256/241.light +316 -0
- stdlib//347/273/237/350/256/241.py +342 -0
- stdlib//347/274/223/345/255/230.light +217 -0
- stdlib//347/274/223/345/255/230.py +106 -0
- stdlib//347/274/226/347/240/201.light +136 -0
- stdlib//347/274/226/347/240/201.py +174 -0
- stdlib//347/274/226/347/240/201/350/247/243/347/240/201.light +577 -0
- stdlib//347/274/226/347/240/201/350/247/243/347/240/201.py +292 -0
- stdlib//347/275/221/347/273/234.light +25 -0
- stdlib//347/275/221/347/273/234.py +292 -0
- stdlib//347/275/221/347/273/234/350/257/267/346/261/202.light +648 -0
- stdlib//347/275/221/347/273/234/350/257/267/346/261/202.py +426 -0
- stdlib//350/243/205/351/245/260/345/231/250.light +99 -0
- stdlib//350/243/205/351/245/260/345/231/250.py +359 -0
- stdlib//350/267/257/345/276/204/346/212/244/346/240/217.light +481 -0
- stdlib//350/267/257/345/276/204/350/277/220/347/256/227.light +141 -0
- stdlib//350/272/253/344/273/275/350/257/201/346/240/241/351/252/214.light +260 -0
- stdlib//350/272/253/344/273/275/350/257/201/346/240/241/351/252/214.py +389 -0
- stdlib//350/277/233/345/272/246/346/235/241.light +162 -0
- stdlib//350/277/233/345/272/246/346/235/241.py +211 -0
- stdlib//350/277/233/347/250/213.light +16 -0
- stdlib//350/277/233/347/250/213.py +448 -0
- stdlib//350/277/233/347/250/213/346/240/221.light +1009 -0
- stdlib//351/200/211/346/213/251/345/231/250.light +210 -0
- stdlib//351/205/215/347/275/256.light +16 -0
- stdlib//351/205/215/347/275/256.py +263 -0
- stdlib//351/207/215/350/257/225.light +49 -0
- stdlib//351/232/217/346/234/272.light +323 -0
- stdlib//351/232/217/346/234/272.py +318 -0
- stdlib//351/233/206/345/220/210.light +463 -0
- stdlib//351/233/206/345/220/210.py +229 -0
- stdlib//351/233/206/345/220/210/345/267/245/345/205/267.light +132 -0
- stdlib//351/233/206/345/220/210/345/267/245/345/205/267.py +193 -0
- stdlib//351/233/206/345/220/210/346/223/215/344/275/234.light +267 -0
- stdlib//351/233/206/345/220/210/346/223/215/344/275/234.py +99 -0
- stdlib//351/242/234/350/211/262.light +287 -0
- stdlib//351/242/234/350/211/262.py +304 -0
- stdlib//351/242/234/350/211/262/345/244/204/347/220/206.py +357 -0
- stdlib//351/253/230/347/272/247/346/226/207/344/273/266.light +162 -0
- stdlib//351/253/230/347/272/247/346/226/207/344/273/266.py +120 -0
- stdlib_v3//345/210/227/350/241/250/345/267/245/345/205/267.light +101 -0
- stdlib_v3//345/255/227/347/254/246/344/270/262/345/267/245/345/205/267.light +20 -0
- stdlib_v3//346/225/260/345/255/246/345/267/245/345/205/267.light +34 -0
- stdlib_v3//347/261/273/345/236/213/345/267/245/345/205/267.light +39 -0
- stdlib_v3//350/276/223/345/205/245/350/276/223/345/207/272.light +28 -0
antlrparser/__init__.py
ADDED
|
@@ -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)
|