zexus 1.8.1 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +89 -64
  2. package/bin/zexus +12 -2
  3. package/bin/zpics +12 -2
  4. package/bin/zpm +12 -2
  5. package/bin/zx +12 -2
  6. package/bin/zx-deploy +12 -2
  7. package/bin/zx-dev +12 -2
  8. package/bin/zx-run +12 -2
  9. package/package.json +1 -1
  10. package/rust_core/Cargo.lock +1 -1
  11. package/scripts/postinstall.js +192 -41
  12. package/src/zexus/__init__.py +1 -1
  13. package/src/zexus/builtin_modules.py +50 -13
  14. package/src/zexus/cli/main.py +46 -1
  15. package/src/zexus/cli/zpm.py +1 -1
  16. package/src/zexus/evaluator/bytecode_compiler.py +11 -2
  17. package/src/zexus/evaluator/core.py +4 -1
  18. package/src/zexus/evaluator/expressions.py +11 -2
  19. package/src/zexus/evaluator/functions.py +72 -0
  20. package/src/zexus/evaluator/resource_limiter.py +1 -1
  21. package/src/zexus/evaluator/statements.py +44 -4
  22. package/src/zexus/kernel/__init__.py +34 -0
  23. package/src/zexus/kernel/hooks.py +276 -0
  24. package/src/zexus/kernel/registry.py +203 -0
  25. package/src/zexus/kernel/zir/__init__.py +145 -0
  26. package/src/zexus/lexer.py +7 -0
  27. package/src/zexus/object.py +28 -5
  28. package/src/zexus/parser/parser.py +87 -20
  29. package/src/zexus/parser/strategy_context.py +270 -12
  30. package/src/zexus/security.py +26 -2
  31. package/src/zexus/stdlib/blockchain.py +84 -0
  32. package/src/zexus/stdlib/http_server.py +2 -2
  33. package/src/zexus/stdlib/math.py +25 -17
  34. package/src/zexus/stdlib_integration.py +119 -2
  35. package/src/zexus/type_checker.py +17 -12
  36. package/src/zexus/vm/compiler.py +521 -49
  37. package/src/zexus/vm/fastops.c +4704 -1263
  38. package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
  39. package/src/zexus/vm/fastops.pyx +81 -3
  40. package/src/zexus/vm/optimizer.py +65 -27
  41. package/src/zexus/vm/vm.py +1120 -130
  42. package/src/zexus/zexus_ast.py +4 -1
  43. package/src/zexus/zpm/package_manager.py +1 -1
  44. package/src/zexus.egg-info/PKG-INFO +90 -65
  45. package/src/zexus.egg-info/SOURCES.txt +60 -0
  46. package/src/zexus.egg-info/entry_points.txt +8 -0
package/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- ![Zexus Logo](https://img.shields.io/badge/Zexus-v1.8.1-FF6B35?style=for-the-badge)
5
+ ![Zexus Logo](https://img.shields.io/badge/Zexus-v1.8.3-FF6B35?style=for-the-badge)
6
6
  [![License](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE)
7
7
  [![Python](https://img.shields.io/badge/Python-3.8+-3776AB?style=for-the-badge&logo=python)](https://python.org)
8
8
  [![GitHub](https://img.shields.io/badge/GitHub-Zaidux/zexus--interpreter-181717?style=for-the-badge&logo=github)](https://github.com/Zaidux/zexus-interpreter)
9
9
 
10
10
  **A modern, security-first programming language with built-in blockchain support, VM-accelerated execution, advanced memory management, and policy-as-code**
11
11
 
12
- [What's New](#-whats-new-in-v171) • [Features](#-key-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [Keywords](#-complete-keyword-reference) • [Documentation](#-documentation) • [Examples](#-examples) • [Troubleshooting](#-getting-help--troubleshooting)
12
+ [What's New](#-whats-new-in-v183) • [Features](#-key-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [Keywords](#-complete-keyword-reference) • [Documentation](#-documentation) • [Examples](#-examples) • [Troubleshooting](#-getting-help--troubleshooting)
13
13
 
14
14
  </div>
15
15
 
@@ -18,7 +18,7 @@
18
18
  ## 📋 Table of Contents
19
19
 
20
20
  - [What is Zexus?](#-what-is-zexus)
21
- - [What's New](#-whats-new-in-v171)
21
+ - [What's New](#-whats-new-in-v183)
22
22
  - [Key Features](#-key-features)
23
23
  - [VM-Accelerated Performance](#-vm-accelerated-performance-new)
24
24
  - [Security & Policy-as-Code](#-security--policy-as-code--verify-enhanced)
@@ -67,71 +67,96 @@ Zexus is a next-generation, general-purpose programming language designed for se
67
67
 
68
68
  ---
69
69
 
70
- ## 🎉 What's New in v1.8.1
71
-
72
- ### Latest Features (v1.8.1)
73
-
74
- **FIND Keyword** - Declarative project search that resolves exact module paths with scope filtering and smart suggestions
75
- ✅ **LOAD Keyword & Manager** - Provider-aware configuration loader with built-in ENV, JSON, and YAML support plus caching
76
- **VM + Bytecode Support** - FIND/LOAD now compile to bytecode with helper bridges so scripts run identically in the VM and interpreter
77
- **Targeted Test Coverage** - Added regression tests that exercise both interpreter and VM paths for FIND/LOAD workflows
78
-
79
- ### Previous Features (v1.6.3)
80
-
81
- **Complete Database Ecosystem** - Production-ready database drivers
82
- **4 Database Drivers** - SQLite, PostgreSQL, MySQL, MongoDB fully tested
83
- **HTTP Server** - Build web servers with routing (GET, POST, PUT, DELETE)
84
- ✅ **Socket/TCP Primitives** - Low-level network programming
85
- **Testing Framework** - Write and run tests with assertions
86
- **ZPM Package Manager** - Fully functional package management system
87
- **Comprehensive Documentation** - 900+ lines of ecosystem guides
88
-
89
- ### Previous Features (v1.5.0)
90
-
91
- ✅ **World-Class Error Reporting** - Production-grade error messages rivaling Rust
92
- **Advanced DATA System** - Generic types, pattern matching, operator overloading
93
- **Stack Trace Formatter** - Beautiful, readable stack traces with source context
94
- **Smart Error Suggestions** - Actionable hints for fixing common errors
95
- **Pattern Matching** - Complete pattern matching with exhaustiveness checking
96
- **CONTINUE Keyword** - Error recovery mode for graceful degradation and batch processing
97
-
98
- ### Recent Enhancements (v0.1.3)
99
-
100
- **130+ Keywords Fully Operational** - All core language features tested and verified
101
- ✅ **Dual-Mode DEBUG** - Function mode (`debug(x)`) and statement mode (`debug x;`)
102
- **Conditional Print** - `print(condition, message)` for dynamic output control
103
- ✅ **Multiple Syntax Styles** - `let x = 5`, `let x : 5`, `let x : int = 5` all supported
104
- **Enterprise Keywords** - MIDDLEWARE, AUTH, THROTTLE, CACHE, INJECT fully functional
105
- **Async/Await Runtime** - Complete Promise-based async system with context propagation
106
- **Main Entry Point** - 15+ builtins for program lifecycle management
107
- ✅ **UI Renderer** - SCREEN, COMPONENT, THEME keywords with 120+ tests
108
- **Enhanced VERIFY** - Email, URL, phone validation, pattern matching, database checks
109
- **Blockchain Keywords** - implements, pure, view, payable, modifier, this, emit
110
- ✅ **Loop Control** - BREAK keyword for early loop exit
111
- **Error Handling** - THROW keyword for explicit error raising, THIS for instance reference
112
- ✅ **100+ Built-in Functions** - Comprehensive standard library
113
- **LOG Keyword Enhancements** - `read_file()` and `eval_file()` for dynamic code generation
114
- **REQUIRE Tolerance Blocks** - Conditional bypasses for VIP/admin/emergency scenarios
115
- ✅ **Function-Level Scoping** - LET/CONST documented with scope behavior and shadowing rules
116
- ✅ **Advanced Error Patterns** - Retry, circuit breaker, error aggregation patterns
117
-
118
- ### Bug Fixes & Improvements
119
-
120
- Fixed array literal parsing (no more duplicate elements)
121
- Fixed ENUM value accessibility
122
- ✅ Fixed WHILE condition parsing without parentheses
123
- Fixed loop execution and variable reassignment
124
- ✅ Fixed DEFER cleanup execution
125
- Fixed SANDBOX return values
126
- ✅ Fixed dependency injection container creation
127
- Added tolerance blocks for REQUIRE
128
- ✅ Improved error messages and debugging output
70
+ ## 🎉 What's New in v1.8.3
71
+
72
+ ### v1.8.3 — Phase 0 Audit Fixes, Closure Scoping Overhaul & VM Hardening (2026-03-01)
73
+
74
+ 19 issues from the [Ziver-Chain Phase 0 rewrite audit](issues/ISSUE8.md) resolved including 3 VM-specific critical fixes. Key changes:
75
+
76
+ **VM Fixes & Hardening:**
77
+ - **R-001:** Entity field access on VM now works proper `EntityDefinition`/`EntityInstance` construction from bytecode
78
+ - **R-002:** Contract `state` declarations now compile correctly (`_compile_StateStatement`)
79
+ - **R-010:** Complex programs no longer silently fail — added `_vm_warn()` diagnostics, replaced 15 silent error handlers
80
+ - Native fast-path (`_vm_native_call`) for `push`/`append`/`length`/`str`/`range` operations on VM-native types
81
+ - `VMRuntimeError(Exception)` replaces non-raisable `ZEvaluationError(Object)` in 15 raise sites
82
+ - Stack overflow protection, execution timeout (30s), opcode limit (100M), configurable VM pool sizing
83
+ - **Rust VM status indicator** CLI/runner show "Rust VM: active", "available but disabled", or "not compiled"
84
+
85
+ **Closure & Scoping Fixes:**
86
+ - Entity/`let` declarations before a contract no longer break contract visibility — declaration order is now flexible
87
+ - Module-level helper functions called from contract methods now correctly propagate side-effects (`list.push()`, `map[k]=v`)
88
+ - `action protect` now works at module level (policy enforcement added to function call path)
89
+ - Storage sync-back in contract methods improved — `list.push()` after `map[key]=val` no longer silently ignored
90
+ - Exported entities can now be used as constructors in importing files
91
+
92
+ **Contract & Language Fixes:**
93
+ - `self` keyword works as alias for `this` inside contracts
94
+ - `init()` auto-called on `Contract()` construction
95
+ - `state { field1: val, field2: val }` multi-field blocks work correctly
96
+ - `for each i, item in list` (indexed) and `for each key, val in map` now supported
97
+ - `INTEGER * FLOAT` implicit coercion and `%` modulo on floats now work
98
+ - Added `range()`, `typeof()`, `abs()`, `str()`, `length()` builtins; 8 parser edge-case fixes
99
+
100
+ **Stats:** 1852 tests pass, 0 regressions. 5 new extreme test suites (83 tests across speed, stability, security, features, VM). See [CHANGELOG](CHANGELOG.md) for full details.
101
+
102
+ ### v1.8.2 Concurrency & Channel Support (2026-02-25)
103
+
104
+ - `watch =>` arrow-lambda fallback no longer hijacks the strategy parser
105
+ - Channel support in VM compiler (`_compile_ChannelStatement`, `_compile_SendStatement`, `_compile_ReceiveStatement`)
106
+ - SPAWN/AWAIT opcodes in sync path using `threading.Thread(daemon=True)`
107
+ - Strategy parser channel/async handlers added
108
+ - Fixed 10+ missing VM node types; zero VM fallbacks achieved
109
+ - All versions bumped to 1.8.2; Rust VM builds with `maturin develop --release`
110
+
111
+ ### v1.8.1 ISSUE7 Audit & Security Remediation (2026-02-23)
112
+
113
+ All 21 issues from the Phase 0 audit resolved:
114
+ - `emit`, `protocol`, `implements` keywords fully operational in all parsers
115
+ - Entity compilation crash in VM fixed; imported functions no longer return raw Action objects
116
+ - `map.has()` / `map.get()` key normalization fixed
117
+ - ExportStatement supported in VM; entity constructor arity validation relaxed
118
+ - `persistent storage` now wires to SQLite backend with `set_persistent`/`get_persistent`
119
+ - 5 new builtins: `track_memory()`, `cache()`, `throttle()`, `audit()`, `verify()`
120
+ - Complete security remediation Phases 0–5 (sandboxing, ReDoS, import sandboxing, compiler parity, dead-code removal, bounded logs)
121
+ - 1852 tests pass
122
+
123
+ ### v1.8.0 Rust VM Pipeline & Major Features (2026-02-23)
124
+
125
+ **Language Features:** Compound assignment (`+=`, `-=`, etc.), string interpolation (`"Hello ${name}"`), block comments (`/* */`), multiline strings, single-quoted strings, exponentiation (`**`), `finally` clause, destructuring assignment.
126
+
127
+ **Developer Tooling:** Circular import detection, LSP go-to-definition, remote ZPM registry, static type checker.
128
+
129
+ **Major Capabilities:** Debug Adapter Protocol (DAP) server, GUI backend (Tk + Web), true concurrent EventLoop, WASM compilation target.
130
+
131
+ **Rust-First Execution (Phases 0–6):** Complete migration achieving **102,000+ TPS** with zero Python fallbacks. Includes binary `.zxc` format, Rust bytecode interpreter (22 MIPS, 20.7x speedup), adaptive VM routing, `RustContractVM` orchestration, GIL-free batch execution (221,593 TPS peak), and 40+ Rust builtins.
132
+
133
+ ### v1.7.x — FIND/LOAD Keywords & Performance (2026-01)
134
+
135
+ - **v1.7.2:** Major interpreter speed improvements, smart storage for lists, optimized stack traces, blockchain perf fix
136
+ - **v1.7.1:** FIND keyword (declarative module search), LOAD keyword (provider-aware config loader), VM bytecode support for both, regression tests
137
+
138
+ ### v1.6.x — Database Ecosystem & Security (2025-12 – 2026-01)
139
+
140
+ - **v1.6.8:** Parser fix for indexed assignments on new lines; contract DATA member declarations
141
+ - **v1.6.7:** Semicolon handling fix, context-aware keyword recognition, standalone block statements
142
+ - **v1.6.6:** Repeated contract action calls, multiple indexed assignments
143
+ - **v1.6.5:** Entity property access, keyword restrictions (`from`/`to` as params), multiple map assignments
144
+ - **v1.6.3:** Comprehensive security remediation (10 OWASP categories), RBAC, bcrypt, input sanitization, resource limits, path traversal prevention
145
+ - **v1.6.2:** 4 database drivers (SQLite, PostgreSQL, MySQL, MongoDB), HTTP server, socket/TCP, testing framework, ZPM
146
+
147
+ ### v1.5.0 — Error Reporting & Type System (2025-12)
148
+
149
+ World-class error messages (rivaling Rust), generic types, pattern matching, operator overloading, stack trace formatter, smart suggestions, CONTINUE keyword.
150
+
151
+ ### v0.1.3 — Foundation (2025-11)
152
+
153
+ 130+ keywords, dual-mode DEBUG, conditional print, multiple syntax styles, enterprise keywords, async/await, UI renderer, enhanced VERIFY, blockchain keywords, 100+ builtins.
129
154
 
130
155
  ---
131
156
 
132
- ## 🔒 Latest Security Patches & Features (v1.6.3)
157
+ ## 🔒 Security Features
133
158
 
134
- Zexus v1.6.3 introduces **comprehensive security enhancements** and developer-friendly safety features. These improvements make Zexus one of the most secure interpreted languages available, with enterprise-grade protection built into the language itself.
159
+ Zexus includes **comprehensive security enhancements** and developer-friendly safety features, making it one of the most secure interpreted languages available with enterprise-grade protection built into the language itself.
135
160
 
136
161
  ### 🛡️ Security Features Added
137
162
 
package/bin/zexus CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zpics CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus.pics "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus.pics', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zpm CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus.zpm "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus.zpm', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zx CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zx-deploy CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus.deploy "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus.deploy', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zx-dev CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus.dev "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus.dev', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/bin/zx-run CHANGED
@@ -1,2 +1,12 @@
1
- #!/usr/bin/env bash
2
- python3 -m zexus.runner "$@"
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const proc = spawn('python3', ['-m', 'zexus.runner', ...process.argv.slice(2)], { stdio: 'inherit' });
4
+ proc.on('error', (err) => {
5
+ if (err.code === 'ENOENT') {
6
+ console.error('Error: python3 not found. Please install Python 3.8+ to use Zexus.');
7
+ process.exit(1);
8
+ }
9
+ console.error('Error:', err.message);
10
+ process.exit(1);
11
+ });
12
+ proc.on('close', (code) => process.exit(code ?? 1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zexus",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "A modern, security-first programming language with blockchain support",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -578,7 +578,7 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
578
578
 
579
579
  [[package]]
580
580
  name = "zeroize"
581
- version = "1.8.2"
581
+ version = "1.8.3"
582
582
  source = "registry+https://github.com/rust-lang/crates.io-index"
583
583
  checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
584
584
 
@@ -3,74 +3,225 @@
3
3
  const { execSync } = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
+ const os = require('os');
6
7
 
7
8
  console.log('\n🚀 Installing Zexus Programming Language...\n');
8
9
 
9
- // Check if Python is available
10
- try {
11
- const pythonVersion = execSync('python3 --version', { encoding: 'utf-8' });
12
- console.log(`✓ Found ${pythonVersion.trim()}`);
13
- } catch (error) {
14
- console.error('❌ Python 3.8+ is required but not found.');
15
- console.error('Please install Python 3.8 or higher: https://www.python.org/downloads/');
16
- process.exit(1);
10
+ // ---------------------------------------------------------------------------
11
+ // Helpers
12
+ // ---------------------------------------------------------------------------
13
+
14
+ function hasCommand(cmd) {
15
+ try {
16
+ execSync(`${cmd} --version`, { stdio: 'ignore' });
17
+ return true;
18
+ } catch {
19
+ return false;
20
+ }
17
21
  }
18
22
 
19
- // Check Python version
20
- try {
21
- const versionCheck = execSync('python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)"');
22
- console.log('✓ Python version is 3.8 or higher');
23
- } catch (error) {
24
- console.error('❌ Python 3.8 or higher is required.');
23
+ function run(cmd, opts = {}) {
24
+ return execSync(cmd, { encoding: 'utf-8', stdio: 'inherit', ...opts });
25
+ }
26
+
27
+ function runQuiet(cmd) {
28
+ return execSync(cmd, { encoding: 'utf-8', stdio: 'pipe' });
29
+ }
30
+
31
+ const isWin = os.platform() === 'win32';
32
+ const pip = isWin ? 'pip' : 'pip3';
33
+ const python = isWin ? 'python' : 'python3';
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // 1. Python — check or install
37
+ // ---------------------------------------------------------------------------
38
+
39
+ let pythonAvailable = false;
40
+
41
+ if (hasCommand(python)) {
42
+ try {
43
+ const ver = runQuiet(`${python} --version`).trim();
44
+ console.log(`✓ Found ${ver}`);
45
+ // Verify >= 3.8
46
+ runQuiet(`${python} -c "import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)"`);
47
+ console.log('✓ Python version is 3.8 or higher');
48
+ pythonAvailable = true;
49
+ } catch {
50
+ console.error('❌ Python was found but version is below 3.8.');
51
+ console.error(' Please upgrade to Python 3.8+: https://www.python.org/downloads/');
52
+ }
53
+ } else {
54
+ console.warn('⚠️ python3 not found on PATH.');
55
+ // Attempt auto-install on common platforms
56
+ if (os.platform() === 'linux') {
57
+ console.log(' Attempting to install python3 via apt...');
58
+ try {
59
+ run('sudo apt-get update -qq && sudo apt-get install -y -qq python3 python3-pip python3-venv');
60
+ pythonAvailable = true;
61
+ console.log('✓ Python 3 installed via apt');
62
+ } catch {
63
+ console.warn(' Could not auto-install Python. Please install manually:');
64
+ console.warn(' https://www.python.org/downloads/');
65
+ }
66
+ } else if (os.platform() === 'darwin') {
67
+ if (hasCommand('brew')) {
68
+ console.log(' Attempting to install python3 via Homebrew...');
69
+ try {
70
+ run('brew install python@3');
71
+ pythonAvailable = true;
72
+ console.log('✓ Python 3 installed via Homebrew');
73
+ } catch {
74
+ console.warn(' Could not auto-install Python. Please install manually:');
75
+ console.warn(' https://www.python.org/downloads/');
76
+ }
77
+ } else {
78
+ console.warn(' Please install Python 3.8+: https://www.python.org/downloads/');
79
+ }
80
+ } else {
81
+ console.warn(' Please install Python 3.8+: https://www.python.org/downloads/');
82
+ }
83
+ }
84
+
85
+ if (!pythonAvailable) {
86
+ console.error('\n❌ Python 3.8+ is required but could not be found or installed.');
87
+ console.error(' Install it from: https://www.python.org/downloads/');
88
+ console.error(' Then re-run: npm rebuild zexus');
25
89
  process.exit(1);
26
90
  }
27
91
 
28
- // Install Zexus Python package
92
+ // ---------------------------------------------------------------------------
93
+ // 2. pip — ensure available
94
+ // ---------------------------------------------------------------------------
95
+
96
+ if (!hasCommand(pip) && !hasCommand('pip')) {
97
+ console.log(' pip not found — bootstrapping...');
98
+ try {
99
+ run(`${python} -m ensurepip --upgrade`);
100
+ } catch {
101
+ try {
102
+ run(`${python} -m pip install --upgrade pip`);
103
+ } catch {
104
+ console.warn('⚠️ Could not bootstrap pip. Python package install may fail.');
105
+ }
106
+ }
107
+ }
108
+
109
+ // ---------------------------------------------------------------------------
110
+ // 3. Install Zexus Python package
111
+ // ---------------------------------------------------------------------------
112
+
29
113
  console.log('\n📦 Installing Zexus Python package...');
114
+
115
+ // Check if zexus is already installed and up-to-date
116
+ let zexusInstalled = false;
30
117
  try {
31
- // Install with "full" extras so blockchain/network/security features work out of the box.
32
- // Use --user to avoid permission issues on global Python installs.
33
- execSync('pip3 install --user "zexus[full]"', { stdio: 'inherit' });
34
- console.log('\n✓ Zexus Python package installed successfully');
35
- } catch (error) {
36
- console.error('\n❌ Failed to install Zexus Python package.');
37
- console.error('Please run manually: pip3 install --user "zexus[full]"');
38
- process.exit(1);
118
+ runQuiet(`${python} -c "import zexus"`);
119
+ zexusInstalled = true;
120
+ console.log(' Zexus Python package already installed');
121
+ } catch {
122
+ // Not installed yet
39
123
  }
40
124
 
41
- // Best-effort: build/install Rust VM extension from bundled sources when available.
42
- // This requires a Rust toolchain and may fail on systems without build tooling.
43
- function hasCommand(cmd) {
125
+ if (!zexusInstalled) {
44
126
  try {
45
- execSync(`${cmd} --version`, { stdio: 'ignore' });
46
- return true;
127
+ run(`${python} -m pip install --user "zexus[full]"`);
128
+ console.log('✓ Zexus Python package installed successfully');
47
129
  } catch {
48
- return false;
130
+ // Retry without --user (some environments like venvs don't need it)
131
+ try {
132
+ run(`${python} -m pip install "zexus[full]"`);
133
+ console.log('✓ Zexus Python package installed successfully');
134
+ } catch {
135
+ console.error('❌ Failed to install Zexus Python package.');
136
+ console.error(` Please run manually: ${python} -m pip install "zexus[full]"`);
137
+ // Don't exit — commands that don't need Python may still work
138
+ }
49
139
  }
50
140
  }
51
141
 
142
+ // ---------------------------------------------------------------------------
143
+ // 4. Rust toolchain — check or install, then build rust_core
144
+ // ---------------------------------------------------------------------------
145
+
52
146
  const pkgRoot = path.resolve(__dirname, '..');
53
147
  const cargoToml = path.join(pkgRoot, 'rust_core', 'Cargo.toml');
54
148
 
55
- if (fs.existsSync(cargoToml) && hasCommand('cargo')) {
56
- console.log('\n🦀 Rust toolchain detected — attempting to build zexus_core...');
57
- try {
58
- execSync('python3 -m pip install --user --upgrade maturin', { stdio: 'inherit' });
59
- execSync(`python3 -m maturin develop -m "${cargoToml}" --release`, { stdio: 'inherit' });
60
- execSync('python3 -c "import zexus_core; print(\"zexus_core OK\", zexus_core.version())"', { stdio: 'inherit' });
61
- console.log('✓ Rust VM extension built and installed');
62
- } catch (error) {
63
- console.warn('\n⚠️ Rust VM build failed; continuing with pure-Python VM.');
64
- console.warn(' To retry manually (from source repo):');
65
- console.warn(' pip install maturin && maturin develop -m rust_core/Cargo.toml --release');
149
+ if (fs.existsSync(cargoToml)) {
150
+ let cargoReady = hasCommand('cargo');
151
+
152
+ if (!cargoReady) {
153
+ console.log('\n🦀 Rust toolchain (cargo) not found.');
154
+ console.log(' Attempting to install Rust via rustup...');
155
+ try {
156
+ if (isWin) {
157
+ // On Windows, download and run rustup-init
158
+ console.log(' Please install Rust manually: https://rustup.rs');
159
+ } else {
160
+ // Unix: install rustup non-interactively
161
+ run('curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y');
162
+ // Source the cargo env so it's available in this session
163
+ const cargoEnv = path.join(os.homedir(), '.cargo', 'env');
164
+ if (fs.existsSync(cargoEnv)) {
165
+ // Read the cargo bin path and add to PATH for child processes
166
+ const cargoBin = path.join(os.homedir(), '.cargo', 'bin');
167
+ process.env.PATH = `${cargoBin}${path.delimiter}${process.env.PATH}`;
168
+ }
169
+ cargoReady = hasCommand('cargo');
170
+ if (cargoReady) {
171
+ console.log('✓ Rust toolchain installed via rustup');
172
+ }
173
+ }
174
+ } catch (err) {
175
+ console.warn('⚠️ Could not auto-install Rust. Continuing with pure-Python VM.');
176
+ console.warn(' To install manually: https://rustup.rs');
177
+ }
178
+ } else {
179
+ console.log('\n✓ Rust toolchain detected');
180
+ }
181
+
182
+ if (cargoReady) {
183
+ // Check if zexus_core is already importable
184
+ let rustVmInstalled = false;
185
+ try {
186
+ runQuiet(`${python} -c "import zexus_core"`);
187
+ rustVmInstalled = true;
188
+ console.log('✓ Rust VM extension (zexus_core) already installed');
189
+ } catch {
190
+ // Need to build
191
+ }
192
+
193
+ if (!rustVmInstalled) {
194
+ console.log('🔨 Building Rust VM extension (zexus_core)...');
195
+ try {
196
+ // Ensure maturin is available
197
+ try {
198
+ runQuiet(`${python} -m maturin --version`);
199
+ } catch {
200
+ console.log(' Installing maturin build tool...');
201
+ run(`${python} -m pip install --user --upgrade maturin`);
202
+ }
203
+ run(`${python} -m maturin develop -m "${cargoToml}" --release`);
204
+ runQuiet(`${python} -c "import zexus_core"`);
205
+ console.log('✓ Rust VM extension built and installed');
206
+ } catch (error) {
207
+ console.warn('\n⚠️ Rust VM build failed; continuing with pure-Python VM.');
208
+ console.warn(' To retry manually:');
209
+ console.warn(` ${python} -m pip install maturin && ${python} -m maturin develop -m rust_core/Cargo.toml --release`);
210
+ }
211
+ }
66
212
  }
67
213
  } else {
68
- console.log('\nℹ️ Skipping Rust VM build (cargo not found or rust_core not bundled).');
214
+ console.log('\nℹ️ rust_core/Cargo.toml not bundled; skipping Rust VM build.');
69
215
  }
70
216
 
217
+ // ---------------------------------------------------------------------------
218
+ // Done
219
+ // ---------------------------------------------------------------------------
220
+
71
221
  console.log('\n✅ Zexus installed successfully!\n');
72
222
  console.log('Get started:');
73
223
  console.log(' zexus --help # Show help');
74
224
  console.log(' zx --version # Check version');
225
+ console.log(' zx run file.zx # Run a Zexus file');
75
226
  console.log(' zexus examples/ # Explore examples\n');
76
227
  console.log('Documentation: https://github.com/Zaidux/zexus-interpreter\n');
@@ -4,7 +4,7 @@ Zexus Programming Language
4
4
  A declarative, intent-based programming language for modern applications.
5
5
  """
6
6
 
7
- __version__ = "1.8.1"
7
+ __version__ = "1.8.3"
8
8
  __author__ = "Ziver Labs"
9
9
  __email__ = "ziverofficial567@gmail.com"
10
10