zexus 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +2513 -0
- package/bin/zexus +2 -0
- package/bin/zpics +2 -0
- package/bin/zpm +2 -0
- package/bin/zx +2 -0
- package/bin/zx-deploy +2 -0
- package/bin/zx-dev +2 -0
- package/bin/zx-run +2 -0
- package/package.json +66 -0
- package/scripts/README.md +24 -0
- package/scripts/postinstall.js +44 -0
- package/shared_config.json +24 -0
- package/src/README.md +1525 -0
- package/src/tests/run_zexus_tests.py +117 -0
- package/src/tests/test_all_phases.zx +346 -0
- package/src/tests/test_blockchain_features.zx +306 -0
- package/src/tests/test_complexity_features.zx +321 -0
- package/src/tests/test_core_integration.py +185 -0
- package/src/tests/test_phase10_ecosystem.zx +177 -0
- package/src/tests/test_phase1_modifiers.zx +87 -0
- package/src/tests/test_phase2_plugins.zx +80 -0
- package/src/tests/test_phase3_security.zx +97 -0
- package/src/tests/test_phase4_vfs.zx +116 -0
- package/src/tests/test_phase5_types.zx +117 -0
- package/src/tests/test_phase6_metaprogramming.zx +125 -0
- package/src/tests/test_phase7_optimization.zx +132 -0
- package/src/tests/test_phase9_advanced_types.zx +157 -0
- package/src/tests/test_security_features.py +419 -0
- package/src/tests/test_security_features.zx +276 -0
- package/src/tests/test_simple_zx.zx +1 -0
- package/src/tests/test_verification_simple.zx +69 -0
- package/src/zexus/__init__.py +28 -0
- package/src/zexus/__main__.py +5 -0
- package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/ecosystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/hybrid_orchestrator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/virtual_filesystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
- package/src/zexus/advanced_types.py +401 -0
- package/src/zexus/blockchain/__init__.py +40 -0
- package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/crypto.py +463 -0
- package/src/zexus/blockchain/ledger.py +255 -0
- package/src/zexus/blockchain/transaction.py +267 -0
- package/src/zexus/builtin_modules.py +284 -0
- package/src/zexus/builtin_plugins.py +317 -0
- package/src/zexus/capability_system.py +372 -0
- package/src/zexus/cli/__init__.py +2 -0
- package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +707 -0
- package/src/zexus/cli/zpm.py +203 -0
- package/src/zexus/compare_interpreter_compiler.py +146 -0
- package/src/zexus/compiler/__init__.py +169 -0
- package/src/zexus/compiler/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/compiler/bytecode.py +266 -0
- package/src/zexus/compiler/compat_runtime.py +277 -0
- package/src/zexus/compiler/lexer.py +257 -0
- package/src/zexus/compiler/parser.py +779 -0
- package/src/zexus/compiler/semantic.py +118 -0
- package/src/zexus/compiler/zexus_ast.py +454 -0
- package/src/zexus/complexity_system.py +575 -0
- package/src/zexus/concurrency_system.py +493 -0
- package/src/zexus/config.py +201 -0
- package/src/zexus/crypto_bridge.py +19 -0
- package/src/zexus/dependency_injection.py +423 -0
- package/src/zexus/ecosystem.py +434 -0
- package/src/zexus/environment.py +101 -0
- package/src/zexus/environment_manager.py +119 -0
- package/src/zexus/error_reporter.py +314 -0
- package/src/zexus/evaluator/__init__.py +12 -0
- package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/integration.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/bytecode_compiler.py +700 -0
- package/src/zexus/evaluator/core.py +891 -0
- package/src/zexus/evaluator/expressions.py +827 -0
- package/src/zexus/evaluator/functions.py +3989 -0
- package/src/zexus/evaluator/integration.py +396 -0
- package/src/zexus/evaluator/statements.py +4303 -0
- package/src/zexus/evaluator/utils.py +126 -0
- package/src/zexus/evaluator_original.py +2041 -0
- package/src/zexus/external_bridge.py +16 -0
- package/src/zexus/find_affected_imports.sh +155 -0
- package/src/zexus/hybrid_orchestrator.py +152 -0
- package/src/zexus/input_validation.py +259 -0
- package/src/zexus/lexer.py +571 -0
- package/src/zexus/logging.py +89 -0
- package/src/zexus/lsp/__init__.py +9 -0
- package/src/zexus/lsp/completion_provider.py +207 -0
- package/src/zexus/lsp/definition_provider.py +22 -0
- package/src/zexus/lsp/hover_provider.py +71 -0
- package/src/zexus/lsp/server.py +269 -0
- package/src/zexus/lsp/symbol_provider.py +31 -0
- package/src/zexus/metaprogramming.py +321 -0
- package/src/zexus/module_cache.py +89 -0
- package/src/zexus/module_manager.py +107 -0
- package/src/zexus/object.py +973 -0
- package/src/zexus/optimization.py +424 -0
- package/src/zexus/parser/__init__.py +31 -0
- package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
- package/src/zexus/parser/integration.py +86 -0
- package/src/zexus/parser/parser.py +3977 -0
- package/src/zexus/parser/strategy_context.py +7254 -0
- package/src/zexus/parser/strategy_structural.py +1033 -0
- package/src/zexus/persistence.py +391 -0
- package/src/zexus/plugin_system.py +290 -0
- package/src/zexus/policy_engine.py +365 -0
- package/src/zexus/profiler/__init__.py +5 -0
- package/src/zexus/profiler/profiler.py +233 -0
- package/src/zexus/purity_system.py +398 -0
- package/src/zexus/runtime/__init__.py +20 -0
- package/src/zexus/runtime/async_runtime.py +324 -0
- package/src/zexus/search_old_imports.sh +65 -0
- package/src/zexus/security.py +1407 -0
- package/src/zexus/stack_trace.py +233 -0
- package/src/zexus/stdlib/__init__.py +27 -0
- package/src/zexus/stdlib/blockchain.py +341 -0
- package/src/zexus/stdlib/compression.py +167 -0
- package/src/zexus/stdlib/crypto.py +124 -0
- package/src/zexus/stdlib/datetime.py +163 -0
- package/src/zexus/stdlib/db_mongo.py +199 -0
- package/src/zexus/stdlib/db_mysql.py +162 -0
- package/src/zexus/stdlib/db_postgres.py +163 -0
- package/src/zexus/stdlib/db_sqlite.py +133 -0
- package/src/zexus/stdlib/encoding.py +230 -0
- package/src/zexus/stdlib/fs.py +195 -0
- package/src/zexus/stdlib/http.py +219 -0
- package/src/zexus/stdlib/http_server.py +248 -0
- package/src/zexus/stdlib/json_module.py +61 -0
- package/src/zexus/stdlib/math.py +360 -0
- package/src/zexus/stdlib/os_module.py +265 -0
- package/src/zexus/stdlib/regex.py +148 -0
- package/src/zexus/stdlib/sockets.py +253 -0
- package/src/zexus/stdlib/test_framework.zx +208 -0
- package/src/zexus/stdlib/test_runner.zx +119 -0
- package/src/zexus/stdlib_integration.py +341 -0
- package/src/zexus/strategy_recovery.py +256 -0
- package/src/zexus/syntax_validator.py +356 -0
- package/src/zexus/testing/zpics.py +407 -0
- package/src/zexus/testing/zpics_runtime.py +369 -0
- package/src/zexus/type_system.py +374 -0
- package/src/zexus/validation_system.py +569 -0
- package/src/zexus/virtual_filesystem.py +355 -0
- package/src/zexus/vm/__init__.py +8 -0
- package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/async_optimizer.py +420 -0
- package/src/zexus/vm/bytecode.py +428 -0
- package/src/zexus/vm/bytecode_converter.py +297 -0
- package/src/zexus/vm/cache.py +532 -0
- package/src/zexus/vm/jit.py +720 -0
- package/src/zexus/vm/memory_manager.py +520 -0
- package/src/zexus/vm/memory_pool.py +511 -0
- package/src/zexus/vm/optimizer.py +478 -0
- package/src/zexus/vm/parallel_vm.py +899 -0
- package/src/zexus/vm/peephole_optimizer.py +452 -0
- package/src/zexus/vm/profiler.py +527 -0
- package/src/zexus/vm/register_allocator.py +462 -0
- package/src/zexus/vm/register_vm.py +520 -0
- package/src/zexus/vm/ssa_converter.py +757 -0
- package/src/zexus/vm/vm.py +1392 -0
- package/src/zexus/zexus_ast.py +1782 -0
- package/src/zexus/zexus_token.py +253 -0
- package/src/zexus/zpm/__init__.py +15 -0
- package/src/zexus/zpm/installer.py +116 -0
- package/src/zexus/zpm/package_manager.py +208 -0
- package/src/zexus/zpm/publisher.py +98 -0
- package/src/zexus/zpm/registry.py +110 -0
- package/src/zexus.egg-info/PKG-INFO +2235 -0
- package/src/zexus.egg-info/SOURCES.txt +876 -0
- package/src/zexus.egg-info/dependency_links.txt +1 -0
- package/src/zexus.egg-info/entry_points.txt +3 -0
- package/src/zexus.egg-info/not-zip-safe +1 -0
- package/src/zexus.egg-info/requires.txt +14 -0
- package/src/zexus.egg-info/top_level.txt +2 -0
- package/zexus.json +14 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
# src/zexus/cli/main.py
|
|
2
|
+
import click
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.syntax import Syntax
|
|
8
|
+
from rich.panel import Panel
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
|
|
11
|
+
# Import your existing modules - UPDATED IMPORTS
|
|
12
|
+
from ..lexer import Lexer
|
|
13
|
+
from ..parser import Parser
|
|
14
|
+
# UPDATED: Import evaluate from evaluator package
|
|
15
|
+
from ..evaluator import evaluate
|
|
16
|
+
# UPDATED: Import Environment and String from object module
|
|
17
|
+
from ..object import Environment, String
|
|
18
|
+
from ..syntax_validator import SyntaxValidator
|
|
19
|
+
from ..hybrid_orchestrator import orchestrator
|
|
20
|
+
from ..config import config
|
|
21
|
+
# Import error handling
|
|
22
|
+
from ..error_reporter import get_error_reporter, ZexusError, print_error
|
|
23
|
+
|
|
24
|
+
console = Console()
|
|
25
|
+
|
|
26
|
+
def show_all_commands():
|
|
27
|
+
"""Display all available Zexus commands with descriptions"""
|
|
28
|
+
console.print("\n[bold cyan]š Zexus Programming Language - Available Commands[/bold cyan]\n")
|
|
29
|
+
|
|
30
|
+
table = Table(show_header=True, header_style="bold magenta")
|
|
31
|
+
table.add_column("Command", style="cyan", width=30)
|
|
32
|
+
table.add_column("Description", style="white")
|
|
33
|
+
|
|
34
|
+
commands = [
|
|
35
|
+
("zx run <file>", "Execute a Zexus program"),
|
|
36
|
+
("zx run --zexus", "Show this command list"),
|
|
37
|
+
("zx check <file>", "Check syntax with detailed validation"),
|
|
38
|
+
("zx validate <file>", "Validate and auto-fix syntax errors"),
|
|
39
|
+
("zx profile <file>", "Profile performance with time and memory tracking"),
|
|
40
|
+
("zx ast <file>", "Display Abstract Syntax Tree"),
|
|
41
|
+
("zx tokens <file>", "Show tokenization output"),
|
|
42
|
+
("zx repl", "Start interactive REPL"),
|
|
43
|
+
("zx init [name]", "Initialize new Zexus project"),
|
|
44
|
+
("zx debug <on|off|minimal|status>", "Control debug logging"),
|
|
45
|
+
("", ""),
|
|
46
|
+
("[bold]Global Options:[/bold]", ""),
|
|
47
|
+
("--syntax-style=<style>", "universal, tolerable, or auto (default)"),
|
|
48
|
+
("--execution-mode=<mode>", "interpreter, compiler, or auto (default)"),
|
|
49
|
+
("--advanced-parsing", "Enable multi-strategy parsing (default: on)"),
|
|
50
|
+
("--debug", "Enable debug output"),
|
|
51
|
+
("--version", "Show Zexus version"),
|
|
52
|
+
("--help", "Show detailed help"),
|
|
53
|
+
("", ""),
|
|
54
|
+
("[bold]Profile Options:[/bold]", ""),
|
|
55
|
+
("--memory/--no-memory", "Enable/disable memory profiling (default: on)"),
|
|
56
|
+
("--top N", "Show top N functions (default: 20)"),
|
|
57
|
+
("--json-output FILE", "Save profile data as JSON"),
|
|
58
|
+
("", ""),
|
|
59
|
+
("[bold]Examples:[/bold]", ""),
|
|
60
|
+
("zx run program.zx", "Run a program with auto-detection"),
|
|
61
|
+
("zx run --syntax-style=universal main.zx", "Run with strict syntax"),
|
|
62
|
+
("zx run --execution-mode=compiler fast.zx", "Force compiler mode"),
|
|
63
|
+
("zx check --debug program.zx", "Check syntax with debug info"),
|
|
64
|
+
("zx profile myapp.zx", "Profile with memory tracking"),
|
|
65
|
+
("zx profile --no-memory --top 10 app.zx", "Profile without memory, show top 10"),
|
|
66
|
+
("", ""),
|
|
67
|
+
("[bold]Built-in Functions:[/bold]", "100+ functions available"),
|
|
68
|
+
("", "Memory: persist_set, persist_get, track_memory"),
|
|
69
|
+
("", "Policy: protect, verify, restrict, sanitize"),
|
|
70
|
+
("", "DI: inject, register_dependency, mock_dependency"),
|
|
71
|
+
("", "Reactive: watch (keyword)"),
|
|
72
|
+
("", "Blockchain: transaction, emit, require, balance"),
|
|
73
|
+
("", "File System: read_file, write_file, mkdir, exists"),
|
|
74
|
+
("", "HTTP: http_get, http_post, http_put, http_delete"),
|
|
75
|
+
("", "JSON: json_parse, json_stringify, json_load, json_save"),
|
|
76
|
+
("", "DateTime: now, timestamp, format, add_days, diff_seconds"),
|
|
77
|
+
("", ""),
|
|
78
|
+
("[bold]Documentation:[/bold]", ""),
|
|
79
|
+
("", "README: github.com/Zaidux/zexus-interpreter"),
|
|
80
|
+
("", "Features: docs/features/ADVANCED_FEATURES_IMPLEMENTATION.md"),
|
|
81
|
+
("", "Dev Guide: src/README.md"),
|
|
82
|
+
("", "LSP Guide: docs/lsp/LSP_GUIDE.md"),
|
|
83
|
+
("", "Profiler: docs/profiler/PROFILER_GUIDE.md"),
|
|
84
|
+
("", "Stdlib: docs/stdlib/README.md"),
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
for cmd, desc in commands:
|
|
88
|
+
table.add_row(cmd, desc)
|
|
89
|
+
|
|
90
|
+
console.print(table)
|
|
91
|
+
console.print("\n[bold green]š” Tip:[/bold green] Use 'zx <command> --help' for detailed command options\n")
|
|
92
|
+
|
|
93
|
+
@click.group(invoke_without_command=True)
|
|
94
|
+
@click.version_option(version="1.6.2", prog_name="Zexus")
|
|
95
|
+
@click.option('--syntax-style', type=click.Choice(['universal', 'tolerable', 'auto']),
|
|
96
|
+
default='auto', help='Syntax style to use (universal=strict, tolerable=flexible)')
|
|
97
|
+
@click.option('--advanced-parsing', is_flag=True, default=True,
|
|
98
|
+
help='Enable advanced multi-strategy parsing (recommended)')
|
|
99
|
+
@click.option('--execution-mode', type=click.Choice(['interpreter', 'compiler', 'auto']),
|
|
100
|
+
default='auto', help='Execution engine to use')
|
|
101
|
+
@click.option('--debug', is_flag=True, help='Enable debug logging')
|
|
102
|
+
@click.option('--zexus', is_flag=True, help='Show all available Zexus commands')
|
|
103
|
+
@click.pass_context
|
|
104
|
+
def cli(ctx, syntax_style, advanced_parsing, execution_mode, debug, zexus):
|
|
105
|
+
"""Zexus Programming Language - Hybrid Interpreter/Compiler
|
|
106
|
+
|
|
107
|
+
Use 'zx run --zexus' or 'zx --zexus' to see all available commands.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
if zexus:
|
|
111
|
+
show_all_commands()
|
|
112
|
+
sys.exit(0)
|
|
113
|
+
|
|
114
|
+
# If no command provided, show help
|
|
115
|
+
if ctx.invoked_subcommand is None:
|
|
116
|
+
click.echo(ctx.get_help())
|
|
117
|
+
return
|
|
118
|
+
|
|
119
|
+
ctx.ensure_object(dict)
|
|
120
|
+
ctx.obj['SYNTAX_STYLE'] = syntax_style
|
|
121
|
+
ctx.obj['ADVANCED_PARSING'] = advanced_parsing
|
|
122
|
+
ctx.obj['EXECUTION_MODE'] = execution_mode
|
|
123
|
+
ctx.obj['DEBUG'] = debug
|
|
124
|
+
|
|
125
|
+
# Update config based on CLI flags
|
|
126
|
+
if debug:
|
|
127
|
+
config.enable_debug_logs = True
|
|
128
|
+
if execution_mode == 'compiler':
|
|
129
|
+
config.use_hybrid_compiler = True
|
|
130
|
+
elif execution_mode == 'interpreter':
|
|
131
|
+
config.use_hybrid_compiler = False
|
|
132
|
+
|
|
133
|
+
@cli.command()
|
|
134
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
135
|
+
@click.argument('args', nargs=-1) # Accept any number of additional arguments
|
|
136
|
+
@click.pass_context
|
|
137
|
+
def run(ctx, file, args):
|
|
138
|
+
"""Run a Zexus program with hybrid execution"""
|
|
139
|
+
# Register source for error reporting
|
|
140
|
+
error_reporter = get_error_reporter()
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
with open(file, 'r') as f:
|
|
144
|
+
source_code = f.read()
|
|
145
|
+
|
|
146
|
+
# Register source with error reporter
|
|
147
|
+
error_reporter.register_source(file, source_code)
|
|
148
|
+
|
|
149
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
150
|
+
advanced_parsing = ctx.obj['ADVANCED_PARSING']
|
|
151
|
+
execution_mode = ctx.obj['EXECUTION_MODE']
|
|
152
|
+
validator = SyntaxValidator()
|
|
153
|
+
|
|
154
|
+
console.print(f"š [bold green]Running[/bold green] {file}")
|
|
155
|
+
console.print(f"š§ [bold blue]Execution mode:[/bold blue] {execution_mode}")
|
|
156
|
+
console.print(f"š [bold blue]Syntax style:[/bold blue] {syntax_style}")
|
|
157
|
+
console.print(f"šÆ [bold blue]Advanced parsing:[/bold blue] {'Enabled' if advanced_parsing else 'Disabled'}")
|
|
158
|
+
|
|
159
|
+
# Auto-detect syntax style if needed
|
|
160
|
+
if syntax_style == 'auto':
|
|
161
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
162
|
+
console.print(f"š [bold blue]Detected syntax style:[/bold blue] {syntax_style}")
|
|
163
|
+
|
|
164
|
+
# Validate syntax
|
|
165
|
+
console.print("[dim]Validating syntax...[/dim]", end="")
|
|
166
|
+
validation_result = validator.validate_code(source_code, syntax_style)
|
|
167
|
+
console.print(" [green]done[/green]")
|
|
168
|
+
if not validation_result['is_valid']:
|
|
169
|
+
console.print(f"[bold yellow]ā ļø Syntax warnings: {validation_result['error_count']} issue(s) found[/bold yellow]")
|
|
170
|
+
for suggestion in validation_result['suggestions']:
|
|
171
|
+
severity_emoji = "ā" if suggestion['severity'] == 'error' else "ā ļø"
|
|
172
|
+
console.print(f" {severity_emoji} Line {suggestion['line']}: {suggestion['message']}")
|
|
173
|
+
|
|
174
|
+
# Auto-fix if there are errors
|
|
175
|
+
if any(s['severity'] == 'error' for s in validation_result['suggestions']):
|
|
176
|
+
console.print("[bold yellow]š ļø Attempting auto-fix...[/bold yellow]")
|
|
177
|
+
fixed_code, fix_result = validator.auto_fix(source_code, syntax_style)
|
|
178
|
+
if fix_result['applied_fixes'] > 0:
|
|
179
|
+
console.print(f"ā
[bold green]Applied {fix_result['applied_fixes']} fixes[/bold green]")
|
|
180
|
+
source_code = fixed_code
|
|
181
|
+
else:
|
|
182
|
+
console.print("[bold red]ā Could not auto-fix errors, attempting to run anyway...[/bold red]")
|
|
183
|
+
|
|
184
|
+
# Parse the program
|
|
185
|
+
lexer = Lexer(source_code, filename=file)
|
|
186
|
+
parser = Parser(lexer, syntax_style, enable_advanced_strategies=advanced_parsing)
|
|
187
|
+
program = parser.parse_program()
|
|
188
|
+
|
|
189
|
+
if parser.errors and any("critical" in e.lower() for e in parser.errors):
|
|
190
|
+
console.print("[bold red]ā Critical parser errors detected, cannot continue:[/bold red]")
|
|
191
|
+
for error in parser.errors:
|
|
192
|
+
console.print(f" ā {error}")
|
|
193
|
+
sys.exit(1)
|
|
194
|
+
|
|
195
|
+
# Use the evaluator package
|
|
196
|
+
env = Environment()
|
|
197
|
+
|
|
198
|
+
# Set module context variables
|
|
199
|
+
import os
|
|
200
|
+
abs_file = os.path.abspath(file)
|
|
201
|
+
env.set("__file__", String(abs_file)) # Absolute file path
|
|
202
|
+
env.set("__FILE__", String(abs_file)) # Alternative name
|
|
203
|
+
env.set("__MODULE__", String("__main__")) # Main entry point
|
|
204
|
+
env.set("__DIR__", String(os.path.dirname(abs_file))) # Directory path
|
|
205
|
+
|
|
206
|
+
# Set command-line arguments
|
|
207
|
+
from ..object import List
|
|
208
|
+
args_list = List([String(arg) for arg in args])
|
|
209
|
+
env.set("__ARGS__", args_list) # Command-line arguments
|
|
210
|
+
env.set("__ARGV__", args_list) # Alternative name
|
|
211
|
+
|
|
212
|
+
# Detect package (if file is in a package structure)
|
|
213
|
+
package_name = String("")
|
|
214
|
+
try:
|
|
215
|
+
rel_path = os.path.relpath(abs_file)
|
|
216
|
+
if '/' in rel_path or '\\' in rel_path:
|
|
217
|
+
parts = rel_path.replace('\\', '/').split('/')
|
|
218
|
+
if len(parts) > 1:
|
|
219
|
+
package_name = String(parts[0])
|
|
220
|
+
except (OSError, ValueError):
|
|
221
|
+
pass # Unable to determine package name
|
|
222
|
+
env.set("__PACKAGE__", package_name)
|
|
223
|
+
|
|
224
|
+
# UPDATED: Use the evaluate function from the evaluator package
|
|
225
|
+
result = evaluate(program, env, debug_mode=ctx.obj['DEBUG'])
|
|
226
|
+
|
|
227
|
+
if result and hasattr(result, 'inspect') and result.inspect() != 'null':
|
|
228
|
+
console.print(f"\nā
[bold green]Result:[/bold green] {result.inspect()}")
|
|
229
|
+
elif isinstance(result, str) and result:
|
|
230
|
+
console.print(f"\nš¤ [bold blue]Output:[/bold blue] {result}")
|
|
231
|
+
elif hasattr(result, 'value') and result.value is not None:
|
|
232
|
+
console.print(f"\nš [bold blue]Result:[/bold blue] {result.value}")
|
|
233
|
+
|
|
234
|
+
except ZexusError as e:
|
|
235
|
+
# Handle our custom Zexus errors with nice formatting
|
|
236
|
+
print_error(e)
|
|
237
|
+
sys.exit(1)
|
|
238
|
+
except Exception as e:
|
|
239
|
+
console.print(f"[bold red]Unexpected Error:[/bold red] {str(e)}")
|
|
240
|
+
if ctx.obj.get('DEBUG'):
|
|
241
|
+
import traceback
|
|
242
|
+
traceback.print_exc()
|
|
243
|
+
sys.exit(1)
|
|
244
|
+
|
|
245
|
+
@cli.command()
|
|
246
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
247
|
+
@click.pass_context
|
|
248
|
+
def check(ctx, file):
|
|
249
|
+
"""Check syntax of a Zexus file with detailed validation"""
|
|
250
|
+
try:
|
|
251
|
+
with open(file, 'r') as f:
|
|
252
|
+
source_code = f.read()
|
|
253
|
+
|
|
254
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
255
|
+
advanced_parsing = ctx.obj['ADVANCED_PARSING']
|
|
256
|
+
validator = SyntaxValidator()
|
|
257
|
+
|
|
258
|
+
# Auto-detect syntax style if needed
|
|
259
|
+
if syntax_style == 'auto':
|
|
260
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
261
|
+
console.print(f"š [bold blue]Detected syntax style:[/bold blue] {syntax_style}")
|
|
262
|
+
|
|
263
|
+
console.print(f"š§ [bold blue]Advanced parsing:[/bold blue] {'Enabled' if advanced_parsing else 'Disabled'}")
|
|
264
|
+
|
|
265
|
+
# Run syntax validation
|
|
266
|
+
validation_result = validator.validate_code(source_code, syntax_style)
|
|
267
|
+
|
|
268
|
+
# Also run parser for additional validation
|
|
269
|
+
lexer = Lexer(source_code)
|
|
270
|
+
parser = Parser(lexer, syntax_style, enable_advanced_strategies=advanced_parsing)
|
|
271
|
+
program = parser.parse_program()
|
|
272
|
+
|
|
273
|
+
# Display results
|
|
274
|
+
if parser.errors or not validation_result['is_valid']:
|
|
275
|
+
console.print("[bold red]ā Syntax Issues Found:[/bold red]")
|
|
276
|
+
|
|
277
|
+
# Show parser errors first
|
|
278
|
+
for error in parser.errors:
|
|
279
|
+
console.print(f" š« Parser: {error}")
|
|
280
|
+
|
|
281
|
+
# Show validator suggestions
|
|
282
|
+
for suggestion in validation_result['suggestions']:
|
|
283
|
+
severity_icon = "š«" if suggestion['severity'] == 'error' else "ā ļø"
|
|
284
|
+
console.print(f" {severity_icon} Validator: {suggestion['message']}")
|
|
285
|
+
|
|
286
|
+
# Show warnings
|
|
287
|
+
for warning in validation_result['warnings']:
|
|
288
|
+
console.print(f" ā ļø Warning: {warning['message']}")
|
|
289
|
+
|
|
290
|
+
# Show recovery info if advanced parsing was used
|
|
291
|
+
if advanced_parsing and hasattr(parser, 'use_advanced_parsing') and parser.use_advanced_parsing:
|
|
292
|
+
console.print(f"\n[bold yellow]š”ļø Advanced parsing recovered {len(program.statements)} statements[/bold yellow]")
|
|
293
|
+
|
|
294
|
+
sys.exit(1)
|
|
295
|
+
else:
|
|
296
|
+
console.print("[bold green]ā
Syntax is valid![/bold green]")
|
|
297
|
+
if advanced_parsing and hasattr(parser, 'use_advanced_parsing') and parser.use_advanced_parsing:
|
|
298
|
+
console.print("[bold green]š§ Advanced multi-strategy parsing successful![/bold green]")
|
|
299
|
+
|
|
300
|
+
if validation_result['warnings']:
|
|
301
|
+
console.print("\n[bold yellow]ā¹ļø Warnings:[/bold yellow]")
|
|
302
|
+
for warning in validation_result['warnings']:
|
|
303
|
+
console.print(f" ā ļø {warning['message']}")
|
|
304
|
+
|
|
305
|
+
except Exception as e:
|
|
306
|
+
console.print(f"[bold red]Error:[/bold red] {str(e)}")
|
|
307
|
+
sys.exit(1)
|
|
308
|
+
|
|
309
|
+
@cli.command()
|
|
310
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
311
|
+
@click.pass_context
|
|
312
|
+
def validate(ctx, file):
|
|
313
|
+
"""Validate and auto-fix Zexus syntax"""
|
|
314
|
+
try:
|
|
315
|
+
with open(file, 'r') as f:
|
|
316
|
+
source_code = f.read()
|
|
317
|
+
|
|
318
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
319
|
+
validator = SyntaxValidator()
|
|
320
|
+
|
|
321
|
+
# Auto-detect syntax style if needed
|
|
322
|
+
if syntax_style == 'auto':
|
|
323
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
324
|
+
console.print(f"š [bold blue]Detected syntax style:[/bold blue] {syntax_style}")
|
|
325
|
+
|
|
326
|
+
console.print(f"š [bold blue]Validating with {syntax_style} syntax...[/bold blue]")
|
|
327
|
+
|
|
328
|
+
# Run validation and auto-fix
|
|
329
|
+
fixed_code, validation_result = validator.auto_fix(source_code, syntax_style)
|
|
330
|
+
|
|
331
|
+
# Show results
|
|
332
|
+
if validation_result['is_valid']:
|
|
333
|
+
console.print("[bold green]ā
Code is valid![/bold green]")
|
|
334
|
+
else:
|
|
335
|
+
console.print(f"[bold yellow]š ļø Applied {validation_result['applied_fixes']} fixes[/bold yellow]")
|
|
336
|
+
console.print("[bold yellow]ā ļø Remaining issues:[/bold yellow]")
|
|
337
|
+
for suggestion in validation_result['suggestions']:
|
|
338
|
+
severity_icon = "š«" if suggestion['severity'] == 'error' else "ā ļø"
|
|
339
|
+
console.print(f" {severity_icon} Line {suggestion['line']}: {suggestion['message']}")
|
|
340
|
+
|
|
341
|
+
for warning in validation_result['warnings']:
|
|
342
|
+
console.print(f" ā ļø Warning: {warning['message']}")
|
|
343
|
+
|
|
344
|
+
# Write fixed code back to file if changes were made
|
|
345
|
+
if validation_result['applied_fixes'] > 0:
|
|
346
|
+
with open(file, 'w') as f:
|
|
347
|
+
f.write(fixed_code)
|
|
348
|
+
console.print(f"š¾ [bold green]Updated {file} with fixes[/bold green]")
|
|
349
|
+
|
|
350
|
+
except Exception as e:
|
|
351
|
+
console.print(f"[bold red]Error:[/bold red] {str(e)}")
|
|
352
|
+
sys.exit(1)
|
|
353
|
+
|
|
354
|
+
@cli.command()
|
|
355
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
356
|
+
@click.pass_context
|
|
357
|
+
def ast(ctx, file):
|
|
358
|
+
"""Show AST of a Zexus file"""
|
|
359
|
+
try:
|
|
360
|
+
with open(file, 'r') as f:
|
|
361
|
+
source_code = f.read()
|
|
362
|
+
|
|
363
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
364
|
+
advanced_parsing = ctx.obj['ADVANCED_PARSING']
|
|
365
|
+
validator = SyntaxValidator()
|
|
366
|
+
|
|
367
|
+
# Auto-detect syntax style if needed
|
|
368
|
+
if syntax_style == 'auto':
|
|
369
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
370
|
+
console.print(f"š [bold blue]Detected syntax style:[/bold blue] {syntax_style}")
|
|
371
|
+
|
|
372
|
+
console.print(f"š§ [bold blue]Advanced parsing:[/bold blue] {'Enabled' if advanced_parsing else 'Disabled'}")
|
|
373
|
+
|
|
374
|
+
lexer = Lexer(source_code)
|
|
375
|
+
parser = Parser(lexer, syntax_style, enable_advanced_strategies=advanced_parsing)
|
|
376
|
+
program = parser.parse_program()
|
|
377
|
+
|
|
378
|
+
parsing_method = "Advanced Multi-Strategy" if (advanced_parsing and hasattr(parser, 'use_advanced_parsing') and parser.use_advanced_parsing) else "Traditional"
|
|
379
|
+
|
|
380
|
+
console.print(Panel.fit(
|
|
381
|
+
str(program),
|
|
382
|
+
title=f"[bold blue]Abstract Syntax Tree ({syntax_style} syntax) - {parsing_method} Parsing[/bold blue]",
|
|
383
|
+
border_style="blue"
|
|
384
|
+
))
|
|
385
|
+
|
|
386
|
+
if parser.errors:
|
|
387
|
+
console.print("\n[bold yellow]ā ļø Parser encountered errors but continued:[/bold yellow]")
|
|
388
|
+
for error in parser.errors:
|
|
389
|
+
console.print(f" ā {error}")
|
|
390
|
+
|
|
391
|
+
except Exception as e:
|
|
392
|
+
console.print(f"[bold red]Error:[/bold red] {str(e)}")
|
|
393
|
+
|
|
394
|
+
@cli.command()
|
|
395
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
396
|
+
@click.pass_context
|
|
397
|
+
def tokens(ctx, file):
|
|
398
|
+
"""Show tokens of a Zexus file"""
|
|
399
|
+
try:
|
|
400
|
+
with open(file, 'r') as f:
|
|
401
|
+
source_code = f.read()
|
|
402
|
+
|
|
403
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
404
|
+
validator = SyntaxValidator()
|
|
405
|
+
|
|
406
|
+
# Auto-detect syntax style if needed
|
|
407
|
+
if syntax_style == 'auto':
|
|
408
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
409
|
+
console.print(f"š [bold blue]Detected syntax style:[/bold blue] {syntax_style}")
|
|
410
|
+
|
|
411
|
+
lexer = Lexer(source_code)
|
|
412
|
+
|
|
413
|
+
table = Table(title=f"Tokens ({syntax_style} syntax)")
|
|
414
|
+
table.add_column("Type", style="cyan")
|
|
415
|
+
table.add_column("Literal", style="green")
|
|
416
|
+
table.add_column("Line", style="yellow")
|
|
417
|
+
table.add_column("Column", style="yellow")
|
|
418
|
+
|
|
419
|
+
while True:
|
|
420
|
+
token = lexer.next_token()
|
|
421
|
+
if token.type == "EOF":
|
|
422
|
+
break
|
|
423
|
+
table.add_row(token.type, token.literal, str(token.line), str(token.column))
|
|
424
|
+
|
|
425
|
+
console.print(table)
|
|
426
|
+
|
|
427
|
+
except Exception as e:
|
|
428
|
+
console.print(f"[bold red]Error:[/bold red] {str(e)}")
|
|
429
|
+
|
|
430
|
+
@cli.command()
|
|
431
|
+
@click.pass_context
|
|
432
|
+
def repl(ctx):
|
|
433
|
+
"""Start Zexus REPL with hybrid execution"""
|
|
434
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
435
|
+
advanced_parsing = ctx.obj['ADVANCED_PARSING']
|
|
436
|
+
execution_mode = ctx.obj['EXECUTION_MODE']
|
|
437
|
+
env = Environment()
|
|
438
|
+
validator = SyntaxValidator()
|
|
439
|
+
|
|
440
|
+
console.print("[bold green]Zexus Hybrid REPL v1.5.0[/bold green]")
|
|
441
|
+
console.print(f"š [bold blue]Execution mode:[/bold blue] {execution_mode}")
|
|
442
|
+
console.print(f"š [bold blue]Syntax style:[/bold blue] {syntax_style}")
|
|
443
|
+
console.print(f"š§ [bold blue]Advanced parsing:[/bold blue] {'Enabled' if advanced_parsing else 'Disabled'}")
|
|
444
|
+
console.print("Type 'mode <interpreter|compiler|auto>' to switch execution mode")
|
|
445
|
+
console.print("Type 'stats' to see execution statistics")
|
|
446
|
+
console.print("Type 'exit' to quit\n")
|
|
447
|
+
|
|
448
|
+
current_mode = execution_mode
|
|
449
|
+
|
|
450
|
+
while True:
|
|
451
|
+
try:
|
|
452
|
+
code = console.input(f"[bold blue]zexus({current_mode})> [/bold blue]")
|
|
453
|
+
|
|
454
|
+
if code.strip() in ['exit', 'quit']:
|
|
455
|
+
break
|
|
456
|
+
elif code.strip() == 'stats':
|
|
457
|
+
console.print(f"š Interpreter uses: {orchestrator.interpreter_used}")
|
|
458
|
+
console.print(f"š Compiler uses: {orchestrator.compiler_used}")
|
|
459
|
+
console.print(f"š Fallbacks: {orchestrator.fallbacks}")
|
|
460
|
+
continue
|
|
461
|
+
elif code.strip().startswith('mode '):
|
|
462
|
+
new_mode = code.split(' ')[1]
|
|
463
|
+
if new_mode in ['interpreter', 'compiler', 'auto']:
|
|
464
|
+
current_mode = new_mode
|
|
465
|
+
console.print(f"š Switched to {current_mode} mode")
|
|
466
|
+
else:
|
|
467
|
+
console.print("ā Invalid mode. Use: interpreter, compiler, or auto")
|
|
468
|
+
continue
|
|
469
|
+
elif not code.strip():
|
|
470
|
+
continue
|
|
471
|
+
|
|
472
|
+
# Validate syntax in REPL
|
|
473
|
+
if syntax_style != 'auto':
|
|
474
|
+
validation_result = validator.validate_code(code, syntax_style)
|
|
475
|
+
if not validation_result['is_valid']:
|
|
476
|
+
for suggestion in validation_result['suggestions']:
|
|
477
|
+
if suggestion['severity'] == 'error':
|
|
478
|
+
console.print(f"[red]Syntax: {suggestion['message']}[/red]")
|
|
479
|
+
|
|
480
|
+
# Parse and evaluate
|
|
481
|
+
lexer = Lexer(code)
|
|
482
|
+
parser = Parser(lexer, syntax_style, enable_advanced_strategies=advanced_parsing)
|
|
483
|
+
program = parser.parse_program()
|
|
484
|
+
|
|
485
|
+
if parser.errors and any("critical" in e.lower() for e in parser.errors):
|
|
486
|
+
console.print("[red]Parser error:[/red]")
|
|
487
|
+
for error in parser.errors:
|
|
488
|
+
console.print(f" ā {error}")
|
|
489
|
+
continue
|
|
490
|
+
|
|
491
|
+
# UPDATED: Use evaluate from the evaluator package
|
|
492
|
+
result = evaluate(program, env, debug_mode=ctx.obj['DEBUG'])
|
|
493
|
+
|
|
494
|
+
if result and hasattr(result, 'inspect') and result.inspect() != 'null':
|
|
495
|
+
console.print(f"[green]{result.inspect()}[/green]")
|
|
496
|
+
|
|
497
|
+
except KeyboardInterrupt:
|
|
498
|
+
console.print("\nš Goodbye!")
|
|
499
|
+
break
|
|
500
|
+
except Exception as e:
|
|
501
|
+
console.print(f"[red]Error: {str(e)}[/red]")
|
|
502
|
+
|
|
503
|
+
@cli.command()
|
|
504
|
+
@click.option('--mode', type=click.Choice(['interpreter', 'compiler', 'auto']),
|
|
505
|
+
default='auto', help='Default execution mode for the project')
|
|
506
|
+
@click.pass_context
|
|
507
|
+
def init(ctx, mode):
|
|
508
|
+
"""Initialize a new Zexus project with hybrid execution support"""
|
|
509
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
510
|
+
project_name = click.prompt("Project name", default="my-zexus-app")
|
|
511
|
+
|
|
512
|
+
project_path = Path(project_name)
|
|
513
|
+
project_path.mkdir(exist_ok=True)
|
|
514
|
+
|
|
515
|
+
# Create basic structure
|
|
516
|
+
(project_path / "src").mkdir()
|
|
517
|
+
(project_path / "tests").mkdir()
|
|
518
|
+
|
|
519
|
+
# Choose template based on syntax style and execution mode
|
|
520
|
+
if syntax_style == "universal":
|
|
521
|
+
main_content = f'''# Welcome to Zexus! (Universal Syntax)
|
|
522
|
+
# Execution Mode: {mode}
|
|
523
|
+
|
|
524
|
+
let app_name = "My Zexus App"
|
|
525
|
+
|
|
526
|
+
action main() {{
|
|
527
|
+
print("š Hello from " + app_name)
|
|
528
|
+
print("⨠Running Zexus v1.5.0 in {mode} mode")
|
|
529
|
+
|
|
530
|
+
# Test some features
|
|
531
|
+
let numbers = [1, 2, 3, 4, 5]
|
|
532
|
+
let doubled = numbers.map(transform: it * 2)
|
|
533
|
+
print("Doubled numbers: " + string(doubled))
|
|
534
|
+
|
|
535
|
+
# Performance test
|
|
536
|
+
let start_time = time.now()
|
|
537
|
+
let sum = 0
|
|
538
|
+
for each number in numbers {{
|
|
539
|
+
sum = sum + number
|
|
540
|
+
}}
|
|
541
|
+
let end_time = time.now()
|
|
542
|
+
print("Sum: " + string(sum))
|
|
543
|
+
print("Calculation time: " + string(end_time - start_time) + "ms")
|
|
544
|
+
}}
|
|
545
|
+
|
|
546
|
+
main()
|
|
547
|
+
'''
|
|
548
|
+
else:
|
|
549
|
+
main_content = f'''# Welcome to Zexus! (Flexible Syntax)
|
|
550
|
+
# Execution Mode: {mode}
|
|
551
|
+
|
|
552
|
+
let app_name = "My Zexus App"
|
|
553
|
+
|
|
554
|
+
action main():
|
|
555
|
+
print "š Hello from " + app_name
|
|
556
|
+
print "⨠Running Zexus v1.5.0 in {mode} mode"
|
|
557
|
+
|
|
558
|
+
# Test some features
|
|
559
|
+
let numbers = [1, 2, 3, 4, 5]
|
|
560
|
+
let doubled = numbers.map(transform: it * 2)
|
|
561
|
+
print "Doubled numbers: " + string(doubled)
|
|
562
|
+
|
|
563
|
+
# Performance test
|
|
564
|
+
let start_time = time.now()
|
|
565
|
+
let sum = 0
|
|
566
|
+
for each number in numbers:
|
|
567
|
+
sum = sum + number
|
|
568
|
+
let end_time = time.now()
|
|
569
|
+
print "Sum: " + string(sum)
|
|
570
|
+
print "Calculation time: " + string(end_time - start_time) + "ms"
|
|
571
|
+
|
|
572
|
+
main()
|
|
573
|
+
'''
|
|
574
|
+
|
|
575
|
+
(project_path / "main.zx").write_text(main_content)
|
|
576
|
+
|
|
577
|
+
# Create config file with hybrid settings
|
|
578
|
+
config_content = f'''{{
|
|
579
|
+
"name": "{project_name}",
|
|
580
|
+
"version": "1.5.0",
|
|
581
|
+
"type": "application",
|
|
582
|
+
"entry_point": "main.zx",
|
|
583
|
+
"syntax_style": "{syntax_style}",
|
|
584
|
+
"execution_mode": "{mode}",
|
|
585
|
+
"hybrid_compiler": true,
|
|
586
|
+
"fallback_to_interpreter": true
|
|
587
|
+
}}
|
|
588
|
+
'''
|
|
589
|
+
|
|
590
|
+
(project_path / "zexus.json").write_text(config_content)
|
|
591
|
+
|
|
592
|
+
console.print(f"\nā
[bold green]Project '{project_name}' created![/bold green]")
|
|
593
|
+
console.print(f"š cd {project_name}")
|
|
594
|
+
console.print("š zx run main.zx")
|
|
595
|
+
console.print(f"š [bold blue]Using {syntax_style} syntax style[/bold blue]")
|
|
596
|
+
console.print(f"š [bold blue]Default execution mode: {mode}[/bold blue]")
|
|
597
|
+
|
|
598
|
+
@cli.command()
|
|
599
|
+
@click.argument('action', type=click.Choice(['on', 'off', 'minimal', 'status']))
|
|
600
|
+
@click.pass_context
|
|
601
|
+
def debug(ctx, action):
|
|
602
|
+
"""Control persistent debug logging: on/off/minimal/status"""
|
|
603
|
+
if action == 'status':
|
|
604
|
+
console.print(f"š Debug level: [bold]{config.debug_level}[/bold]")
|
|
605
|
+
return
|
|
606
|
+
|
|
607
|
+
if action == 'on':
|
|
608
|
+
config.enable_debug('full')
|
|
609
|
+
console.print("ā
Debugging enabled (full)")
|
|
610
|
+
return
|
|
611
|
+
|
|
612
|
+
if action == 'minimal':
|
|
613
|
+
config.enable_debug('minimal')
|
|
614
|
+
console.print("ā
Debugging set to minimal (errors/warnings)")
|
|
615
|
+
return
|
|
616
|
+
|
|
617
|
+
if action == 'off':
|
|
618
|
+
config.disable_debug()
|
|
619
|
+
console.print("ā
Debugging disabled")
|
|
620
|
+
return
|
|
621
|
+
|
|
622
|
+
@cli.command()
|
|
623
|
+
@click.argument('file', type=click.Path(exists=True))
|
|
624
|
+
@click.option('--memory/--no-memory', default=True, help='Enable memory profiling')
|
|
625
|
+
@click.option('--top', default=20, help='Number of functions to show in report')
|
|
626
|
+
@click.option('--json-output', type=click.Path(), help='Save profile data as JSON')
|
|
627
|
+
@click.pass_context
|
|
628
|
+
def profile(ctx, file, memory, top, json_output):
|
|
629
|
+
"""Profile performance of a Zexus program"""
|
|
630
|
+
try:
|
|
631
|
+
from ..profiler import Profiler
|
|
632
|
+
import json as json_lib
|
|
633
|
+
except ImportError as e:
|
|
634
|
+
console.print(f"[bold red]Error:[/bold red] Profiler module not available: {e}")
|
|
635
|
+
console.print("[yellow]The profiler requires additional dependencies.[/yellow]")
|
|
636
|
+
sys.exit(1)
|
|
637
|
+
|
|
638
|
+
console.print(f"ā” [bold green]Profiling[/bold green] {file}")
|
|
639
|
+
console.print(f"š¾ [bold blue]Memory profiling:[/bold blue] {'Enabled' if memory else 'Disabled'}")
|
|
640
|
+
|
|
641
|
+
try:
|
|
642
|
+
with open(file, 'r') as f:
|
|
643
|
+
source_code = f.read()
|
|
644
|
+
|
|
645
|
+
syntax_style = ctx.obj['SYNTAX_STYLE']
|
|
646
|
+
advanced_parsing = ctx.obj['ADVANCED_PARSING']
|
|
647
|
+
validator = SyntaxValidator()
|
|
648
|
+
|
|
649
|
+
# Auto-detect syntax style if needed
|
|
650
|
+
if syntax_style == 'auto':
|
|
651
|
+
syntax_style = validator.suggest_syntax_style(source_code)
|
|
652
|
+
|
|
653
|
+
# Parse the program
|
|
654
|
+
lexer = Lexer(source_code, filename=file)
|
|
655
|
+
parser = Parser(lexer, syntax_style, enable_advanced_strategies=advanced_parsing)
|
|
656
|
+
program = parser.parse_program()
|
|
657
|
+
|
|
658
|
+
if parser.errors and any("critical" in e.lower() for e in parser.errors):
|
|
659
|
+
console.print("[bold red]ā Critical parser errors, cannot profile:[/bold red]")
|
|
660
|
+
for error in parser.errors:
|
|
661
|
+
console.print(f" ā {error}")
|
|
662
|
+
sys.exit(1)
|
|
663
|
+
|
|
664
|
+
# Set up environment
|
|
665
|
+
env = Environment()
|
|
666
|
+
import os
|
|
667
|
+
abs_file = os.path.abspath(file)
|
|
668
|
+
env.set("__file__", String(abs_file))
|
|
669
|
+
env.set("__FILE__", String(abs_file))
|
|
670
|
+
env.set("__MODULE__", String("__main__"))
|
|
671
|
+
env.set("__DIR__", String(os.path.dirname(abs_file)))
|
|
672
|
+
|
|
673
|
+
# Create and start profiler
|
|
674
|
+
profiler = Profiler()
|
|
675
|
+
profiler.start(enable_memory=memory)
|
|
676
|
+
|
|
677
|
+
try:
|
|
678
|
+
# Execute with profiling
|
|
679
|
+
console.print("[dim]Executing with profiling...[/dim]")
|
|
680
|
+
result = evaluate(program, env, debug_mode=ctx.obj['DEBUG'])
|
|
681
|
+
finally:
|
|
682
|
+
# Stop profiler and get report (ensure cleanup even if evaluate fails)
|
|
683
|
+
report = profiler.stop()
|
|
684
|
+
|
|
685
|
+
# Print report
|
|
686
|
+
profiler.print_report(report, top_n=top)
|
|
687
|
+
|
|
688
|
+
# Save JSON if requested
|
|
689
|
+
if json_output:
|
|
690
|
+
data = report.to_dict()
|
|
691
|
+
with open(json_output, 'w') as f:
|
|
692
|
+
json_lib.dump(data, f, indent=2)
|
|
693
|
+
console.print(f"\nš¾ [bold green]Profile data saved to:[/bold green] {json_output}")
|
|
694
|
+
|
|
695
|
+
# Print result if any
|
|
696
|
+
if result and hasattr(result, 'inspect') and result.inspect() != 'null':
|
|
697
|
+
console.print(f"\nā
[bold green]Program Result:[/bold green] {result.inspect()}")
|
|
698
|
+
|
|
699
|
+
except Exception as e:
|
|
700
|
+
console.print(f"[bold red]Error during profiling:[/bold red] {str(e)}")
|
|
701
|
+
if ctx.obj.get('DEBUG'):
|
|
702
|
+
import traceback
|
|
703
|
+
traceback.print_exc()
|
|
704
|
+
sys.exit(1)
|
|
705
|
+
|
|
706
|
+
if __name__ == "__main__":
|
|
707
|
+
cli()
|