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,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Minimal/Resilient Semantic Analyzer for the compiler frontend.
|
|
3
|
+
|
|
4
|
+
Provides:
|
|
5
|
+
- `SemanticAnalyzer` with a simple `environment` mapping
|
|
6
|
+
- `register_builtins(builtins)` to accept interpreter builtins
|
|
7
|
+
- `analyze(ast)` returning a list of semantic errors (empty = ok)
|
|
8
|
+
|
|
9
|
+
This implementation is intentionally permissive so the compiler pipeline can run
|
|
10
|
+
while you incrementally implement full semantic checks (name resolution, types).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import List, Dict, Any
|
|
14
|
+
# Import compiler AST node classes we need to inspect
|
|
15
|
+
from .zexus_ast import Program, ActionStatement, AwaitExpression, ProtocolDeclaration, EventDeclaration, MapLiteral, BlockStatement
|
|
16
|
+
|
|
17
|
+
class SemanticAnalyzer:
|
|
18
|
+
def __init__(self):
|
|
19
|
+
# Simple environment used by the compiler frontend (name -> value)
|
|
20
|
+
self.environment: Dict[str, Any] = {}
|
|
21
|
+
self._builtins_registered = False
|
|
22
|
+
|
|
23
|
+
def register_builtins(self, builtins: Dict[str, Any]):
|
|
24
|
+
"""Register builtin functions/values into the analyzer environment.
|
|
25
|
+
|
|
26
|
+
Best-effort: won't raise on unexpected builtin shapes.
|
|
27
|
+
"""
|
|
28
|
+
if not builtins:
|
|
29
|
+
return
|
|
30
|
+
try:
|
|
31
|
+
for name, val in builtins.items():
|
|
32
|
+
if name not in self.environment:
|
|
33
|
+
self.environment[name] = val
|
|
34
|
+
self._builtins_registered = True
|
|
35
|
+
except Exception:
|
|
36
|
+
# Non-fatal: leave environment as-is
|
|
37
|
+
self._builtins_registered = False
|
|
38
|
+
|
|
39
|
+
def analyze(self, ast) -> List[str]:
|
|
40
|
+
"""Perform minimal semantic analysis and return a list of error messages.
|
|
41
|
+
|
|
42
|
+
Currently lightweight: verifies AST structure and allows compilation to proceed.
|
|
43
|
+
Extend this with full name resolution, type checks, export checks, etc.
|
|
44
|
+
"""
|
|
45
|
+
errors: List[str] = []
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
if ast is None:
|
|
49
|
+
errors.append("No AST provided")
|
|
50
|
+
return errors
|
|
51
|
+
|
|
52
|
+
stmts = getattr(ast, "statements", None)
|
|
53
|
+
if stmts is None:
|
|
54
|
+
errors.append("Invalid AST: missing 'statements' list")
|
|
55
|
+
return errors
|
|
56
|
+
|
|
57
|
+
# Run new checks: await usage and protocol/event validation
|
|
58
|
+
# Walk AST with context
|
|
59
|
+
def walk(node, in_async=False):
|
|
60
|
+
# Protect against cycles by tracking visited node ids
|
|
61
|
+
if not hasattr(walk, '_visited'):
|
|
62
|
+
walk._visited = set()
|
|
63
|
+
if node is None:
|
|
64
|
+
return
|
|
65
|
+
node_id = id(node)
|
|
66
|
+
if node_id in walk._visited:
|
|
67
|
+
return
|
|
68
|
+
walk._visited.add(node_id)
|
|
69
|
+
# Quick type checks for relevant nodes
|
|
70
|
+
if isinstance(node, AwaitExpression):
|
|
71
|
+
if not in_async:
|
|
72
|
+
errors.append("Semantic error: 'await' used outside an async function")
|
|
73
|
+
# ActionStatement may have is_async flag
|
|
74
|
+
if isinstance(node, ActionStatement):
|
|
75
|
+
body = getattr(node, "body", None)
|
|
76
|
+
async_flag = getattr(node, "is_async", False)
|
|
77
|
+
if body:
|
|
78
|
+
# walk body with in_async = async_flag
|
|
79
|
+
for s in getattr(body, "statements", []):
|
|
80
|
+
walk(s, in_async=async_flag)
|
|
81
|
+
return
|
|
82
|
+
if isinstance(node, ProtocolDeclaration):
|
|
83
|
+
spec = getattr(node, "spec", {})
|
|
84
|
+
methods = spec.get("methods") if isinstance(spec, dict) else None
|
|
85
|
+
if not isinstance(methods, list):
|
|
86
|
+
errors.append(f"Protocol '{node.name.value}' spec invalid: 'methods' list missing")
|
|
87
|
+
else:
|
|
88
|
+
for m in methods:
|
|
89
|
+
if not isinstance(m, str):
|
|
90
|
+
errors.append(f"Protocol '{node.name.value}' has non-string method name: {m}")
|
|
91
|
+
return
|
|
92
|
+
if isinstance(node, EventDeclaration):
|
|
93
|
+
props = getattr(node, "properties", None)
|
|
94
|
+
if not isinstance(props, (MapLiteral, BlockStatement)):
|
|
95
|
+
errors.append(f"Event '{node.name.value}' properties should be a map or block")
|
|
96
|
+
# further checks can be added
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
# Generic traversal
|
|
100
|
+
for attr in dir(node):
|
|
101
|
+
if attr.startswith("_") or attr in ("token_literal", "__repr__"):
|
|
102
|
+
continue
|
|
103
|
+
val = getattr(node, attr)
|
|
104
|
+
if isinstance(val, list):
|
|
105
|
+
for item in val:
|
|
106
|
+
if hasattr(item, "__class__"):
|
|
107
|
+
walk(item, in_async=in_async)
|
|
108
|
+
elif hasattr(val, "__class__"):
|
|
109
|
+
walk(val, in_async=in_async)
|
|
110
|
+
|
|
111
|
+
# Walk top-level statements
|
|
112
|
+
for s in stmts:
|
|
113
|
+
walk(s, in_async=False)
|
|
114
|
+
|
|
115
|
+
except Exception as e:
|
|
116
|
+
errors.append(f"Semantic analyzer internal error: {e}")
|
|
117
|
+
|
|
118
|
+
return errors
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Clean AST Definitions for Compiler Phase
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Base classes
|
|
6
|
+
class Node:
|
|
7
|
+
def token_literal(self):
|
|
8
|
+
return ""
|
|
9
|
+
|
|
10
|
+
def __repr__(self):
|
|
11
|
+
return f"{self.__class__.__name__}()"
|
|
12
|
+
|
|
13
|
+
class Statement(Node):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
class Expression(Node):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
class Program(Node):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.statements = []
|
|
22
|
+
|
|
23
|
+
def token_literal(self):
|
|
24
|
+
if len(self.statements) > 0:
|
|
25
|
+
return self.statements[0].token_literal()
|
|
26
|
+
return ""
|
|
27
|
+
|
|
28
|
+
def __repr__(self):
|
|
29
|
+
return f"Program({len(self.statements)} statements)"
|
|
30
|
+
|
|
31
|
+
# Statement Nodes
|
|
32
|
+
class LetStatement(Statement):
|
|
33
|
+
def __init__(self, name, value):
|
|
34
|
+
self.name = name
|
|
35
|
+
self.value = value
|
|
36
|
+
|
|
37
|
+
def token_literal(self):
|
|
38
|
+
return "let"
|
|
39
|
+
|
|
40
|
+
def __repr__(self):
|
|
41
|
+
return f"LetStatement({self.name})"
|
|
42
|
+
|
|
43
|
+
class ReturnStatement(Statement):
|
|
44
|
+
def __init__(self, return_value):
|
|
45
|
+
self.return_value = return_value
|
|
46
|
+
|
|
47
|
+
def token_literal(self):
|
|
48
|
+
return "return"
|
|
49
|
+
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
return f"ReturnStatement({self.return_value})"
|
|
52
|
+
|
|
53
|
+
class ExpressionStatement(Statement):
|
|
54
|
+
def __init__(self, expression):
|
|
55
|
+
self.expression = expression
|
|
56
|
+
|
|
57
|
+
def token_literal(self):
|
|
58
|
+
return self.expression.token_literal()
|
|
59
|
+
|
|
60
|
+
def __repr__(self):
|
|
61
|
+
return f"ExpressionStatement({self.expression})"
|
|
62
|
+
|
|
63
|
+
class BlockStatement(Statement):
|
|
64
|
+
def __init__(self):
|
|
65
|
+
self.statements = []
|
|
66
|
+
|
|
67
|
+
def token_literal(self):
|
|
68
|
+
if len(self.statements) > 0:
|
|
69
|
+
return self.statements[0].token_literal()
|
|
70
|
+
return ""
|
|
71
|
+
|
|
72
|
+
def __repr__(self):
|
|
73
|
+
return f"BlockStatement({len(self.statements)} statements)"
|
|
74
|
+
|
|
75
|
+
class PrintStatement(Statement):
|
|
76
|
+
def __init__(self, value):
|
|
77
|
+
self.value = value
|
|
78
|
+
|
|
79
|
+
def token_literal(self):
|
|
80
|
+
return "print"
|
|
81
|
+
|
|
82
|
+
def __repr__(self):
|
|
83
|
+
return f"PrintStatement({self.value})"
|
|
84
|
+
|
|
85
|
+
class IfStatement(Statement):
|
|
86
|
+
def __init__(self, condition, consequence, alternative=None):
|
|
87
|
+
self.condition = condition
|
|
88
|
+
self.consequence = consequence
|
|
89
|
+
self.alternative = alternative
|
|
90
|
+
|
|
91
|
+
def token_literal(self):
|
|
92
|
+
return "if"
|
|
93
|
+
|
|
94
|
+
def __repr__(self):
|
|
95
|
+
return f"IfStatement(condition={self.condition})"
|
|
96
|
+
|
|
97
|
+
class WhileStatement(Statement):
|
|
98
|
+
def __init__(self, condition, body):
|
|
99
|
+
self.condition = condition
|
|
100
|
+
self.body = body
|
|
101
|
+
|
|
102
|
+
def token_literal(self):
|
|
103
|
+
return "while"
|
|
104
|
+
|
|
105
|
+
def __repr__(self):
|
|
106
|
+
return f"WhileStatement(condition={self.condition})"
|
|
107
|
+
|
|
108
|
+
class ForEachStatement(Statement):
|
|
109
|
+
def __init__(self, item, iterable, body):
|
|
110
|
+
self.item = item
|
|
111
|
+
self.iterable = iterable
|
|
112
|
+
self.body = body
|
|
113
|
+
|
|
114
|
+
def token_literal(self):
|
|
115
|
+
return "for"
|
|
116
|
+
|
|
117
|
+
def __repr__(self):
|
|
118
|
+
return f"ForEachStatement(item={self.item}, iterable={self.iterable})"
|
|
119
|
+
|
|
120
|
+
class ActionStatement(Statement):
|
|
121
|
+
def __init__(self, name, parameters, body):
|
|
122
|
+
self.name = name
|
|
123
|
+
self.parameters = parameters
|
|
124
|
+
self.body = body
|
|
125
|
+
|
|
126
|
+
def token_literal(self):
|
|
127
|
+
return "action"
|
|
128
|
+
|
|
129
|
+
def __repr__(self):
|
|
130
|
+
return f"ActionStatement({self.name}, {len(self.parameters)} params)"
|
|
131
|
+
|
|
132
|
+
class UseStatement(Statement):
|
|
133
|
+
def __init__(self, file_path, alias=None):
|
|
134
|
+
self.file_path = file_path
|
|
135
|
+
self.alias = alias
|
|
136
|
+
|
|
137
|
+
def token_literal(self):
|
|
138
|
+
return "use"
|
|
139
|
+
|
|
140
|
+
def __repr__(self):
|
|
141
|
+
return f"UseStatement('{self.file_path}')"
|
|
142
|
+
|
|
143
|
+
# NEW: Compiler-side Screen/Component/Theme nodes
|
|
144
|
+
class ScreenStatement(Statement):
|
|
145
|
+
def __init__(self, name, body):
|
|
146
|
+
self.name = name
|
|
147
|
+
self.body = body
|
|
148
|
+
|
|
149
|
+
def token_literal(self):
|
|
150
|
+
return "screen"
|
|
151
|
+
|
|
152
|
+
def __repr__(self):
|
|
153
|
+
return f"ScreenStatement({self.name})"
|
|
154
|
+
|
|
155
|
+
class ComponentStatement(Statement):
|
|
156
|
+
def __init__(self, name, properties):
|
|
157
|
+
self.name = name
|
|
158
|
+
self.properties = properties
|
|
159
|
+
|
|
160
|
+
def token_literal(self):
|
|
161
|
+
return "component"
|
|
162
|
+
|
|
163
|
+
def __repr__(self):
|
|
164
|
+
return f"ComponentStatement({self.name})"
|
|
165
|
+
|
|
166
|
+
class ThemeStatement(Statement):
|
|
167
|
+
def __init__(self, name, properties):
|
|
168
|
+
self.name = name
|
|
169
|
+
self.properties = properties
|
|
170
|
+
|
|
171
|
+
def token_literal(self):
|
|
172
|
+
return "theme"
|
|
173
|
+
|
|
174
|
+
def __repr__(self):
|
|
175
|
+
return f"ThemeStatement({self.name})"
|
|
176
|
+
|
|
177
|
+
# NEW: TryCatchStatement for compiler AST (matches interpreter node)
|
|
178
|
+
class TryCatchStatement(Statement):
|
|
179
|
+
def __init__(self, try_block, error_variable, catch_block):
|
|
180
|
+
self.try_block = try_block
|
|
181
|
+
self.error_variable = error_variable
|
|
182
|
+
self.catch_block = catch_block
|
|
183
|
+
|
|
184
|
+
def token_literal(self):
|
|
185
|
+
return "try"
|
|
186
|
+
|
|
187
|
+
def __repr__(self):
|
|
188
|
+
return f"TryCatchStatement(error_var={self.error_variable})"
|
|
189
|
+
|
|
190
|
+
# NEW: ExternalDeclaration for compiler AST (matches interpreter node)
|
|
191
|
+
class ExternalDeclaration(Statement):
|
|
192
|
+
def __init__(self, name, parameters, module_path):
|
|
193
|
+
self.name = name
|
|
194
|
+
self.parameters = parameters or []
|
|
195
|
+
self.module_path = module_path
|
|
196
|
+
|
|
197
|
+
def token_literal(self):
|
|
198
|
+
return "external"
|
|
199
|
+
|
|
200
|
+
def __repr__(self):
|
|
201
|
+
return f"ExternalDeclaration(name={self.name}, module={self.module_path})"
|
|
202
|
+
|
|
203
|
+
# Expression Nodes
|
|
204
|
+
class Identifier(Expression):
|
|
205
|
+
def __init__(self, value):
|
|
206
|
+
self.value = value
|
|
207
|
+
|
|
208
|
+
def token_literal(self):
|
|
209
|
+
return self.value
|
|
210
|
+
|
|
211
|
+
def __repr__(self):
|
|
212
|
+
return f"Identifier('{self.value}')"
|
|
213
|
+
|
|
214
|
+
class IntegerLiteral(Expression):
|
|
215
|
+
def __init__(self, value):
|
|
216
|
+
self.value = value
|
|
217
|
+
|
|
218
|
+
def token_literal(self):
|
|
219
|
+
return str(self.value)
|
|
220
|
+
|
|
221
|
+
def __repr__(self):
|
|
222
|
+
return f"IntegerLiteral({self.value})"
|
|
223
|
+
|
|
224
|
+
class FloatLiteral(Expression):
|
|
225
|
+
def __init__(self, value):
|
|
226
|
+
self.value = value
|
|
227
|
+
|
|
228
|
+
def token_literal(self):
|
|
229
|
+
return str(self.value)
|
|
230
|
+
|
|
231
|
+
def __repr__(self):
|
|
232
|
+
return f"FloatLiteral({self.value})"
|
|
233
|
+
|
|
234
|
+
class StringLiteral(Expression):
|
|
235
|
+
def __init__(self, value):
|
|
236
|
+
self.value = value
|
|
237
|
+
|
|
238
|
+
def token_literal(self):
|
|
239
|
+
return self.value
|
|
240
|
+
|
|
241
|
+
def __repr__(self):
|
|
242
|
+
return f"StringLiteral('{self.value}')"
|
|
243
|
+
|
|
244
|
+
class Boolean(Expression):
|
|
245
|
+
def __init__(self, value):
|
|
246
|
+
self.value = value
|
|
247
|
+
|
|
248
|
+
def token_literal(self):
|
|
249
|
+
return "true" if self.value else "false"
|
|
250
|
+
|
|
251
|
+
def __repr__(self):
|
|
252
|
+
return f"Boolean({self.value})"
|
|
253
|
+
|
|
254
|
+
class ListLiteral(Expression):
|
|
255
|
+
def __init__(self, elements):
|
|
256
|
+
self.elements = elements
|
|
257
|
+
|
|
258
|
+
def token_literal(self):
|
|
259
|
+
return "["
|
|
260
|
+
|
|
261
|
+
def __repr__(self):
|
|
262
|
+
return f"ListLiteral({len(self.elements)} elements)"
|
|
263
|
+
|
|
264
|
+
class MapLiteral(Expression):
|
|
265
|
+
def __init__(self, pairs):
|
|
266
|
+
self.pairs = pairs
|
|
267
|
+
|
|
268
|
+
def token_literal(self):
|
|
269
|
+
return "{"
|
|
270
|
+
|
|
271
|
+
def __repr__(self):
|
|
272
|
+
return f"MapLiteral({len(self.pairs)} pairs)"
|
|
273
|
+
|
|
274
|
+
class PrefixExpression(Expression):
|
|
275
|
+
def __init__(self, operator, right):
|
|
276
|
+
self.operator = operator
|
|
277
|
+
self.right = right
|
|
278
|
+
|
|
279
|
+
def token_literal(self):
|
|
280
|
+
return self.operator
|
|
281
|
+
|
|
282
|
+
def __repr__(self):
|
|
283
|
+
return f"PrefixExpression('{self.operator}', {self.right})"
|
|
284
|
+
|
|
285
|
+
class InfixExpression(Expression):
|
|
286
|
+
def __init__(self, left, operator, right):
|
|
287
|
+
self.left = left
|
|
288
|
+
self.operator = operator
|
|
289
|
+
self.right = right
|
|
290
|
+
|
|
291
|
+
def token_literal(self):
|
|
292
|
+
return self.operator
|
|
293
|
+
|
|
294
|
+
def __repr__(self):
|
|
295
|
+
return f"InfixExpression({self.left}, '{self.operator}', {self.right})"
|
|
296
|
+
|
|
297
|
+
class CallExpression(Expression):
|
|
298
|
+
def __init__(self, function, arguments):
|
|
299
|
+
self.function = function
|
|
300
|
+
self.arguments = arguments
|
|
301
|
+
|
|
302
|
+
def token_literal(self):
|
|
303
|
+
return self.function.token_literal()
|
|
304
|
+
|
|
305
|
+
def __repr__(self):
|
|
306
|
+
return f"CallExpression({self.function}, {len(self.arguments)} args)"
|
|
307
|
+
|
|
308
|
+
class AssignmentExpression(Expression):
|
|
309
|
+
def __init__(self, name, value):
|
|
310
|
+
self.name = name
|
|
311
|
+
self.value = value
|
|
312
|
+
|
|
313
|
+
def token_literal(self):
|
|
314
|
+
return "="
|
|
315
|
+
|
|
316
|
+
def __repr__(self):
|
|
317
|
+
return f"AssignmentExpression({self.name}, {self.value})"
|
|
318
|
+
|
|
319
|
+
class MethodCallExpression(Expression):
|
|
320
|
+
def __init__(self, object, method, arguments):
|
|
321
|
+
self.object = object
|
|
322
|
+
self.method = method
|
|
323
|
+
self.arguments = arguments
|
|
324
|
+
|
|
325
|
+
def token_literal(self):
|
|
326
|
+
return self.method.token_literal()
|
|
327
|
+
|
|
328
|
+
def __repr__(self):
|
|
329
|
+
return f"MethodCallExpression({self.object}.{self.method})"
|
|
330
|
+
|
|
331
|
+
class PropertyAccessExpression(Expression):
|
|
332
|
+
def __init__(self, object, property):
|
|
333
|
+
self.object = object
|
|
334
|
+
self.property = property
|
|
335
|
+
|
|
336
|
+
def token_literal(self):
|
|
337
|
+
return self.property.token_literal()
|
|
338
|
+
|
|
339
|
+
def __repr__(self):
|
|
340
|
+
return f"PropertyAccessExpression({self.object}.{self.property})"
|
|
341
|
+
|
|
342
|
+
class LambdaExpression(Expression):
|
|
343
|
+
def __init__(self, parameters, body):
|
|
344
|
+
self.parameters = parameters
|
|
345
|
+
self.body = body
|
|
346
|
+
|
|
347
|
+
def token_literal(self):
|
|
348
|
+
return "lambda"
|
|
349
|
+
|
|
350
|
+
def __repr__(self):
|
|
351
|
+
return f"LambdaExpression({len(self.parameters)} params)"
|
|
352
|
+
|
|
353
|
+
class ActionLiteral(Expression):
|
|
354
|
+
def __init__(self, parameters, body):
|
|
355
|
+
self.parameters = parameters
|
|
356
|
+
self.body = body
|
|
357
|
+
|
|
358
|
+
def token_literal(self):
|
|
359
|
+
return "action"
|
|
360
|
+
|
|
361
|
+
def __repr__(self):
|
|
362
|
+
return f"ActionLiteral({len(self.parameters)} params)"
|
|
363
|
+
|
|
364
|
+
class IfExpression(Expression):
|
|
365
|
+
def __init__(self, condition, consequence, alternative=None):
|
|
366
|
+
self.condition = condition
|
|
367
|
+
self.consequence = consequence
|
|
368
|
+
self.alternative = alternative
|
|
369
|
+
|
|
370
|
+
def token_literal(self):
|
|
371
|
+
return "if"
|
|
372
|
+
|
|
373
|
+
def __repr__(self):
|
|
374
|
+
return f"IfExpression(condition={self.condition})"
|
|
375
|
+
|
|
376
|
+
class EmbeddedLiteral(Expression):
|
|
377
|
+
def __init__(self, language, code):
|
|
378
|
+
self.language = language
|
|
379
|
+
self.code = code
|
|
380
|
+
|
|
381
|
+
def token_literal(self):
|
|
382
|
+
return "embedded"
|
|
383
|
+
|
|
384
|
+
def __repr__(self):
|
|
385
|
+
return f"EmbeddedLiteral({self.language})"
|
|
386
|
+
|
|
387
|
+
# NEW: AwaitExpression (used in compiler AST)
|
|
388
|
+
class AwaitExpression(Expression):
|
|
389
|
+
def __init__(self, expression):
|
|
390
|
+
self.expression = expression
|
|
391
|
+
|
|
392
|
+
def token_literal(self):
|
|
393
|
+
return "await"
|
|
394
|
+
|
|
395
|
+
def __repr__(self):
|
|
396
|
+
return f"AwaitExpression({self.expression})"
|
|
397
|
+
|
|
398
|
+
# NEW: EventDeclaration / EmitStatement
|
|
399
|
+
class EventDeclaration(Statement):
|
|
400
|
+
def __init__(self, name, properties):
|
|
401
|
+
self.name = name
|
|
402
|
+
self.properties = properties
|
|
403
|
+
|
|
404
|
+
def token_literal(self):
|
|
405
|
+
return "event"
|
|
406
|
+
|
|
407
|
+
def __repr__(self):
|
|
408
|
+
return f"EventDeclaration({self.name})"
|
|
409
|
+
|
|
410
|
+
class EmitStatement(Statement):
|
|
411
|
+
def __init__(self, name, payload=None):
|
|
412
|
+
self.name = name
|
|
413
|
+
self.payload = payload
|
|
414
|
+
|
|
415
|
+
def token_literal(self):
|
|
416
|
+
return "emit"
|
|
417
|
+
|
|
418
|
+
def __repr__(self):
|
|
419
|
+
return f"EmitStatement({self.name}, payload={self.payload})"
|
|
420
|
+
|
|
421
|
+
# NEW: EnumDeclaration and ProtocolDeclaration
|
|
422
|
+
class EnumDeclaration(Statement):
|
|
423
|
+
def __init__(self, name, members):
|
|
424
|
+
self.name = name
|
|
425
|
+
self.members = members
|
|
426
|
+
|
|
427
|
+
def token_literal(self):
|
|
428
|
+
return "enum"
|
|
429
|
+
|
|
430
|
+
def __repr__(self):
|
|
431
|
+
return f"EnumDeclaration({self.name})"
|
|
432
|
+
|
|
433
|
+
class ProtocolDeclaration(Statement):
|
|
434
|
+
def __init__(self, name, spec):
|
|
435
|
+
self.name = name
|
|
436
|
+
self.spec = spec
|
|
437
|
+
|
|
438
|
+
def token_literal(self):
|
|
439
|
+
return "protocol"
|
|
440
|
+
|
|
441
|
+
def __repr__(self):
|
|
442
|
+
return f"ProtocolDeclaration({self.name})"
|
|
443
|
+
|
|
444
|
+
# NEW: ImportStatement (explicit import syntax)
|
|
445
|
+
class ImportStatement(Statement):
|
|
446
|
+
def __init__(self, module_path, alias=None):
|
|
447
|
+
self.module_path = module_path
|
|
448
|
+
self.alias = alias
|
|
449
|
+
|
|
450
|
+
def token_literal(self):
|
|
451
|
+
return "import"
|
|
452
|
+
|
|
453
|
+
def __repr__(self):
|
|
454
|
+
return f"ImportStatement({self.module_path} as {self.alias})"
|