zexus 1.7.1 → 1.7.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/README.md +3 -3
- package/package.json +1 -1
- package/src/__init__.py +7 -0
- package/src/zexus/__init__.py +1 -1
- package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/debug_sanitizer.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__/input_validation.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_manager.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security_enforcement.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/syntax_validator.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/access_control_system/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/access_control_system/__pycache__/access_control.cpython-312.pyc +0 -0
- package/src/zexus/advanced_types.py +17 -2
- package/src/zexus/blockchain/__init__.py +411 -0
- package/src/zexus/blockchain/accelerator.py +1160 -0
- package/src/zexus/blockchain/chain.py +660 -0
- package/src/zexus/blockchain/consensus.py +821 -0
- package/src/zexus/blockchain/contract_vm.py +1019 -0
- package/src/zexus/blockchain/crypto.py +79 -14
- package/src/zexus/blockchain/events.py +526 -0
- package/src/zexus/blockchain/loadtest.py +721 -0
- package/src/zexus/blockchain/monitoring.py +350 -0
- package/src/zexus/blockchain/mpt.py +716 -0
- package/src/zexus/blockchain/multichain.py +951 -0
- package/src/zexus/blockchain/multiprocess_executor.py +338 -0
- package/src/zexus/blockchain/network.py +886 -0
- package/src/zexus/blockchain/node.py +666 -0
- package/src/zexus/blockchain/rpc.py +1203 -0
- package/src/zexus/blockchain/rust_bridge.py +421 -0
- package/src/zexus/blockchain/storage.py +423 -0
- package/src/zexus/blockchain/tokens.py +750 -0
- package/src/zexus/blockchain/upgradeable.py +1004 -0
- package/src/zexus/blockchain/verification.py +1602 -0
- package/src/zexus/blockchain/wallet.py +621 -0
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +300 -20
- package/src/zexus/cli/zpm.py +1 -1
- package/src/zexus/compiler/__pycache__/bytecode.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__/semantic.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/compiler/lexer.py +10 -5
- package/src/zexus/concurrency_system.py +79 -0
- package/src/zexus/config.py +54 -0
- package/src/zexus/crypto_bridge.py +244 -8
- package/src/zexus/dap/__init__.py +10 -0
- package/src/zexus/dap/__main__.py +4 -0
- package/src/zexus/dap/dap_server.py +391 -0
- package/src/zexus/dap/debug_engine.py +298 -0
- package/src/zexus/environment.py +10 -1
- 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__/resource_limiter.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/unified_execution.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/bytecode_compiler.py +441 -37
- package/src/zexus/evaluator/core.py +560 -49
- package/src/zexus/evaluator/expressions.py +122 -49
- package/src/zexus/evaluator/functions.py +417 -16
- package/src/zexus/evaluator/statements.py +521 -118
- package/src/zexus/evaluator/unified_execution.py +573 -72
- package/src/zexus/evaluator/utils.py +14 -2
- package/src/zexus/event_loop.py +186 -0
- package/src/zexus/lexer.py +742 -486
- package/src/zexus/lsp/__init__.py +1 -1
- package/src/zexus/lsp/definition_provider.py +163 -9
- package/src/zexus/lsp/server.py +22 -8
- package/src/zexus/lsp/symbol_provider.py +182 -9
- package/src/zexus/module_cache.py +237 -9
- package/src/zexus/object.py +64 -6
- 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/parser.py +786 -285
- package/src/zexus/parser/strategy_context.py +407 -66
- package/src/zexus/parser/strategy_structural.py +117 -19
- package/src/zexus/persistence.py +15 -1
- package/src/zexus/renderer/__init__.py +15 -0
- package/src/zexus/renderer/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/backend.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/canvas.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/color_system.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/layout.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/main_renderer.cpython-312.pyc +0 -0
- package/src/zexus/renderer/__pycache__/painter.cpython-312.pyc +0 -0
- package/src/zexus/renderer/tk_backend.py +208 -0
- package/src/zexus/renderer/web_backend.py +260 -0
- package/src/zexus/runtime/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/runtime/__pycache__/async_runtime.cpython-312.pyc +0 -0
- package/src/zexus/runtime/__pycache__/load_manager.cpython-312.pyc +0 -0
- package/src/zexus/runtime/file_flags.py +137 -0
- package/src/zexus/safety/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/safety/__pycache__/memory_safety.cpython-312.pyc +0 -0
- package/src/zexus/security.py +424 -34
- package/src/zexus/stdlib/fs.py +23 -18
- package/src/zexus/stdlib/http.py +289 -186
- package/src/zexus/stdlib/sockets.py +207 -163
- package/src/zexus/stdlib/websockets.py +282 -0
- package/src/zexus/stdlib_integration.py +369 -2
- package/src/zexus/strategy_recovery.py +6 -3
- package/src/zexus/type_checker.py +423 -0
- package/src/zexus/virtual_filesystem.py +189 -2
- package/src/zexus/vm/__init__.py +113 -3
- 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__/bytecode_converter.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/compiler.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/gas_metering.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/async_optimizer.py +14 -1
- package/src/zexus/vm/binary_bytecode.py +659 -0
- package/src/zexus/vm/bytecode.py +28 -1
- package/src/zexus/vm/bytecode_converter.py +26 -12
- package/src/zexus/vm/cabi.c +1985 -0
- package/src/zexus/vm/cabi.cpython-312-x86_64-linux-gnu.so +0 -0
- package/src/zexus/vm/cabi.h +127 -0
- package/src/zexus/vm/cache.py +557 -17
- package/src/zexus/vm/compiler.py +703 -5
- package/src/zexus/vm/fastops.c +15743 -0
- package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
- package/src/zexus/vm/fastops.pyx +288 -0
- package/src/zexus/vm/gas_metering.py +50 -9
- package/src/zexus/vm/jit.py +83 -2
- package/src/zexus/vm/native_jit_backend.py +1816 -0
- package/src/zexus/vm/native_runtime.cpp +1388 -0
- package/src/zexus/vm/native_runtime.cpython-312-x86_64-linux-gnu.so +0 -0
- package/src/zexus/vm/optimizer.py +161 -11
- package/src/zexus/vm/parallel_vm.py +118 -42
- package/src/zexus/vm/peephole_optimizer.py +82 -4
- package/src/zexus/vm/profiler.py +38 -18
- package/src/zexus/vm/register_allocator.py +16 -5
- package/src/zexus/vm/register_vm.py +8 -5
- package/src/zexus/vm/vm.py +3411 -573
- package/src/zexus/vm/wasm_compiler.py +658 -0
- package/src/zexus/zexus_ast.py +63 -11
- package/src/zexus/zexus_token.py +13 -5
- package/src/zexus/zpm/installer.py +55 -15
- package/src/zexus/zpm/package_manager.py +1 -1
- package/src/zexus/zpm/registry.py +257 -28
- package/src/zexus.egg-info/PKG-INFO +7 -4
- package/src/zexus.egg-info/SOURCES.txt +116 -9
- package/src/zexus.egg-info/entry_points.txt +1 -0
- package/src/zexus.egg-info/requires.txt +4 -0
|
@@ -22,7 +22,7 @@ def is_error(obj):
|
|
|
22
22
|
|
|
23
23
|
def debug_log(message, data=None, level='debug'):
|
|
24
24
|
# Fast path: most hot paths pass level='debug' with logging disabled
|
|
25
|
-
if level == 'debug' and not zexus_config.
|
|
25
|
+
if level == 'debug' and not zexus_config.fast_debug_enabled:
|
|
26
26
|
return
|
|
27
27
|
try:
|
|
28
28
|
if not zexus_config.should_log(level):
|
|
@@ -42,10 +42,22 @@ def _is_awaitable(obj):
|
|
|
42
42
|
return False
|
|
43
43
|
|
|
44
44
|
def _resolve_awaitable(obj):
|
|
45
|
+
"""Resolve an awaitable on the shared Zexus event loop.
|
|
46
|
+
|
|
47
|
+
Instead of creating a throw-away loop with ``asyncio.run()``, we submit
|
|
48
|
+
the coroutine to the persistent background loop so that all async
|
|
49
|
+
operations share the same event loop and can coordinate (gather, wait,
|
|
50
|
+
semaphores, etc.).
|
|
51
|
+
"""
|
|
45
52
|
if _is_awaitable(obj):
|
|
46
53
|
try:
|
|
47
54
|
EVAL_SUMMARY['async_tasks_run'] += 1
|
|
48
|
-
|
|
55
|
+
from ..event_loop import submit, is_loop_thread
|
|
56
|
+
if is_loop_thread():
|
|
57
|
+
# Already on the event-loop thread — can't block; return the
|
|
58
|
+
# coroutine so the caller can await it.
|
|
59
|
+
return obj
|
|
60
|
+
return submit(obj)
|
|
49
61
|
except RuntimeError:
|
|
50
62
|
return obj
|
|
51
63
|
return obj
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Zexus Shared Event Loop
|
|
3
|
+
|
|
4
|
+
Provides a single, persistent asyncio event loop running on a dedicated
|
|
5
|
+
background thread. Every async operation in the evaluator and VM submits
|
|
6
|
+
work to this loop instead of creating throw-away loops with asyncio.run().
|
|
7
|
+
|
|
8
|
+
Benefits:
|
|
9
|
+
- Tasks can communicate via shared state / asyncio primitives
|
|
10
|
+
- asyncio.gather, asyncio.wait, Semaphore, etc. all work correctly
|
|
11
|
+
- No overhead of creating + tearing down a loop per await
|
|
12
|
+
- True cooperative concurrency between Zexus async actions
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
from zexus.event_loop import get_event_loop, submit, spawn, shutdown
|
|
16
|
+
|
|
17
|
+
# Submit a coroutine and block for the result
|
|
18
|
+
result = submit(some_coro())
|
|
19
|
+
|
|
20
|
+
# Fire-and-forget
|
|
21
|
+
spawn(background_work())
|
|
22
|
+
|
|
23
|
+
# Graceful shutdown (called once at interpreter exit)
|
|
24
|
+
shutdown()
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import asyncio
|
|
30
|
+
import atexit
|
|
31
|
+
import threading
|
|
32
|
+
from concurrent.futures import Future as ConcurrentFuture
|
|
33
|
+
from typing import Any, Coroutine, Optional, TypeVar
|
|
34
|
+
|
|
35
|
+
T = TypeVar("T")
|
|
36
|
+
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
# Module-level singleton
|
|
39
|
+
# ---------------------------------------------------------------------------
|
|
40
|
+
_loop: Optional[asyncio.AbstractEventLoop] = None
|
|
41
|
+
_thread: Optional[threading.Thread] = None
|
|
42
|
+
_lock = threading.Lock()
|
|
43
|
+
_started = threading.Event()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _loop_thread_main() -> None:
|
|
47
|
+
"""Entry-point for the background thread that owns the event loop."""
|
|
48
|
+
global _loop
|
|
49
|
+
_loop = asyncio.new_event_loop()
|
|
50
|
+
asyncio.set_event_loop(_loop)
|
|
51
|
+
_started.set()
|
|
52
|
+
_loop.run_forever()
|
|
53
|
+
# After run_forever returns (shutdown was called) — clean up pending tasks
|
|
54
|
+
pending = asyncio.all_tasks(_loop)
|
|
55
|
+
if pending:
|
|
56
|
+
_loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
|
|
57
|
+
_loop.run_until_complete(_loop.shutdown_asyncgens())
|
|
58
|
+
_loop.close()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _ensure_loop() -> asyncio.AbstractEventLoop:
|
|
62
|
+
"""Start the background loop thread if it hasn't been started yet."""
|
|
63
|
+
global _thread
|
|
64
|
+
if _started.is_set() and _loop is not None and _loop.is_running():
|
|
65
|
+
return _loop
|
|
66
|
+
with _lock:
|
|
67
|
+
if _started.is_set() and _loop is not None and _loop.is_running():
|
|
68
|
+
return _loop
|
|
69
|
+
_thread = threading.Thread(
|
|
70
|
+
target=_loop_thread_main,
|
|
71
|
+
name="zexus-event-loop",
|
|
72
|
+
daemon=True,
|
|
73
|
+
)
|
|
74
|
+
_thread.start()
|
|
75
|
+
_started.wait() # block until the loop is actually running
|
|
76
|
+
assert _loop is not None
|
|
77
|
+
return _loop
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# ---------------------------------------------------------------------------
|
|
81
|
+
# Public API
|
|
82
|
+
# ---------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
def get_event_loop() -> asyncio.AbstractEventLoop:
|
|
85
|
+
"""Return the shared Zexus event loop (starting it lazily if needed)."""
|
|
86
|
+
return _ensure_loop()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def submit(coro: Coroutine[Any, Any, T], *, timeout: Optional[float] = None) -> T:
|
|
90
|
+
"""Submit *coro* to the shared loop and **block** until the result is ready.
|
|
91
|
+
|
|
92
|
+
This is safe to call from any non-event-loop thread (including the main
|
|
93
|
+
interpreter thread). If you call it from inside the event loop thread
|
|
94
|
+
you'll deadlock — use ``await`` directly in that case.
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
coro : coroutine
|
|
99
|
+
The coroutine to run.
|
|
100
|
+
timeout : float | None
|
|
101
|
+
Maximum seconds to wait. ``None`` = wait forever.
|
|
102
|
+
|
|
103
|
+
Returns
|
|
104
|
+
-------
|
|
105
|
+
The coroutine's return value.
|
|
106
|
+
|
|
107
|
+
Raises
|
|
108
|
+
------
|
|
109
|
+
Any exception the coroutine raises.
|
|
110
|
+
TimeoutError if *timeout* expires.
|
|
111
|
+
"""
|
|
112
|
+
loop = _ensure_loop()
|
|
113
|
+
future: ConcurrentFuture[T] = asyncio.run_coroutine_threadsafe(coro, loop)
|
|
114
|
+
return future.result(timeout=timeout)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def submit_async(coro: Coroutine[Any, Any, T]) -> ConcurrentFuture[T]:
|
|
118
|
+
"""Submit *coro* and return a :class:`concurrent.futures.Future`.
|
|
119
|
+
|
|
120
|
+
The caller can poll / wait on the future at their leisure.
|
|
121
|
+
"""
|
|
122
|
+
loop = _ensure_loop()
|
|
123
|
+
return asyncio.run_coroutine_threadsafe(coro, loop)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def spawn(coro: Coroutine[Any, Any, Any]) -> asyncio.Task:
|
|
127
|
+
"""Fire-and-forget: schedule *coro* as a task on the shared loop.
|
|
128
|
+
|
|
129
|
+
Returns the :class:`asyncio.Task` handle (which lives on the shared
|
|
130
|
+
loop's thread — do **not** await it from the main thread; use
|
|
131
|
+
:func:`submit` instead if you need the result).
|
|
132
|
+
"""
|
|
133
|
+
loop = _ensure_loop()
|
|
134
|
+
|
|
135
|
+
# asyncio.run_coroutine_threadsafe returns a Future, but we want the Task
|
|
136
|
+
# object so callers can cancel / inspect it. We wrap via call_soon_threadsafe.
|
|
137
|
+
task_holder: list[asyncio.Task] = []
|
|
138
|
+
ready = threading.Event()
|
|
139
|
+
|
|
140
|
+
def _create_task() -> None:
|
|
141
|
+
task = loop.create_task(coro)
|
|
142
|
+
task_holder.append(task)
|
|
143
|
+
ready.set()
|
|
144
|
+
|
|
145
|
+
loop.call_soon_threadsafe(_create_task)
|
|
146
|
+
ready.wait()
|
|
147
|
+
return task_holder[0]
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def call_soon(callback, *args) -> None:
|
|
151
|
+
"""Schedule a plain callback on the shared loop (thread-safe)."""
|
|
152
|
+
loop = _ensure_loop()
|
|
153
|
+
loop.call_soon_threadsafe(callback, *args)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def is_loop_thread() -> bool:
|
|
157
|
+
"""Return True if the caller is on the event-loop thread."""
|
|
158
|
+
return _thread is not None and threading.current_thread() is _thread
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def task_count() -> int:
|
|
162
|
+
"""Return the number of currently pending tasks on the shared loop."""
|
|
163
|
+
if _loop is None or not _loop.is_running():
|
|
164
|
+
return 0
|
|
165
|
+
return len(asyncio.all_tasks(_loop))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def shutdown(timeout: float = 5.0) -> None:
|
|
169
|
+
"""Stop the shared event loop and join the background thread.
|
|
170
|
+
|
|
171
|
+
Safe to call multiple times; subsequent calls are no-ops.
|
|
172
|
+
"""
|
|
173
|
+
global _loop, _thread
|
|
174
|
+
with _lock:
|
|
175
|
+
if _loop is not None and _loop.is_running():
|
|
176
|
+
_loop.call_soon_threadsafe(_loop.stop)
|
|
177
|
+
if _thread is not None and _thread.is_alive():
|
|
178
|
+
_thread.join(timeout=timeout)
|
|
179
|
+
_loop = None
|
|
180
|
+
_thread = None
|
|
181
|
+
_started.clear()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# Register shutdown at interpreter exit so the background thread doesn't
|
|
185
|
+
# prevent a clean exit.
|
|
186
|
+
atexit.register(shutdown)
|