zexus 1.6.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/LICENSE +0 -0
- package/README.md +2513 -0
- package/bin/zexus +2 -0
- package/bin/zpics +2 -0
- package/bin/zpm +2 -0
- package/bin/zx +2 -0
- package/bin/zx-deploy +2 -0
- package/bin/zx-dev +2 -0
- package/bin/zx-run +2 -0
- package/package.json +66 -0
- package/scripts/README.md +24 -0
- package/scripts/postinstall.js +44 -0
- package/shared_config.json +24 -0
- package/src/README.md +1525 -0
- package/src/tests/run_zexus_tests.py +117 -0
- package/src/tests/test_all_phases.zx +346 -0
- package/src/tests/test_blockchain_features.zx +306 -0
- package/src/tests/test_complexity_features.zx +321 -0
- package/src/tests/test_core_integration.py +185 -0
- package/src/tests/test_phase10_ecosystem.zx +177 -0
- package/src/tests/test_phase1_modifiers.zx +87 -0
- package/src/tests/test_phase2_plugins.zx +80 -0
- package/src/tests/test_phase3_security.zx +97 -0
- package/src/tests/test_phase4_vfs.zx +116 -0
- package/src/tests/test_phase5_types.zx +117 -0
- package/src/tests/test_phase6_metaprogramming.zx +125 -0
- package/src/tests/test_phase7_optimization.zx +132 -0
- package/src/tests/test_phase9_advanced_types.zx +157 -0
- package/src/tests/test_security_features.py +419 -0
- package/src/tests/test_security_features.zx +276 -0
- package/src/tests/test_simple_zx.zx +1 -0
- package/src/tests/test_verification_simple.zx +69 -0
- package/src/zexus/__init__.py +28 -0
- package/src/zexus/__main__.py +5 -0
- package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/ecosystem.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__/hybrid_orchestrator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/virtual_filesystem.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/advanced_types.py +401 -0
- package/src/zexus/blockchain/__init__.py +40 -0
- package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/crypto.py +463 -0
- package/src/zexus/blockchain/ledger.py +255 -0
- package/src/zexus/blockchain/transaction.py +267 -0
- package/src/zexus/builtin_modules.py +284 -0
- package/src/zexus/builtin_plugins.py +317 -0
- package/src/zexus/capability_system.py +372 -0
- package/src/zexus/cli/__init__.py +2 -0
- package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +707 -0
- package/src/zexus/cli/zpm.py +203 -0
- package/src/zexus/compare_interpreter_compiler.py +146 -0
- package/src/zexus/compiler/__init__.py +169 -0
- package/src/zexus/compiler/__pycache__/__init__.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__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/compiler/bytecode.py +266 -0
- package/src/zexus/compiler/compat_runtime.py +277 -0
- package/src/zexus/compiler/lexer.py +257 -0
- package/src/zexus/compiler/parser.py +779 -0
- package/src/zexus/compiler/semantic.py +118 -0
- package/src/zexus/compiler/zexus_ast.py +454 -0
- package/src/zexus/complexity_system.py +575 -0
- package/src/zexus/concurrency_system.py +493 -0
- package/src/zexus/config.py +201 -0
- package/src/zexus/crypto_bridge.py +19 -0
- package/src/zexus/dependency_injection.py +423 -0
- package/src/zexus/ecosystem.py +434 -0
- package/src/zexus/environment.py +101 -0
- package/src/zexus/environment_manager.py +119 -0
- package/src/zexus/error_reporter.py +314 -0
- package/src/zexus/evaluator/__init__.py +12 -0
- package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
- 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__/integration.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/bytecode_compiler.py +700 -0
- package/src/zexus/evaluator/core.py +891 -0
- package/src/zexus/evaluator/expressions.py +827 -0
- package/src/zexus/evaluator/functions.py +3989 -0
- package/src/zexus/evaluator/integration.py +396 -0
- package/src/zexus/evaluator/statements.py +4303 -0
- package/src/zexus/evaluator/utils.py +126 -0
- package/src/zexus/evaluator_original.py +2041 -0
- package/src/zexus/external_bridge.py +16 -0
- package/src/zexus/find_affected_imports.sh +155 -0
- package/src/zexus/hybrid_orchestrator.py +152 -0
- package/src/zexus/input_validation.py +259 -0
- package/src/zexus/lexer.py +571 -0
- package/src/zexus/logging.py +89 -0
- package/src/zexus/lsp/__init__.py +9 -0
- package/src/zexus/lsp/completion_provider.py +207 -0
- package/src/zexus/lsp/definition_provider.py +22 -0
- package/src/zexus/lsp/hover_provider.py +71 -0
- package/src/zexus/lsp/server.py +269 -0
- package/src/zexus/lsp/symbol_provider.py +31 -0
- package/src/zexus/metaprogramming.py +321 -0
- package/src/zexus/module_cache.py +89 -0
- package/src/zexus/module_manager.py +107 -0
- package/src/zexus/object.py +973 -0
- package/src/zexus/optimization.py +424 -0
- package/src/zexus/parser/__init__.py +31 -0
- package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
- 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/integration.py +86 -0
- package/src/zexus/parser/parser.py +3977 -0
- package/src/zexus/parser/strategy_context.py +7254 -0
- package/src/zexus/parser/strategy_structural.py +1033 -0
- package/src/zexus/persistence.py +391 -0
- package/src/zexus/plugin_system.py +290 -0
- package/src/zexus/policy_engine.py +365 -0
- package/src/zexus/profiler/__init__.py +5 -0
- package/src/zexus/profiler/profiler.py +233 -0
- package/src/zexus/purity_system.py +398 -0
- package/src/zexus/runtime/__init__.py +20 -0
- package/src/zexus/runtime/async_runtime.py +324 -0
- package/src/zexus/search_old_imports.sh +65 -0
- package/src/zexus/security.py +1407 -0
- package/src/zexus/stack_trace.py +233 -0
- package/src/zexus/stdlib/__init__.py +27 -0
- package/src/zexus/stdlib/blockchain.py +341 -0
- package/src/zexus/stdlib/compression.py +167 -0
- package/src/zexus/stdlib/crypto.py +124 -0
- package/src/zexus/stdlib/datetime.py +163 -0
- package/src/zexus/stdlib/db_mongo.py +199 -0
- package/src/zexus/stdlib/db_mysql.py +162 -0
- package/src/zexus/stdlib/db_postgres.py +163 -0
- package/src/zexus/stdlib/db_sqlite.py +133 -0
- package/src/zexus/stdlib/encoding.py +230 -0
- package/src/zexus/stdlib/fs.py +195 -0
- package/src/zexus/stdlib/http.py +219 -0
- package/src/zexus/stdlib/http_server.py +248 -0
- package/src/zexus/stdlib/json_module.py +61 -0
- package/src/zexus/stdlib/math.py +360 -0
- package/src/zexus/stdlib/os_module.py +265 -0
- package/src/zexus/stdlib/regex.py +148 -0
- package/src/zexus/stdlib/sockets.py +253 -0
- package/src/zexus/stdlib/test_framework.zx +208 -0
- package/src/zexus/stdlib/test_runner.zx +119 -0
- package/src/zexus/stdlib_integration.py +341 -0
- package/src/zexus/strategy_recovery.py +256 -0
- package/src/zexus/syntax_validator.py +356 -0
- package/src/zexus/testing/zpics.py +407 -0
- package/src/zexus/testing/zpics_runtime.py +369 -0
- package/src/zexus/type_system.py +374 -0
- package/src/zexus/validation_system.py +569 -0
- package/src/zexus/virtual_filesystem.py +355 -0
- package/src/zexus/vm/__init__.py +8 -0
- package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
- 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__/cache.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/async_optimizer.py +420 -0
- package/src/zexus/vm/bytecode.py +428 -0
- package/src/zexus/vm/bytecode_converter.py +297 -0
- package/src/zexus/vm/cache.py +532 -0
- package/src/zexus/vm/jit.py +720 -0
- package/src/zexus/vm/memory_manager.py +520 -0
- package/src/zexus/vm/memory_pool.py +511 -0
- package/src/zexus/vm/optimizer.py +478 -0
- package/src/zexus/vm/parallel_vm.py +899 -0
- package/src/zexus/vm/peephole_optimizer.py +452 -0
- package/src/zexus/vm/profiler.py +527 -0
- package/src/zexus/vm/register_allocator.py +462 -0
- package/src/zexus/vm/register_vm.py +520 -0
- package/src/zexus/vm/ssa_converter.py +757 -0
- package/src/zexus/vm/vm.py +1392 -0
- package/src/zexus/zexus_ast.py +1782 -0
- package/src/zexus/zexus_token.py +253 -0
- package/src/zexus/zpm/__init__.py +15 -0
- package/src/zexus/zpm/installer.py +116 -0
- package/src/zexus/zpm/package_manager.py +208 -0
- package/src/zexus/zpm/publisher.py +98 -0
- package/src/zexus/zpm/registry.py +110 -0
- package/src/zexus.egg-info/PKG-INFO +2235 -0
- package/src/zexus.egg-info/SOURCES.txt +876 -0
- package/src/zexus.egg-info/dependency_links.txt +1 -0
- package/src/zexus.egg-info/entry_points.txt +3 -0
- package/src/zexus.egg-info/not-zip-safe +1 -0
- package/src/zexus.egg-info/requires.txt +14 -0
- package/src/zexus.egg-info/top_level.txt +2 -0
- package/zexus.json +14 -0
|
@@ -0,0 +1,2235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zexus
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: A modern, security-first programming language with blockchain support
|
|
5
|
+
Home-page: https://github.com/Zaidux/zexus-interpreter
|
|
6
|
+
Author: Zaidux
|
|
7
|
+
Author-email: Zaidux <zaiduabubakar777@gmail.com>
|
|
8
|
+
Maintainer-email: Zaidux <zaiduabubakar888@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://github.com/Zaidux/zexus-interpreter
|
|
11
|
+
Project-URL: Documentation, https://github.com/Zaidux/zexus-interpreter/blob/main/docs/
|
|
12
|
+
Project-URL: Repository, https://github.com/Zaidux/zexus-interpreter
|
|
13
|
+
Project-URL: Issues, https://github.com/Zaidux/zexus-interpreter/issues
|
|
14
|
+
Project-URL: Changelog, https://github.com/Zaidux/zexus-interpreter/blob/main/CHANGELOG.md
|
|
15
|
+
Keywords: programming-language,interpreter,compiler,blockchain,smart-contracts,security,policy-as-code
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
19
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Operating System :: OS Independent
|
|
29
|
+
Requires-Python: >=3.8
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: click>=8.0
|
|
33
|
+
Requires-Dist: rich>=10.0
|
|
34
|
+
Requires-Dist: pygls>=1.0.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
38
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
39
|
+
Requires-Dist: flake8>=3.9; extra == "dev"
|
|
40
|
+
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
41
|
+
Provides-Extra: blockchain
|
|
42
|
+
Requires-Dist: web3>=5.0; extra == "blockchain"
|
|
43
|
+
Requires-Dist: eth-account>=0.5; extra == "blockchain"
|
|
44
|
+
Dynamic: author
|
|
45
|
+
Dynamic: home-page
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
Dynamic: requires-python
|
|
48
|
+
|
|
49
|
+
# Zexus Programming Language
|
|
50
|
+
|
|
51
|
+
<div align="center">
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
[](LICENSE)
|
|
55
|
+
[](https://python.org)
|
|
56
|
+
[](https://github.com/Zaidux/zexus-interpreter)
|
|
57
|
+
|
|
58
|
+
**A modern, security-first programming language with built-in blockchain support, VM-accelerated execution, advanced memory management, and policy-as-code**
|
|
59
|
+
|
|
60
|
+
[What's New](#-whats-new-in-v150) • [Features](#-key-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [Keywords](#-complete-keyword-reference) • [Documentation](#-documentation) • [Examples](#-examples) • [Troubleshooting](#-getting-help--troubleshooting)
|
|
61
|
+
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 📋 Table of Contents
|
|
67
|
+
|
|
68
|
+
- [What is Zexus?](#-what-is-zexus)
|
|
69
|
+
- [What's New](#-whats-new-in-v150)
|
|
70
|
+
- [Key Features](#-key-features)
|
|
71
|
+
- [VM-Accelerated Performance](#-vm-accelerated-performance-new)
|
|
72
|
+
- [Security & Policy-as-Code](#-security--policy-as-code--verify-enhanced)
|
|
73
|
+
- [Blockchain Support](#️-native-blockchain-support)
|
|
74
|
+
- [Persistent Memory](#-persistent-memory-management)
|
|
75
|
+
- [Dependency Injection](#-dependency-injection--testing)
|
|
76
|
+
- [Reactive State](#-reactive-state-management)
|
|
77
|
+
- [Advanced Features](#-advanced-features)
|
|
78
|
+
- [Installation](#-installation)
|
|
79
|
+
- [Quick Start](#-quick-start)
|
|
80
|
+
- [Examples](#-examples)
|
|
81
|
+
- [Complete Feature Reference](#-complete-feature-reference)
|
|
82
|
+
- [Complete Keyword Reference](#-complete-keyword-reference)
|
|
83
|
+
- [Built-in Functions](#built-in-functions-100)
|
|
84
|
+
- [CLI Commands](#-cli-commands)
|
|
85
|
+
- [Architecture](#️-architecture)
|
|
86
|
+
- [Documentation](#-documentation)
|
|
87
|
+
- [Contributing](#-contributing)
|
|
88
|
+
- [Testing](#-testing)
|
|
89
|
+
- [Getting Help & Troubleshooting](#-getting-help--troubleshooting)
|
|
90
|
+
- [License](#-license)
|
|
91
|
+
- [Roadmap](#️-roadmap)
|
|
92
|
+
- [Project Stats](#-project-stats)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 🎯 What is Zexus?
|
|
99
|
+
|
|
100
|
+
Zexus is a next-generation, general-purpose programming language designed for security-conscious developers who need:
|
|
101
|
+
|
|
102
|
+
- **🎨 World-Class Error Messages** - Beginner-friendly errors with helpful suggestions (NEW in v1.5!)
|
|
103
|
+
- **🔐 Policy-as-code** - Declarative security rules and access control
|
|
104
|
+
- **⚡ VM-Accelerated Execution** - Hybrid interpreter/compiler with bytecode VM
|
|
105
|
+
- **📦 Advanced Type System** - Generic types, pattern matching, and dataclasses (NEW in v1.5!)
|
|
106
|
+
- **⛓️ Built-in Blockchain** - Native smart contracts and DApp primitives
|
|
107
|
+
- **💾 Persistent Memory** - Cross-session data with automatic leak detection
|
|
108
|
+
- **🔌 Dependency Injection** - Powerful DI system with mocking for testing
|
|
109
|
+
- **👀 Reactive State** - WATCH for automatic state change reactions
|
|
110
|
+
- **🎭 Flexible Syntax** - Support for both universal (`{}`) and tolerant (`:`) styles
|
|
111
|
+
- **📦 Package Manager** - ZPM for dependency management
|
|
112
|
+
- **🚀 Main Entry Point** - Python-style `if __name__ == "__main__"` pattern support
|
|
113
|
+
- **🎨 UI Rendering** - Built-in screen, component, and theme system
|
|
114
|
+
- **🔒 Enterprise Features** - Middleware, authentication, throttling, and caching
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 🎉 What's New in v1.5.0
|
|
119
|
+
|
|
120
|
+
### Latest Features (v1.5.0)
|
|
121
|
+
|
|
122
|
+
✅ **World-Class Error Reporting** - Production-grade error messages rivaling Rust
|
|
123
|
+
✅ **Advanced DATA System** - Generic types, pattern matching, operator overloading
|
|
124
|
+
✅ **Stack Trace Formatter** - Beautiful, readable stack traces with source context
|
|
125
|
+
✅ **Smart Error Suggestions** - Actionable hints for fixing common errors
|
|
126
|
+
✅ **Pattern Matching** - Complete pattern matching with exhaustiveness checking
|
|
127
|
+
✅ **CONTINUE Keyword** - Error recovery mode for graceful degradation and batch processing
|
|
128
|
+
|
|
129
|
+
### Recent Enhancements (v0.1.3)
|
|
130
|
+
|
|
131
|
+
✅ **130+ Keywords Fully Operational** - All core language features tested and verified
|
|
132
|
+
✅ **Dual-Mode DEBUG** - Function mode (`debug(x)`) and statement mode (`debug x;`)
|
|
133
|
+
✅ **Multiple Syntax Styles** - `let x = 5`, `let x : 5`, `let x : int = 5` all supported
|
|
134
|
+
✅ **Enterprise Keywords** - MIDDLEWARE, AUTH, THROTTLE, CACHE, INJECT fully functional
|
|
135
|
+
✅ **Async/Await Runtime** - Complete Promise-based async system with context propagation
|
|
136
|
+
✅ **Main Entry Point** - 15+ builtins for program lifecycle management
|
|
137
|
+
✅ **UI Renderer** - SCREEN, COMPONENT, THEME keywords with 120+ tests
|
|
138
|
+
✅ **Enhanced VERIFY** - Email, URL, phone validation, pattern matching, database checks
|
|
139
|
+
✅ **Blockchain Keywords** - implements, pure, view, payable, modifier, this, emit
|
|
140
|
+
✅ **100+ Built-in Functions** - Comprehensive standard library
|
|
141
|
+
✅ **LOG Keyword Enhancements** - `read_file()` and `eval_file()` for dynamic code generation
|
|
142
|
+
✅ **REQUIRE Tolerance Blocks** - Conditional bypasses for VIP/admin/emergency scenarios
|
|
143
|
+
✅ **Function-Level Scoping** - LET/CONST documented with scope behavior and shadowing rules
|
|
144
|
+
✅ **Advanced Error Patterns** - Retry, circuit breaker, error aggregation patterns
|
|
145
|
+
|
|
146
|
+
### Bug Fixes & Improvements
|
|
147
|
+
|
|
148
|
+
✅ Fixed array literal parsing (no more duplicate elements)
|
|
149
|
+
✅ Fixed ENUM value accessibility
|
|
150
|
+
✅ Fixed WHILE condition parsing without parentheses
|
|
151
|
+
✅ Fixed loop execution and variable reassignment
|
|
152
|
+
✅ Fixed DEFER cleanup execution
|
|
153
|
+
✅ Fixed SANDBOX return values
|
|
154
|
+
✅ Fixed dependency injection container creation
|
|
155
|
+
✅ Added tolerance blocks for REQUIRE
|
|
156
|
+
✅ Improved error messages and debugging output
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## ✨ Key Features
|
|
161
|
+
|
|
162
|
+
### 🎨 **NEW!** World-Class Error Reporting (v1.5.0)
|
|
163
|
+
|
|
164
|
+
Zexus now features **production-grade error messages** that rival Rust and surpass Python:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
ERROR: SyntaxError[SYNTAX]
|
|
168
|
+
→ myfile.zx:10:16
|
|
169
|
+
|
|
170
|
+
10 | let message = "Hello world
|
|
171
|
+
^
|
|
172
|
+
|
|
173
|
+
Unterminated string literal
|
|
174
|
+
|
|
175
|
+
💡 Suggestion: Add a closing quote " to terminate the string.
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Error Reporting Features:**
|
|
179
|
+
- ✅ **Color-coded output** - Errors in red, warnings in yellow, info in blue
|
|
180
|
+
- ✅ **Source code context** - See exactly where the error occurred
|
|
181
|
+
- ✅ **Helpful suggestions** - Actionable hints for fixing errors
|
|
182
|
+
- ✅ **Beginner-friendly** - Clear messages, no cryptic codes
|
|
183
|
+
- ✅ **Category distinction** - Know if it's your code or an interpreter bug
|
|
184
|
+
- ✅ **Smart detection** - Single `&` suggests `&&`, unclosed strings, etc.
|
|
185
|
+
|
|
186
|
+
**Better than Python**: No confusing indentation errors!
|
|
187
|
+
**On par with Rust**: Same quality formatting and helpful suggestions!
|
|
188
|
+
**Better than TypeScript**: More informative with built-in fix suggestions!
|
|
189
|
+
|
|
190
|
+
[Learn more about error reporting →](docs/ERROR_REPORTING.md)
|
|
191
|
+
|
|
192
|
+
### 📦 **NEW!** Advanced DATA Features (v1.5.0)
|
|
193
|
+
|
|
194
|
+
Complete dataclass system with **8/8 features** including generics and pattern matching:
|
|
195
|
+
|
|
196
|
+
#### Generic Types
|
|
197
|
+
```zexus
|
|
198
|
+
data Box<T> {
|
|
199
|
+
value: T
|
|
200
|
+
|
|
201
|
+
unwrap() { this.value }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
data Pair<K, V> {
|
|
205
|
+
key: K
|
|
206
|
+
value: V
|
|
207
|
+
|
|
208
|
+
operator + (other) {
|
|
209
|
+
Pair(this.key, this.value + other.value)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let numberBox = Box<number>(42)
|
|
214
|
+
let stringBox = Box<string>("hello")
|
|
215
|
+
let pair = Pair<string, number>("age", 30)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Pattern Matching
|
|
219
|
+
```zexus
|
|
220
|
+
data Shape {
|
|
221
|
+
// Base shape
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
data Circle extends Shape {
|
|
225
|
+
radius: number
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
data Rectangle extends Shape {
|
|
229
|
+
width: number
|
|
230
|
+
height: number
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
action calculateArea(shape) {
|
|
234
|
+
match shape {
|
|
235
|
+
Circle(r) => 3.14 * r * r,
|
|
236
|
+
Rectangle(w, h) => w * h,
|
|
237
|
+
_ => 0
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**DATA Features:**
|
|
243
|
+
- ✅ Generic type parameters (`<T>`, `<K, V>`)
|
|
244
|
+
- ✅ Pattern matching with destructuring
|
|
245
|
+
- ✅ Operator overloading
|
|
246
|
+
- ✅ Inheritance and extends
|
|
247
|
+
- ✅ Instance methods
|
|
248
|
+
- ✅ Static methods
|
|
249
|
+
- ✅ Property validation
|
|
250
|
+
- ✅ Immutability options
|
|
251
|
+
|
|
252
|
+
[Learn more about DATA keyword →](docs/keywords/DATA.md)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
let circle = Circle(5)
|
|
257
|
+
let area = calculateArea(circle) // 78.5
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Complete Feature Set:**
|
|
261
|
+
1. ✅ Static `default()` method
|
|
262
|
+
2. ✅ Computed properties with `get`
|
|
263
|
+
3. ✅ Method definitions
|
|
264
|
+
4. ✅ Operator overloading
|
|
265
|
+
5. ✅ Inheritance with `extends`
|
|
266
|
+
6. ✅ Decorators
|
|
267
|
+
7. ✅ **Generic types** (NEW!)
|
|
268
|
+
8. ✅ **Pattern matching** (NEW!)
|
|
269
|
+
|
|
270
|
+
[Learn more about DATA features →](docs/keywords/DATA.md)
|
|
271
|
+
|
|
272
|
+
### ⚡ VM-Accelerated Performance
|
|
273
|
+
|
|
274
|
+
Zexus now includes a sophisticated Virtual Machine for optimized execution:
|
|
275
|
+
|
|
276
|
+
```zexus
|
|
277
|
+
# Automatically optimized via VM
|
|
278
|
+
let sum = 0
|
|
279
|
+
let i = 0
|
|
280
|
+
while (i < 1000) {
|
|
281
|
+
sum = sum + i
|
|
282
|
+
i = i + 1
|
|
283
|
+
}
|
|
284
|
+
# ↑ This loop executes 2-10x faster via bytecode!
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**VM Features:**
|
|
288
|
+
- ✅ Stack-based bytecode execution
|
|
289
|
+
- ✅ Automatic optimization for loops and math-heavy code
|
|
290
|
+
- ✅ Async/await support (SPAWN, AWAIT opcodes)
|
|
291
|
+
- ✅ Function call optimization
|
|
292
|
+
- ✅ Collection operations (lists, maps)
|
|
293
|
+
- ✅ Event system
|
|
294
|
+
- ✅ Module imports
|
|
295
|
+
- ✅ Smart fallback to interpreter for unsupported features
|
|
296
|
+
|
|
297
|
+
[Learn more about VM integration →](VM_INTEGRATION_SUMMARY.md)
|
|
298
|
+
|
|
299
|
+
### 🔐 Security & Policy-as-Code (✨ VERIFY Enhanced!)
|
|
300
|
+
```zexus
|
|
301
|
+
# Define security policies declaratively
|
|
302
|
+
protect(transfer_funds, {
|
|
303
|
+
rate_limit: 100,
|
|
304
|
+
auth_required: true,
|
|
305
|
+
require_https: true,
|
|
306
|
+
allowed_ips: ["10.0.0.0/8"]
|
|
307
|
+
}, "strict")
|
|
308
|
+
|
|
309
|
+
# Enhanced runtime verification with custom logic
|
|
310
|
+
verify is_email(email) {
|
|
311
|
+
log_error("Invalid email attempt");
|
|
312
|
+
block_submission();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
# Access control with blocking
|
|
316
|
+
verify userRole == "admin" {
|
|
317
|
+
log_unauthorized_access(user);
|
|
318
|
+
block_request();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# Database and environment verification
|
|
322
|
+
verify:db userId exists_in "users", "User not found"
|
|
323
|
+
verify:env "API_KEY" is_set, "API_KEY not configured"
|
|
324
|
+
|
|
325
|
+
# Data constraints
|
|
326
|
+
restrict(amount, {
|
|
327
|
+
range: [0, 10000],
|
|
328
|
+
type: "integer"
|
|
329
|
+
})
|
|
330
|
+
```
|
|
331
|
+
**NEW**: VERIFY now includes email/URL/phone validation, pattern matching, database checks, environment variables, input sanitization, and custom logic blocks! [See VERIFY Guide →](docs/VERIFY_ENHANCEMENT_GUIDE.md)
|
|
332
|
+
|
|
333
|
+
### ⛓️ Native Blockchain Support
|
|
334
|
+
```zexus
|
|
335
|
+
# Smart contracts made easy
|
|
336
|
+
contract Token {
|
|
337
|
+
persistent storage balances: Map<Address, integer>
|
|
338
|
+
|
|
339
|
+
action transfer(from: Address, to: Address, amount: integer) {
|
|
340
|
+
require(balances[from] >= amount, "Insufficient balance")
|
|
341
|
+
balances[from] = balances[from] - amount
|
|
342
|
+
balances[to] = balances.get(to, 0) + amount
|
|
343
|
+
emit Transfer(from, to, amount)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### 💾 Persistent Memory Management
|
|
349
|
+
```zexus
|
|
350
|
+
# Store data across program runs
|
|
351
|
+
persist_set("user_preferences", preferences)
|
|
352
|
+
let prefs = persist_get("user_preferences")
|
|
353
|
+
|
|
354
|
+
# Automatic memory tracking
|
|
355
|
+
track_memory() # Detects leaks automatically
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### 🔌 Dependency Injection & Testing
|
|
359
|
+
```zexus
|
|
360
|
+
# Register dependencies
|
|
361
|
+
register_dependency("database", ProductionDB())
|
|
362
|
+
|
|
363
|
+
# Inject at runtime
|
|
364
|
+
inject database
|
|
365
|
+
|
|
366
|
+
# Mock for testing
|
|
367
|
+
test_mode(true)
|
|
368
|
+
mock_dependency("database", MockDB())
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### 👀 Reactive State Management
|
|
372
|
+
```zexus
|
|
373
|
+
# Watch variables for changes
|
|
374
|
+
let count = 0
|
|
375
|
+
watch count {
|
|
376
|
+
print("Count changed to: " + string(count))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
count = 5 # Automatically triggers watch callback
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### 🚀 Advanced Features
|
|
383
|
+
|
|
384
|
+
- **Multi-strategy parsing**: Tolerates syntax variations
|
|
385
|
+
- **Hybrid execution**: Auto-selects interpreter or compiler/VM
|
|
386
|
+
- **Type safety**: Strong typing with inference
|
|
387
|
+
- **Pattern matching**: Powerful match expressions
|
|
388
|
+
- **Async/await**: Built-in concurrency primitives
|
|
389
|
+
- **Module system**: Import/export with access control
|
|
390
|
+
- **Rich built-ins**: 100+ built-in functions
|
|
391
|
+
- **Plugin system**: Extensible architecture
|
|
392
|
+
- **Advanced types**: Entities, Contracts, Enums, Protocols
|
|
393
|
+
- **Syntax flexibility**: Multiple syntax styles (`:` and `=` for assignments)
|
|
394
|
+
- **130+ keywords**: Comprehensive language features
|
|
395
|
+
- **Main entry point**: Run/execute patterns like Python's `if __name__ == "__main__"`
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## 🔍 Why Choose Zexus?
|
|
400
|
+
|
|
401
|
+
### Language Comparison
|
|
402
|
+
|
|
403
|
+
| Feature | Zexus | Python | Solidity | Rust | TypeScript |
|
|
404
|
+
|---------|-------|--------|----------|------|------------|
|
|
405
|
+
| **Blockchain Native** | ✅ Built-in | ❌ Libraries | ✅ Native | ❌ Libraries | ❌ Libraries |
|
|
406
|
+
| **Policy-as-Code** | ✅ Native | ⚠️ Manual | ⚠️ Modifiers | ❌ None | ❌ None |
|
|
407
|
+
| **VM Execution** | ✅ Hybrid | ✅ Bytecode | ✅ EVM | ✅ Native | ⚠️ V8/Node |
|
|
408
|
+
| **Type Safety** | ✅ Strong+Inference | ⚠️ Optional | ✅ Strong | ✅ Strong | ✅ Strong |
|
|
409
|
+
| **Async/Await** | ✅ Native | ✅ Native | ❌ None | ✅ Native | ✅ Native |
|
|
410
|
+
| **Dependency Injection** | ✅ Built-in | ⚠️ Libraries | ❌ None | ⚠️ Manual | ⚠️ Libraries |
|
|
411
|
+
| **Reactive State** | ✅ WATCH | ⚠️ Libraries | ❌ None | ⚠️ Libraries | ⚠️ Libraries |
|
|
412
|
+
| **Memory Tracking** | ✅ Automatic | ⚠️ Manual | ⚠️ Gas-based | ✅ Ownership | ⚠️ Manual |
|
|
413
|
+
| **Security Features** | ✅✅✅ Extensive | ⚠️ Libraries | ⚠️ Limited | ✅ Safe | ⚠️ Libraries |
|
|
414
|
+
| **Syntax Flexibility** | ✅ Multiple styles | ✅ PEP-8 | ✅ Solidity | ✅ Strict | ✅ Strict |
|
|
415
|
+
| **Learning Curve** | 🟢 Easy | 🟢 Easy | 🟡 Medium | 🔴 Hard | 🟡 Medium |
|
|
416
|
+
|
|
417
|
+
### Use Zexus When You Need
|
|
418
|
+
|
|
419
|
+
✅ **Smart contracts without EVM complexity** - Cleaner syntax than Solidity
|
|
420
|
+
✅ **Security-first development** - Built-in policy enforcement
|
|
421
|
+
✅ **Rapid prototyping with production-ready features** - Faster than Rust
|
|
422
|
+
✅ **Cross-platform blockchain apps** - No separate contracts needed
|
|
423
|
+
✅ **Enterprise features out-of-the-box** - DI, middleware, auth, caching
|
|
424
|
+
✅ **Reactive applications** - Built-in WATCH for state management
|
|
425
|
+
✅ **Memory-safe applications** - Automatic leak detection
|
|
426
|
+
|
|
427
|
+
### Zexus = Python's Ease + Solidity's Blockchain + Rust's Safety
|
|
428
|
+
|
|
429
|
+
```zexus
|
|
430
|
+
# Python-like simplicity
|
|
431
|
+
let users = []
|
|
432
|
+
for each user in get_users() {
|
|
433
|
+
print(user.name)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
# Solidity-like contracts
|
|
437
|
+
contract Token {
|
|
438
|
+
persistent storage balances: Map<Address, integer>
|
|
439
|
+
action payable transfer(to, amount) { ... }
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
# Rust-like safety
|
|
443
|
+
verify balance >= amount {
|
|
444
|
+
log_error("Insufficient balance")
|
|
445
|
+
revert("Not enough funds")
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
## 📦 Installation
|
|
452
|
+
|
|
453
|
+
### Quick Install (Recommended)
|
|
454
|
+
|
|
455
|
+
```bash
|
|
456
|
+
pip install zexus
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**Includes:**
|
|
460
|
+
- `zx` - Main Zexus CLI
|
|
461
|
+
- `zpm` - Zexus Package Manager
|
|
462
|
+
|
|
463
|
+
### From Source
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
git clone https://github.com/Zaidux/zexus-interpreter.git
|
|
467
|
+
cd zexus-interpreter
|
|
468
|
+
pip install -e .
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Verify Installation
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
zx --version # Should show: Zexus v1.5.0
|
|
475
|
+
zpm --version # Should show: ZPM v1.5.0
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
## 🚀 Quick Start
|
|
481
|
+
|
|
482
|
+
### 1. Hello World
|
|
483
|
+
|
|
484
|
+
```zexus
|
|
485
|
+
# hello.zx
|
|
486
|
+
let name = "World"
|
|
487
|
+
print("Hello, " + name + "!")
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Run it:
|
|
491
|
+
```bash
|
|
492
|
+
zx run hello.zx
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### 2. Interactive REPL
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
zx repl
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
```zexus
|
|
502
|
+
>> let x = 10 + 5
|
|
503
|
+
>> print(x * 2)
|
|
504
|
+
30
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### 3. Create a Project
|
|
508
|
+
|
|
509
|
+
```bash
|
|
510
|
+
zx init my-app
|
|
511
|
+
cd my-app
|
|
512
|
+
zx run main.zx
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
## 💡 Examples
|
|
518
|
+
|
|
519
|
+
### Example 1: Secure API with Policy-as-Code
|
|
520
|
+
|
|
521
|
+
```zexus
|
|
522
|
+
entity ApiRequest {
|
|
523
|
+
endpoint: string,
|
|
524
|
+
method: string,
|
|
525
|
+
user_id: integer
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
action handle_request(request: ApiRequest) -> string {
|
|
529
|
+
# Verify authentication
|
|
530
|
+
verify(request.user_id > 0)
|
|
531
|
+
|
|
532
|
+
# Restrict input
|
|
533
|
+
restrict(request.method, {
|
|
534
|
+
allowed: ["GET", "POST", "PUT", "DELETE"]
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
return "Request handled successfully"
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
# Protect the endpoint
|
|
541
|
+
protect(handle_request, {
|
|
542
|
+
rate_limit: 100,
|
|
543
|
+
auth_required: true,
|
|
544
|
+
require_https: true
|
|
545
|
+
}, "strict")
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Example 2: Blockchain Token
|
|
549
|
+
|
|
550
|
+
```zexus
|
|
551
|
+
contract ERC20Token {
|
|
552
|
+
persistent storage total_supply: integer
|
|
553
|
+
persistent storage balances: Map<Address, integer>
|
|
554
|
+
|
|
555
|
+
action constructor(initial_supply: integer) {
|
|
556
|
+
total_supply = initial_supply
|
|
557
|
+
balances[msg.sender] = initial_supply
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
action transfer(to: Address, amount: integer) -> boolean {
|
|
561
|
+
require(balances[msg.sender] >= amount, "Insufficient balance")
|
|
562
|
+
balances[msg.sender] = balances[msg.sender] - amount
|
|
563
|
+
balances[to] = balances.get(to, 0) + amount
|
|
564
|
+
emit Transfer(msg.sender, to, amount)
|
|
565
|
+
return true
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
action balance_of(account: Address) -> integer {
|
|
569
|
+
return balances.get(account, 0)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Example 3: Reactive State Management
|
|
575
|
+
|
|
576
|
+
```zexus
|
|
577
|
+
# E-commerce cart with reactive updates
|
|
578
|
+
let cart_items = []
|
|
579
|
+
let cart_total = 0
|
|
580
|
+
|
|
581
|
+
watch cart_items {
|
|
582
|
+
# Recalculate total when cart changes
|
|
583
|
+
cart_total = cart_items.reduce(
|
|
584
|
+
initial: 0,
|
|
585
|
+
transform: total + item.price
|
|
586
|
+
)
|
|
587
|
+
print("Cart updated! New total: $" + string(cart_total))
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
# Add items (automatically triggers watch)
|
|
591
|
+
cart_items.push({name: "Laptop", price: 999})
|
|
592
|
+
cart_items.push({name: "Mouse", price: 29})
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Example 4: VM-Optimized Computation
|
|
596
|
+
|
|
597
|
+
```zexus
|
|
598
|
+
# Fibonacci with automatic VM optimization
|
|
599
|
+
action fibonacci(n: integer) -> integer {
|
|
600
|
+
if n <= 1 {
|
|
601
|
+
return n
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
let a = 0
|
|
605
|
+
let b = 1
|
|
606
|
+
let i = 2
|
|
607
|
+
|
|
608
|
+
while (i <= n) {
|
|
609
|
+
let temp = a + b
|
|
610
|
+
a = b
|
|
611
|
+
b = temp
|
|
612
|
+
i = i + 1
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return b
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
# VM automatically compiles this for faster execution
|
|
619
|
+
let result = fibonacci(100)
|
|
620
|
+
print(result)
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### Example 5: Main Entry Point Pattern
|
|
624
|
+
|
|
625
|
+
```zexus
|
|
626
|
+
# Similar to Python's if __name__ == "__main__"
|
|
627
|
+
action main() {
|
|
628
|
+
print("Running main program")
|
|
629
|
+
let result = process_data()
|
|
630
|
+
print("Result: " + string(result))
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
# Only runs if this is the main module
|
|
634
|
+
if is_main() {
|
|
635
|
+
run(main)
|
|
636
|
+
}
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
### Example 6: Middleware & Enterprise Features
|
|
640
|
+
|
|
641
|
+
```zexus
|
|
642
|
+
# Define authentication middleware
|
|
643
|
+
middleware("auth", action(req, res) {
|
|
644
|
+
if !req.has_token {
|
|
645
|
+
return {status: 401, message: "Unauthorized"}
|
|
646
|
+
}
|
|
647
|
+
return true
|
|
648
|
+
})
|
|
649
|
+
|
|
650
|
+
# Configure authentication
|
|
651
|
+
auth {
|
|
652
|
+
provider: "oauth2",
|
|
653
|
+
scopes: ["read", "write"],
|
|
654
|
+
token_expiry: 3600
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
# Apply rate limiting
|
|
658
|
+
throttle(api_endpoint, {
|
|
659
|
+
requests_per_minute: 100,
|
|
660
|
+
burst: 20
|
|
661
|
+
})
|
|
662
|
+
|
|
663
|
+
# Enable caching
|
|
664
|
+
cache(expensive_query, {
|
|
665
|
+
ttl: 300,
|
|
666
|
+
strategy: "lru"
|
|
667
|
+
})
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
### Example 7: Concurrency with Channels
|
|
671
|
+
|
|
672
|
+
```zexus
|
|
673
|
+
# Create typed channel
|
|
674
|
+
channel<integer> numbers
|
|
675
|
+
|
|
676
|
+
# Producer
|
|
677
|
+
action producer() {
|
|
678
|
+
for each i in range(0, 10) {
|
|
679
|
+
send(numbers, i)
|
|
680
|
+
sleep(0.1)
|
|
681
|
+
}
|
|
682
|
+
close_channel(numbers)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
# Consumer
|
|
686
|
+
action consumer() {
|
|
687
|
+
while true {
|
|
688
|
+
let value = receive(numbers)
|
|
689
|
+
if value == null {
|
|
690
|
+
break
|
|
691
|
+
}
|
|
692
|
+
print("Received: " + string(value))
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
# Run concurrently
|
|
697
|
+
async producer()
|
|
698
|
+
async consumer()
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
### Example 8: Output Redirection & Code Generation with LOG
|
|
702
|
+
|
|
703
|
+
```zexus
|
|
704
|
+
# Redirect output to file for logging
|
|
705
|
+
action processData(items) {
|
|
706
|
+
log > "processing.log"
|
|
707
|
+
print("Processing started at: " + timestamp())
|
|
708
|
+
|
|
709
|
+
for each item in items {
|
|
710
|
+
print("Processing item: " + item)
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
print("Processing complete")
|
|
714
|
+
# Output automatically restored when action exits
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
# Generate Python code dynamically
|
|
718
|
+
action generatePythonModule() {
|
|
719
|
+
log >> "calculator.py"
|
|
720
|
+
print("def add(a, b):")
|
|
721
|
+
print(" return a + b")
|
|
722
|
+
print("")
|
|
723
|
+
print("def multiply(a, b):")
|
|
724
|
+
print(" return a * b")
|
|
725
|
+
print("")
|
|
726
|
+
print("# Generated by Zexus")
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
# Generate and execute code
|
|
730
|
+
generatePythonModule()
|
|
731
|
+
eval_file("calculator.py", "python")
|
|
732
|
+
|
|
733
|
+
# Multiple outputs to different files
|
|
734
|
+
action generateReports() {
|
|
735
|
+
log >> "summary.txt"
|
|
736
|
+
print("Summary Report")
|
|
737
|
+
print("==============")
|
|
738
|
+
|
|
739
|
+
log >> "details.txt"
|
|
740
|
+
print("Detailed Report")
|
|
741
|
+
print("===============")
|
|
742
|
+
}
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
### Example 9: Advanced Error Handling with Tolerance Blocks
|
|
746
|
+
|
|
747
|
+
```zexus
|
|
748
|
+
# REQUIRE with tolerance blocks - VIP bypass
|
|
749
|
+
action processPremiumAccess(user, balance, isVIP) {
|
|
750
|
+
# Standard users need 1.0 ETH, VIP bypass
|
|
751
|
+
require balance >= 1.0 {
|
|
752
|
+
if (isVIP) return true;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
print("Premium access granted to: " + user)
|
|
756
|
+
return true
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
# Advanced error patterns - Circuit breaker
|
|
760
|
+
let failureCount = 0
|
|
761
|
+
let circuitOpen = false
|
|
762
|
+
|
|
763
|
+
action protectedOperation(data) {
|
|
764
|
+
try {
|
|
765
|
+
if (circuitOpen) {
|
|
766
|
+
revert("Circuit breaker activated - too many failures")
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
# Process operation
|
|
770
|
+
let result = processData(data)
|
|
771
|
+
failureCount = 0 # Reset on success
|
|
772
|
+
return result
|
|
773
|
+
} catch (error) {
|
|
774
|
+
failureCount = failureCount + 1
|
|
775
|
+
if (failureCount >= 3) {
|
|
776
|
+
circuitOpen = true
|
|
777
|
+
}
|
|
778
|
+
return null
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
# Retry pattern with error aggregation
|
|
783
|
+
action retryableOperation(maxAttempts) {
|
|
784
|
+
let attempts = 0
|
|
785
|
+
let errors = []
|
|
786
|
+
|
|
787
|
+
while (attempts < maxAttempts) {
|
|
788
|
+
try {
|
|
789
|
+
return performOperation()
|
|
790
|
+
} catch (e) {
|
|
791
|
+
attempts = attempts + 1
|
|
792
|
+
errors = errors + [e]
|
|
793
|
+
if (attempts < maxAttempts) {
|
|
794
|
+
sleep(1) # Wait before retry
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
print("Failed after " + attempts + " attempts")
|
|
800
|
+
return null
|
|
801
|
+
}
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
### Example 10: Error Recovery with CONTINUE Keyword
|
|
805
|
+
|
|
806
|
+
```zexus
|
|
807
|
+
# Enable error recovery mode - continue execution despite errors
|
|
808
|
+
print "=== Batch Processing with Error Recovery ==="
|
|
809
|
+
continue;
|
|
810
|
+
|
|
811
|
+
# Process multiple records, logging errors but not stopping
|
|
812
|
+
action processRecord(id, data) {
|
|
813
|
+
if (data < 0) {
|
|
814
|
+
revert("Invalid data for record " + id);
|
|
815
|
+
return null; # This executes with CONTINUE
|
|
816
|
+
}
|
|
817
|
+
return "Processed: " + data;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
let records = [
|
|
821
|
+
{id: 1, data: 100},
|
|
822
|
+
{id: 2, data: -50}, # Error - but continues
|
|
823
|
+
{id: 3, data: 200},
|
|
824
|
+
{id: 4, data: -30}, # Error - but continues
|
|
825
|
+
{id: 5, data: 300}
|
|
826
|
+
];
|
|
827
|
+
|
|
828
|
+
let successCount = 0;
|
|
829
|
+
for each record in records {
|
|
830
|
+
let result = processRecord(record.id, record.data);
|
|
831
|
+
if (result != null) {
|
|
832
|
+
successCount = successCount + 1;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
print "Processed " + successCount + " out of " + length(records) + " records";
|
|
837
|
+
print "Program completed despite errors!";
|
|
838
|
+
|
|
839
|
+
# Use case: Testing framework
|
|
840
|
+
action runTests() {
|
|
841
|
+
continue; # Run all tests even if some fail
|
|
842
|
+
|
|
843
|
+
test_addition(); # Pass
|
|
844
|
+
test_subtraction(); # Fail - but continue
|
|
845
|
+
test_multiplication(); # Pass
|
|
846
|
+
test_division(); # Fail - but continue
|
|
847
|
+
|
|
848
|
+
print "All tests executed!";
|
|
849
|
+
}
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
---
|
|
853
|
+
|
|
854
|
+
## 📚 Complete Feature Reference
|
|
855
|
+
|
|
856
|
+
### Core Language Features
|
|
857
|
+
|
|
858
|
+
#### Variables & Constants
|
|
859
|
+
```zexus
|
|
860
|
+
# Multiple syntax options supported
|
|
861
|
+
let mutable_var = 42 # Standard assignment
|
|
862
|
+
let mutable_var : 42 # Colon syntax (tolerant style)
|
|
863
|
+
let typed_var : int = 42 # With type annotation
|
|
864
|
+
const IMMUTABLE = 3.14159 # Immutable constant
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
**Variable Scoping**: Zexus uses function-level scoping (not block-level). Variables can only be shadowed within function boundaries.
|
|
868
|
+
|
|
869
|
+
#### Data Types
|
|
870
|
+
- **Primitives**: Integer, Float, String, Boolean, Null
|
|
871
|
+
- **Collections**: List, Map, Set
|
|
872
|
+
- **Advanced**: Entity, Contract, Action, Lambda
|
|
873
|
+
- **Special**: DateTime, File, Math
|
|
874
|
+
|
|
875
|
+
#### Functions
|
|
876
|
+
```zexus
|
|
877
|
+
action greet(name: string) -> string {
|
|
878
|
+
return "Hello, " + name
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
# Lambda functions
|
|
882
|
+
let double = lambda(x) { x * 2 }
|
|
883
|
+
|
|
884
|
+
# Deferred cleanup (executes on scope exit)
|
|
885
|
+
defer {
|
|
886
|
+
cleanup_resources()
|
|
887
|
+
}
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
#### Debugging
|
|
891
|
+
```zexus
|
|
892
|
+
# DUAL-MODE DEBUG:
|
|
893
|
+
# Function mode - returns value, usable in expressions
|
|
894
|
+
let x = debug(42) # Outputs: [DEBUG] 42, x = 42
|
|
895
|
+
|
|
896
|
+
# Statement mode - logs with metadata
|
|
897
|
+
debug myVariable; # Outputs: 🔍 DEBUG: <value> with context
|
|
898
|
+
|
|
899
|
+
# Other debug tools
|
|
900
|
+
debug_log("message", context)
|
|
901
|
+
debug_trace() # Stack trace
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
#### Control Flow
|
|
905
|
+
```zexus
|
|
906
|
+
# Conditionals
|
|
907
|
+
if condition {
|
|
908
|
+
# code
|
|
909
|
+
} elif other_condition {
|
|
910
|
+
# code
|
|
911
|
+
} else {
|
|
912
|
+
# code
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
# Loops
|
|
916
|
+
while condition {
|
|
917
|
+
# code
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
for each item in collection {
|
|
921
|
+
# code
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
# Pattern Matching
|
|
925
|
+
match value {
|
|
926
|
+
case 1: print("One")
|
|
927
|
+
case 2: print("Two")
|
|
928
|
+
default: print("Other")
|
|
929
|
+
}
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### Entities & Contracts
|
|
933
|
+
```zexus
|
|
934
|
+
entity User {
|
|
935
|
+
name: string,
|
|
936
|
+
age: integer,
|
|
937
|
+
email: string
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
contract MyContract {
|
|
941
|
+
persistent storage state: integer
|
|
942
|
+
|
|
943
|
+
action update(new_value: integer) {
|
|
944
|
+
state = new_value
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
### Advanced Features
|
|
950
|
+
|
|
951
|
+
#### 🔐 Security Features
|
|
952
|
+
|
|
953
|
+
**PROTECT** - Policy-as-code security:
|
|
954
|
+
```zexus
|
|
955
|
+
protect(function_name, {
|
|
956
|
+
rate_limit: 100, # Max calls per minute
|
|
957
|
+
auth_required: true, # Require authentication
|
|
958
|
+
require_https: true, # HTTPS only
|
|
959
|
+
allowed_ips: ["10.0.0.0/8"], # IP allowlist
|
|
960
|
+
blocked_ips: ["192.168.1.100"], # IP blocklist
|
|
961
|
+
log_access: true # Audit logging
|
|
962
|
+
}, "strict") # Enforcement mode: strict, warn, log
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
**VERIFY** - Runtime assertions:
|
|
966
|
+
```zexus
|
|
967
|
+
verify(user.is_admin)
|
|
968
|
+
verify(amount > 0 and amount < 1000)
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
**RESTRICT** - Input validation:
|
|
972
|
+
```zexus
|
|
973
|
+
restrict(input_value, {
|
|
974
|
+
type: "string",
|
|
975
|
+
min_length: 5,
|
|
976
|
+
max_length: 100,
|
|
977
|
+
pattern: "^[a-zA-Z0-9]+$",
|
|
978
|
+
range: [0, 100], # For numbers
|
|
979
|
+
allowed: ["GET", "POST"] # Enum values
|
|
980
|
+
})
|
|
981
|
+
```
|
|
982
|
+
|
|
983
|
+
**SEAL** - Immutable objects:
|
|
984
|
+
```zexus
|
|
985
|
+
seal(config) # Make config immutable
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
**SANDBOX** - Isolated execution:
|
|
989
|
+
```zexus
|
|
990
|
+
sandbox {
|
|
991
|
+
# Code runs in restricted environment
|
|
992
|
+
# Limited file system, network access
|
|
993
|
+
}
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
**TRAIL** - Audit logging:
|
|
997
|
+
```zexus
|
|
998
|
+
trail(operation, "user_action", {
|
|
999
|
+
user_id: user.id,
|
|
1000
|
+
action: "transfer",
|
|
1001
|
+
amount: 1000
|
|
1002
|
+
})
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
#### 💾 Persistence & Memory
|
|
1006
|
+
|
|
1007
|
+
**Persistent Storage:**
|
|
1008
|
+
```zexus
|
|
1009
|
+
persist_set("key", value)
|
|
1010
|
+
let value = persist_get("key")
|
|
1011
|
+
persist_clear("key")
|
|
1012
|
+
let all_keys = persist_list()
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
**Memory Tracking:**
|
|
1016
|
+
```zexus
|
|
1017
|
+
track_memory() # Enable tracking
|
|
1018
|
+
let stats = memory_stats() # Get statistics
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
#### 🔌 Dependency Injection
|
|
1022
|
+
|
|
1023
|
+
**Register Dependencies:**
|
|
1024
|
+
```zexus
|
|
1025
|
+
register_dependency("logger", FileLogger("/var/log/app.log"))
|
|
1026
|
+
register_dependency("database", PostgresDB("localhost:5432"))
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
**Inject Dependencies:**
|
|
1030
|
+
```zexus
|
|
1031
|
+
inject logger
|
|
1032
|
+
inject database
|
|
1033
|
+
|
|
1034
|
+
action save_user(user: Entity) {
|
|
1035
|
+
logger.info("Saving user: " + user.name)
|
|
1036
|
+
database.insert("users", user)
|
|
1037
|
+
}
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
**Mocking for Tests:**
|
|
1041
|
+
```zexus
|
|
1042
|
+
test_mode(true)
|
|
1043
|
+
mock_dependency("logger", MockLogger())
|
|
1044
|
+
mock_dependency("database", MockDB())
|
|
1045
|
+
|
|
1046
|
+
# Now all injected dependencies use mocks
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
#### 👀 Reactive State (WATCH)
|
|
1050
|
+
|
|
1051
|
+
```zexus
|
|
1052
|
+
let counter = 0
|
|
1053
|
+
|
|
1054
|
+
watch counter {
|
|
1055
|
+
print("Counter changed to: " + string(counter))
|
|
1056
|
+
# Can trigger other logic
|
|
1057
|
+
if counter > 10 {
|
|
1058
|
+
send_alert()
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
counter = counter + 1 # Triggers watch
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
#### ⛓️ Blockchain Features
|
|
1066
|
+
|
|
1067
|
+
**Transactions:**
|
|
1068
|
+
```zexus
|
|
1069
|
+
let tx = transaction({
|
|
1070
|
+
from: sender_address,
|
|
1071
|
+
to: recipient_address,
|
|
1072
|
+
value: 100,
|
|
1073
|
+
data: "0x1234"
|
|
1074
|
+
})
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
**Events:**
|
|
1078
|
+
```zexus
|
|
1079
|
+
emit Transfer(from, to, amount)
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
**Smart Contract Primitives:**
|
|
1083
|
+
```zexus
|
|
1084
|
+
require(condition, "Error message") # Revert if false
|
|
1085
|
+
assert(condition) # Always check
|
|
1086
|
+
revert("Reason") # Explicit revert
|
|
1087
|
+
let balance = balance_of(address)
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
**Cryptographic Functions:**
|
|
1091
|
+
```zexus
|
|
1092
|
+
let hash = keccak256(data)
|
|
1093
|
+
let sig = signature(data, private_key)
|
|
1094
|
+
let valid = verify_sig(data, sig, public_key)
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
#### 🔄 Concurrency
|
|
1098
|
+
|
|
1099
|
+
**Async/Await:**
|
|
1100
|
+
```zexus
|
|
1101
|
+
async action fetch_data(url: string) -> string {
|
|
1102
|
+
let response = await http_get(url)
|
|
1103
|
+
return response.body
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
let data = await fetch_data("https://api.example.com/data")
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
**Channels:**
|
|
1110
|
+
```zexus
|
|
1111
|
+
channel messages
|
|
1112
|
+
|
|
1113
|
+
# Send
|
|
1114
|
+
messages.send("Hello")
|
|
1115
|
+
|
|
1116
|
+
# Receive
|
|
1117
|
+
let msg = messages.receive()
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
**Atomic Operations:**
|
|
1121
|
+
```zexus
|
|
1122
|
+
atomic {
|
|
1123
|
+
# Thread-safe operations
|
|
1124
|
+
counter = counter + 1
|
|
1125
|
+
}
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
#### 📦 Module System
|
|
1129
|
+
|
|
1130
|
+
```zexus
|
|
1131
|
+
# Export from module
|
|
1132
|
+
export action public_function() {
|
|
1133
|
+
return "accessible"
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
private action internal_function() {
|
|
1137
|
+
return "not exported"
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
# Import in another file
|
|
1141
|
+
use {public_function} from "mymodule"
|
|
1142
|
+
|
|
1143
|
+
# Import with alias
|
|
1144
|
+
use {public_function as pf} from "mymodule"
|
|
1145
|
+
|
|
1146
|
+
# Import entire module
|
|
1147
|
+
use * from "utilities"
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
#### 🎨 Pattern Matching
|
|
1151
|
+
|
|
1152
|
+
```zexus
|
|
1153
|
+
match response_code {
|
|
1154
|
+
case 200: print("Success")
|
|
1155
|
+
case 404: print("Not Found")
|
|
1156
|
+
case 500: print("Server Error")
|
|
1157
|
+
case x where x >= 400 and x < 500: print("Client Error")
|
|
1158
|
+
default: print("Unknown status")
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
# Pattern matching with destructuring
|
|
1162
|
+
match request {
|
|
1163
|
+
case {method: "GET", path: p}: handle_get(p)
|
|
1164
|
+
case {method: "POST", body: b}: handle_post(b)
|
|
1165
|
+
default: handle_other()
|
|
1166
|
+
}
|
|
1167
|
+
```
|
|
1168
|
+
|
|
1169
|
+
#### 🔧 Advanced Types
|
|
1170
|
+
|
|
1171
|
+
**Enums:**
|
|
1172
|
+
```zexus
|
|
1173
|
+
enum Status {
|
|
1174
|
+
PENDING,
|
|
1175
|
+
ACTIVE,
|
|
1176
|
+
COMPLETED,
|
|
1177
|
+
CANCELLED
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
let status = Status.ACTIVE
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
**Protocols (Interfaces):**
|
|
1184
|
+
```zexus
|
|
1185
|
+
protocol Serializable {
|
|
1186
|
+
action serialize() -> string
|
|
1187
|
+
action deserialize(data: string) -> Entity
|
|
1188
|
+
}
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
**Type Aliases:**
|
|
1192
|
+
```zexus
|
|
1193
|
+
type_alias UserId = integer
|
|
1194
|
+
type_alias UserMap = Map<UserId, User>
|
|
1195
|
+
```
|
|
1196
|
+
|
|
1197
|
+
### Built-in Functions (100+)
|
|
1198
|
+
|
|
1199
|
+
#### I/O Functions
|
|
1200
|
+
```zexus
|
|
1201
|
+
print(value) # Print without newline
|
|
1202
|
+
println(value) # Print with newline
|
|
1203
|
+
input(prompt) # Get user input
|
|
1204
|
+
read_text(path) # Read text file
|
|
1205
|
+
write_text(path, content) # Write text file
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
#### Type Conversion
|
|
1209
|
+
```zexus
|
|
1210
|
+
string(value) # Convert to string
|
|
1211
|
+
int(value) # Convert to integer
|
|
1212
|
+
float(value) # Convert to float
|
|
1213
|
+
bool(value) # Convert to boolean
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
#### Collection Operations
|
|
1217
|
+
```zexus
|
|
1218
|
+
len(collection) # Length/size
|
|
1219
|
+
list(items...) # Create list
|
|
1220
|
+
map(pairs...) # Create map
|
|
1221
|
+
set(items...) # Create set
|
|
1222
|
+
range(start, end, step) # Generate range
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
#### Functional Programming
|
|
1226
|
+
```zexus
|
|
1227
|
+
filter(collection, predicate) # Filter elements
|
|
1228
|
+
map(collection, transform) # Transform elements
|
|
1229
|
+
reduce(collection, fn, initial) # Reduce to single value
|
|
1230
|
+
sort(collection, comparator) # Sort elements
|
|
1231
|
+
reverse(collection) # Reverse order
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
#### String Operations
|
|
1235
|
+
```zexus
|
|
1236
|
+
join(array, separator) # Join strings
|
|
1237
|
+
split(string, delimiter) # Split string
|
|
1238
|
+
replace(string, old, new) # Replace substring
|
|
1239
|
+
uppercase(string) # Convert to uppercase
|
|
1240
|
+
lowercase(string) # Convert to lowercase
|
|
1241
|
+
trim(string) # Remove whitespace
|
|
1242
|
+
substring(string, start, end) # Extract substring
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
#### Math Operations
|
|
1246
|
+
```zexus
|
|
1247
|
+
abs(number) # Absolute value
|
|
1248
|
+
ceil(number) # Ceiling
|
|
1249
|
+
floor(number) # Floor
|
|
1250
|
+
round(number, decimals) # Round
|
|
1251
|
+
min(numbers...) # Minimum
|
|
1252
|
+
max(numbers...) # Maximum
|
|
1253
|
+
sum(numbers) # Sum
|
|
1254
|
+
sqrt(number) # Square root
|
|
1255
|
+
pow(base, exponent) # Power
|
|
1256
|
+
random() # Random number
|
|
1257
|
+
random(max) # Random 0 to max
|
|
1258
|
+
random(min, max) # Random in range
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
#### Date & Time
|
|
1262
|
+
```zexus
|
|
1263
|
+
now() # Current datetime
|
|
1264
|
+
timestamp() # Unix timestamp
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1267
|
+
#### File I/O
|
|
1268
|
+
```zexus
|
|
1269
|
+
file_read_text(path) # Read text file
|
|
1270
|
+
file_write_text(path, content) # Write text file
|
|
1271
|
+
file_exists(path) # Check if file exists
|
|
1272
|
+
file_read_json(path) # Read JSON file
|
|
1273
|
+
file_write_json(path, data) # Write JSON file
|
|
1274
|
+
file_append(path, content) # Append to file
|
|
1275
|
+
file_list_dir(path) # List directory
|
|
1276
|
+
read_file(path) # Read file contents (alias for file_read_text)
|
|
1277
|
+
eval_file(path, [language]) # Execute code from file (Zexus, Python, JS)
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
**New in v0.1.3**: `read_file()` and `eval_file()` enable dynamic code generation and multi-language execution:
|
|
1281
|
+
```zexus
|
|
1282
|
+
# Generate and execute Zexus code
|
|
1283
|
+
log >> "helper.zx"
|
|
1284
|
+
print("action add(a, b) { return a + b; }")
|
|
1285
|
+
eval_file("helper.zx")
|
|
1286
|
+
let result = add(5, 10) # Uses generated function
|
|
1287
|
+
|
|
1288
|
+
# Execute Python code
|
|
1289
|
+
log >> "script.py"
|
|
1290
|
+
print("print('Hello from Python!')")
|
|
1291
|
+
eval_file("script.py", "python")
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
#### Persistence
|
|
1295
|
+
```zexus
|
|
1296
|
+
persist_set(key, value) # Store persistent data
|
|
1297
|
+
persist_get(key) # Retrieve persistent data
|
|
1298
|
+
persist_clear(key) # Delete persistent data
|
|
1299
|
+
persist_list() # List all keys
|
|
1300
|
+
```
|
|
1301
|
+
|
|
1302
|
+
#### Memory Management
|
|
1303
|
+
```zexus
|
|
1304
|
+
track_memory() # Enable memory tracking
|
|
1305
|
+
memory_stats() # Get memory statistics
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
#### Security & Policy
|
|
1309
|
+
```zexus
|
|
1310
|
+
protect(function, policy, mode) # Apply security policy
|
|
1311
|
+
verify(condition) # Runtime verification
|
|
1312
|
+
restrict(value, constraints) # Validate input
|
|
1313
|
+
create_policy(rules) # Create custom policy
|
|
1314
|
+
enforce_policy(policy, value) # Apply policy
|
|
1315
|
+
```
|
|
1316
|
+
|
|
1317
|
+
#### Dependency Injection
|
|
1318
|
+
```zexus
|
|
1319
|
+
register_dependency(name, impl) # Register dependency
|
|
1320
|
+
inject_dependency(name) # Inject dependency
|
|
1321
|
+
mock_dependency(name, mock) # Mock for testing
|
|
1322
|
+
test_mode(enabled) # Enable/disable test mode
|
|
1323
|
+
```
|
|
1324
|
+
|
|
1325
|
+
#### Concurrency & Channels
|
|
1326
|
+
```zexus
|
|
1327
|
+
channel<type> name # Create typed channel
|
|
1328
|
+
send(channel, value) # Send to channel
|
|
1329
|
+
receive(channel) # Receive from channel
|
|
1330
|
+
close_channel(channel) # Close channel
|
|
1331
|
+
atomic { } # Atomic operation block
|
|
1332
|
+
```
|
|
1333
|
+
emit(event, ...args) # Emit event
|
|
1334
|
+
require(condition, message) # Assert with revert
|
|
1335
|
+
assert(condition) # Assert
|
|
1336
|
+
balance_of(address) # Get balance
|
|
1337
|
+
transfer(to, amount) # Transfer value
|
|
1338
|
+
hash(data) # Hash data
|
|
1339
|
+
keccak256(data) # Keccak-256 hash
|
|
1340
|
+
signature(data, key) # Sign data
|
|
1341
|
+
verify_sig(data, sig, key) # Verify signature
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
#### Renderer (UI)
|
|
1345
|
+
```zexus
|
|
1346
|
+
define_screen(name, props) # Define UI screen
|
|
1347
|
+
define_component(name, props) # Define component
|
|
1348
|
+
render_screen(name) # Render screen
|
|
1349
|
+
set_theme(theme) # Set UI theme
|
|
1350
|
+
create_canvas(width, height) # Create drawing canvas
|
|
1351
|
+
draw_line(canvas, x1, y1, x2, y2) # Draw line
|
|
1352
|
+
draw_text(canvas, text, x, y) # Draw text
|
|
1353
|
+
```
|
|
1354
|
+
|
|
1355
|
+
#### Debug & Development
|
|
1356
|
+
```zexus
|
|
1357
|
+
debug(value) # Debug function (returns value)
|
|
1358
|
+
debug value; # Debug statement (logs with metadata)
|
|
1359
|
+
debug_log(message, context) # Debug logging
|
|
1360
|
+
debug_trace() # Stack trace
|
|
1361
|
+
is_main() # Check if module is main entry point
|
|
1362
|
+
exit_program(code) # Exit with status code
|
|
1363
|
+
module_info() # Get module metadata
|
|
1364
|
+
```
|
|
1365
|
+
|
|
1366
|
+
#### Main Entry Point Features
|
|
1367
|
+
```zexus
|
|
1368
|
+
run(task_fn) # Execute task function
|
|
1369
|
+
execute(fn) # Execute function immediately
|
|
1370
|
+
is_main() # True if current module is main
|
|
1371
|
+
exit_program(code) # Exit with status code
|
|
1372
|
+
on_start(fn) # Register startup handler
|
|
1373
|
+
on_exit(fn) # Register cleanup handler
|
|
1374
|
+
signal_handler(signal, fn) # Handle OS signals
|
|
1375
|
+
schedule(fn, delay) # Schedule delayed execution
|
|
1376
|
+
sleep(seconds) # Sleep for duration
|
|
1377
|
+
daemonize(fn) # Run as background daemon
|
|
1378
|
+
watch_and_reload(path) # Auto-reload on file changes
|
|
1379
|
+
get_module_name() # Get current module name
|
|
1380
|
+
get_module_path() # Get current module path
|
|
1381
|
+
list_imports() # List imported modules
|
|
1382
|
+
get_exported_names() # List exported names
|
|
1383
|
+
```
|
|
1384
|
+
|
|
1385
|
+
#### Validation & Verification
|
|
1386
|
+
```zexus
|
|
1387
|
+
is_email(string) # Validate email format
|
|
1388
|
+
is_url(string) # Validate URL format
|
|
1389
|
+
is_phone(string) # Validate phone format
|
|
1390
|
+
is_numeric(string) # Check if numeric
|
|
1391
|
+
is_alpha(string) # Check if alphabetic
|
|
1392
|
+
is_alphanumeric(string) # Check if alphanumeric
|
|
1393
|
+
matches_pattern(str, pattern) # Regex pattern matching
|
|
1394
|
+
password_strength(password) # Check password strength
|
|
1395
|
+
sanitize_input(text, type) # Sanitize user input
|
|
1396
|
+
validate_length(str, min, max) # Validate string length
|
|
1397
|
+
env_get(name) # Get environment variable
|
|
1398
|
+
env_set(name, value) # Set environment variable
|
|
1399
|
+
env_exists(name) # Check if env var exists
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
---
|
|
1403
|
+
|
|
1404
|
+
## 📖 Complete Keyword Reference
|
|
1405
|
+
|
|
1406
|
+
Zexus supports **130+ keywords** organized into functional categories:
|
|
1407
|
+
|
|
1408
|
+
### Core Language Keywords
|
|
1409
|
+
|
|
1410
|
+
#### Variable Declaration & Constants
|
|
1411
|
+
- **`let`** - Mutable variable declaration (supports `=` and `:` syntax)
|
|
1412
|
+
- **`const`** - Immutable constant declaration
|
|
1413
|
+
- **`immutable`** - Mark variable as permanently immutable
|
|
1414
|
+
|
|
1415
|
+
#### Control Flow
|
|
1416
|
+
- **`if`** / **`elif`** / **`else`** - Conditional execution
|
|
1417
|
+
- **`while`** - While loop
|
|
1418
|
+
- **`for`** / **`each`** / **`in`** - For-each iteration
|
|
1419
|
+
- **`match`** / **`case`** / **`default`** - Pattern matching
|
|
1420
|
+
- **`break`** / **`continue`** - Loop control
|
|
1421
|
+
- **`return`** - Return from function
|
|
1422
|
+
|
|
1423
|
+
#### Functions & Actions
|
|
1424
|
+
- **`action`** - Define action (Zexus function)
|
|
1425
|
+
- **`function`** - Define function
|
|
1426
|
+
- **`lambda`** - Anonymous function
|
|
1427
|
+
- **`defer`** - Deferred cleanup execution
|
|
1428
|
+
|
|
1429
|
+
#### I/O & Output
|
|
1430
|
+
- **`print`** - Output to console
|
|
1431
|
+
- **`debug`** - Debug output (dual-mode: function returns value, statement logs with metadata)
|
|
1432
|
+
- **`log`** - Redirect output to file (scope-aware, supports any extension)
|
|
1433
|
+
|
|
1434
|
+
#### Types & Structures
|
|
1435
|
+
- **`entity`** - Define data structure
|
|
1436
|
+
- **`data`** - Define dataclass with generics and pattern matching (v1.5.0)
|
|
1437
|
+
- **`enum`** - Define enumeration
|
|
1438
|
+
- **`protocol`** / **`interface`** - Define interface
|
|
1439
|
+
- **`type_alias`** - Create type alias
|
|
1440
|
+
- **`implements`** - Implement protocol
|
|
1441
|
+
|
|
1442
|
+
### Module System Keywords
|
|
1443
|
+
|
|
1444
|
+
- **`use`** - Import modules/symbols
|
|
1445
|
+
- **`import`** - Alternative import syntax
|
|
1446
|
+
- **`export`** - Export symbols
|
|
1447
|
+
- **`module`** - Define module
|
|
1448
|
+
- **`package`** - Define package/namespace
|
|
1449
|
+
- **`from`** - Import from specific module
|
|
1450
|
+
- **`external`** - Declare external function
|
|
1451
|
+
|
|
1452
|
+
**Note**: All keywords link to detailed documentation with syntax examples and use cases. See the [Documentation](#-documentation) section below for comprehensive guides.
|
|
1453
|
+
|
|
1454
|
+
### Security & Policy Keywords
|
|
1455
|
+
|
|
1456
|
+
#### Policy Enforcement
|
|
1457
|
+
- **`protect`** - Apply security policy to function
|
|
1458
|
+
- **`verify`** - Runtime verification with custom logic
|
|
1459
|
+
- **`restrict`** - Input validation and constraints
|
|
1460
|
+
- **`require`** - Assert condition (with tolerance blocks)
|
|
1461
|
+
- **`assert`** - Always-check assertion
|
|
1462
|
+
|
|
1463
|
+
#### Access Control & Isolation
|
|
1464
|
+
- **`seal`** - Make object immutable
|
|
1465
|
+
- **`sandbox`** - Isolated execution environment
|
|
1466
|
+
- **`audit`** - Compliance logging
|
|
1467
|
+
- **`trail`** - Event tracking and audit trails
|
|
1468
|
+
- **`capability`** - Define capability
|
|
1469
|
+
- **`grant`** / **`revoke`** - Capability management
|
|
1470
|
+
|
|
1471
|
+
#### Data Validation
|
|
1472
|
+
- **`validate`** - Schema validation
|
|
1473
|
+
- **`sanitize`** - Input sanitization
|
|
1474
|
+
|
|
1475
|
+
### Blockchain Keywords
|
|
1476
|
+
|
|
1477
|
+
#### Smart Contracts
|
|
1478
|
+
- **`contract`** - Define smart contract
|
|
1479
|
+
- **`state`** - Mutable contract state
|
|
1480
|
+
- **`ledger`** - Immutable ledger
|
|
1481
|
+
- **`persistent`** / **`storage`** - Persistent storage
|
|
1482
|
+
- **`tx`** - Transaction context
|
|
1483
|
+
- **`gas`** - Gas tracking
|
|
1484
|
+
- **`limit`** - Gas/resource limits
|
|
1485
|
+
|
|
1486
|
+
#### Cryptography
|
|
1487
|
+
- **`hash`** - Cryptographic hashing
|
|
1488
|
+
- **`signature`** - Digital signatures
|
|
1489
|
+
- **`verify_sig`** - Signature verification
|
|
1490
|
+
|
|
1491
|
+
#### Contract Features
|
|
1492
|
+
- **`emit`** - Emit event
|
|
1493
|
+
- **`event`** - Event type
|
|
1494
|
+
- **`revert`** - Revert transaction
|
|
1495
|
+
- **`this`** - Current contract reference
|
|
1496
|
+
|
|
1497
|
+
### Modifiers
|
|
1498
|
+
|
|
1499
|
+
#### Visibility
|
|
1500
|
+
- **`public`** - Public visibility (auto-export)
|
|
1501
|
+
- **`private`** - Private/module-only visibility
|
|
1502
|
+
|
|
1503
|
+
#### Contract Modifiers
|
|
1504
|
+
- **`pure`** / **`view`** - Read-only functions
|
|
1505
|
+
- **`payable`** - Can receive value
|
|
1506
|
+
- **`modifier`** - Define function modifier
|
|
1507
|
+
- **`sealed`** - Prevent override
|
|
1508
|
+
- **`secure`** - Security flag
|
|
1509
|
+
|
|
1510
|
+
### Concurrency & Async Keywords
|
|
1511
|
+
|
|
1512
|
+
- **`async`** - Async function
|
|
1513
|
+
- **`await`** - Await promise/coroutine
|
|
1514
|
+
- **`channel`** - Create channel
|
|
1515
|
+
- **`send`** / **`receive`** - Channel operations
|
|
1516
|
+
- **`atomic`** - Atomic operation block
|
|
1517
|
+
- **`stream`** - Event streaming
|
|
1518
|
+
- **`watch`** - Reactive state monitoring
|
|
1519
|
+
|
|
1520
|
+
### Error Handling Keywords
|
|
1521
|
+
|
|
1522
|
+
- **`try`** / **`catch`** - Exception handling
|
|
1523
|
+
- **`throw`** - Throw exception
|
|
1524
|
+
- **`finally`** - Cleanup block
|
|
1525
|
+
- **`require`** - Assert condition (with tolerance blocks for conditional bypasses)
|
|
1526
|
+
- **`revert`** - Revert transaction
|
|
1527
|
+
- **`continue`** - Enable error recovery mode (execution continues despite errors)
|
|
1528
|
+
|
|
1529
|
+
**New in v1.5.0**: CONTINUE enables error recovery mode - program continues running even when errors occur:
|
|
1530
|
+
```zexus
|
|
1531
|
+
# Enable error recovery mode
|
|
1532
|
+
continue;
|
|
1533
|
+
|
|
1534
|
+
# Errors are logged but don't halt execution
|
|
1535
|
+
revert("Error 1"); # Logged, execution continues
|
|
1536
|
+
print "Still running!";
|
|
1537
|
+
|
|
1538
|
+
revert("Error 2"); # Logged, execution continues
|
|
1539
|
+
print "Program completed despite errors!";
|
|
1540
|
+
```
|
|
1541
|
+
|
|
1542
|
+
**New in v0.1.3**: REQUIRE supports tolerance blocks for conditional requirement bypasses:
|
|
1543
|
+
```zexus
|
|
1544
|
+
# VIP users bypass balance requirement
|
|
1545
|
+
require balance >= 0.1 {
|
|
1546
|
+
if (isVIP) return true;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
# Emergency admin access overrides maintenance mode
|
|
1550
|
+
require !maintenanceMode {
|
|
1551
|
+
if (isAdmin && emergency) return true;
|
|
1552
|
+
}
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
### Performance Optimization Keywords
|
|
1556
|
+
|
|
1557
|
+
- **`native`** - Native C/C++ FFI
|
|
1558
|
+
- **`inline`** - Function inlining hint
|
|
1559
|
+
- **`gc`** - Garbage collection control
|
|
1560
|
+
- **`buffer`** - Memory buffer operations
|
|
1561
|
+
- **`simd`** - SIMD vector operations
|
|
1562
|
+
|
|
1563
|
+
### Advanced Language Features
|
|
1564
|
+
|
|
1565
|
+
- **`pattern`** - Pattern matching blocks
|
|
1566
|
+
- **`exactly`** - Exact matching block
|
|
1567
|
+
- **`embedded`** - Embed foreign language code
|
|
1568
|
+
- **`using`** - Resource management
|
|
1569
|
+
|
|
1570
|
+
### Renderer/UI Keywords
|
|
1571
|
+
|
|
1572
|
+
- **`screen`** - Define UI screen
|
|
1573
|
+
- **`component`** - Define UI component
|
|
1574
|
+
- **`theme`** - Theme declaration
|
|
1575
|
+
- **`canvas`** - Canvas for drawing
|
|
1576
|
+
- **`graphics`** - Graphics context
|
|
1577
|
+
- **`animation`** - Animation definition
|
|
1578
|
+
- **`clock`** - Timing/clock
|
|
1579
|
+
- **`color`** - Color definition
|
|
1580
|
+
|
|
1581
|
+
### Enterprise Features
|
|
1582
|
+
|
|
1583
|
+
- **`middleware`** - Request/response middleware
|
|
1584
|
+
- **`auth`** - Authentication configuration
|
|
1585
|
+
- **`throttle`** - Rate limiting
|
|
1586
|
+
- **`cache`** - Caching directive
|
|
1587
|
+
- **`inject`** - Dependency injection
|
|
1588
|
+
|
|
1589
|
+
### Special Keywords
|
|
1590
|
+
|
|
1591
|
+
- **`true`** / **`false`** - Boolean literals
|
|
1592
|
+
- **`null`** - Null value
|
|
1593
|
+
- **`map`** - Map/object literal
|
|
1594
|
+
|
|
1595
|
+
### Reserved Transaction Context
|
|
1596
|
+
|
|
1597
|
+
- **`TX`** - Global transaction context object with properties:
|
|
1598
|
+
- `TX.caller` - Transaction sender
|
|
1599
|
+
- `TX.value` - Sent value
|
|
1600
|
+
- `TX.timestamp` - Block timestamp
|
|
1601
|
+
- `TX.block_hash` - Current block hash
|
|
1602
|
+
- `TX.gas_used` - Gas consumed
|
|
1603
|
+
- `TX.gas_remaining` - Gas remaining
|
|
1604
|
+
- `TX.gas_limit` - Gas limit
|
|
1605
|
+
|
|
1606
|
+
[Complete keyword testing documentation →](docs/KEYWORD_TESTING_MASTER_LIST.md)
|
|
1607
|
+
|
|
1608
|
+
---
|
|
1609
|
+
|
|
1610
|
+
## 🎮 CLI Commands
|
|
1611
|
+
|
|
1612
|
+
### Zexus CLI (`zx`)
|
|
1613
|
+
|
|
1614
|
+
```bash
|
|
1615
|
+
# Execution
|
|
1616
|
+
zx run program.zx # Run a program
|
|
1617
|
+
zx run --debug program.zx # Run with debugging
|
|
1618
|
+
zx repl # Start interactive REPL
|
|
1619
|
+
|
|
1620
|
+
# Analysis
|
|
1621
|
+
zx check program.zx # Check syntax
|
|
1622
|
+
zx validate program.zx # Validate and auto-fix
|
|
1623
|
+
zx ast program.zx # Show AST
|
|
1624
|
+
zx tokens program.zx # Show tokens
|
|
1625
|
+
|
|
1626
|
+
# Project Management
|
|
1627
|
+
zx init my-project # Create new project
|
|
1628
|
+
zx test # Run tests
|
|
1629
|
+
|
|
1630
|
+
# Configuration
|
|
1631
|
+
zx debug on # Enable debugging
|
|
1632
|
+
zx debug off # Disable debugging
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
**Advanced Options:**
|
|
1636
|
+
```bash
|
|
1637
|
+
# Syntax style
|
|
1638
|
+
zx --syntax-style=universal run program.zx
|
|
1639
|
+
zx --syntax-style=tolerable run program.zx
|
|
1640
|
+
zx --syntax-style=auto run program.zx # Auto-detect (default)
|
|
1641
|
+
|
|
1642
|
+
# Execution mode
|
|
1643
|
+
zx --execution-mode=interpreter run program.zx
|
|
1644
|
+
zx --execution-mode=compiler run program.zx
|
|
1645
|
+
zx --execution-mode=auto run program.zx # Auto-select (default)
|
|
1646
|
+
|
|
1647
|
+
# VM control
|
|
1648
|
+
zx --use-vm run program.zx # Use VM when beneficial (default)
|
|
1649
|
+
zx --no-vm run program.zx # Disable VM
|
|
1650
|
+
```
|
|
1651
|
+
|
|
1652
|
+
### Package Manager (`zpm`)
|
|
1653
|
+
|
|
1654
|
+
```bash
|
|
1655
|
+
# Initialize
|
|
1656
|
+
zpm init # Create new project
|
|
1657
|
+
|
|
1658
|
+
# Install packages
|
|
1659
|
+
zpm install # Install all from zexus.json
|
|
1660
|
+
zpm install std # Install specific package
|
|
1661
|
+
zpm install web@0.2.0 # Install specific version
|
|
1662
|
+
zpm install testing -D # Install as dev dependency
|
|
1663
|
+
|
|
1664
|
+
# Manage packages
|
|
1665
|
+
zpm list # List installed packages
|
|
1666
|
+
zpm search <query> # Search for packages
|
|
1667
|
+
zpm uninstall <package> # Remove a package
|
|
1668
|
+
zpm clean # Remove zpm_modules/
|
|
1669
|
+
|
|
1670
|
+
# Publishing
|
|
1671
|
+
zpm info # Show project info
|
|
1672
|
+
zpm publish # Publish to registry
|
|
1673
|
+
```
|
|
1674
|
+
|
|
1675
|
+
---
|
|
1676
|
+
|
|
1677
|
+
## 🏗️ Architecture
|
|
1678
|
+
|
|
1679
|
+
```
|
|
1680
|
+
zexus-interpreter/
|
|
1681
|
+
├── src/zexus/ # Core interpreter
|
|
1682
|
+
│ ├── lexer.py # Tokenization
|
|
1683
|
+
│ ├── parser/ # Parsing (multi-strategy)
|
|
1684
|
+
│ │ ├── parser.py # Main parser
|
|
1685
|
+
│ │ └── ... # Parser utilities
|
|
1686
|
+
│ ├── evaluator/ # Evaluation engine
|
|
1687
|
+
│ │ ├── core.py # Main evaluator
|
|
1688
|
+
│ │ ├── bytecode_compiler.py # VM bytecode compiler
|
|
1689
|
+
│ │ ├── expressions.py # Expression evaluation
|
|
1690
|
+
│ │ ├── statements.py # Statement evaluation
|
|
1691
|
+
│ │ └── functions.py # Function handling & builtins
|
|
1692
|
+
│ ├── vm/ # Virtual Machine
|
|
1693
|
+
│ │ ├── vm.py # VM execution engine
|
|
1694
|
+
│ │ ├── bytecode.py # Bytecode definitions
|
|
1695
|
+
│ │ └── jit.py # JIT compilation
|
|
1696
|
+
│ ├── compiler/ # Compiler frontend
|
|
1697
|
+
│ │ ├── __init__.py # Compiler main
|
|
1698
|
+
│ │ ├── parser.py # Production parser
|
|
1699
|
+
│ │ ├── semantic.py # Semantic analysis
|
|
1700
|
+
│ │ └── bytecode.py # Bytecode generation
|
|
1701
|
+
│ ├── object.py # Object system
|
|
1702
|
+
│ ├── zexus_ast.py # AST definitions
|
|
1703
|
+
│ ├── persistence.py # Persistent storage
|
|
1704
|
+
│ ├── policy_engine.py # Security policies
|
|
1705
|
+
│ ├── dependency_injection.py # DI system
|
|
1706
|
+
│ ├── blockchain/ # Blockchain features
|
|
1707
|
+
│ │ ├── transaction.py # Transaction handling
|
|
1708
|
+
│ │ ├── crypto.py # Cryptography
|
|
1709
|
+
│ │ └── ... # Other blockchain features
|
|
1710
|
+
│ ├── security.py # Security features
|
|
1711
|
+
│ ├── module_manager.py # Module system
|
|
1712
|
+
│ └── ... # Other components
|
|
1713
|
+
├── tests/ # Test suite
|
|
1714
|
+
│ ├── unit/ # Unit tests
|
|
1715
|
+
│ ├── integration/ # Integration tests
|
|
1716
|
+
│ └── examples/ # Example programs
|
|
1717
|
+
├── docs/ # Documentation
|
|
1718
|
+
│ ├── features/ # Feature docs
|
|
1719
|
+
│ ├── guides/ # User guides
|
|
1720
|
+
│ └── api/ # API reference
|
|
1721
|
+
├── syntaxes/ # Syntax highlighting
|
|
1722
|
+
├── zpm_modules/ # Installed packages
|
|
1723
|
+
└── examples/ # Example programs
|
|
1724
|
+
```
|
|
1725
|
+
|
|
1726
|
+
### Execution Flow
|
|
1727
|
+
|
|
1728
|
+
```
|
|
1729
|
+
Source Code (.zx)
|
|
1730
|
+
↓
|
|
1731
|
+
[Lexer] → Tokens
|
|
1732
|
+
↓
|
|
1733
|
+
[Parser] → AST
|
|
1734
|
+
↓
|
|
1735
|
+
[Evaluator] ←→ [Bytecode Compiler]
|
|
1736
|
+
↓ ↓
|
|
1737
|
+
Direct Eval [VM Execution]
|
|
1738
|
+
↓ ↓
|
|
1739
|
+
Result ←─────────┘
|
|
1740
|
+
```
|
|
1741
|
+
|
|
1742
|
+
---
|
|
1743
|
+
|
|
1744
|
+
## 📖 Documentation
|
|
1745
|
+
|
|
1746
|
+
### Complete Documentation
|
|
1747
|
+
|
|
1748
|
+
- **[Feature Guide](docs/ADVANCED_FEATURES_IMPLEMENTATION.md)** - Complete feature reference
|
|
1749
|
+
- **[Developer Guide](src/README.md)** - Internal architecture and API
|
|
1750
|
+
- **[Documentation Index](docs/INDEX.md)** - All documentation organized
|
|
1751
|
+
- **[Quick Start](docs/QUICK_START.md)** - Getting started tutorial
|
|
1752
|
+
- **[Architecture](docs/ARCHITECTURE.md)** - System design
|
|
1753
|
+
- **[Philosophy](docs/PHILOSOPHY.md)** - Design principles
|
|
1754
|
+
|
|
1755
|
+
### Keyword & Syntax Documentation
|
|
1756
|
+
|
|
1757
|
+
- **[Keyword Testing Master List](docs/KEYWORD_TESTING_MASTER_LIST.md)** - Complete keyword reference with 130+ keywords
|
|
1758
|
+
- **[Blockchain Keywords](docs/BLOCKCHAIN_KEYWORDS.md)** - Smart contract keywords (implements, pure, view, payable, modifier, this, emit)
|
|
1759
|
+
- **[Advanced Keywords](docs/keywords/ADVANCED_KEYWORDS.md)** - Advanced language features
|
|
1760
|
+
- **[Modifiers](docs/MODIFIERS.md)** - Function and access modifiers
|
|
1761
|
+
|
|
1762
|
+
### Language Features by Category
|
|
1763
|
+
|
|
1764
|
+
#### Core Language
|
|
1765
|
+
- **[LET](docs/keywords/LET.md)** - Variable declaration (multiple syntax styles)
|
|
1766
|
+
- **[CONST](docs/keywords/CONST.md)** - Constant declaration
|
|
1767
|
+
- **[ACTION/FUNCTION/LAMBDA/RETURN](docs/keywords/ACTION_FUNCTION_LAMBDA_RETURN.md)** - Function definitions
|
|
1768
|
+
- **[IF/ELIF/ELSE](docs/keywords/IF_ELIF_ELSE.md)** - Conditional execution
|
|
1769
|
+
- **[WHILE/FOR/EACH/IN](docs/keywords/WHILE_FOR_EACH_IN.md)** - Loops and iteration
|
|
1770
|
+
- **[PRINT/DEBUG](docs/keywords/PRINT_DEBUG.md)** - Output and debugging
|
|
1771
|
+
- **[LOG](docs/keywords/LOG.md)** - Output redirection and code generation
|
|
1772
|
+
|
|
1773
|
+
#### Module System
|
|
1774
|
+
- **[MODULE_SYSTEM](docs/keywords/MODULE_SYSTEM.md)** - USE, IMPORT, EXPORT, MODULE, PACKAGE
|
|
1775
|
+
- **[Main Entry Point](docs/MAIN_ENTRY_POINT.md)** - run, execute, is_main patterns
|
|
1776
|
+
|
|
1777
|
+
#### Async & Concurrency
|
|
1778
|
+
- **[ASYNC/AWAIT](docs/keywords/ASYNC_AWAIT.md)** - Asynchronous programming
|
|
1779
|
+
- **[ASYNC_CONCURRENCY](docs/keywords/ASYNC_CONCURRENCY.md)** - Channels, send, receive, atomic
|
|
1780
|
+
|
|
1781
|
+
#### Events & Reactive
|
|
1782
|
+
- **[EVENTS_REACTIVE](docs/keywords/EVENTS_REACTIVE.md)** - Event system
|
|
1783
|
+
- **[WATCH](docs/keywords/COMMAND_watch.md)** - Reactive state management
|
|
1784
|
+
|
|
1785
|
+
#### Security Features
|
|
1786
|
+
- **[SECURITY](docs/keywords/SECURITY.md)** - Security features overview
|
|
1787
|
+
- **[RESTRICT](docs/keywords/COMMAND_restrict.md)** - Input validation
|
|
1788
|
+
- **[SANDBOX](docs/keywords/COMMAND_sandbox.md)** - Isolated execution
|
|
1789
|
+
- **[AUDIT](docs/keywords/COMMAND_audit.md)** - Compliance logging
|
|
1790
|
+
- **[TRAIL](docs/keywords/COMMAND_trail.md)** - Event tracking
|
|
1791
|
+
|
|
1792
|
+
#### Performance
|
|
1793
|
+
- **[PERFORMANCE](docs/keywords/PERFORMANCE.md)** - Performance features
|
|
1794
|
+
- **[NATIVE](docs/keywords/COMMAND_native.md)** - C/C++ FFI
|
|
1795
|
+
- **[INLINE](docs/keywords/COMMAND_inline.md)** - Function inlining
|
|
1796
|
+
- **[GC](docs/keywords/COMMAND_gc.md)** - Garbage collection control
|
|
1797
|
+
- **[BUFFER](docs/keywords/COMMAND_buffer.md)** - Memory buffers
|
|
1798
|
+
- **[SIMD](docs/keywords/COMMAND_simd.md)** - SIMD operations
|
|
1799
|
+
|
|
1800
|
+
#### Advanced Features
|
|
1801
|
+
- **[DEFER](docs/keywords/COMMAND_defer.md)** - Deferred cleanup
|
|
1802
|
+
- **[PATTERN](docs/keywords/COMMAND_pattern.md)** - Pattern matching
|
|
1803
|
+
- **[ENUM](docs/keywords/COMMAND_enum.md)** - Enumerations
|
|
1804
|
+
- **[STREAM](docs/keywords/COMMAND_stream.md)** - Event streaming
|
|
1805
|
+
|
|
1806
|
+
#### Blockchain & State
|
|
1807
|
+
- **[BLOCKCHAIN_STATE](docs/keywords/BLOCKCHAIN_STATE.md)** - State management
|
|
1808
|
+
- **[Error Handling](docs/keywords/ERROR_HANDLING.md)** - TRY/CATCH/REQUIRE/REVERT
|
|
1809
|
+
|
|
1810
|
+
#### Renderer/UI
|
|
1811
|
+
- **[RENDERER_UI](docs/keywords/RENDERER_UI.md)** - UI and rendering system
|
|
1812
|
+
|
|
1813
|
+
### Specific Features
|
|
1814
|
+
|
|
1815
|
+
- **[VM Integration](VM_INTEGRATION_SUMMARY.md)** - Virtual Machine details
|
|
1816
|
+
- **[VM Quick Reference](VM_QUICK_REFERENCE.md)** - VM API and usage
|
|
1817
|
+
- **[Blockchain](docs/BLOCKCHAIN_FEATURES.md)** - Smart contracts and DApps
|
|
1818
|
+
- **[Security](docs/SECURITY_FEATURES.md)** - Security features guide
|
|
1819
|
+
- **[Concurrency](docs/CONCURRENCY.md)** - Async/await and channels
|
|
1820
|
+
- **[Module System](docs/MODULE_SYSTEM.md)** - Import/export system
|
|
1821
|
+
- **[Plugin System](docs/PLUGIN_SYSTEM.md)** - Extending Zexus
|
|
1822
|
+
- **[ZPM Guide](docs/ZPM_GUIDE.md)** - Package manager
|
|
1823
|
+
- **[Performance](docs/PERFORMANCE_FEATURES.md)** - Optimization features
|
|
1824
|
+
|
|
1825
|
+
### Command Documentation
|
|
1826
|
+
|
|
1827
|
+
Each advanced feature has detailed documentation:
|
|
1828
|
+
- [PROTECT](docs/keywords/COMMAND_protect.md) - Security policies
|
|
1829
|
+
- [WATCH](docs/keywords/COMMAND_watch.md) - Reactive state
|
|
1830
|
+
- [RESTRICT](docs/keywords/COMMAND_restrict.md) - Input validation
|
|
1831
|
+
- [SANDBOX](docs/keywords/COMMAND_sandbox.md) - Isolated execution
|
|
1832
|
+
- [TRAIL](docs/keywords/COMMAND_trail.md) - Audit logging
|
|
1833
|
+
- [DEFER](docs/keywords/COMMAND_defer.md) - Deferred execution
|
|
1834
|
+
- [PATTERN](docs/keywords/COMMAND_pattern.md) - Pattern matching
|
|
1835
|
+
- And many more in [docs/keywords/](docs/keywords/)
|
|
1836
|
+
|
|
1837
|
+
---
|
|
1838
|
+
|
|
1839
|
+
## 🤝 Contributing
|
|
1840
|
+
|
|
1841
|
+
We welcome contributions! Here's how:
|
|
1842
|
+
|
|
1843
|
+
1. **Fork** the repository
|
|
1844
|
+
2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
|
|
1845
|
+
3. **Commit** your changes: `git commit -m 'Add amazing feature'`
|
|
1846
|
+
4. **Push** to the branch: `git push origin feature/amazing-feature`
|
|
1847
|
+
5. **Open** a Pull Request
|
|
1848
|
+
|
|
1849
|
+
See [CONTRIBUTING.md](docs/CONTRIBUTING.md) for detailed guidelines.
|
|
1850
|
+
|
|
1851
|
+
---
|
|
1852
|
+
|
|
1853
|
+
## 🧪 Testing
|
|
1854
|
+
|
|
1855
|
+
### Run Test Suite
|
|
1856
|
+
|
|
1857
|
+
```bash
|
|
1858
|
+
# Unit tests
|
|
1859
|
+
pytest tests/unit/
|
|
1860
|
+
|
|
1861
|
+
# Integration tests
|
|
1862
|
+
cd tests/integration
|
|
1863
|
+
zx run test_builtins_simple.zx
|
|
1864
|
+
zx run test_advanced_features_complete.zx
|
|
1865
|
+
|
|
1866
|
+
# VM integration tests
|
|
1867
|
+
python test_vm_integration.py
|
|
1868
|
+
```
|
|
1869
|
+
|
|
1870
|
+
---
|
|
1871
|
+
|
|
1872
|
+
## 💡 Best Practices
|
|
1873
|
+
|
|
1874
|
+
### Code Organization
|
|
1875
|
+
|
|
1876
|
+
```zexus
|
|
1877
|
+
# Use modules for organization
|
|
1878
|
+
module UserManagement {
|
|
1879
|
+
export action createUser(name, email) { ... }
|
|
1880
|
+
export action deleteUser(id) { ... }
|
|
1881
|
+
|
|
1882
|
+
private action hashPassword(password) { ... }
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
# Import only what you need
|
|
1886
|
+
use {createUser, deleteUser} from "UserManagement"
|
|
1887
|
+
```
|
|
1888
|
+
|
|
1889
|
+
### Security First
|
|
1890
|
+
|
|
1891
|
+
```zexus
|
|
1892
|
+
# Always validate inputs
|
|
1893
|
+
action processPayment(amount, recipient) {
|
|
1894
|
+
# Validate amount
|
|
1895
|
+
verify amount > 0, "Amount must be positive"
|
|
1896
|
+
restrict(amount, {
|
|
1897
|
+
type: "integer",
|
|
1898
|
+
range: [1, 1000000]
|
|
1899
|
+
})
|
|
1900
|
+
|
|
1901
|
+
# Validate recipient
|
|
1902
|
+
verify is_email(recipient), "Invalid email"
|
|
1903
|
+
|
|
1904
|
+
# Sanitize inputs
|
|
1905
|
+
let clean_recipient = sanitize(recipient, "email")
|
|
1906
|
+
|
|
1907
|
+
# Apply security policies
|
|
1908
|
+
protect(processPayment, {
|
|
1909
|
+
auth_required: true,
|
|
1910
|
+
rate_limit: 10,
|
|
1911
|
+
log_access: true
|
|
1912
|
+
}, "strict")
|
|
1913
|
+
}
|
|
1914
|
+
```
|
|
1915
|
+
|
|
1916
|
+
### Error Handling
|
|
1917
|
+
|
|
1918
|
+
```zexus
|
|
1919
|
+
# Use try-catch for error recovery
|
|
1920
|
+
try {
|
|
1921
|
+
let data = file_read_json("config.json")
|
|
1922
|
+
process_config(data)
|
|
1923
|
+
} catch (error) {
|
|
1924
|
+
# Fallback to defaults
|
|
1925
|
+
let data = get_default_config()
|
|
1926
|
+
debug_log("Using default config", {error: error})
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
# Use defer for cleanup
|
|
1930
|
+
action process_file(path) {
|
|
1931
|
+
let handle = open_file(path)
|
|
1932
|
+
defer {
|
|
1933
|
+
close_file(handle) # Always executes
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
# Process file...
|
|
1937
|
+
return result
|
|
1938
|
+
}
|
|
1939
|
+
```
|
|
1940
|
+
|
|
1941
|
+
### Performance Optimization
|
|
1942
|
+
|
|
1943
|
+
```zexus
|
|
1944
|
+
# Use native for CPU-intensive tasks
|
|
1945
|
+
native action calculate_hash(data: string) -> string {
|
|
1946
|
+
source: "crypto.cpp"
|
|
1947
|
+
function: "sha256_hash"
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
# Mark read-only functions as pure
|
|
1951
|
+
action pure calculate_total(items) {
|
|
1952
|
+
return reduce(items, lambda(sum, item) { sum + item.price }, 0)
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
# Use inline for small frequently-called functions
|
|
1956
|
+
inline action square(x) {
|
|
1957
|
+
return x * x
|
|
1958
|
+
}
|
|
1959
|
+
```
|
|
1960
|
+
|
|
1961
|
+
### Async Patterns
|
|
1962
|
+
|
|
1963
|
+
```zexus
|
|
1964
|
+
# Use async/await for I/O operations
|
|
1965
|
+
async action fetch_user_data(user_id) {
|
|
1966
|
+
let profile = await http_get("/users/" + user_id)
|
|
1967
|
+
let posts = await http_get("/users/" + user_id + "/posts")
|
|
1968
|
+
|
|
1969
|
+
return {profile: profile, posts: posts}
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
# Use channels for producer-consumer patterns
|
|
1973
|
+
channel<Task> work_queue
|
|
1974
|
+
|
|
1975
|
+
action producer() {
|
|
1976
|
+
for each task in pending_tasks {
|
|
1977
|
+
send(work_queue, task)
|
|
1978
|
+
}
|
|
1979
|
+
close_channel(work_queue)
|
|
1980
|
+
}
|
|
1981
|
+
```
|
|
1982
|
+
|
|
1983
|
+
### Testing with Dependency Injection
|
|
1984
|
+
|
|
1985
|
+
```zexus
|
|
1986
|
+
# Production code
|
|
1987
|
+
register_dependency("database", ProductionDB())
|
|
1988
|
+
|
|
1989
|
+
action saveUser(user) {
|
|
1990
|
+
inject database
|
|
1991
|
+
database.insert("users", user)
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
# Test code
|
|
1995
|
+
test_mode(true)
|
|
1996
|
+
mock_dependency("database", MockDB())
|
|
1997
|
+
# Now saveUser() uses mocks
|
|
1998
|
+
```
|
|
1999
|
+
|
|
2000
|
+
### Smart Contract Best Practices
|
|
2001
|
+
|
|
2002
|
+
```zexus
|
|
2003
|
+
# Use modifiers for reusable guards
|
|
2004
|
+
contract Vault {
|
|
2005
|
+
state owner
|
|
2006
|
+
|
|
2007
|
+
modifier onlyOwner {
|
|
2008
|
+
require(TX.caller == owner, "Not authorized")
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
action payable withdraw(amount) modifier onlyOwner {
|
|
2012
|
+
require(balance >= amount, "Insufficient balance")
|
|
2013
|
+
transfer(TX.caller, amount)
|
|
2014
|
+
emit Withdrawal(TX.caller, amount)
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
```
|
|
2018
|
+
|
|
2019
|
+
### Code Style Guidelines
|
|
2020
|
+
|
|
2021
|
+
1. **Naming**: `snake_case` for variables/functions, `PascalCase` for types
|
|
2022
|
+
2. **Indentation**: 4 spaces (not tabs)
|
|
2023
|
+
3. **Comments**: Use `#` for single-line comments
|
|
2024
|
+
4. **Functions**: Keep under 50 lines when possible
|
|
2025
|
+
5. **Error Messages**: Be descriptive and actionable
|
|
2026
|
+
|
|
2027
|
+
---
|
|
2028
|
+
|
|
2029
|
+
## 📄 License
|
|
2030
|
+
|
|
2031
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
2032
|
+
|
|
2033
|
+
---
|
|
2034
|
+
|
|
2035
|
+
## 🙏 Acknowledgments
|
|
2036
|
+
|
|
2037
|
+
- **Community Contributors** - Thank you for your support!
|
|
2038
|
+
- **Open Source Libraries** - Built with Python, Click, and Rich
|
|
2039
|
+
- **Inspiration** - From modern languages like Rust, Python, Solidity, TypeScript, and Go
|
|
2040
|
+
|
|
2041
|
+
---
|
|
2042
|
+
|
|
2043
|
+
## 📞 Contact & Support
|
|
2044
|
+
|
|
2045
|
+
- **Issues**: [GitHub Issues](https://github.com/Zaidux/zexus-interpreter/issues)
|
|
2046
|
+
- **Discussions**: [GitHub Discussions](https://github.com/Zaidux/zexus-interpreter/discussions)
|
|
2047
|
+
- **Email**: zaidux@example.com
|
|
2048
|
+
|
|
2049
|
+
---
|
|
2050
|
+
|
|
2051
|
+
## 🗺️ Roadmap
|
|
2052
|
+
|
|
2053
|
+
### Completed ✅
|
|
2054
|
+
- [x] Core interpreter with hybrid execution
|
|
2055
|
+
- [x] VM-accelerated bytecode execution with JIT compilation
|
|
2056
|
+
- [x] 130+ language keywords fully implemented and tested
|
|
2057
|
+
- [x] Policy-as-code (PROTECT/VERIFY/RESTRICT)
|
|
2058
|
+
- [x] Enhanced VERIFY with validation builtins (email, URL, phone, patterns)
|
|
2059
|
+
- [x] Persistent memory management with leak detection
|
|
2060
|
+
- [x] Dependency injection system with auto-container creation
|
|
2061
|
+
- [x] Reactive state (WATCH) for automatic change reactions
|
|
2062
|
+
- [x] Blockchain primitives and smart contracts
|
|
2063
|
+
- [x] Blockchain modifiers (pure, view, payable, modifier, this, implements, emit)
|
|
2064
|
+
- [x] Module system (USE, EXPORT, MODULE, PACKAGE) with access control
|
|
2065
|
+
- [x] Package manager (ZPM) for dependency management
|
|
2066
|
+
- [x] 100+ built-in functions across all categories
|
|
2067
|
+
- [x] Advanced types (entities, contracts, protocols, enums, type_alias)
|
|
2068
|
+
- [x] Security features (sandbox, seal, trail, audit, capability, grant/revoke)
|
|
2069
|
+
- [x] Concurrency primitives (async/await with Promises, channels, send/receive, atomic)
|
|
2070
|
+
- [x] Main entry point system (run, execute, is_main, exit_program, on_start/on_exit)
|
|
2071
|
+
- [x] Enterprise features (middleware, auth, throttle, cache, inject)
|
|
2072
|
+
- [x] UI rendering system (screen, component, theme, canvas)
|
|
2073
|
+
- [x] Performance optimization (native, inline, gc, buffer, simd)
|
|
2074
|
+
- [x] Advanced features (defer, pattern, stream, exactly, embedded)
|
|
2075
|
+
- [x] Dual-mode DEBUG (function and statement modes)
|
|
2076
|
+
- [x] Multiple syntax styles (`:` and `=` for assignments)
|
|
2077
|
+
- [x] Tolerance blocks for enhanced REQUIRE
|
|
2078
|
+
- [x] Comprehensive test suite (1175+ tests)
|
|
2079
|
+
- [x] **World-class error reporting system (v1.5.0)**
|
|
2080
|
+
- [x] **Generic types and advanced DATA features (v1.5.0)**
|
|
2081
|
+
- [x] **Pattern matching with exhaustiveness checking (v1.5.0)**
|
|
2082
|
+
- [x] **Stack trace formatter with source context (v1.5.0)**
|
|
2083
|
+
|
|
2084
|
+
### In Progress 🚧
|
|
2085
|
+
- [x] VS Code extension with full IntelliSense ✅
|
|
2086
|
+
- [x] Language Server Protocol (LSP) ✅
|
|
2087
|
+
- [x] Standard library expansion (fs, http, json, datetime) ✅
|
|
2088
|
+
- [x] Performance profiling tools ✅
|
|
2089
|
+
- [ ] Debugger integration (Debug Adapter Protocol in progress)
|
|
2090
|
+
|
|
2091
|
+
### Planned 🎯
|
|
2092
|
+
- [ ] WASM compilation target
|
|
2093
|
+
- [ ] JIT compilation for hot paths
|
|
2094
|
+
- [ ] Official package registry
|
|
2095
|
+
- [ ] CI/CD templates
|
|
2096
|
+
- [ ] Docker images
|
|
2097
|
+
- [ ] Production monitoring tools
|
|
2098
|
+
|
|
2099
|
+
### Future Enhancements 🚀
|
|
2100
|
+
- [ ] GPU acceleration for SIMD operations
|
|
2101
|
+
- [ ] Distributed computing primitives
|
|
2102
|
+
- [ ] Native mobile app support
|
|
2103
|
+
- [ ] WebAssembly interop
|
|
2104
|
+
- [ ] Advanced static analysis
|
|
2105
|
+
|
|
2106
|
+
---
|
|
2107
|
+
|
|
2108
|
+
## 📊 Project Stats
|
|
2109
|
+
|
|
2110
|
+
- **Language**: Python 3.8+
|
|
2111
|
+
- **Version**: 1.5.0 (Stable)
|
|
2112
|
+
- **Lines of Code**: ~50,000+
|
|
2113
|
+
- **Keywords**: 130+ language keywords
|
|
2114
|
+
- **Built-in Functions**: 100+ built-in functions
|
|
2115
|
+
- **Documentation Pages**: 100+
|
|
2116
|
+
- **Test Cases**: 1175+ comprehensive tests
|
|
2117
|
+
- **Features**: 100+ language features
|
|
2118
|
+
- **Supported Platforms**: Linux, macOS, Windows
|
|
2119
|
+
|
|
2120
|
+
---
|
|
2121
|
+
|
|
2122
|
+
## ❓ Getting Help & Troubleshooting
|
|
2123
|
+
|
|
2124
|
+
### Common Issues
|
|
2125
|
+
|
|
2126
|
+
#### "Identifier not found" errors
|
|
2127
|
+
- Check variable spelling and case sensitivity
|
|
2128
|
+
- Ensure variable is declared in current or parent scope
|
|
2129
|
+
- Remember: Zexus uses function-level scoping (not block-level)
|
|
2130
|
+
- Variables declared in blocks persist in function scope
|
|
2131
|
+
|
|
2132
|
+
#### Import/Module errors
|
|
2133
|
+
- Use `use {symbol} from "module"` syntax for imports
|
|
2134
|
+
- Check that module file exists and has `.zx` extension
|
|
2135
|
+
- Ensure exported symbols are marked with `export` keyword
|
|
2136
|
+
- Use `zpm install` to install package dependencies
|
|
2137
|
+
|
|
2138
|
+
#### Syntax errors
|
|
2139
|
+
- Zexus supports multiple syntax styles: `let x = 5` or `let x : 5`
|
|
2140
|
+
- Ensure proper braces `{}` for blocks
|
|
2141
|
+
- Use `;` for statement termination (optional in some contexts)
|
|
2142
|
+
- Check for unmatched parentheses, brackets, or braces
|
|
2143
|
+
|
|
2144
|
+
#### Performance issues
|
|
2145
|
+
- Enable VM execution for compute-heavy code (default: auto)
|
|
2146
|
+
- Use `--use-vm` flag for explicit VM mode
|
|
2147
|
+
- Consider using `native` keyword for C/C++ FFI
|
|
2148
|
+
- Profile with `memory_stats()` to check for leaks
|
|
2149
|
+
|
|
2150
|
+
#### Blockchain/Contract issues
|
|
2151
|
+
- Remember `TX` is a global context object (uppercase)
|
|
2152
|
+
- Use `persistent storage` for contract state
|
|
2153
|
+
- Mark value-receiving functions as `payable`
|
|
2154
|
+
- Use `pure` or `view` for read-only functions
|
|
2155
|
+
|
|
2156
|
+
### Documentation Quick Links
|
|
2157
|
+
|
|
2158
|
+
- **Beginner**: Start with [Quick Start Guide](docs/QUICK_START.md)
|
|
2159
|
+
- **Keywords**: See [Keyword Master List](docs/KEYWORD_TESTING_MASTER_LIST.md)
|
|
2160
|
+
- **Examples**: Check [examples/](examples/) directory
|
|
2161
|
+
- **API Reference**: Browse [docs/](docs/) for detailed docs
|
|
2162
|
+
- **Advanced**: Read [Advanced Features Guide](docs/ADVANCED_FEATURES_IMPLEMENTATION.md)
|
|
2163
|
+
|
|
2164
|
+
### Debug Tools
|
|
2165
|
+
|
|
2166
|
+
```zexus
|
|
2167
|
+
# Enable detailed debugging
|
|
2168
|
+
debug myVariable; # Logs with context
|
|
2169
|
+
|
|
2170
|
+
# Check execution context
|
|
2171
|
+
print(is_main()) # Am I the main module?
|
|
2172
|
+
print(get_module_name()) # Current module name
|
|
2173
|
+
print(module_info()) # Module metadata
|
|
2174
|
+
|
|
2175
|
+
# Memory debugging
|
|
2176
|
+
track_memory() # Enable tracking
|
|
2177
|
+
print(memory_stats()) # Check for leaks
|
|
2178
|
+
|
|
2179
|
+
# AST/Token inspection
|
|
2180
|
+
# Run: zx ast program.zx
|
|
2181
|
+
# Run: zx tokens program.zx
|
|
2182
|
+
```
|
|
2183
|
+
|
|
2184
|
+
### Getting Support
|
|
2185
|
+
|
|
2186
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/Zaidux/zexus-interpreter/issues)
|
|
2187
|
+
- **Discussions**: [Ask questions and share ideas](https://github.com/Zaidux/zexus-interpreter/discussions)
|
|
2188
|
+
- **Documentation**: [Browse complete docs](docs/)
|
|
2189
|
+
- **Examples**: [See working code samples](examples/)
|
|
2190
|
+
|
|
2191
|
+
### Community & Ecosystem
|
|
2192
|
+
|
|
2193
|
+
#### Official Resources
|
|
2194
|
+
- **GitHub Repository**: [Zaidux/zexus-interpreter](https://github.com/Zaidux/zexus-interpreter)
|
|
2195
|
+
- **Documentation Site**: [docs/](docs/)
|
|
2196
|
+
- **VS Code Extension**: [.vscode/extensions/zexus-language/](.vscode/extensions/zexus-language/)
|
|
2197
|
+
- **Syntax Highlighting**: [syntaxes/](syntaxes/)
|
|
2198
|
+
|
|
2199
|
+
#### Standard Library Packages
|
|
2200
|
+
- **zexus-blockchain**: Blockchain utilities and helpers
|
|
2201
|
+
- **zexus-network**: HTTP, WebSocket, and networking
|
|
2202
|
+
- **zexus-math**: Advanced mathematical operations
|
|
2203
|
+
- **zexus-stdlib**: Standard library modules
|
|
2204
|
+
|
|
2205
|
+
Install packages with ZPM:
|
|
2206
|
+
```bash
|
|
2207
|
+
zpm install zexus-blockchain
|
|
2208
|
+
zpm install zexus-network
|
|
2209
|
+
zpm install zexus-math
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
#### Learning Resources
|
|
2213
|
+
- **Quick Start**: [docs/QUICK_START.md](docs/QUICK_START.md)
|
|
2214
|
+
- **Examples Directory**: [examples/](examples/)
|
|
2215
|
+
- **Test Suite**: [tests/](tests/) - 1175+ working examples
|
|
2216
|
+
- **Keyword Testing**: [docs/KEYWORD_TESTING_MASTER_LIST.md](docs/KEYWORD_TESTING_MASTER_LIST.md)
|
|
2217
|
+
- **Feature Guides**: [docs/features/](docs/features/)
|
|
2218
|
+
|
|
2219
|
+
#### Development Tools
|
|
2220
|
+
- **CLI**: `zx` for running programs
|
|
2221
|
+
- **Package Manager**: `zpm` for dependencies
|
|
2222
|
+
- **REPL**: Interactive shell with `zx repl`
|
|
2223
|
+
- **AST Inspector**: `zx ast program.zx`
|
|
2224
|
+
- **Token Viewer**: `zx tokens program.zx`
|
|
2225
|
+
- **Validator**: `zx validate program.zx`
|
|
2226
|
+
|
|
2227
|
+
---
|
|
2228
|
+
|
|
2229
|
+
<div align="center">
|
|
2230
|
+
|
|
2231
|
+
**Made with ❤️ by the Zexus Team**
|
|
2232
|
+
|
|
2233
|
+
[⭐ Star us on GitHub](https://github.com/Zaidux/zexus-interpreter) | [📖 Read the Docs](docs/) | [🐛 Report Bug](https://github.com/Zaidux/zexus-interpreter/issues) | [💡 Request Feature](https://github.com/Zaidux/zexus-interpreter/issues/new)
|
|
2234
|
+
|
|
2235
|
+
</div>
|