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.
Files changed (159) hide show
  1. package/README.md +3 -3
  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/cli/__pycache__/main.cpython-312.pyc +0 -0
  45. package/src/zexus/cli/main.py +300 -20
  46. package/src/zexus/cli/zpm.py +1 -1
  47. package/src/zexus/compiler/__pycache__/bytecode.cpython-312.pyc +0 -0
  48. package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
  49. package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
  50. package/src/zexus/compiler/__pycache__/semantic.cpython-312.pyc +0 -0
  51. package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  52. package/src/zexus/compiler/lexer.py +10 -5
  53. package/src/zexus/concurrency_system.py +79 -0
  54. package/src/zexus/config.py +54 -0
  55. package/src/zexus/crypto_bridge.py +244 -8
  56. package/src/zexus/dap/__init__.py +10 -0
  57. package/src/zexus/dap/__main__.py +4 -0
  58. package/src/zexus/dap/dap_server.py +391 -0
  59. package/src/zexus/dap/debug_engine.py +298 -0
  60. package/src/zexus/environment.py +10 -1
  61. package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
  62. package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
  63. package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
  64. package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
  65. package/src/zexus/evaluator/__pycache__/resource_limiter.cpython-312.pyc +0 -0
  66. package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
  67. package/src/zexus/evaluator/__pycache__/unified_execution.cpython-312.pyc +0 -0
  68. package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
  69. package/src/zexus/evaluator/bytecode_compiler.py +441 -37
  70. package/src/zexus/evaluator/core.py +560 -49
  71. package/src/zexus/evaluator/expressions.py +122 -49
  72. package/src/zexus/evaluator/functions.py +417 -16
  73. package/src/zexus/evaluator/statements.py +521 -118
  74. package/src/zexus/evaluator/unified_execution.py +573 -72
  75. package/src/zexus/evaluator/utils.py +14 -2
  76. package/src/zexus/event_loop.py +186 -0
  77. package/src/zexus/lexer.py +742 -486
  78. package/src/zexus/lsp/__init__.py +1 -1
  79. package/src/zexus/lsp/definition_provider.py +163 -9
  80. package/src/zexus/lsp/server.py +22 -8
  81. package/src/zexus/lsp/symbol_provider.py +182 -9
  82. package/src/zexus/module_cache.py +237 -9
  83. package/src/zexus/object.py +64 -6
  84. package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
  85. package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
  86. package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
  87. package/src/zexus/parser/parser.py +786 -285
  88. package/src/zexus/parser/strategy_context.py +407 -66
  89. package/src/zexus/parser/strategy_structural.py +117 -19
  90. package/src/zexus/persistence.py +15 -1
  91. package/src/zexus/renderer/__init__.py +15 -0
  92. package/src/zexus/renderer/__pycache__/__init__.cpython-312.pyc +0 -0
  93. package/src/zexus/renderer/__pycache__/backend.cpython-312.pyc +0 -0
  94. package/src/zexus/renderer/__pycache__/canvas.cpython-312.pyc +0 -0
  95. package/src/zexus/renderer/__pycache__/color_system.cpython-312.pyc +0 -0
  96. package/src/zexus/renderer/__pycache__/layout.cpython-312.pyc +0 -0
  97. package/src/zexus/renderer/__pycache__/main_renderer.cpython-312.pyc +0 -0
  98. package/src/zexus/renderer/__pycache__/painter.cpython-312.pyc +0 -0
  99. package/src/zexus/renderer/tk_backend.py +208 -0
  100. package/src/zexus/renderer/web_backend.py +260 -0
  101. package/src/zexus/runtime/__pycache__/__init__.cpython-312.pyc +0 -0
  102. package/src/zexus/runtime/__pycache__/async_runtime.cpython-312.pyc +0 -0
  103. package/src/zexus/runtime/__pycache__/load_manager.cpython-312.pyc +0 -0
  104. package/src/zexus/runtime/file_flags.py +137 -0
  105. package/src/zexus/safety/__pycache__/__init__.cpython-312.pyc +0 -0
  106. package/src/zexus/safety/__pycache__/memory_safety.cpython-312.pyc +0 -0
  107. package/src/zexus/security.py +424 -34
  108. package/src/zexus/stdlib/fs.py +23 -18
  109. package/src/zexus/stdlib/http.py +289 -186
  110. package/src/zexus/stdlib/sockets.py +207 -163
  111. package/src/zexus/stdlib/websockets.py +282 -0
  112. package/src/zexus/stdlib_integration.py +369 -2
  113. package/src/zexus/strategy_recovery.py +6 -3
  114. package/src/zexus/type_checker.py +423 -0
  115. package/src/zexus/virtual_filesystem.py +189 -2
  116. package/src/zexus/vm/__init__.py +113 -3
  117. package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
  118. package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
  119. package/src/zexus/vm/__pycache__/bytecode_converter.cpython-312.pyc +0 -0
  120. package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
  121. package/src/zexus/vm/__pycache__/compiler.cpython-312.pyc +0 -0
  122. package/src/zexus/vm/__pycache__/gas_metering.cpython-312.pyc +0 -0
  123. package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
  124. package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
  125. package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
  126. package/src/zexus/vm/async_optimizer.py +14 -1
  127. package/src/zexus/vm/binary_bytecode.py +659 -0
  128. package/src/zexus/vm/bytecode.py +28 -1
  129. package/src/zexus/vm/bytecode_converter.py +26 -12
  130. package/src/zexus/vm/cabi.c +1985 -0
  131. package/src/zexus/vm/cabi.cpython-312-x86_64-linux-gnu.so +0 -0
  132. package/src/zexus/vm/cabi.h +127 -0
  133. package/src/zexus/vm/cache.py +557 -17
  134. package/src/zexus/vm/compiler.py +703 -5
  135. package/src/zexus/vm/fastops.c +15743 -0
  136. package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
  137. package/src/zexus/vm/fastops.pyx +288 -0
  138. package/src/zexus/vm/gas_metering.py +50 -9
  139. package/src/zexus/vm/jit.py +83 -2
  140. package/src/zexus/vm/native_jit_backend.py +1816 -0
  141. package/src/zexus/vm/native_runtime.cpp +1388 -0
  142. package/src/zexus/vm/native_runtime.cpython-312-x86_64-linux-gnu.so +0 -0
  143. package/src/zexus/vm/optimizer.py +161 -11
  144. package/src/zexus/vm/parallel_vm.py +118 -42
  145. package/src/zexus/vm/peephole_optimizer.py +82 -4
  146. package/src/zexus/vm/profiler.py +38 -18
  147. package/src/zexus/vm/register_allocator.py +16 -5
  148. package/src/zexus/vm/register_vm.py +8 -5
  149. package/src/zexus/vm/vm.py +3411 -573
  150. package/src/zexus/vm/wasm_compiler.py +658 -0
  151. package/src/zexus/zexus_ast.py +63 -11
  152. package/src/zexus/zexus_token.py +13 -5
  153. package/src/zexus/zpm/installer.py +55 -15
  154. package/src/zexus/zpm/package_manager.py +1 -1
  155. package/src/zexus/zpm/registry.py +257 -28
  156. package/src/zexus.egg-info/PKG-INFO +7 -4
  157. package/src/zexus.egg-info/SOURCES.txt +116 -9
  158. package/src/zexus.egg-info/entry_points.txt +1 -0
  159. package/src/zexus.egg-info/requires.txt +4 -0
@@ -40,6 +40,8 @@ class InstructionStats:
40
40
 
41
41
  # Timing samples (for percentile calculation)
42
42
  timing_samples: List[float] = field(default_factory=list)
43
+ max_samples: int = 2048
44
+ sample_index: int = 0
43
45
 
44
46
  # Memory tracking
45
47
  memory_reads: int = 0
@@ -57,16 +59,12 @@ class InstructionStats:
57
59
  self.total_time += execution_time
58
60
  self.min_time = min(self.min_time, execution_time)
59
61
  self.max_time = max(self.max_time, execution_time)
60
- self.timing_samples.append(execution_time)
61
-
62
- # Keep sample size manageable (max 10000 samples)
63
- if len(self.timing_samples) > 10000:
64
- # Keep percentiles and random samples
65
- self.timing_samples = sorted(self.timing_samples)
66
- keep = [self.timing_samples[i] for i in
67
- [0, len(self.timing_samples)//4, len(self.timing_samples)//2,
68
- 3*len(self.timing_samples)//4, -1]]
69
- self.timing_samples = keep
62
+ if self.max_samples > 0:
63
+ if len(self.timing_samples) < self.max_samples:
64
+ self.timing_samples.append(execution_time)
65
+ else:
66
+ self.timing_samples[self.sample_index] = execution_time
67
+ self.sample_index = (self.sample_index + 1) % self.max_samples
70
68
 
71
69
  def avg_time(self) -> float:
72
70
  """Average execution time"""
@@ -139,9 +137,19 @@ class InstructionProfiler:
139
137
  Tracks execution statistics at instruction level with minimal overhead.
140
138
  """
141
139
 
142
- def __init__(self, level: ProfilingLevel = ProfilingLevel.DETAILED):
140
+ def __init__(
141
+ self,
142
+ level: ProfilingLevel = ProfilingLevel.DETAILED,
143
+ sample_rate: float = 1.0,
144
+ max_samples: int = 2048,
145
+ track_overhead: bool = False
146
+ ):
143
147
  self.level = level
144
148
  self.enabled = level != ProfilingLevel.NONE
149
+ self.sample_rate = max(0.0, min(1.0, float(sample_rate)))
150
+ self.max_samples = max(0, int(max_samples))
151
+ self.track_overhead = bool(track_overhead)
152
+ self._sample_every = int(1 / self.sample_rate) if 0 < self.sample_rate < 1.0 else 1
145
153
 
146
154
  # Per-instruction statistics (keyed by instruction pointer)
147
155
  self.stats: Dict[int, InstructionStats] = {}
@@ -213,8 +221,10 @@ class InstructionProfiler:
213
221
  """
214
222
  if not self.enabled:
215
223
  return
216
-
217
- overhead_start = time.perf_counter()
224
+
225
+ overhead_start = time.perf_counter() if self.track_overhead else None
226
+ if self.start_time is None:
227
+ self.start_time = time.perf_counter()
218
228
 
219
229
  # Update counters
220
230
  self.total_instructions += 1
@@ -222,7 +232,12 @@ class InstructionProfiler:
222
232
 
223
233
  # Get or create stats for this instruction
224
234
  if ip not in self.stats:
225
- self.stats[ip] = InstructionStats(opcode=opcode, operand=operand, ip=ip)
235
+ self.stats[ip] = InstructionStats(
236
+ opcode=opcode,
237
+ operand=operand,
238
+ ip=ip,
239
+ max_samples=self.max_samples
240
+ )
226
241
 
227
242
  stat = self.stats[ip]
228
243
 
@@ -271,7 +286,8 @@ class InstructionProfiler:
271
286
  stat.branch_not_taken += 1
272
287
 
273
288
  # Minimal overhead tracking for non-FULL levels
274
- self.profiling_overhead += (time.perf_counter() - overhead_start)
289
+ if self.track_overhead and overhead_start is not None:
290
+ self.profiling_overhead += (time.perf_counter() - overhead_start)
275
291
 
276
292
  def measure_instruction(self, ip: int, execution_time: float):
277
293
  """
@@ -283,12 +299,16 @@ class InstructionProfiler:
283
299
  """
284
300
  if not self.enabled or self.level == ProfilingLevel.BASIC:
285
301
  return
286
-
302
+
303
+ if self._sample_every > 1 and (self.total_instructions % self._sample_every) != 0:
304
+ return
305
+
287
306
  if ip in self.stats:
288
- overhead_start = time.perf_counter()
307
+ overhead_start = time.perf_counter() if self.track_overhead else None
289
308
  # Don't increment count - that was already done by record_instruction
290
309
  self.stats[ip].record_execution(execution_time, increment_count=False)
291
- self.profiling_overhead += (time.perf_counter() - overhead_start)
310
+ if self.track_overhead and overhead_start is not None:
311
+ self.profiling_overhead += (time.perf_counter() - overhead_start)
292
312
 
293
313
  def get_hottest_instructions(self, top_n: int = 10) -> List[InstructionStats]:
294
314
  """Get top N hottest instructions by execution count"""
@@ -157,7 +157,8 @@ class RegisterAllocator:
157
157
  # Color the graph
158
158
  allocation, spilled = self._color_graph(
159
159
  interference_graph,
160
- self.available_registers
160
+ self.available_registers,
161
+ live_ranges
161
162
  )
162
163
 
163
164
  return AllocationResult(
@@ -295,7 +296,8 @@ class RegisterAllocator:
295
296
  def _color_graph(
296
297
  self,
297
298
  graph: InterferenceGraph,
298
- available_colors: Set[int]
299
+ available_colors: Set[int],
300
+ live_ranges: Optional[Dict[str, LiveRange]] = None
299
301
  ) -> Tuple[Dict[str, int], Set[str]]:
300
302
  """
301
303
  Color the interference graph using graph coloring algorithm
@@ -328,11 +330,20 @@ class RegisterAllocator:
328
330
  stack.append((low_degree_node, remaining_graph.neighbors(low_degree_node).copy()))
329
331
  remaining_graph.remove_node(low_degree_node)
330
332
  else:
331
- # Need to spill - choose node with highest degree
333
+ # Need to spill - choose lowest-cost node
332
334
  if not remaining_graph.nodes:
333
335
  break
334
-
335
- spill_node = max(remaining_graph.nodes, key=lambda n: remaining_graph.degree(n))
336
+
337
+ def spill_cost(var: str) -> float:
338
+ degree = max(1, remaining_graph.degree(var))
339
+ if live_ranges and var in live_ranges:
340
+ lr = live_ranges[var]
341
+ uses = len(lr.uses) + len(lr.defs)
342
+ span = max(1, lr.end - lr.start)
343
+ return (uses / span) / degree
344
+ return 1.0 / degree
345
+
346
+ spill_node = min(remaining_graph.nodes, key=spill_cost)
336
347
  stack.append((spill_node, remaining_graph.neighbors(spill_node).copy()))
337
348
  remaining_graph.remove_node(spill_node)
338
349
  spilled.add(spill_node)
@@ -283,18 +283,21 @@ class RegisterVM:
283
283
 
284
284
  # Execute instruction stream
285
285
  pc = 0 # Program counter
286
+ reg_exec = self._execute_register_instruction
287
+ stack_exec = self._execute_stack_instruction
288
+ reg_ops = set(RegisterOpcode.__members__.values())
286
289
  while pc < len(instructions):
287
290
  inst = instructions[pc]
288
291
  opcode = inst[0] if isinstance(inst, tuple) else inst
289
-
292
+
290
293
  # Dispatch to handler
291
- if opcode in RegisterOpcode.__members__.values():
292
- pc = self._execute_register_instruction(inst, pc)
294
+ if opcode in reg_ops:
295
+ pc = reg_exec(inst, pc)
293
296
  elif self.hybrid_mode:
294
- pc = self._execute_stack_instruction(inst, pc)
297
+ pc = stack_exec(inst, pc)
295
298
  else:
296
299
  raise ValueError(f"Stack opcode {opcode} in register-only mode")
297
-
300
+
298
301
  self.stats['instructions_executed'] += 1
299
302
  pc += 1
300
303