zexus 1.6.8 → 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.
Files changed (177) hide show
  1. package/README.md +12 -5
  2. package/package.json +1 -1
  3. package/src/__init__.py +7 -0
  4. package/src/zexus/__init__.py +1 -1
  5. package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
  6. package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
  7. package/src/zexus/__pycache__/debug_sanitizer.cpython-312.pyc +0 -0
  8. package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
  9. package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
  10. package/src/zexus/__pycache__/input_validation.cpython-312.pyc +0 -0
  11. package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
  12. package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
  13. package/src/zexus/__pycache__/module_manager.cpython-312.pyc +0 -0
  14. package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
  15. package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
  16. package/src/zexus/__pycache__/security_enforcement.cpython-312.pyc +0 -0
  17. package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
  18. package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  19. package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
  20. package/src/zexus/access_control_system/__pycache__/__init__.cpython-312.pyc +0 -0
  21. package/src/zexus/access_control_system/__pycache__/access_control.cpython-312.pyc +0 -0
  22. package/src/zexus/advanced_types.py +17 -2
  23. package/src/zexus/blockchain/__init__.py +411 -0
  24. package/src/zexus/blockchain/accelerator.py +1160 -0
  25. package/src/zexus/blockchain/chain.py +660 -0
  26. package/src/zexus/blockchain/consensus.py +821 -0
  27. package/src/zexus/blockchain/contract_vm.py +1019 -0
  28. package/src/zexus/blockchain/crypto.py +79 -14
  29. package/src/zexus/blockchain/events.py +526 -0
  30. package/src/zexus/blockchain/loadtest.py +721 -0
  31. package/src/zexus/blockchain/monitoring.py +350 -0
  32. package/src/zexus/blockchain/mpt.py +716 -0
  33. package/src/zexus/blockchain/multichain.py +951 -0
  34. package/src/zexus/blockchain/multiprocess_executor.py +338 -0
  35. package/src/zexus/blockchain/network.py +886 -0
  36. package/src/zexus/blockchain/node.py +666 -0
  37. package/src/zexus/blockchain/rpc.py +1203 -0
  38. package/src/zexus/blockchain/rust_bridge.py +421 -0
  39. package/src/zexus/blockchain/storage.py +423 -0
  40. package/src/zexus/blockchain/tokens.py +750 -0
  41. package/src/zexus/blockchain/upgradeable.py +1004 -0
  42. package/src/zexus/blockchain/verification.py +1602 -0
  43. package/src/zexus/blockchain/wallet.py +621 -0
  44. package/src/zexus/capability_system.py +184 -9
  45. package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
  46. package/src/zexus/cli/main.py +383 -34
  47. package/src/zexus/cli/zpm.py +1 -1
  48. package/src/zexus/compiler/__pycache__/bytecode.cpython-312.pyc +0 -0
  49. package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
  50. package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
  51. package/src/zexus/compiler/__pycache__/semantic.cpython-312.pyc +0 -0
  52. package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  53. package/src/zexus/compiler/bytecode.py +124 -7
  54. package/src/zexus/compiler/compat_runtime.py +6 -2
  55. package/src/zexus/compiler/lexer.py +16 -5
  56. package/src/zexus/compiler/parser.py +108 -7
  57. package/src/zexus/compiler/semantic.py +18 -19
  58. package/src/zexus/compiler/zexus_ast.py +26 -1
  59. package/src/zexus/concurrency_system.py +79 -0
  60. package/src/zexus/config.py +54 -0
  61. package/src/zexus/crypto_bridge.py +244 -8
  62. package/src/zexus/dap/__init__.py +10 -0
  63. package/src/zexus/dap/__main__.py +4 -0
  64. package/src/zexus/dap/dap_server.py +391 -0
  65. package/src/zexus/dap/debug_engine.py +298 -0
  66. package/src/zexus/environment.py +112 -9
  67. package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
  68. package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
  69. package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
  70. package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
  71. package/src/zexus/evaluator/__pycache__/resource_limiter.cpython-312.pyc +0 -0
  72. package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
  73. package/src/zexus/evaluator/__pycache__/unified_execution.cpython-312.pyc +0 -0
  74. package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
  75. package/src/zexus/evaluator/bytecode_compiler.py +457 -37
  76. package/src/zexus/evaluator/core.py +644 -50
  77. package/src/zexus/evaluator/expressions.py +358 -62
  78. package/src/zexus/evaluator/functions.py +458 -20
  79. package/src/zexus/evaluator/resource_limiter.py +4 -4
  80. package/src/zexus/evaluator/statements.py +774 -122
  81. package/src/zexus/evaluator/unified_execution.py +573 -72
  82. package/src/zexus/evaluator/utils.py +14 -2
  83. package/src/zexus/evaluator_original.py +1 -1
  84. package/src/zexus/event_loop.py +186 -0
  85. package/src/zexus/lexer.py +742 -458
  86. package/src/zexus/lsp/__init__.py +1 -1
  87. package/src/zexus/lsp/definition_provider.py +163 -9
  88. package/src/zexus/lsp/server.py +22 -8
  89. package/src/zexus/lsp/symbol_provider.py +182 -9
  90. package/src/zexus/module_cache.py +239 -9
  91. package/src/zexus/module_manager.py +129 -1
  92. package/src/zexus/object.py +76 -6
  93. package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
  94. package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
  95. package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
  96. package/src/zexus/parser/parser.py +1349 -408
  97. package/src/zexus/parser/strategy_context.py +755 -58
  98. package/src/zexus/parser/strategy_structural.py +121 -21
  99. package/src/zexus/persistence.py +15 -1
  100. package/src/zexus/renderer/__init__.py +61 -0
  101. package/src/zexus/renderer/__pycache__/__init__.cpython-312.pyc +0 -0
  102. package/src/zexus/renderer/__pycache__/backend.cpython-312.pyc +0 -0
  103. package/src/zexus/renderer/__pycache__/canvas.cpython-312.pyc +0 -0
  104. package/src/zexus/renderer/__pycache__/color_system.cpython-312.pyc +0 -0
  105. package/src/zexus/renderer/__pycache__/layout.cpython-312.pyc +0 -0
  106. package/src/zexus/renderer/__pycache__/main_renderer.cpython-312.pyc +0 -0
  107. package/src/zexus/renderer/__pycache__/painter.cpython-312.pyc +0 -0
  108. package/src/zexus/renderer/backend.py +261 -0
  109. package/src/zexus/renderer/canvas.py +78 -0
  110. package/src/zexus/renderer/color_system.py +201 -0
  111. package/src/zexus/renderer/graphics.py +31 -0
  112. package/src/zexus/renderer/layout.py +222 -0
  113. package/src/zexus/renderer/main_renderer.py +66 -0
  114. package/src/zexus/renderer/painter.py +30 -0
  115. package/src/zexus/renderer/tk_backend.py +208 -0
  116. package/src/zexus/renderer/web_backend.py +260 -0
  117. package/src/zexus/runtime/__init__.py +10 -2
  118. package/src/zexus/runtime/__pycache__/__init__.cpython-312.pyc +0 -0
  119. package/src/zexus/runtime/__pycache__/async_runtime.cpython-312.pyc +0 -0
  120. package/src/zexus/runtime/__pycache__/load_manager.cpython-312.pyc +0 -0
  121. package/src/zexus/runtime/file_flags.py +137 -0
  122. package/src/zexus/runtime/load_manager.py +368 -0
  123. package/src/zexus/safety/__pycache__/__init__.cpython-312.pyc +0 -0
  124. package/src/zexus/safety/__pycache__/memory_safety.cpython-312.pyc +0 -0
  125. package/src/zexus/security.py +424 -34
  126. package/src/zexus/stdlib/fs.py +23 -18
  127. package/src/zexus/stdlib/http.py +289 -186
  128. package/src/zexus/stdlib/sockets.py +207 -163
  129. package/src/zexus/stdlib/websockets.py +282 -0
  130. package/src/zexus/stdlib_integration.py +369 -2
  131. package/src/zexus/strategy_recovery.py +6 -3
  132. package/src/zexus/type_checker.py +423 -0
  133. package/src/zexus/virtual_filesystem.py +189 -2
  134. package/src/zexus/vm/__init__.py +113 -3
  135. package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
  136. package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
  137. package/src/zexus/vm/__pycache__/bytecode_converter.cpython-312.pyc +0 -0
  138. package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
  139. package/src/zexus/vm/__pycache__/compiler.cpython-312.pyc +0 -0
  140. package/src/zexus/vm/__pycache__/gas_metering.cpython-312.pyc +0 -0
  141. package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
  142. package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
  143. package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
  144. package/src/zexus/vm/async_optimizer.py +80 -6
  145. package/src/zexus/vm/binary_bytecode.py +659 -0
  146. package/src/zexus/vm/bytecode.py +59 -11
  147. package/src/zexus/vm/bytecode_converter.py +26 -12
  148. package/src/zexus/vm/cabi.c +1985 -0
  149. package/src/zexus/vm/cabi.cpython-312-x86_64-linux-gnu.so +0 -0
  150. package/src/zexus/vm/cabi.h +127 -0
  151. package/src/zexus/vm/cache.py +561 -17
  152. package/src/zexus/vm/compiler.py +818 -51
  153. package/src/zexus/vm/fastops.c +15743 -0
  154. package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
  155. package/src/zexus/vm/fastops.pyx +288 -0
  156. package/src/zexus/vm/gas_metering.py +50 -9
  157. package/src/zexus/vm/jit.py +364 -20
  158. package/src/zexus/vm/native_jit_backend.py +1816 -0
  159. package/src/zexus/vm/native_runtime.cpp +1388 -0
  160. package/src/zexus/vm/native_runtime.cpython-312-x86_64-linux-gnu.so +0 -0
  161. package/src/zexus/vm/optimizer.py +161 -11
  162. package/src/zexus/vm/parallel_vm.py +140 -45
  163. package/src/zexus/vm/peephole_optimizer.py +82 -4
  164. package/src/zexus/vm/profiler.py +38 -18
  165. package/src/zexus/vm/register_allocator.py +16 -5
  166. package/src/zexus/vm/register_vm.py +8 -5
  167. package/src/zexus/vm/vm.py +3581 -531
  168. package/src/zexus/vm/wasm_compiler.py +658 -0
  169. package/src/zexus/zexus_ast.py +137 -11
  170. package/src/zexus/zexus_token.py +16 -5
  171. package/src/zexus/zpm/installer.py +55 -15
  172. package/src/zexus/zpm/package_manager.py +1 -1
  173. package/src/zexus/zpm/registry.py +257 -28
  174. package/src/zexus.egg-info/PKG-INFO +16 -6
  175. package/src/zexus.egg-info/SOURCES.txt +129 -17
  176. package/src/zexus.egg-info/entry_points.txt +1 -0
  177. package/src/zexus.egg-info/requires.txt +4 -0
@@ -1,8 +1,118 @@
1
1
  """
2
2
  Zexus Virtual Machine - Backend Execution Engine
3
+
4
+ This package provides a comprehensive VM system for Zexus with:
5
+ - Stack-based VM (standard execution)
6
+ - Register-based VM (optimized paths)
7
+ - Parallel VM (multi-core execution)
8
+ - JIT compilation (hot path native code)
9
+ - Peephole optimizer (bytecode optimization)
10
+ - Bytecode caching (persistent across runs)
11
+ - Memory pooling (efficient allocation)
12
+ - Gas metering (resource control)
3
13
  """
4
14
 
5
- from .vm import VM as ZexusVM
6
- from .bytecode import Bytecode
15
+ # Core VM
16
+ from .vm import VM as ZexusVM, VMMode
17
+ from .bytecode import Bytecode, Opcode, BytecodeBuilder
18
+
19
+ # Caching system (with file-based persistence)
20
+ from .cache import BytecodeCache, CacheStats, FileMetadata
21
+
22
+ # Compilers
23
+ from .compiler import BytecodeCompiler
24
+
25
+ # Optimizers
26
+ try:
27
+ from .optimizer import BytecodeOptimizer
28
+ OPTIMIZER_AVAILABLE = True
29
+ except ImportError:
30
+ BytecodeOptimizer = None
31
+ OPTIMIZER_AVAILABLE = False
32
+
33
+ try:
34
+ from .peephole_optimizer import PeepholeOptimizer, OptimizationLevel
35
+ PEEPHOLE_AVAILABLE = True
36
+ except ImportError:
37
+ PeepholeOptimizer = None
38
+ OptimizationLevel = None
39
+ PEEPHOLE_AVAILABLE = False
40
+
41
+ # JIT
42
+ try:
43
+ from .jit import JITCompiler, ExecutionTier
44
+ JIT_AVAILABLE = True
45
+ except ImportError:
46
+ JITCompiler = None
47
+ ExecutionTier = None
48
+ JIT_AVAILABLE = False
49
+
50
+ # Register VM
51
+ try:
52
+ from .register_vm import RegisterVM
53
+ REGISTER_VM_AVAILABLE = True
54
+ except ImportError:
55
+ RegisterVM = None
56
+ REGISTER_VM_AVAILABLE = False
57
+
58
+ # Parallel VM
59
+ try:
60
+ from .parallel_vm import ParallelVM, ExecutionMode
61
+ PARALLEL_VM_AVAILABLE = True
62
+ except ImportError:
63
+ ParallelVM = None
64
+ ExecutionMode = None
65
+ PARALLEL_VM_AVAILABLE = False
66
+
67
+ # Memory management
68
+ try:
69
+ from .memory_pool import IntegerPool, StringPool, ListPool
70
+ MEMORY_POOL_AVAILABLE = True
71
+ except ImportError:
72
+ IntegerPool = None
73
+ StringPool = None
74
+ ListPool = None
75
+ MEMORY_POOL_AVAILABLE = False
76
+
77
+ # Gas metering
78
+ try:
79
+ from .gas_metering import GasMetering, OutOfGasError
80
+ GAS_METERING_AVAILABLE = True
81
+ except ImportError:
82
+ GasMetering = None
83
+ OutOfGasError = None
84
+ GAS_METERING_AVAILABLE = False
85
+
86
+ # Profiler
87
+ try:
88
+ from .profiler import InstructionProfiler, ProfilingLevel
89
+ PROFILER_AVAILABLE = True
90
+ except ImportError:
91
+ InstructionProfiler = None
92
+ ProfilingLevel = None
93
+ PROFILER_AVAILABLE = False
7
94
 
8
- __all__ = ['ZexusVM', 'Bytecode']
95
+ __all__ = [
96
+ # Core
97
+ 'ZexusVM', 'VMMode', 'Bytecode', 'Opcode', 'BytecodeBuilder',
98
+ # Cache
99
+ 'BytecodeCache', 'CacheStats', 'FileMetadata',
100
+ # Compiler
101
+ 'BytecodeCompiler',
102
+ # Optimizers
103
+ 'BytecodeOptimizer', 'PeepholeOptimizer', 'OptimizationLevel',
104
+ # JIT
105
+ 'JITCompiler', 'ExecutionTier',
106
+ # Advanced VMs
107
+ 'RegisterVM', 'ParallelVM', 'ExecutionMode',
108
+ # Memory
109
+ 'IntegerPool', 'StringPool', 'ListPool',
110
+ # Gas
111
+ 'GasMetering', 'OutOfGasError',
112
+ # Profiler
113
+ 'InstructionProfiler', 'ProfilingLevel',
114
+ # Availability flags
115
+ 'OPTIMIZER_AVAILABLE', 'PEEPHOLE_AVAILABLE', 'JIT_AVAILABLE',
116
+ 'REGISTER_VM_AVAILABLE', 'PARALLEL_VM_AVAILABLE',
117
+ 'MEMORY_POOL_AVAILABLE', 'GAS_METERING_AVAILABLE', 'PROFILER_AVAILABLE',
118
+ ]
@@ -97,7 +97,7 @@ class FastFuture:
97
97
  """Make it awaitable - fast path, no event loop"""
98
98
  if self._exception:
99
99
  raise self._exception
100
- yield from [].__iter__() # Make it a generator
100
+ yield from ()
101
101
  return self._value
102
102
 
103
103
 
@@ -143,6 +143,10 @@ class CoroutinePool:
143
143
  Args:
144
144
  wrapper: Wrapper to release
145
145
  """
146
+ # Make sure underlying coroutine isn't left pending
147
+ if hasattr(wrapper, "_dispose_coroutine"):
148
+ wrapper._dispose_coroutine()
149
+
146
150
  if len(self.pool) < self.max_size:
147
151
  self.pool.append(wrapper)
148
152
 
@@ -169,15 +173,72 @@ class PooledCoroutineWrapper:
169
173
  return self._coro.send(value)
170
174
 
171
175
  def throw(self, typ, val=None, tb=None):
172
- """Forward throw"""
173
- return self._coro.throw(typ, val, tb)
176
+ """Forward throw while supporting modern coroutine semantics."""
177
+ coro_throw = getattr(self._coro, "throw", None)
178
+ if coro_throw is None:
179
+ raise AttributeError("Wrapped coroutine does not support throw()")
180
+
181
+ # Normalize exception according to modern coroutine API expectations
182
+ if tb is None and val is None:
183
+ return coro_throw(typ)
184
+
185
+ if tb is None and isinstance(typ, BaseException) and val is None:
186
+ return coro_throw(typ)
187
+
188
+ if isinstance(typ, BaseException):
189
+ exc = typ
190
+ if val is not None and val is not exc:
191
+ exc.args = exc.args or ()
192
+ exc.args += (val,)
193
+ elif isinstance(typ, type) and issubclass(typ, BaseException):
194
+ if isinstance(val, typ):
195
+ exc = val
196
+ elif val is None:
197
+ exc = typ()
198
+ else:
199
+ exc = typ(val)
200
+ else:
201
+ # Fall back to legacy behaviour for non-exception inputs
202
+ if tb is not None:
203
+ return coro_throw(typ, val, tb)
204
+ if val is not None:
205
+ return coro_throw(typ, val)
206
+ return coro_throw(typ)
207
+
208
+ if tb is not None and hasattr(exc, "with_traceback"):
209
+ exc = exc.with_traceback(tb)
210
+
211
+ return coro_throw(exc)
174
212
 
175
213
  def close(self):
176
214
  """Close and return to pool"""
215
+ self._dispose_coroutine()
216
+ self._pool.release_wrapper(self)
217
+
218
+ # Internal helpers -------------------------------------------------
219
+
220
+ def _dispose_coroutine(self):
221
+ coro = getattr(self, "_coro", None)
222
+ if coro is None:
223
+ return
224
+
177
225
  try:
178
- self._coro.close()
226
+ close = getattr(coro, "close", None)
227
+ if callable(close):
228
+ try:
229
+ close()
230
+ except RuntimeError:
231
+ # Coroutine already completed or running elsewhere
232
+ pass
179
233
  finally:
180
- self._pool.release_wrapper(self)
234
+ self._coro = None
235
+
236
+ def __del__(self):
237
+ try:
238
+ self._dispose_coroutine()
239
+ except Exception:
240
+ # Destructors must never raise
241
+ pass
181
242
 
182
243
 
183
244
  class BatchAwaitDetector:
@@ -267,9 +328,18 @@ class AsyncOptimizer:
267
328
 
268
329
  # Use pooling if enabled
269
330
  if self.coroutine_pool and self.level.value >= AsyncOptimizationLevel.BASIC.value:
270
- return self.coroutine_pool.get_wrapper(coro)
331
+ wrapper = self.coroutine_pool.get_wrapper(coro)
332
+ return self._wrap_pooled(wrapper)
271
333
 
272
334
  return coro
335
+
336
+ async def _wrap_pooled(self, wrapper: PooledCoroutineWrapper) -> Any:
337
+ """Ensure pooled wrappers are released after completion."""
338
+ try:
339
+ return await wrapper
340
+ finally:
341
+ if self.coroutine_pool:
342
+ self.coroutine_pool.release_wrapper(wrapper)
273
343
 
274
344
  async def await_optimized(self, awaitable: Any) -> Any:
275
345
  """
@@ -285,6 +355,10 @@ class AsyncOptimizer:
285
355
 
286
356
  # Fast path for already-resolved futures (MODERATE+)
287
357
  if self.level.value >= AsyncOptimizationLevel.MODERATE.value:
358
+ if not asyncio.isfuture(awaitable) and not asyncio.iscoroutine(awaitable) and not hasattr(awaitable, "__await__"):
359
+ self.stats.fast_path_hits += 1
360
+ self.stats.event_loop_skips += 1
361
+ return awaitable
288
362
  if isinstance(awaitable, FastFuture):
289
363
  self.stats.fast_path_hits += 1
290
364
  self.stats.event_loop_skips += 1