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.
- package/README.md +12 -5
- 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/capability_system.py +184 -9
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +383 -34
- 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/bytecode.py +124 -7
- package/src/zexus/compiler/compat_runtime.py +6 -2
- package/src/zexus/compiler/lexer.py +16 -5
- package/src/zexus/compiler/parser.py +108 -7
- package/src/zexus/compiler/semantic.py +18 -19
- package/src/zexus/compiler/zexus_ast.py +26 -1
- 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 +112 -9
- 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 +457 -37
- package/src/zexus/evaluator/core.py +644 -50
- package/src/zexus/evaluator/expressions.py +358 -62
- package/src/zexus/evaluator/functions.py +458 -20
- package/src/zexus/evaluator/resource_limiter.py +4 -4
- package/src/zexus/evaluator/statements.py +774 -122
- package/src/zexus/evaluator/unified_execution.py +573 -72
- package/src/zexus/evaluator/utils.py +14 -2
- package/src/zexus/evaluator_original.py +1 -1
- package/src/zexus/event_loop.py +186 -0
- package/src/zexus/lexer.py +742 -458
- 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 +239 -9
- package/src/zexus/module_manager.py +129 -1
- package/src/zexus/object.py +76 -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 +1349 -408
- package/src/zexus/parser/strategy_context.py +755 -58
- package/src/zexus/parser/strategy_structural.py +121 -21
- package/src/zexus/persistence.py +15 -1
- package/src/zexus/renderer/__init__.py +61 -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/backend.py +261 -0
- package/src/zexus/renderer/canvas.py +78 -0
- package/src/zexus/renderer/color_system.py +201 -0
- package/src/zexus/renderer/graphics.py +31 -0
- package/src/zexus/renderer/layout.py +222 -0
- package/src/zexus/renderer/main_renderer.py +66 -0
- package/src/zexus/renderer/painter.py +30 -0
- package/src/zexus/renderer/tk_backend.py +208 -0
- package/src/zexus/renderer/web_backend.py +260 -0
- package/src/zexus/runtime/__init__.py +10 -2
- 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/runtime/load_manager.py +368 -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 +80 -6
- package/src/zexus/vm/binary_bytecode.py +659 -0
- package/src/zexus/vm/bytecode.py +59 -11
- 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 +561 -17
- package/src/zexus/vm/compiler.py +818 -51
- 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 +364 -20
- 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 +140 -45
- 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 +3581 -531
- package/src/zexus/vm/wasm_compiler.py +658 -0
- package/src/zexus/zexus_ast.py +137 -11
- package/src/zexus/zexus_token.py +16 -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 +16 -6
- package/src/zexus.egg-info/SOURCES.txt +129 -17
- package/src/zexus.egg-info/entry_points.txt +1 -0
- package/src/zexus.egg-info/requires.txt +4 -0
package/src/zexus/zexus_ast.py
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# Base classes
|
|
4
4
|
class Node:
|
|
5
|
+
# Source location for debugger / error reporting (set by parser)
|
|
6
|
+
line: int = 0
|
|
7
|
+
column: int = 0
|
|
8
|
+
|
|
5
9
|
def __repr__(self):
|
|
6
10
|
return f"{self.__class__.__name__}()"
|
|
7
11
|
|
|
@@ -33,13 +37,16 @@ class ConstStatement(Statement):
|
|
|
33
37
|
"""Const statement - immutable variable declaration
|
|
34
38
|
|
|
35
39
|
const MAX_VALUE = 100;
|
|
40
|
+
const PI: float = 3.14;
|
|
36
41
|
"""
|
|
37
|
-
def __init__(self, name, value):
|
|
42
|
+
def __init__(self, name, value, type_annotation=None):
|
|
38
43
|
self.name = name
|
|
39
44
|
self.value = value
|
|
45
|
+
self.type_annotation = type_annotation
|
|
40
46
|
|
|
41
47
|
def __repr__(self):
|
|
42
|
-
|
|
48
|
+
type_str = f", type={self.type_annotation}" if self.type_annotation else ""
|
|
49
|
+
return f"ConstStatement(name={self.name}, value={self.value}{type_str})"
|
|
43
50
|
|
|
44
51
|
class DataStatement(Statement):
|
|
45
52
|
"""Data statement - dataclass definition
|
|
@@ -279,6 +286,53 @@ class ThemeStatement(Statement):
|
|
|
279
286
|
def __repr__(self):
|
|
280
287
|
return f"ThemeStatement(name={self.name}, properties={self.properties})"
|
|
281
288
|
|
|
289
|
+
|
|
290
|
+
class ColorStatement(Statement):
|
|
291
|
+
def __init__(self, name, value):
|
|
292
|
+
self.name = name
|
|
293
|
+
self.value = value # Expression describing the colour
|
|
294
|
+
|
|
295
|
+
def __repr__(self):
|
|
296
|
+
return f"ColorStatement(name={self.name}, value={self.value})"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class CanvasStatement(Statement):
|
|
300
|
+
def __init__(self, name, properties=None, body=None):
|
|
301
|
+
self.name = name
|
|
302
|
+
self.properties = properties # Optional expression (MapLiteral or Identifier)
|
|
303
|
+
self.body = body # Optional BlockStatement with drawing directives
|
|
304
|
+
|
|
305
|
+
def __repr__(self):
|
|
306
|
+
return f"CanvasStatement(name={self.name}, properties={self.properties}, body={self.body})"
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
class GraphicsStatement(Statement):
|
|
310
|
+
def __init__(self, name, body=None):
|
|
311
|
+
self.name = name
|
|
312
|
+
self.body = body # Optional BlockStatement defining layers/operations
|
|
313
|
+
|
|
314
|
+
def __repr__(self):
|
|
315
|
+
return f"GraphicsStatement(name={self.name}, body={self.body})"
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class AnimationStatement(Statement):
|
|
319
|
+
def __init__(self, name, body=None, properties=None):
|
|
320
|
+
self.name = name
|
|
321
|
+
self.body = body # Optional BlockStatement for frame definitions
|
|
322
|
+
self.properties = properties # Optional expression (e.g. map literal)
|
|
323
|
+
|
|
324
|
+
def __repr__(self):
|
|
325
|
+
return f"AnimationStatement(name={self.name}, properties={self.properties}, body={self.body})"
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class ClockStatement(Statement):
|
|
329
|
+
def __init__(self, name, properties=None):
|
|
330
|
+
self.name = name
|
|
331
|
+
self.properties = properties # Optional expression (map literal or string)
|
|
332
|
+
|
|
333
|
+
def __repr__(self):
|
|
334
|
+
return f"ClockStatement(name={self.name}, properties={self.properties})"
|
|
335
|
+
|
|
282
336
|
class ActionStatement(Statement):
|
|
283
337
|
def __init__(self, name, parameters, body, is_async=False, return_type=None):
|
|
284
338
|
self.name = name
|
|
@@ -339,13 +393,15 @@ class DebugStatement(Statement):
|
|
|
339
393
|
|
|
340
394
|
# NEW: Try-catch statement
|
|
341
395
|
class TryCatchStatement(Statement):
|
|
342
|
-
def __init__(self, try_block, error_variable, catch_block):
|
|
396
|
+
def __init__(self, try_block, error_variable, catch_block, finally_block=None):
|
|
343
397
|
self.try_block = try_block
|
|
344
398
|
self.error_variable = error_variable
|
|
345
399
|
self.catch_block = catch_block
|
|
400
|
+
self.finally_block = finally_block
|
|
346
401
|
|
|
347
402
|
def __repr__(self):
|
|
348
|
-
|
|
403
|
+
has_finally = " +finally" if self.finally_block else ""
|
|
404
|
+
return f"TryCatchStatement(error_var={self.error_variable}{has_finally})"
|
|
349
405
|
|
|
350
406
|
# NEW: External function declaration
|
|
351
407
|
class ExternalDeclaration(Statement):
|
|
@@ -417,11 +473,13 @@ class TrailStatement(Statement):
|
|
|
417
473
|
|
|
418
474
|
# Expression Nodes
|
|
419
475
|
class Identifier(Expression):
|
|
420
|
-
def __init__(self, value):
|
|
476
|
+
def __init__(self, value, type_annotation=None):
|
|
421
477
|
self.value = value
|
|
478
|
+
self.type_annotation = type_annotation # Optional[str] for typed parameters
|
|
422
479
|
|
|
423
480
|
def __repr__(self):
|
|
424
|
-
|
|
481
|
+
type_str = f": {self.type_annotation}" if self.type_annotation else ""
|
|
482
|
+
return f"Identifier('{self.value}{type_str}')"
|
|
425
483
|
|
|
426
484
|
def __str__(self):
|
|
427
485
|
return self.value
|
|
@@ -450,6 +508,19 @@ class StringLiteral(Expression):
|
|
|
450
508
|
def __str__(self):
|
|
451
509
|
return self.value
|
|
452
510
|
|
|
511
|
+
class StringInterpolationExpression(Expression):
|
|
512
|
+
"""String interpolation: "hello ${name}, you are ${age} years old"
|
|
513
|
+
|
|
514
|
+
parts is a list of (type, value) where type is "str" or "expr".
|
|
515
|
+
For "str" parts, value is a string literal.
|
|
516
|
+
For "expr" parts, value is a parsed Expression AST node.
|
|
517
|
+
"""
|
|
518
|
+
def __init__(self, parts):
|
|
519
|
+
self.parts = parts # list of ("str", string) or ("expr", Expression)
|
|
520
|
+
|
|
521
|
+
def __repr__(self):
|
|
522
|
+
return f"StringInterpolation({len(self.parts)} parts)"
|
|
523
|
+
|
|
453
524
|
class Boolean(Expression):
|
|
454
525
|
def __init__(self, value):
|
|
455
526
|
self.value = value
|
|
@@ -472,6 +543,25 @@ class ThisExpression(Expression):
|
|
|
472
543
|
return "ThisExpression()"
|
|
473
544
|
|
|
474
545
|
|
|
546
|
+
class DestructurePattern(Expression):
|
|
547
|
+
"""Destructuring pattern for let/const assignments.
|
|
548
|
+
|
|
549
|
+
kind='map': let {a, b} = expr or let {a: x, b: y} = expr
|
|
550
|
+
kind='list': let [x, y, z] = expr
|
|
551
|
+
|
|
552
|
+
bindings: list of (source_key, target_name) tuples
|
|
553
|
+
- map: [("a", "a"), ("b", "renamed")] for {a, b: renamed}
|
|
554
|
+
- list: [(0, "x"), (1, "y")] for [x, y]
|
|
555
|
+
rest: optional name for rest element (..rest)
|
|
556
|
+
"""
|
|
557
|
+
def __init__(self, kind, bindings, rest=None):
|
|
558
|
+
self.kind = kind # 'map' or 'list'
|
|
559
|
+
self.bindings = bindings # list of (source, target_name_str)
|
|
560
|
+
self.rest = rest # optional rest variable name
|
|
561
|
+
|
|
562
|
+
def __repr__(self):
|
|
563
|
+
return f"DestructurePattern(kind={self.kind}, bindings={len(self.bindings)}, rest={self.rest})"
|
|
564
|
+
|
|
475
565
|
class ListLiteral(Expression):
|
|
476
566
|
def __init__(self, elements):
|
|
477
567
|
self.elements = elements
|
|
@@ -600,6 +690,17 @@ class PropertyAccessExpression(Expression):
|
|
|
600
690
|
def __repr__(self):
|
|
601
691
|
return f"PropertyAccessExpression(object={self.object}, property={self.property}, computed={self.computed})"
|
|
602
692
|
|
|
693
|
+
|
|
694
|
+
class SliceExpression(Expression):
|
|
695
|
+
"""Slice expression: obj[start:end]"""
|
|
696
|
+
def __init__(self, object, start=None, end=None):
|
|
697
|
+
self.object = object
|
|
698
|
+
self.start = start
|
|
699
|
+
self.end = end
|
|
700
|
+
|
|
701
|
+
def __repr__(self):
|
|
702
|
+
return f"SliceExpression(object={self.object}, start={self.start}, end={self.end})"
|
|
703
|
+
|
|
603
704
|
class AssignmentExpression(Expression):
|
|
604
705
|
def __init__(self, name, value):
|
|
605
706
|
self.name = name
|
|
@@ -621,6 +722,33 @@ class AwaitExpression(Expression):
|
|
|
621
722
|
def __repr__(self):
|
|
622
723
|
return f"AwaitExpression(expression={self.expression})"
|
|
623
724
|
|
|
725
|
+
|
|
726
|
+
class FindExpression(Expression):
|
|
727
|
+
def __init__(self, target, scope=None):
|
|
728
|
+
self.target = target
|
|
729
|
+
self.scope = scope
|
|
730
|
+
|
|
731
|
+
def __repr__(self):
|
|
732
|
+
parts = [f"target={self.target}"]
|
|
733
|
+
if self.scope is not None:
|
|
734
|
+
parts.append(f"scope={self.scope}")
|
|
735
|
+
return f"FindExpression({', '.join(parts)})"
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
class LoadExpression(Expression):
|
|
739
|
+
def __init__(self, target, source=None, provider_hint=None):
|
|
740
|
+
self.target = target
|
|
741
|
+
self.source = source
|
|
742
|
+
self.provider_hint = provider_hint
|
|
743
|
+
|
|
744
|
+
def __repr__(self):
|
|
745
|
+
parts = [f"target={self.target}"]
|
|
746
|
+
if self.source is not None:
|
|
747
|
+
parts.append(f"source={self.source}")
|
|
748
|
+
if self.provider_hint:
|
|
749
|
+
parts.append(f"provider_hint={self.provider_hint}")
|
|
750
|
+
return f"LoadExpression({', '.join(parts)})"
|
|
751
|
+
|
|
624
752
|
class FileImportExpression(Expression):
|
|
625
753
|
"""File import expression for << operator
|
|
626
754
|
|
|
@@ -1089,9 +1217,6 @@ class WatchStatement(Statement):
|
|
|
1089
1217
|
def __repr__(self):
|
|
1090
1218
|
return f"WatchStatement(expr={self.watched_expr}, reaction={self.reaction})"
|
|
1091
1219
|
|
|
1092
|
-
def __repr__(self):
|
|
1093
|
-
return f"WatchStatement(watch={self.watched_expr})"
|
|
1094
|
-
|
|
1095
1220
|
|
|
1096
1221
|
class LogStatement(Statement):
|
|
1097
1222
|
"""Log statement - Redirect output to file
|
|
@@ -1500,12 +1625,13 @@ class StateStatement(Statement):
|
|
|
1500
1625
|
state owner = TX.caller;
|
|
1501
1626
|
state locked = false;
|
|
1502
1627
|
"""
|
|
1503
|
-
def __init__(self, name, initial_value=None):
|
|
1628
|
+
def __init__(self, name, initial_value=None, modifiers=None):
|
|
1504
1629
|
self.name = name # Identifier: state variable name
|
|
1505
1630
|
self.initial_value = initial_value # Optional Expression: initial value
|
|
1631
|
+
self.modifiers = modifiers or [] # List[str]: modifiers (private, public, etc.)
|
|
1506
1632
|
|
|
1507
1633
|
def __repr__(self):
|
|
1508
|
-
return f"StateStatement(name={self.name}, initial={self.initial_value})"
|
|
1634
|
+
return f"StateStatement(name={self.name}, initial={self.initial_value}, modifiers={self.modifiers})"
|
|
1509
1635
|
|
|
1510
1636
|
|
|
1511
1637
|
class ContractStatement(Statement):
|
package/src/zexus/zexus_token.py
CHANGED
|
@@ -32,6 +32,16 @@ OR = "||"
|
|
|
32
32
|
QUESTION = "?" # Ternary operator: condition ? true_val : false_val
|
|
33
33
|
NULLISH = "??" # Nullish coalescing: value ?? default
|
|
34
34
|
|
|
35
|
+
# Compound Assignment Operators
|
|
36
|
+
PLUS_ASSIGN = "+=" # Addition assignment: x += 5
|
|
37
|
+
MINUS_ASSIGN = "-=" # Subtraction assignment: x -= 5
|
|
38
|
+
STAR_ASSIGN = "*=" # Multiplication assignment: x *= 5
|
|
39
|
+
SLASH_ASSIGN = "/=" # Division assignment: x /= 5
|
|
40
|
+
MOD_ASSIGN = "%=" # Modulo assignment: x %= 5
|
|
41
|
+
POWER = "**" # Exponentiation: x ** 2
|
|
42
|
+
POWER_ASSIGN = "**=" # Exponentiation assignment: x **= 2
|
|
43
|
+
INTERP_STRING = "INTERP_STRING" # String interpolation: "hello ${name}"
|
|
44
|
+
|
|
35
45
|
# Delimiters
|
|
36
46
|
COMMA = ","
|
|
37
47
|
SEMICOLON = ";"
|
|
@@ -78,6 +88,8 @@ CLOCK = "CLOCK"
|
|
|
78
88
|
MAP = "MAP"
|
|
79
89
|
WHILE = "WHILE"
|
|
80
90
|
USE = "USE"
|
|
91
|
+
FIND = "FIND"
|
|
92
|
+
LOAD = "LOAD"
|
|
81
93
|
EXACTLY = "EXACTLY"
|
|
82
94
|
EMBEDDED = "EMBEDDED"
|
|
83
95
|
EXPORT = "EXPORT"
|
|
@@ -85,11 +97,13 @@ LAMBDA = "LAMBDA"
|
|
|
85
97
|
DEBUG = "DEBUG" # NEW: Debug token
|
|
86
98
|
TRY = "TRY" # NEW: Try token
|
|
87
99
|
CATCH = "CATCH" # NEW: Catch token
|
|
100
|
+
FINALLY = "FINALLY" # NEW: Finally token
|
|
88
101
|
CONTINUE = "CONTINUE" # NEW: Continue on error token
|
|
89
102
|
BREAK = "BREAK" # NEW: Break loop statement
|
|
90
103
|
THROW = "THROW" # NEW: Throw error statement
|
|
91
104
|
EXTERNAL = "EXTERNAL" # NEW: From token
|
|
92
105
|
FROM = "FROM" # NEW: From token
|
|
106
|
+
AS = "AS"
|
|
93
107
|
|
|
94
108
|
# ASYNC / AWAIT / MODULE / EVENT / ENUM / PROTOCOL tokens
|
|
95
109
|
ASYNC = "ASYNC"
|
|
@@ -174,7 +188,6 @@ LIMIT = "LIMIT" # Gas/resource limit: action transfer() limit 100
|
|
|
174
188
|
GAS = "GAS" # Gas tracking: gas_used(), gas_remaining()
|
|
175
189
|
PERSISTENT = "PERSISTENT"
|
|
176
190
|
STORAGE = "STORAGE"
|
|
177
|
-
REQUIRE = "REQUIRE"
|
|
178
191
|
|
|
179
192
|
# PERFORMANCE OPTIMIZATION TOKENS
|
|
180
193
|
NATIVE = "NATIVE" # Call C/C++ code: native { "func_name", arg1, arg2 }
|
|
@@ -187,9 +200,10 @@ SIMD = "SIMD" # Vector operations: simd(operation, vector1, vecto
|
|
|
187
200
|
DEFER = "DEFER" # Cleanup code execution: defer cleanup_code;
|
|
188
201
|
PATTERN = "PATTERN" # Pattern matching: pattern value { case x => ...; }
|
|
189
202
|
MATCH = "MATCH" # Match expression: match value { Point(x, y) => ... }
|
|
203
|
+
CASE = "CASE" # Case clause in match/pattern
|
|
204
|
+
DEFAULT = "DEFAULT" # Default case in match
|
|
190
205
|
|
|
191
206
|
# ADVANCED FEATURES TOKENS
|
|
192
|
-
ENUM = "ENUM" # Type-safe enumerations: enum Color { Red, Green, Blue }
|
|
193
207
|
STREAM = "STREAM" # Event streaming: stream name as event => handler;
|
|
194
208
|
WATCH = "WATCH" # Reactive state management: watch variable => reaction;
|
|
195
209
|
LOG = "LOG" # Output logging: log > filename.txt
|
|
@@ -198,9 +212,6 @@ LOG = "LOG" # Output logging: log > filename.txt
|
|
|
198
212
|
PUBLIC = "PUBLIC"
|
|
199
213
|
PRIVATE = "PRIVATE"
|
|
200
214
|
SEALED = "SEALED"
|
|
201
|
-
ASYNC = "ASYNC"
|
|
202
|
-
NATIVE = "NATIVE"
|
|
203
|
-
INLINE = "INLINE"
|
|
204
215
|
SECURE = "SECURE"
|
|
205
216
|
PURE = "PURE"
|
|
206
217
|
VIEW = "VIEW" # View function (alias for pure, read-only)
|
|
@@ -4,6 +4,7 @@ Package Installer - Handles package installation and dependencies
|
|
|
4
4
|
import os
|
|
5
5
|
import json
|
|
6
6
|
import shutil
|
|
7
|
+
import tarfile
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from typing import Dict, Optional
|
|
9
10
|
|
|
@@ -11,9 +12,10 @@ from typing import Dict, Optional
|
|
|
11
12
|
class PackageInstaller:
|
|
12
13
|
"""Handles package installation"""
|
|
13
14
|
|
|
14
|
-
def __init__(self, install_dir: Path):
|
|
15
|
+
def __init__(self, install_dir: Path, registry=None):
|
|
15
16
|
self.install_dir = Path(install_dir)
|
|
16
17
|
self.install_dir.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
self.registry = registry # PackageRegistry for tarball downloads
|
|
17
19
|
|
|
18
20
|
def install(self, package_info: Dict) -> bool:
|
|
19
21
|
"""Install a package"""
|
|
@@ -40,14 +42,12 @@ class PackageInstaller:
|
|
|
40
42
|
if pkg_type == "builtin":
|
|
41
43
|
self._install_builtin(name, version, target_dir)
|
|
42
44
|
else:
|
|
43
|
-
# TODO: Download and extract package
|
|
44
45
|
self._install_from_source(package_info, target_dir)
|
|
45
46
|
|
|
46
47
|
return True
|
|
47
48
|
|
|
48
49
|
def _install_builtin(self, name: str, version: str, target_dir: Path):
|
|
49
50
|
"""Install a built-in package"""
|
|
50
|
-
# Create package.json
|
|
51
51
|
pkg_json = {
|
|
52
52
|
"name": name,
|
|
53
53
|
"version": version,
|
|
@@ -58,7 +58,6 @@ class PackageInstaller:
|
|
|
58
58
|
with open(target_dir / "zexus.json", "w") as f:
|
|
59
59
|
json.dump(pkg_json, f, indent=2)
|
|
60
60
|
|
|
61
|
-
# Create stub main file
|
|
62
61
|
main_file = target_dir / "index.zx"
|
|
63
62
|
main_file.write_text(f"""// {name} - Built-in Zexus package
|
|
64
63
|
// Version: {version}
|
|
@@ -72,23 +71,64 @@ export {{
|
|
|
72
71
|
""")
|
|
73
72
|
|
|
74
73
|
def _install_from_source(self, package_info: Dict, target_dir: Path):
|
|
75
|
-
"""Install package from
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
"""Install package from a remote tarball or local path.
|
|
75
|
+
|
|
76
|
+
If the package metadata contains a ``tarball`` key pointing to a
|
|
77
|
+
local file, that tarball is extracted directly. Otherwise the
|
|
78
|
+
installer attempts to download the tarball from the registry via
|
|
79
|
+
``registry.download_tarball(name, version)``.
|
|
80
|
+
"""
|
|
81
|
+
name = package_info["name"]
|
|
82
|
+
version = package_info["version"]
|
|
83
|
+
|
|
84
|
+
# 1. Check for a local tarball path in the metadata
|
|
85
|
+
tarball_path = package_info.get("tarball")
|
|
86
|
+
if tarball_path and os.path.isfile(tarball_path):
|
|
87
|
+
self._extract_tarball(Path(tarball_path), target_dir, name)
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
# 2. Try to download from the remote registry
|
|
91
|
+
if self.registry is not None:
|
|
92
|
+
downloaded = self.registry.download_tarball(name, version)
|
|
93
|
+
if downloaded and downloaded.exists():
|
|
94
|
+
print(f"📦 Downloaded {name}@{version}")
|
|
95
|
+
self._extract_tarball(downloaded, target_dir, name)
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
# 3. Fallback — create placeholder with metadata
|
|
99
|
+
print(f"⚠️ Could not download {name}@{version} — creating placeholder")
|
|
79
100
|
pkg_json = {
|
|
80
|
-
"name":
|
|
81
|
-
"version":
|
|
101
|
+
"name": name,
|
|
102
|
+
"version": version,
|
|
82
103
|
"description": package_info.get("description", ""),
|
|
83
104
|
}
|
|
84
|
-
|
|
85
105
|
with open(target_dir / "zexus.json", "w") as f:
|
|
86
106
|
json.dump(pkg_json, f, indent=2)
|
|
87
|
-
|
|
88
107
|
main_file = target_dir / "index.zx"
|
|
89
|
-
main_file.write_text(f
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
main_file.write_text(f'// {name}@{version} — placeholder (tarball not available)\n')
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def _extract_tarball(tarball_path: Path, target_dir: Path, package_name: str):
|
|
112
|
+
"""Extract a ``.tar.gz`` tarball into *target_dir*.
|
|
113
|
+
|
|
114
|
+
Tarballs created by ``PackagePublisher`` contain files under a
|
|
115
|
+
``<package_name>/`` prefix. We strip that prefix so the files
|
|
116
|
+
land directly in *target_dir*.
|
|
117
|
+
"""
|
|
118
|
+
with tarfile.open(tarball_path, "r:gz") as tar:
|
|
119
|
+
# Security: filter out absolute paths and ..'s
|
|
120
|
+
safe_members = []
|
|
121
|
+
prefix = f"{package_name}/"
|
|
122
|
+
for member in tar.getmembers():
|
|
123
|
+
if member.name.startswith("/") or ".." in member.name:
|
|
124
|
+
continue
|
|
125
|
+
# Strip the package-name prefix from the archive path
|
|
126
|
+
if member.name.startswith(prefix):
|
|
127
|
+
member.name = member.name[len(prefix):]
|
|
128
|
+
elif member.name == package_name:
|
|
129
|
+
continue # skip the bare directory entry
|
|
130
|
+
safe_members.append(member)
|
|
131
|
+
tar.extractall(path=target_dir, members=safe_members)
|
|
92
132
|
|
|
93
133
|
def uninstall(self, package: str) -> bool:
|
|
94
134
|
"""Uninstall a package"""
|
|
@@ -23,7 +23,7 @@ class PackageManager:
|
|
|
23
23
|
self.installer = PackageInstaller(self.zpm_dir)
|
|
24
24
|
self.publisher = PackagePublisher(self.registry)
|
|
25
25
|
|
|
26
|
-
def init(self, name: str = None, version: str = "1.
|
|
26
|
+
def init(self, name: str = None, version: str = "1.7.2") -> Dict:
|
|
27
27
|
"""Initialize a new Zexus project with package.json"""
|
|
28
28
|
if self.config_file.exists():
|
|
29
29
|
print(f"⚠️ {self.config_file} already exists")
|