zexus 1.8.1 → 1.8.3

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 (46) hide show
  1. package/README.md +89 -64
  2. package/bin/zexus +12 -2
  3. package/bin/zpics +12 -2
  4. package/bin/zpm +12 -2
  5. package/bin/zx +12 -2
  6. package/bin/zx-deploy +12 -2
  7. package/bin/zx-dev +12 -2
  8. package/bin/zx-run +12 -2
  9. package/package.json +1 -1
  10. package/rust_core/Cargo.lock +1 -1
  11. package/scripts/postinstall.js +192 -41
  12. package/src/zexus/__init__.py +1 -1
  13. package/src/zexus/builtin_modules.py +50 -13
  14. package/src/zexus/cli/main.py +46 -1
  15. package/src/zexus/cli/zpm.py +1 -1
  16. package/src/zexus/evaluator/bytecode_compiler.py +11 -2
  17. package/src/zexus/evaluator/core.py +4 -1
  18. package/src/zexus/evaluator/expressions.py +11 -2
  19. package/src/zexus/evaluator/functions.py +72 -0
  20. package/src/zexus/evaluator/resource_limiter.py +1 -1
  21. package/src/zexus/evaluator/statements.py +44 -4
  22. package/src/zexus/kernel/__init__.py +34 -0
  23. package/src/zexus/kernel/hooks.py +276 -0
  24. package/src/zexus/kernel/registry.py +203 -0
  25. package/src/zexus/kernel/zir/__init__.py +145 -0
  26. package/src/zexus/lexer.py +7 -0
  27. package/src/zexus/object.py +28 -5
  28. package/src/zexus/parser/parser.py +87 -20
  29. package/src/zexus/parser/strategy_context.py +270 -12
  30. package/src/zexus/security.py +26 -2
  31. package/src/zexus/stdlib/blockchain.py +84 -0
  32. package/src/zexus/stdlib/http_server.py +2 -2
  33. package/src/zexus/stdlib/math.py +25 -17
  34. package/src/zexus/stdlib_integration.py +119 -2
  35. package/src/zexus/type_checker.py +17 -12
  36. package/src/zexus/vm/compiler.py +521 -49
  37. package/src/zexus/vm/fastops.c +4704 -1263
  38. package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
  39. package/src/zexus/vm/fastops.pyx +81 -3
  40. package/src/zexus/vm/optimizer.py +65 -27
  41. package/src/zexus/vm/vm.py +1120 -130
  42. package/src/zexus/zexus_ast.py +4 -1
  43. package/src/zexus/zpm/package_manager.py +1 -1
  44. package/src/zexus.egg-info/PKG-INFO +90 -65
  45. package/src/zexus.egg-info/SOURCES.txt +60 -0
  46. package/src/zexus.egg-info/entry_points.txt +8 -0
@@ -121,28 +121,65 @@ def create_builtin_modules(evaluator):
121
121
  def _crypto_aes_encrypt(*args):
122
122
  if len(args) != 2:
123
123
  return EvaluationError("aes_encrypt() expects 2 arguments: data, key")
124
- # Simplified AES - would need proper implementation
125
124
  data = args[0].value if hasattr(args[0], 'value') else str(args[0])
126
125
  key = args[1].value if hasattr(args[1], 'value') else str(args[1])
127
- # For now, return a mock encrypted value (TODO: implement proper AES)
128
- import base64
129
- encoded = base64.b64encode(data.encode()).decode()
130
- return String(f"aes_encrypted:{encoded}")
126
+ try:
127
+ import hashlib, base64, os
128
+ # Derive 256-bit key from user key via SHA-256
129
+ aes_key = hashlib.sha256(key.encode('utf-8')).digest()
130
+ # Use AES-256-GCM for authenticated encryption
131
+ from Crypto.Cipher import AES as _AES
132
+ nonce = os.urandom(12)
133
+ cipher = _AES.new(aes_key, _AES.MODE_GCM, nonce=nonce)
134
+ ciphertext, tag = cipher.encrypt_and_digest(data.encode('utf-8'))
135
+ # Pack: nonce (12) + tag (16) + ciphertext, base64-encoded
136
+ packed = base64.b64encode(nonce + tag + ciphertext).decode('ascii')
137
+ return String(packed)
138
+ except ImportError:
139
+ # Fallback: if pycryptodome not available, use Fernet from cryptography
140
+ try:
141
+ import hashlib, base64
142
+ from cryptography.fernet import Fernet as _Fernet
143
+ fernet_key = base64.urlsafe_b64encode(hashlib.sha256(key.encode('utf-8')).digest())
144
+ f = _Fernet(fernet_key)
145
+ encrypted = f.encrypt(data.encode('utf-8'))
146
+ return String(encrypted.decode('ascii'))
147
+ except ImportError:
148
+ return EvaluationError("aes_encrypt() requires pycryptodome or cryptography package")
149
+ except Exception as e:
150
+ return EvaluationError(f"aes_encrypt() failed: {str(e)}")
131
151
 
132
152
  # aes_decrypt(encrypted_data, key)
133
153
  def _crypto_aes_decrypt(*args):
134
154
  if len(args) != 2:
135
155
  return EvaluationError("aes_decrypt() expects 2 arguments: encrypted_data, key")
136
- # Simplified AES - would need proper implementation
137
156
  encrypted = args[0].value if hasattr(args[0], 'value') else str(args[0])
138
157
  key = args[1].value if hasattr(args[1], 'value') else str(args[1])
139
- # For now, decode the mock encryption (TODO: implement proper AES)
140
- import base64
141
- if encrypted.startswith("aes_encrypted:"):
142
- encoded = encrypted.split(":", 1)[1]
143
- decoded = base64.b64decode(encoded).decode()
144
- return String(decoded)
145
- return String(encrypted)
158
+ try:
159
+ import hashlib, base64
160
+ aes_key = hashlib.sha256(key.encode('utf-8')).digest()
161
+ raw = base64.b64decode(encrypted)
162
+ if len(raw) < 28: # 12 nonce + 16 tag minimum
163
+ return EvaluationError("aes_decrypt() invalid ciphertext (too short)")
164
+ nonce = raw[:12]
165
+ tag = raw[12:28]
166
+ ciphertext = raw[28:]
167
+ from Crypto.Cipher import AES as _AES
168
+ cipher = _AES.new(aes_key, _AES.MODE_GCM, nonce=nonce)
169
+ plaintext = cipher.decrypt_and_verify(ciphertext, tag)
170
+ return String(plaintext.decode('utf-8'))
171
+ except ImportError:
172
+ try:
173
+ import hashlib, base64
174
+ from cryptography.fernet import Fernet as _Fernet
175
+ fernet_key = base64.urlsafe_b64encode(hashlib.sha256(key.encode('utf-8')).digest())
176
+ f = _Fernet(fernet_key)
177
+ decrypted = f.decrypt(encrypted.encode('ascii'))
178
+ return String(decrypted.decode('utf-8'))
179
+ except ImportError:
180
+ return EvaluationError("aes_decrypt() requires pycryptodome or cryptography package")
181
+ except Exception as e:
182
+ return EvaluationError(f"aes_decrypt() failed: {str(e)}")
146
183
 
147
184
  # Register all crypto functions
148
185
  crypto_env.set("keccak256", Builtin(_crypto_keccak256, "keccak256"))
@@ -81,6 +81,15 @@ from ..error_reporter import get_error_reporter, ZexusError, print_error
81
81
  from ..vm.vm import VM, VMMode
82
82
  from ..vm.compiler import compile_ast_to_bytecode, UnsupportedNodeError
83
83
 
84
+ # Kernel extension layer (opt-in, non-breaking)
85
+ try:
86
+ from ..kernel import get_kernel as _get_kernel
87
+ _kernel = _get_kernel().boot()
88
+ KERNEL_AVAILABLE = True
89
+ except Exception:
90
+ _kernel = None
91
+ KERNEL_AVAILABLE = False
92
+
84
93
  console = Console()
85
94
 
86
95
  def show_all_commands():
@@ -156,7 +165,7 @@ def show_all_commands():
156
165
  console.print("\n[bold green]💡 Tip:[/bold green] Use 'zx <command> --help' for detailed command options\n")
157
166
 
158
167
  @click.group(invoke_without_command=True)
159
- @click.version_option(version="1.8.1", prog_name="Zexus")
168
+ @click.version_option(version="1.8.3", prog_name="Zexus")
160
169
  @click.option('--syntax-style', type=click.Choice(['universal', 'tolerable', 'auto']),
161
170
  default='auto', help='Syntax style to use (universal=strict, tolerable=flexible)')
162
171
  @click.option('--advanced-parsing', is_flag=True, default=True,
@@ -556,6 +565,14 @@ def run(ctx, file, args, use_vm, vm_mode, no_optimize, precompile_modules):
556
565
  vm.env["__PACKAGE__"] = package_name.value if hasattr(package_name, "value") else package_name
557
566
  console.print(" [green]done[/green]")
558
567
 
568
+ # --- Rust VM status indicator ---
569
+ if getattr(vm, '_rust_vm_available', False) and getattr(vm, '_rust_vm_enabled', False):
570
+ console.print("[bold cyan]⚡ Rust VM:[/bold cyan] [green]active[/green] — native acceleration enabled")
571
+ elif getattr(vm, '_rust_vm_available', False):
572
+ console.print("[bold cyan]⚡ Rust VM:[/bold cyan] [yellow]available but disabled[/yellow]")
573
+ else:
574
+ console.print("[bold yellow]⚠️ Rust VM:[/bold yellow] [dim]not compiled — using Python VM (install zexus_core for native speed)[/dim]")
575
+
559
576
  console.print("[dim]Executing on VM...[/dim]")
560
577
  try:
561
578
  result = vm.execute(bytecode, debug=ctx.obj.get('DEBUG', False))
@@ -1105,5 +1122,33 @@ def profile(ctx, file, memory, top, json_output):
1105
1122
  traceback.print_exc()
1106
1123
  sys.exit(1)
1107
1124
 
1125
+
1126
+ @cli.command(name="kernel")
1127
+ @click.pass_context
1128
+ def kernel_status(ctx):
1129
+ """Show Zexus kernel status and registered domains"""
1130
+ if not KERNEL_AVAILABLE or _kernel is None:
1131
+ console.print("[yellow]Kernel not available[/yellow]")
1132
+ sys.exit(1)
1133
+
1134
+ status = _kernel.status()
1135
+ console.print("\n[bold cyan]⚙️ Zexus Kernel Status[/bold cyan]\n")
1136
+ console.print(f" Booted: [green]{status['booted']}[/green]")
1137
+ console.print(f" Domains: [green]{status['domain_count']}[/green]")
1138
+ console.print(f" Opcodes: [green]{status['opcode_handlers']}[/green] handlers")
1139
+ console.print(f" Middleware: [green]{status['middleware']}[/green]\n")
1140
+
1141
+ if status['domains']:
1142
+ table = Table(show_header=True, header_style="bold magenta")
1143
+ table.add_column("Domain", style="cyan")
1144
+ table.add_column("Version", style="white")
1145
+ table.add_column("Status", style="green")
1146
+ for name, version in status['domains'].items():
1147
+ domain = _kernel.registry.get_domain(name)
1148
+ n_ops = len(domain.opcodes) if domain else 0
1149
+ table.add_row(name, version, f"{n_ops} opcodes")
1150
+ console.print(table)
1151
+
1152
+
1108
1153
  if __name__ == "__main__":
1109
1154
  cli()
@@ -18,7 +18,7 @@ console = Console()
18
18
 
19
19
 
20
20
  @click.group()
21
- @click.version_option(version="1.8.1", prog_name="ZPM")
21
+ @click.version_option(version="1.8.3", prog_name="ZPM")
22
22
  def cli():
23
23
  """ZPM - Zexus Package Manager
24
24
 
@@ -813,12 +813,21 @@ class EvaluatorBytecodeCompiler:
813
813
 
814
814
  def _compile_MapLiteral(self, node: zexus_ast.MapLiteral):
815
815
  """Compile map/dictionary literal"""
816
+ # node.pairs may be a dict (older parser) or a list of (key, value) tuples
817
+ pairs = node.pairs or []
818
+ if isinstance(pairs, dict):
819
+ iterable = pairs.items()
820
+ count = len(pairs)
821
+ else:
822
+ iterable = pairs
823
+ count = len(pairs)
824
+
816
825
  # Push key-value pairs
817
- for key_expr, value_expr in node.pairs:
826
+ for key_expr, value_expr in iterable:
818
827
  self._compile_node(key_expr)
819
828
  self._compile_node(value_expr)
820
829
  # Build map from stack
821
- self.builder.emit("BUILD_MAP", len(node.pairs))
830
+ self.builder.emit("BUILD_MAP", count)
822
831
 
823
832
  # LI12: _compile_PropertyAccessExpression is defined later in this file.
824
833
  # The earlier duplicate implementation was dead code (overridden).
@@ -494,7 +494,10 @@ class Evaluator(ExpressionEvaluatorMixin, StatementEvaluatorMixin, FunctionEvalu
494
494
  enable_gas_metering=True,
495
495
  gas_limit=1_000_000 # Default 1M gas limit
496
496
  )
497
- debug_log("Evaluator", "VM integration initialized successfully (cache + JIT + gas metering)")
497
+ # Report Rust VM status
498
+ rust_active = getattr(self.vm_instance, '_rust_vm_available', False) and getattr(self.vm_instance, '_rust_vm_enabled', False)
499
+ rust_label = "Rust VM active" if rust_active else "Python VM"
500
+ debug_log("Evaluator", f"VM integration initialized successfully (cache + JIT + gas metering, {rust_label})")
498
501
  except Exception as e:
499
502
  debug_log("Evaluator", f"Failed to initialize VM: {e}")
500
503
  self.use_vm = False
@@ -89,8 +89,9 @@ class ExpressionEvaluatorMixin:
89
89
  if zexus_config.fast_debug_enabled:
90
90
  debug_log("eval_identifier", f"Looking up: {name}")
91
91
 
92
- # Special case: 'this' keyword should be treated like ThisExpression
93
- if name == "this":
92
+ # Special case: 'this' and 'self' keywords should be treated like ThisExpression
93
+ # R-003 fix: 'self' is now recognized as an alias for 'this'
94
+ if name == "this" or name == "self":
94
95
  # Look for contract instance first
95
96
  contract_instance = env.get("__contract_instance__")
96
97
  if contract_instance is not None:
@@ -279,6 +280,11 @@ class ExpressionEvaluatorMixin:
279
280
  return Float(left_val ** right_val)
280
281
  except (OverflowError, ValueError) as e:
281
282
  return EvaluationError(f"Exponentiation error: {e}")
283
+ # R-017 fix: Add modulo support for floats
284
+ elif operator == "%":
285
+ if right_val == 0:
286
+ return EvaluationError("Modulo by zero")
287
+ return Float(left_val % right_val)
282
288
 
283
289
  return EvaluationError(f"Unknown float operator: {operator}")
284
290
 
@@ -388,6 +394,9 @@ class ExpressionEvaluatorMixin:
388
394
  f"String repetition count {n} exceeds maximum ({_MAX_STRING_REPEAT})"
389
395
  )
390
396
  return String(right.value * n)
397
+ # R-016 fix: Handle mixed Integer/Float multiplication
398
+ elif isinstance(left, (Integer, Float)) and isinstance(right, (Integer, Float)):
399
+ return Float(float(left.value) * float(right.value))
391
400
 
392
401
  # Array Concatenation
393
402
  elif operator == "+" and isinstance(left, List) and isinstance(right, List):
@@ -348,6 +348,32 @@ class FunctionEvaluatorMixin:
348
348
  # Synchronous function execution
349
349
  new_env = Environment(outer=fn.env)
350
350
 
351
+ # R-008 fix: Enforce protection policies for module-level actions.
352
+ # When ``action protect`` is used at module level, the policy is
353
+ # stored in the environment as ``__policy_<name>__``. Check and
354
+ # enforce it before the action body runs.
355
+ _fn_name = getattr(fn, 'name', func_name)
356
+ if _fn_name and env is not None:
357
+ _policy_key = f"__policy_{_fn_name}__"
358
+ _policy = None
359
+ try:
360
+ _policy = env.get(_policy_key) if hasattr(env, 'get') else None
361
+ except Exception:
362
+ pass
363
+ if _policy is not None and _policy is not NULL:
364
+ try:
365
+ from ..policy_engine import get_policy_registry
366
+ registry = get_policy_registry()
367
+ violation = registry.check_policy(_fn_name, {
368
+ "args": args,
369
+ "env": env,
370
+ "caller": env.get("TX.caller") if hasattr(env, 'get') else None,
371
+ })
372
+ if violation:
373
+ return EvaluationError(f"Policy violation on '{_fn_name}': {violation}")
374
+ except (ImportError, AttributeError):
375
+ pass
376
+
351
377
  param_names = []
352
378
  for i, param in enumerate(fn.parameters):
353
379
  if i < len(args):
@@ -2512,6 +2538,47 @@ class FunctionEvaluatorMixin:
2512
2538
  return EvaluationError("filter(arr, fn)")
2513
2539
  return self._array_filter(a[0], a[1])
2514
2540
 
2541
+ def _range(*a):
2542
+ """range(end) or range(start, end) or range(start, end, step)"""
2543
+ if len(a) == 0:
2544
+ return EvaluationError("range() requires 1-3 arguments, got 0")
2545
+ if len(a) == 1:
2546
+ end_val = a[0].value if hasattr(a[0], 'value') else int(a[0])
2547
+ return List([Integer(i) for i in range(end_val)])
2548
+ elif len(a) >= 2:
2549
+ start_val = a[0].value if hasattr(a[0], 'value') else int(a[0])
2550
+ end_val = a[1].value if hasattr(a[1], 'value') else int(a[1])
2551
+ step_val = 1
2552
+ if len(a) >= 3:
2553
+ step_val = a[2].value if hasattr(a[2], 'value') else int(a[2])
2554
+ return List([Integer(i) for i in range(start_val, end_val, step_val)])
2555
+
2556
+ def _typeof(*a):
2557
+ """typeof(value) - returns the type name as a string"""
2558
+ if len(a) != 1:
2559
+ return EvaluationError("typeof() requires exactly 1 argument")
2560
+ obj = a[0]
2561
+ if isinstance(obj, Integer): return String("integer")
2562
+ if isinstance(obj, Float): return String("float")
2563
+ if isinstance(obj, String): return String("string")
2564
+ if isinstance(obj, BooleanObj): return String("boolean")
2565
+ if obj is NULL or obj is None: return String("null")
2566
+ if isinstance(obj, List): return String("list")
2567
+ if isinstance(obj, Map): return String("map")
2568
+ if isinstance(obj, Action) or isinstance(obj, LambdaFunction): return String("function")
2569
+ from ..security import SmartContract
2570
+ if isinstance(obj, SmartContract): return String("contract")
2571
+ return String(type(obj).__name__.lower())
2572
+
2573
+ def _abs(*a):
2574
+ """abs(number) - returns absolute value"""
2575
+ if len(a) != 1:
2576
+ return EvaluationError("abs() requires exactly 1 argument")
2577
+ val = a[0]
2578
+ if isinstance(val, Integer): return Integer(abs(val.value))
2579
+ if isinstance(val, Float): return Float(abs(val.value))
2580
+ return EvaluationError("abs() requires a number argument")
2581
+
2515
2582
  def _vfs_stats(*a):
2516
2583
  """Return VFS file cache statistics as a Map: vfs_stats()"""
2517
2584
  mgr = _get_vfs_manager()
@@ -2762,6 +2829,7 @@ class FunctionEvaluatorMixin:
2762
2829
  "debug_log": Builtin(_debug_log, "debug_log"),
2763
2830
  "debug_trace": Builtin(_debug_trace, "debug_trace"),
2764
2831
  "string": Builtin(_string, "string"),
2832
+ "str": Builtin(_string, "str"), # alias for string()
2765
2833
  "int": Builtin(_int, "int"),
2766
2834
  "float": Builtin(_float, "float"),
2767
2835
  "uppercase": Builtin(_uppercase, "uppercase"),
@@ -2770,6 +2838,7 @@ class FunctionEvaluatorMixin:
2770
2838
  "persist_set": Builtin(_persist_set, "persist_set"),
2771
2839
  "persist_get": Builtin(_persist_get, "persist_get"),
2772
2840
  "len": Builtin(_len, "len"),
2841
+ "length": Builtin(_len, "length"), # alias for len()
2773
2842
  "type": Builtin(_type, "type"),
2774
2843
  "first": Builtin(_first, "first"),
2775
2844
  "rest": Builtin(_rest, "rest"),
@@ -2785,6 +2854,9 @@ class FunctionEvaluatorMixin:
2785
2854
  "values": Builtin(_values, "values"),
2786
2855
  "entries": Builtin(_entries, "entries"),
2787
2856
  "size": Builtin(_size, "size"),
2857
+ "range": Builtin(_range, "range"),
2858
+ "typeof": Builtin(_typeof, "typeof"),
2859
+ "abs": Builtin(_abs, "abs"),
2788
2860
  })
2789
2861
 
2790
2862
  # Register access control builtins
@@ -250,7 +250,7 @@ class ResourceLimiter:
250
250
  stats['memory_mb'] = memory_mb
251
251
  stats['max_memory_mb'] = self.max_memory_mb
252
252
  stats['memory_percent'] = (memory_mb / self.max_memory_mb) * 100
253
- except:
253
+ except (OSError, AttributeError, ZeroDivisionError):
254
254
  pass
255
255
 
256
256
  return stats
@@ -1228,11 +1228,45 @@ class StatementEvaluatorMixin:
1228
1228
  if is_error(iterable):
1229
1229
  return iterable
1230
1230
 
1231
+ # R-007 fix: Support Map iteration in for-each loops
1232
+ if isinstance(iterable, Map):
1233
+ result = NULL
1234
+ for key, val in iterable.pairs.items():
1235
+ try:
1236
+ self.resource_limiter.check_iterations()
1237
+ except Exception as e:
1238
+ from ..evaluator.resource_limiter import ResourceError, TimeoutError
1239
+ if isinstance(e, (ResourceError, TimeoutError)):
1240
+ return EvaluationError(str(e))
1241
+ raise
1242
+
1243
+ if node.index:
1244
+ # for each key, val in map
1245
+ key_obj = String(key) if isinstance(key, str) else key
1246
+ env.set(node.index.value, key_obj)
1247
+ env.set(node.item.value, val)
1248
+ else:
1249
+ # for each key in map (single variable gets the key)
1250
+ key_obj = String(key) if isinstance(key, str) else key
1251
+ env.set(node.item.value, key_obj)
1252
+
1253
+ result = self.eval_node(node.body, env, stack_trace)
1254
+ if isinstance(result, ReturnValue):
1255
+ return result
1256
+ if isinstance(result, BreakException):
1257
+ return NULL
1258
+ if isinstance(result, ContinueException):
1259
+ result = NULL
1260
+ continue
1261
+ if isinstance(result, EvaluationError):
1262
+ return result
1263
+ return result
1264
+
1231
1265
  if not isinstance(iterable, List):
1232
- return EvaluationError("ForEach expects List")
1266
+ return EvaluationError("ForEach expects List or Map")
1233
1267
 
1234
1268
  result = NULL
1235
- for item in iterable.elements:
1269
+ for idx, item in enumerate(iterable.elements):
1236
1270
  # Resource limit check (Security Fix #7)
1237
1271
  try:
1238
1272
  self.resource_limiter.check_iterations()
@@ -1243,6 +1277,9 @@ class StatementEvaluatorMixin:
1243
1277
  return EvaluationError(str(e))
1244
1278
  raise # Re-raise if not a resource error
1245
1279
 
1280
+ # R-006 fix: Support indexed for-each (for each i, item in list)
1281
+ if node.index:
1282
+ env.set(node.index.value, Integer(idx))
1246
1283
  env.set(node.item.value, item)
1247
1284
  result = self.eval_node(node.body, env, stack_trace)
1248
1285
  if isinstance(result, ReturnValue):
@@ -1881,7 +1918,10 @@ class StatementEvaluatorMixin:
1881
1918
 
1882
1919
  for nm in names:
1883
1920
  val = env.get(nm)
1884
- if not val:
1921
+ # R-011 fix: Use ``is None`` instead of ``not val`` so that valid
1922
+ # objects which might be falsy (empty lists, NULL placeholders from
1923
+ # pre-registration, etc.) are not incorrectly rejected.
1924
+ if val is None:
1885
1925
  return EvaluationError(f"Cannot export undefined: {nm}")
1886
1926
 
1887
1927
  # If inside a module, add to module's exports list
@@ -2302,7 +2342,7 @@ class StatementEvaluatorMixin:
2302
2342
 
2303
2343
  if isinstance(prop, dict):
2304
2344
  # For dict format, default_value is in the dict
2305
- if 'default_value' in prop:
2345
+ if 'default_value' in prop and prop['default_value'] is not None:
2306
2346
  def_val = self.eval_node(prop['default_value'], env, stack_trace)
2307
2347
  if is_error(def_val):
2308
2348
  return def_val
@@ -0,0 +1,34 @@
1
+ """
2
+ Zexus Kernel — Extension layer for the interpreter and VM.
3
+
4
+ The kernel sits *alongside* the existing evaluator and VM. It does NOT
5
+ replace them. Instead it provides:
6
+
7
+ * **DomainRegistry** — a place where feature domains (blockchain, web,
8
+ system, …) register their capabilities so the interpreter can discover
9
+ them at runtime.
10
+ * **ZIR** — a formal opcode catalogue that documents (and validates) the
11
+ bytecode the VM already uses, plus domain-specific opcode ranges.
12
+ * **Hooks** — optional integration points the evaluator/VM can call into
13
+ (e.g. ``kernel.resolve_opcode()``, ``kernel.check_security()``).
14
+
15
+ The kernel is entirely opt-in. Everything works without it — but with
16
+ it, third-party domains can plug into the Zexus runtime cleanly.
17
+
18
+ Quick start
19
+ -----------
20
+ >>> from zexus.kernel import get_kernel
21
+ >>> k = get_kernel()
22
+ >>> k.registry.list_domains() # see what's loaded
23
+ >>> k.registry.get_domain("blockchain") # query a specific domain
24
+ """
25
+
26
+ from .registry import DomainRegistry, get_registry
27
+ from .hooks import Kernel, get_kernel
28
+
29
+ __all__ = [
30
+ "DomainRegistry",
31
+ "get_registry",
32
+ "Kernel",
33
+ "get_kernel",
34
+ ]