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,16 @@
|
|
|
1
|
+
# External function bridge for Zexus
|
|
2
|
+
import hashlib
|
|
3
|
+
|
|
4
|
+
external_functions = {
|
|
5
|
+
"sha256_hash": lambda data: hashlib.sha256(data.encode()).hexdigest(),
|
|
6
|
+
"generate_sphincs_keypair": lambda: {
|
|
7
|
+
"public_key": "sphincs_pub_placeholder",
|
|
8
|
+
"private_key": "sphincs_priv_placeholder"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def call_external(function_name, args):
|
|
13
|
+
if function_name in external_functions:
|
|
14
|
+
return external_functions[function_name](*args)
|
|
15
|
+
else:
|
|
16
|
+
raise Exception(f"External function not found: {function_name}")
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# find_affected_imports.sh
|
|
3
|
+
echo "🔍 FINDING FILES AFFECTED BY PARSER DIRECTORY MOVE"
|
|
4
|
+
echo "=================================================="
|
|
5
|
+
echo ""
|
|
6
|
+
|
|
7
|
+
# First, let's see what files import parser-related modules
|
|
8
|
+
echo "1. Searching for files that import parser modules..."
|
|
9
|
+
echo "---------------------------------------------------"
|
|
10
|
+
|
|
11
|
+
# Search for imports of parser, strategy_context, strategy_structural
|
|
12
|
+
patterns=(
|
|
13
|
+
"from.*\.parser"
|
|
14
|
+
"import.*parser"
|
|
15
|
+
"from.*strategy_context"
|
|
16
|
+
"from.*strategy_structural"
|
|
17
|
+
"from.*strategy_recovery"
|
|
18
|
+
"Parser.*import"
|
|
19
|
+
"UltimateParser"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
for pattern in "${patterns[@]}"; do
|
|
23
|
+
echo ""
|
|
24
|
+
echo "📌 Searching for: $pattern"
|
|
25
|
+
echo "--------------------------------"
|
|
26
|
+
grep -r "$pattern" . --include="*.py" 2>/dev/null | \
|
|
27
|
+
grep -v "__pycache__" | \
|
|
28
|
+
grep -v "compiler/parser.py" | \
|
|
29
|
+
grep -v "parser/parser.py" | \
|
|
30
|
+
head -20
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
echo ""
|
|
34
|
+
echo "2. Checking specific known files that might need updates:"
|
|
35
|
+
echo "---------------------------------------------------------"
|
|
36
|
+
|
|
37
|
+
# List of files likely to need updates
|
|
38
|
+
critical_files=(
|
|
39
|
+
"cli/main.py"
|
|
40
|
+
"hybrid_orchestrator.py"
|
|
41
|
+
"__init__.py"
|
|
42
|
+
"syntax_validator.py"
|
|
43
|
+
"strategy_recovery.py"
|
|
44
|
+
"compiler/compat_runtime.py"
|
|
45
|
+
"compiler/__init__.py"
|
|
46
|
+
"compiler/semantic.py"
|
|
47
|
+
"vm/vm.py"
|
|
48
|
+
"evaluator/core.py"
|
|
49
|
+
"evaluator/statements.py"
|
|
50
|
+
"module_cache.py"
|
|
51
|
+
"environment_manager.py"
|
|
52
|
+
"compare_interpreter_compiler.py"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
for file in "${critical_files[@]}"; do
|
|
56
|
+
if [ -f "$file" ]; then
|
|
57
|
+
echo ""
|
|
58
|
+
echo "🔎 Checking: $file"
|
|
59
|
+
# Check for parser imports
|
|
60
|
+
if grep -q "parser" "$file"; then
|
|
61
|
+
echo " ⚠️ Contains 'parser' references:"
|
|
62
|
+
grep -n "parser" "$file" | head -3 | sed 's/^/ /'
|
|
63
|
+
fi
|
|
64
|
+
# Check for specific parser classes
|
|
65
|
+
if grep -q "Parser\|UltimateParser" "$file"; then
|
|
66
|
+
echo " ⚠️ Contains parser class references:"
|
|
67
|
+
grep -n "Parser\|UltimateParser" "$file" | head -3 | sed 's/^/ /'
|
|
68
|
+
fi
|
|
69
|
+
fi
|
|
70
|
+
done
|
|
71
|
+
|
|
72
|
+
echo ""
|
|
73
|
+
echo "3. Analyzing import patterns in parser directory:"
|
|
74
|
+
echo "-------------------------------------------------"
|
|
75
|
+
|
|
76
|
+
# Look at what the parser files themselves export
|
|
77
|
+
echo "Parser directory structure:"
|
|
78
|
+
ls -la parser/
|
|
79
|
+
|
|
80
|
+
echo ""
|
|
81
|
+
echo "Parser/__init__.py contents:"
|
|
82
|
+
if [ -f "parser/__init__.py" ]; then
|
|
83
|
+
cat parser/__init__.py
|
|
84
|
+
else
|
|
85
|
+
echo "No __init__.py in parser directory"
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
echo ""
|
|
89
|
+
echo "4. Finding import statements that need changing:"
|
|
90
|
+
echo "-----------------------------------------------"
|
|
91
|
+
|
|
92
|
+
# Most common patterns that need updating
|
|
93
|
+
echo "Common patterns that need updating:"
|
|
94
|
+
echo " OLD: from .parser import Parser"
|
|
95
|
+
echo " NEW: from .parser.parser import Parser"
|
|
96
|
+
echo ""
|
|
97
|
+
echo " OLD: from . import parser"
|
|
98
|
+
echo " NEW: from .parser import parser"
|
|
99
|
+
echo ""
|
|
100
|
+
echo " OLD: from ..parser import ..."
|
|
101
|
+
echo " NEW: from ..parser.parser import ... (or from ..parser.strategy_context import ...)"
|
|
102
|
+
|
|
103
|
+
echo ""
|
|
104
|
+
echo "5. Running actual import test to see what breaks:"
|
|
105
|
+
echo "-------------------------------------------------"
|
|
106
|
+
|
|
107
|
+
# Quick Python test to see what imports work
|
|
108
|
+
echo "Testing imports..."
|
|
109
|
+
python3 -c "
|
|
110
|
+
import sys
|
|
111
|
+
sys.path.insert(0, '.')
|
|
112
|
+
|
|
113
|
+
print('Testing parser imports...')
|
|
114
|
+
try:
|
|
115
|
+
from parser import Parser
|
|
116
|
+
print('✓ from parser import Parser - WORKS')
|
|
117
|
+
except ImportError as e:
|
|
118
|
+
print(f'✗ from parser import Parser - FAILS: {e}')
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
from parser.parser import Parser
|
|
122
|
+
print('✓ from parser.parser import Parser - WORKS')
|
|
123
|
+
except ImportError as e:
|
|
124
|
+
print(f'✗ from parser.parser import Parser - FAILS: {e}')
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
from parser.strategy_context import StrategyContext
|
|
128
|
+
print('✓ from parser.strategy_context import StrategyContext - WORKS')
|
|
129
|
+
except ImportError as e:
|
|
130
|
+
print(f'✗ from parser.strategy_context import StrategyContext - FAILS: {e}')
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
from parser.strategy_structural import StructuralStrategy
|
|
134
|
+
print('✓ from parser.strategy_structural import StructuralStrategy - WORKS')
|
|
135
|
+
except ImportError as e:
|
|
136
|
+
print(f'✗ from parser.strategy_structural import StructuralStrategy - FAILS: {e}')
|
|
137
|
+
"
|
|
138
|
+
|
|
139
|
+
echo ""
|
|
140
|
+
echo "6. Creating migration commands:"
|
|
141
|
+
echo "------------------------------"
|
|
142
|
+
|
|
143
|
+
# Generate sed commands for common replacements
|
|
144
|
+
echo "To update imports, you might need these sed commands:"
|
|
145
|
+
echo ""
|
|
146
|
+
echo "# Update imports in the same directory as parser/"
|
|
147
|
+
echo "sed -i 's/from \\.parser import/from \\.parser.parser import/g' *.py"
|
|
148
|
+
echo "sed -i 's/from parser import/from parser.parser import/g' *.py"
|
|
149
|
+
echo ""
|
|
150
|
+
echo "# Update imports from parent directory"
|
|
151
|
+
echo "sed -i 's/from \\.\\.parser import/from \\.\\.parser.parser import/g' *.py"
|
|
152
|
+
echo ""
|
|
153
|
+
echo "# Update specific strategy imports"
|
|
154
|
+
echo "sed -i 's/from \\.strategy_context import/from \\.parser.strategy_context import/g' *.py"
|
|
155
|
+
echo "sed -i 's/from \\.strategy_structural import/from \\.parser.strategy_structural import/g' *.py"
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# src/zexus/hybrid_orchestrator.py
|
|
2
|
+
"""
|
|
3
|
+
Hybrid Orchestrator - Intelligently chooses between interpreter and compiler
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import time
|
|
8
|
+
from .lexer import Lexer
|
|
9
|
+
from .parser import UltimateParser
|
|
10
|
+
# UPDATED: Import from new structure
|
|
11
|
+
from .evaluator import evaluate
|
|
12
|
+
from .object import Environment
|
|
13
|
+
from .config import config
|
|
14
|
+
|
|
15
|
+
# Try to import compiler components
|
|
16
|
+
try:
|
|
17
|
+
from .compiler import ZexusCompiler
|
|
18
|
+
from .vm import ZexusVM
|
|
19
|
+
COMPILER_AVAILABLE = True
|
|
20
|
+
except ImportError:
|
|
21
|
+
COMPILER_AVAILABLE = False
|
|
22
|
+
|
|
23
|
+
class HybridOrchestrator:
|
|
24
|
+
def __init__(self):
|
|
25
|
+
self.interpreter_used = 0
|
|
26
|
+
self.compiler_used = 0
|
|
27
|
+
self.fallbacks = 0
|
|
28
|
+
|
|
29
|
+
def should_use_compiler(self, code, syntax_style="auto"):
|
|
30
|
+
"""
|
|
31
|
+
Smart rules for when to use compiler vs interpreter
|
|
32
|
+
"""
|
|
33
|
+
if not config.use_hybrid_compiler or not COMPILER_AVAILABLE:
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
# Rule 1: Large files (> 100 lines) benefit from compilation
|
|
37
|
+
line_count = len(code.split('\n'))
|
|
38
|
+
if line_count > config.compiler_line_threshold:
|
|
39
|
+
return True
|
|
40
|
+
|
|
41
|
+
# Rule 2: Code with complex loops (for, while)
|
|
42
|
+
complex_constructs = ['for', 'while', 'each', 'function', 'action']
|
|
43
|
+
if any(construct in code for construct in complex_constructs):
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
# Rule 3: Mathematical/computational intensive code
|
|
47
|
+
math_keywords = ['*', '/', '%', 'math.', 'calculate']
|
|
48
|
+
if any(keyword in code for keyword in math_keywords):
|
|
49
|
+
return True
|
|
50
|
+
|
|
51
|
+
# Rule 4: User explicitly wants compilation
|
|
52
|
+
if "// compile" in code or "# compile" in code:
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
# Rule 5: Universal syntax is more compiler-friendly
|
|
56
|
+
if syntax_style == "universal":
|
|
57
|
+
return True
|
|
58
|
+
|
|
59
|
+
# Default: Use interpreter for simple scripts
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
def compile_and_execute(self, code, environment=None, syntax_style="auto"):
|
|
63
|
+
"""
|
|
64
|
+
Execute code using the compiler/VM path
|
|
65
|
+
"""
|
|
66
|
+
try:
|
|
67
|
+
if not COMPILER_AVAILABLE:
|
|
68
|
+
raise Exception("Compiler not available")
|
|
69
|
+
|
|
70
|
+
print("🔧 Compiling code...")
|
|
71
|
+
|
|
72
|
+
# Use the ZexusCompiler
|
|
73
|
+
compiler = ZexusCompiler(code)
|
|
74
|
+
bytecode = compiler.compile()
|
|
75
|
+
|
|
76
|
+
if compiler.errors:
|
|
77
|
+
raise Exception(f"Compilation errors: {compiler.errors}")
|
|
78
|
+
|
|
79
|
+
# Execute in VM
|
|
80
|
+
vm = ZexusVM(bytecode)
|
|
81
|
+
result = vm.execute()
|
|
82
|
+
|
|
83
|
+
self.compiler_used += 1
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
except Exception as e:
|
|
87
|
+
print(f"❌ Compilation failed: {e}")
|
|
88
|
+
if config.fallback_to_interpreter:
|
|
89
|
+
print("🔄 Falling back to interpreter...")
|
|
90
|
+
self.fallbacks += 1
|
|
91
|
+
return self.interpret(code, environment, syntax_style)
|
|
92
|
+
else:
|
|
93
|
+
raise
|
|
94
|
+
|
|
95
|
+
def interpret(self, code, environment=None, syntax_style="auto"):
|
|
96
|
+
"""
|
|
97
|
+
Execute code using the interpreter path
|
|
98
|
+
"""
|
|
99
|
+
lexer = Lexer(code)
|
|
100
|
+
parser = UltimateParser(lexer, syntax_style)
|
|
101
|
+
program = parser.parse_program()
|
|
102
|
+
|
|
103
|
+
if len(parser.errors) > 0:
|
|
104
|
+
raise Exception(f"Parse errors: {parser.errors}")
|
|
105
|
+
|
|
106
|
+
if environment is None:
|
|
107
|
+
environment = Environment()
|
|
108
|
+
|
|
109
|
+
# UPDATED: Use evaluate instead of eval_node
|
|
110
|
+
result = evaluate(program, environment)
|
|
111
|
+
|
|
112
|
+
self.interpreter_used += 1
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
def execute(self, code, environment=None, mode="auto", syntax_style="auto"):
|
|
116
|
+
"""
|
|
117
|
+
Main entry point - decides execution strategy
|
|
118
|
+
"""
|
|
119
|
+
start_time = time.time()
|
|
120
|
+
|
|
121
|
+
if mode == "interpreter":
|
|
122
|
+
result = self.interpret(code, environment, syntax_style)
|
|
123
|
+
elif mode == "compiler":
|
|
124
|
+
result = self.compile_and_execute(code, environment, syntax_style)
|
|
125
|
+
else: # auto mode
|
|
126
|
+
if self.should_use_compiler(code, syntax_style):
|
|
127
|
+
result = self.compile_and_execute(code, environment, syntax_style)
|
|
128
|
+
else:
|
|
129
|
+
result = self.interpret(code, environment, syntax_style)
|
|
130
|
+
|
|
131
|
+
execution_time = time.time() - start_time
|
|
132
|
+
|
|
133
|
+
if config.enable_debug_logs and config.enable_execution_stats:
|
|
134
|
+
self._print_execution_stats(execution_time, mode)
|
|
135
|
+
|
|
136
|
+
return result
|
|
137
|
+
|
|
138
|
+
def _print_execution_stats(self, execution_time, mode):
|
|
139
|
+
"""Print execution statistics"""
|
|
140
|
+
print(f"\n📊 Execution Statistics:")
|
|
141
|
+
print(f" Mode: {mode}")
|
|
142
|
+
print(f" Time: {execution_time:.4f}s")
|
|
143
|
+
print(f" Interpreter uses: {self.interpreter_used}")
|
|
144
|
+
print(f" Compiler uses: {self.compiler_used}")
|
|
145
|
+
print(f" Fallbacks: {self.fallbacks}")
|
|
146
|
+
total = self.interpreter_used + self.compiler_used
|
|
147
|
+
if total > 0:
|
|
148
|
+
compiler_percent = (self.compiler_used / total) * 100
|
|
149
|
+
print(f" Compiler usage: {compiler_percent:.1f}%")
|
|
150
|
+
|
|
151
|
+
# Global orchestrator instance
|
|
152
|
+
orchestrator = HybridOrchestrator()
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Input Validation Module for Zexus Interpreter
|
|
3
|
+
|
|
4
|
+
Provides comprehensive input validation for all public APIs to ensure
|
|
5
|
+
robust error handling and prevent crashes.
|
|
6
|
+
|
|
7
|
+
Location: src/zexus/input_validation.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def validate_string_input(value, param_name="value", allow_empty=True, max_length=None):
|
|
12
|
+
"""
|
|
13
|
+
Validate string input parameters.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
value: The value to validate
|
|
17
|
+
param_name: Name of the parameter (for error messages)
|
|
18
|
+
allow_empty: Whether empty strings are allowed
|
|
19
|
+
max_length: Maximum allowed length (None for unlimited)
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
str: The validated string value
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
TypeError: If value is not a string
|
|
26
|
+
ValueError: If validation constraints are violated
|
|
27
|
+
"""
|
|
28
|
+
if not isinstance(value, str):
|
|
29
|
+
raise TypeError(f"{param_name} must be a string, got {type(value).__name__}")
|
|
30
|
+
|
|
31
|
+
if not allow_empty and len(value) == 0:
|
|
32
|
+
raise ValueError(f"{param_name} cannot be empty")
|
|
33
|
+
|
|
34
|
+
if max_length is not None and len(value) > max_length:
|
|
35
|
+
raise ValueError(f"{param_name} exceeds maximum length of {max_length}")
|
|
36
|
+
|
|
37
|
+
return value
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def validate_integer_input(value, param_name="value", min_value=None, max_value=None):
|
|
41
|
+
"""
|
|
42
|
+
Validate integer input parameters.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
value: The value to validate
|
|
46
|
+
param_name: Name of the parameter (for error messages)
|
|
47
|
+
min_value: Minimum allowed value (None for unlimited)
|
|
48
|
+
max_value: Maximum allowed value (None for unlimited)
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
int: The validated integer value
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
TypeError: If value is not an integer
|
|
55
|
+
ValueError: If validation constraints are violated
|
|
56
|
+
"""
|
|
57
|
+
if not isinstance(value, int) or isinstance(value, bool):
|
|
58
|
+
raise TypeError(f"{param_name} must be an integer, got {type(value).__name__}")
|
|
59
|
+
|
|
60
|
+
if min_value is not None and value < min_value:
|
|
61
|
+
raise ValueError(f"{param_name} must be >= {min_value}, got {value}")
|
|
62
|
+
|
|
63
|
+
if max_value is not None and value > max_value:
|
|
64
|
+
raise ValueError(f"{param_name} must be <= {max_value}, got {value}")
|
|
65
|
+
|
|
66
|
+
return value
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def validate_number_input(value, param_name="value", min_value=None, max_value=None):
|
|
70
|
+
"""
|
|
71
|
+
Validate numeric (int or float) input parameters.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
value: The value to validate
|
|
75
|
+
param_name: Name of the parameter (for error messages)
|
|
76
|
+
min_value: Minimum allowed value (None for unlimited)
|
|
77
|
+
max_value: Maximum allowed value (None for unlimited)
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
The validated numeric value
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
TypeError: If value is not numeric
|
|
84
|
+
ValueError: If validation constraints are violated
|
|
85
|
+
"""
|
|
86
|
+
if not isinstance(value, (int, float)) or isinstance(value, bool):
|
|
87
|
+
raise TypeError(f"{param_name} must be numeric, got {type(value).__name__}")
|
|
88
|
+
|
|
89
|
+
if min_value is not None and value < min_value:
|
|
90
|
+
raise ValueError(f"{param_name} must be >= {min_value}, got {value}")
|
|
91
|
+
|
|
92
|
+
if max_value is not None and value > max_value:
|
|
93
|
+
raise ValueError(f"{param_name} must be <= {max_value}, got {value}")
|
|
94
|
+
|
|
95
|
+
return value
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def validate_collection_input(value, param_name="value", min_length=None, max_length=None):
|
|
99
|
+
"""
|
|
100
|
+
Validate collection (list, tuple, set) input parameters.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
value: The value to validate
|
|
104
|
+
param_name: Name of the parameter (for error messages)
|
|
105
|
+
min_length: Minimum allowed length (None for unlimited)
|
|
106
|
+
max_length: Maximum allowed length (None for unlimited)
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
The validated collection
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
TypeError: If value is not a collection
|
|
113
|
+
ValueError: If validation constraints are violated
|
|
114
|
+
"""
|
|
115
|
+
if not hasattr(value, '__len__') or isinstance(value, (str, bytes)):
|
|
116
|
+
raise TypeError(f"{param_name} must be a collection, got {type(value).__name__}")
|
|
117
|
+
|
|
118
|
+
length = len(value)
|
|
119
|
+
|
|
120
|
+
if min_length is not None and length < min_length:
|
|
121
|
+
raise ValueError(f"{param_name} must have at least {min_length} elements, got {length}")
|
|
122
|
+
|
|
123
|
+
if max_length is not None and length > max_length:
|
|
124
|
+
raise ValueError(f"{param_name} must have at most {max_length} elements, got {length}")
|
|
125
|
+
|
|
126
|
+
return value
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def validate_index(index, collection, param_name="index"):
|
|
130
|
+
"""
|
|
131
|
+
Validate that an index is within bounds for a collection.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
index: The index to validate
|
|
135
|
+
collection: The collection being indexed
|
|
136
|
+
param_name: Name of the parameter (for error messages)
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
int: The validated index
|
|
140
|
+
|
|
141
|
+
Raises:
|
|
142
|
+
TypeError: If index is not an integer
|
|
143
|
+
IndexError: If index is out of bounds
|
|
144
|
+
"""
|
|
145
|
+
if not isinstance(index, int) or isinstance(index, bool):
|
|
146
|
+
raise TypeError(f"{param_name} must be an integer, got {type(index).__name__}")
|
|
147
|
+
|
|
148
|
+
if not hasattr(collection, '__len__'):
|
|
149
|
+
raise TypeError(f"Cannot index into {type(collection).__name__}")
|
|
150
|
+
|
|
151
|
+
length = len(collection)
|
|
152
|
+
|
|
153
|
+
# Handle negative indices
|
|
154
|
+
if index < 0:
|
|
155
|
+
index = length + index
|
|
156
|
+
|
|
157
|
+
if index < 0 or index >= length:
|
|
158
|
+
raise IndexError(f"{param_name} {index} is out of bounds for collection of length {length}")
|
|
159
|
+
|
|
160
|
+
return index
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def validate_file_path(path, param_name="path", must_exist=False, must_be_file=False):
|
|
164
|
+
"""
|
|
165
|
+
Validate file path input.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
path: The file path to validate
|
|
169
|
+
param_name: Name of the parameter (for error messages)
|
|
170
|
+
must_exist: Whether the path must exist
|
|
171
|
+
must_be_file: Whether the path must be a file (not directory)
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
str: The validated path
|
|
175
|
+
|
|
176
|
+
Raises:
|
|
177
|
+
TypeError: If path is not a string
|
|
178
|
+
ValueError: If validation constraints are violated
|
|
179
|
+
"""
|
|
180
|
+
import os
|
|
181
|
+
|
|
182
|
+
if not isinstance(path, str):
|
|
183
|
+
raise TypeError(f"{param_name} must be a string, got {type(path).__name__}")
|
|
184
|
+
|
|
185
|
+
if len(path) == 0:
|
|
186
|
+
raise ValueError(f"{param_name} cannot be empty")
|
|
187
|
+
|
|
188
|
+
if must_exist and not os.path.exists(path):
|
|
189
|
+
raise ValueError(f"{param_name} does not exist: {path}")
|
|
190
|
+
|
|
191
|
+
if must_be_file and os.path.exists(path) and not os.path.isfile(path):
|
|
192
|
+
raise ValueError(f"{param_name} must be a file, got directory: {path}")
|
|
193
|
+
|
|
194
|
+
return path
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def validate_enum_input(value, allowed_values, param_name="value"):
|
|
198
|
+
"""
|
|
199
|
+
Validate that a value is one of a set of allowed values.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
value: The value to validate
|
|
203
|
+
allowed_values: Collection of allowed values
|
|
204
|
+
param_name: Name of the parameter (for error messages)
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
The validated value
|
|
208
|
+
|
|
209
|
+
Raises:
|
|
210
|
+
ValueError: If value is not in allowed_values
|
|
211
|
+
"""
|
|
212
|
+
if value not in allowed_values:
|
|
213
|
+
raise ValueError(
|
|
214
|
+
f"{param_name} must be one of {allowed_values}, got {value}"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
return value
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def validate_not_none(value, param_name="value"):
|
|
221
|
+
"""
|
|
222
|
+
Validate that a value is not None.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
value: The value to validate
|
|
226
|
+
param_name: Name of the parameter (for error messages)
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
The validated value (not None)
|
|
230
|
+
|
|
231
|
+
Raises:
|
|
232
|
+
ValueError: If value is None
|
|
233
|
+
"""
|
|
234
|
+
if value is None:
|
|
235
|
+
raise ValueError(f"{param_name} cannot be None")
|
|
236
|
+
|
|
237
|
+
return value
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# Convenience validators for common patterns
|
|
241
|
+
|
|
242
|
+
def validate_positive_integer(value, param_name="value"):
|
|
243
|
+
"""Validate that value is a positive integer (> 0)."""
|
|
244
|
+
return validate_integer_input(value, param_name, min_value=1)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def validate_non_negative_integer(value, param_name="value"):
|
|
248
|
+
"""Validate that value is a non-negative integer (>= 0)."""
|
|
249
|
+
return validate_integer_input(value, param_name, min_value=0)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def validate_non_empty_string(value, param_name="value"):
|
|
253
|
+
"""Validate that value is a non-empty string."""
|
|
254
|
+
return validate_string_input(value, param_name, allow_empty=False)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def validate_percentage(value, param_name="value"):
|
|
258
|
+
"""Validate that value is a number between 0 and 100."""
|
|
259
|
+
return validate_number_input(value, param_name, min_value=0, max_value=100)
|