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.
- package/README.md +89 -64
- package/bin/zexus +12 -2
- package/bin/zpics +12 -2
- package/bin/zpm +12 -2
- package/bin/zx +12 -2
- package/bin/zx-deploy +12 -2
- package/bin/zx-dev +12 -2
- package/bin/zx-run +12 -2
- package/package.json +1 -1
- package/rust_core/Cargo.lock +1 -1
- package/scripts/postinstall.js +192 -41
- package/src/zexus/__init__.py +1 -1
- package/src/zexus/builtin_modules.py +50 -13
- package/src/zexus/cli/main.py +46 -1
- package/src/zexus/cli/zpm.py +1 -1
- package/src/zexus/evaluator/bytecode_compiler.py +11 -2
- package/src/zexus/evaluator/core.py +4 -1
- package/src/zexus/evaluator/expressions.py +11 -2
- package/src/zexus/evaluator/functions.py +72 -0
- package/src/zexus/evaluator/resource_limiter.py +1 -1
- package/src/zexus/evaluator/statements.py +44 -4
- package/src/zexus/kernel/__init__.py +34 -0
- package/src/zexus/kernel/hooks.py +276 -0
- package/src/zexus/kernel/registry.py +203 -0
- package/src/zexus/kernel/zir/__init__.py +145 -0
- package/src/zexus/lexer.py +7 -0
- package/src/zexus/object.py +28 -5
- package/src/zexus/parser/parser.py +87 -20
- package/src/zexus/parser/strategy_context.py +270 -12
- package/src/zexus/security.py +26 -2
- package/src/zexus/stdlib/blockchain.py +84 -0
- package/src/zexus/stdlib/http_server.py +2 -2
- package/src/zexus/stdlib/math.py +25 -17
- package/src/zexus/stdlib_integration.py +119 -2
- package/src/zexus/type_checker.py +17 -12
- package/src/zexus/vm/compiler.py +521 -49
- package/src/zexus/vm/fastops.c +4704 -1263
- package/src/zexus/vm/fastops.cpython-312-x86_64-linux-gnu.so +0 -0
- package/src/zexus/vm/fastops.pyx +81 -3
- package/src/zexus/vm/optimizer.py +65 -27
- package/src/zexus/vm/vm.py +1120 -130
- package/src/zexus/zexus_ast.py +4 -1
- package/src/zexus/zpm/package_manager.py +1 -1
- package/src/zexus.egg-info/PKG-INFO +90 -65
- package/src/zexus.egg-info/SOURCES.txt +60 -0
- 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
|
-

|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://python.org)
|
|
8
8
|
[](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-
|
|
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-
|
|
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.
|
|
71
|
-
|
|
72
|
-
###
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
## 🔒
|
|
157
|
+
## 🔒 Security Features
|
|
133
158
|
|
|
134
|
-
Zexus
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
|
|
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
package/rust_core/Cargo.lock
CHANGED
|
@@ -578,7 +578,7 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
|
578
578
|
|
|
579
579
|
[[package]]
|
|
580
580
|
name = "zeroize"
|
|
581
|
-
version = "1.8.
|
|
581
|
+
version = "1.8.3"
|
|
582
582
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
583
583
|
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
|
584
584
|
|
package/scripts/postinstall.js
CHANGED
|
@@ -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
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
127
|
+
run(`${python} -m pip install --user "zexus[full]"`);
|
|
128
|
+
console.log('✓ Zexus Python package installed successfully');
|
|
47
129
|
} catch {
|
|
48
|
-
|
|
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)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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ℹ️
|
|
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');
|
package/src/zexus/__init__.py
CHANGED