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,116 @@
|
|
|
1
|
+
// Zexus Phase 4: Virtual Filesystem Test Suite
|
|
2
|
+
// Tests sandboxed file operations
|
|
3
|
+
|
|
4
|
+
// Test 1: Path resolution
|
|
5
|
+
function resolvePath(virtualPath) {
|
|
6
|
+
print("Resolving virtual path: " + virtualPath);
|
|
7
|
+
return "/sandbox/resolved/" + virtualPath;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Test 2: File access checking
|
|
11
|
+
function checkFileAccess(path, mode) {
|
|
12
|
+
print("Checking " + mode + " access to: " + path);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Test 3: Virtual file operations
|
|
17
|
+
function readVirtualFile(path) {
|
|
18
|
+
print("Reading virtual file: " + path);
|
|
19
|
+
if (checkFileAccess(path, "read")) {
|
|
20
|
+
return "virtual_file_contents";
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function writeVirtualFile(path, content) {
|
|
26
|
+
print("Writing to virtual file: " + path);
|
|
27
|
+
if (checkFileAccess(path, "write")) {
|
|
28
|
+
print("File written: " + path);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Test 4: Directory operations
|
|
35
|
+
function listDirectory(path) {
|
|
36
|
+
print("Listing directory: " + path);
|
|
37
|
+
let files = ["file1.txt", "file2.zx", "file3.json"];
|
|
38
|
+
return files;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Test 5: Memory quota checking
|
|
42
|
+
function checkMemoryQuota() {
|
|
43
|
+
print("Checking memory quota usage");
|
|
44
|
+
return 65536; // 64KB used
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function allocateMemory(size) {
|
|
48
|
+
let available = checkMemoryQuota();
|
|
49
|
+
if (available > size) {
|
|
50
|
+
print("Allocated " + size + " bytes");
|
|
51
|
+
return true;
|
|
52
|
+
} else {
|
|
53
|
+
print("Memory quota exceeded");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Test 6: Sandbox creation
|
|
59
|
+
function createSandbox(name) {
|
|
60
|
+
print("Creating sandbox: " + name);
|
|
61
|
+
let sandbox = {
|
|
62
|
+
"name": name,
|
|
63
|
+
"readonly": false,
|
|
64
|
+
"memoryLimit": 1048576
|
|
65
|
+
};
|
|
66
|
+
return sandbox;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Test suite execution
|
|
70
|
+
print("Phase 4: Virtual Filesystem Test Suite");
|
|
71
|
+
print("======================================");
|
|
72
|
+
|
|
73
|
+
// Test path resolution
|
|
74
|
+
print("\nTesting path resolution:");
|
|
75
|
+
let path1 = resolvePath("documents/file.txt");
|
|
76
|
+
print("Resolved path: " + path1);
|
|
77
|
+
|
|
78
|
+
let path2 = resolvePath("config/settings.json");
|
|
79
|
+
print("Resolved path: " + path2);
|
|
80
|
+
|
|
81
|
+
// Test file access
|
|
82
|
+
print("\nTesting file access checks:");
|
|
83
|
+
checkFileAccess("/sandbox/file.txt", "read");
|
|
84
|
+
checkFileAccess("/sandbox/file.txt", "write");
|
|
85
|
+
checkFileAccess("/sandbox/file.txt", "execute");
|
|
86
|
+
|
|
87
|
+
// Test virtual file operations
|
|
88
|
+
print("\nTesting virtual file operations:");
|
|
89
|
+
let content = readVirtualFile("/sandbox/data.txt");
|
|
90
|
+
print("Read content: " + content);
|
|
91
|
+
|
|
92
|
+
writeVirtualFile("/sandbox/output.txt", "test data");
|
|
93
|
+
|
|
94
|
+
// Test directory operations
|
|
95
|
+
print("\nTesting directory operations:");
|
|
96
|
+
let files = listDirectory("/sandbox/documents");
|
|
97
|
+
print("Files in directory: " + files);
|
|
98
|
+
|
|
99
|
+
// Test memory operations
|
|
100
|
+
print("\nTesting memory quota:");
|
|
101
|
+
let quota = checkMemoryQuota();
|
|
102
|
+
print("Memory quota used: " + quota + " bytes");
|
|
103
|
+
|
|
104
|
+
allocateMemory(1024);
|
|
105
|
+
allocateMemory(2048);
|
|
106
|
+
allocateMemory(10000000); // This might exceed quota
|
|
107
|
+
|
|
108
|
+
// Test sandbox creation
|
|
109
|
+
print("\nTesting sandbox creation:");
|
|
110
|
+
let sandbox1 = createSandbox("untrusted_plugin");
|
|
111
|
+
print("Sandbox created: " + sandbox1["name"]);
|
|
112
|
+
|
|
113
|
+
let sandbox2 = createSandbox("trusted_app");
|
|
114
|
+
print("Sandbox created: " + sandbox2["name"]);
|
|
115
|
+
|
|
116
|
+
print("\n✓ All virtual filesystem tests completed");
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Zexus Phase 5: Type System Test Suite
|
|
2
|
+
// Tests runtime type checking and inference
|
|
3
|
+
|
|
4
|
+
// Test 1: Basic type inference
|
|
5
|
+
function inferType(value) {
|
|
6
|
+
if (value == 42 || value == 99) {
|
|
7
|
+
return "int";
|
|
8
|
+
}
|
|
9
|
+
if (value == "hello" || value == "world") {
|
|
10
|
+
return "string";
|
|
11
|
+
}
|
|
12
|
+
if (value == true || value == false) {
|
|
13
|
+
return "bool";
|
|
14
|
+
}
|
|
15
|
+
return "unknown";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Test 2: Type validation
|
|
19
|
+
function isValidType(value, expectedType) {
|
|
20
|
+
let actualType = inferType(value);
|
|
21
|
+
print("Checking type: expected=" + expectedType + ", actual=" + actualType);
|
|
22
|
+
return actualType == expectedType;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Test 3: Function signature with types
|
|
26
|
+
function typedAdd(a, b) {
|
|
27
|
+
// a and b should be integers
|
|
28
|
+
return a + b;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Test 4: Collection type inference
|
|
32
|
+
function getCollectionType(collection) {
|
|
33
|
+
if (collection[0] == 1 || collection[0] == 2) {
|
|
34
|
+
return "[int]";
|
|
35
|
+
}
|
|
36
|
+
if (collection[0] == "a" || collection[0] == "b") {
|
|
37
|
+
return "[string]";
|
|
38
|
+
}
|
|
39
|
+
return "[unknown]";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Test 5: Type checking for operations
|
|
43
|
+
function safeAdd(a, b) {
|
|
44
|
+
print("Safe add: a=" + a + " (type=" + inferType(a) + "), b=" + b + " (type=" + inferType(b) + ")");
|
|
45
|
+
if (inferType(a) == "int" && inferType(b) == "int") {
|
|
46
|
+
return a + b;
|
|
47
|
+
}
|
|
48
|
+
print("Type mismatch in add operation");
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Test 6: Generic type handling
|
|
53
|
+
function genericMap(collection, transformer) {
|
|
54
|
+
print("Mapping collection of type: " + getCollectionType(collection));
|
|
55
|
+
let result = [];
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (i < 3) {
|
|
58
|
+
result[i] = transformer(collection[i]);
|
|
59
|
+
i = i + 1;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Test 7: Type constraints
|
|
65
|
+
function constrainedOperation(value, minType, maxType) {
|
|
66
|
+
print("Constraining value to type range: " + minType + " to " + maxType);
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Test suite execution
|
|
71
|
+
print("Phase 5: Type System Test Suite");
|
|
72
|
+
print("================================");
|
|
73
|
+
|
|
74
|
+
// Test type inference
|
|
75
|
+
print("\nTesting type inference:");
|
|
76
|
+
print("Type of 42: " + inferType(42));
|
|
77
|
+
print("Type of 'hello': " + inferType("hello"));
|
|
78
|
+
print("Type of true: " + inferType(true));
|
|
79
|
+
print("Type of false: " + inferType(false));
|
|
80
|
+
|
|
81
|
+
// Test type validation
|
|
82
|
+
print("\nTesting type validation:");
|
|
83
|
+
isValidType(42, "int");
|
|
84
|
+
isValidType("world", "string");
|
|
85
|
+
isValidType(true, "bool");
|
|
86
|
+
|
|
87
|
+
// Test typed operations
|
|
88
|
+
print("\nTesting typed operations:");
|
|
89
|
+
let sum = typedAdd(10, 20);
|
|
90
|
+
print("Typed add(10, 20) = " + sum);
|
|
91
|
+
|
|
92
|
+
// Test collection types
|
|
93
|
+
print("\nTesting collection types:");
|
|
94
|
+
let intList = [1, 2, 3, 4, 5];
|
|
95
|
+
print("Collection type: " + getCollectionType(intList));
|
|
96
|
+
|
|
97
|
+
let stringList = ["apple", "banana", "cherry"];
|
|
98
|
+
print("Collection type: " + getCollectionType(stringList));
|
|
99
|
+
|
|
100
|
+
// Test safe operations
|
|
101
|
+
print("\nTesting safe operations:");
|
|
102
|
+
safeAdd(5, 10);
|
|
103
|
+
safeAdd(3, 7);
|
|
104
|
+
|
|
105
|
+
// Test generic mapping
|
|
106
|
+
print("\nTesting generic mapping:");
|
|
107
|
+
let mapped = genericMap([1, 2, 3], function(x) {
|
|
108
|
+
return x * 2;
|
|
109
|
+
});
|
|
110
|
+
print("Mapped result: " + mapped);
|
|
111
|
+
|
|
112
|
+
// Test type constraints
|
|
113
|
+
print("\nTesting type constraints:");
|
|
114
|
+
constrainedOperation(50, "int", "int");
|
|
115
|
+
constrainedOperation("data", "string", "string");
|
|
116
|
+
|
|
117
|
+
print("\n✓ All type system tests completed");
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Zexus Phase 6: Metaprogramming Test Suite
|
|
2
|
+
// Tests AST manipulation, reflection, and macros
|
|
3
|
+
|
|
4
|
+
// Test 1: Reflection API
|
|
5
|
+
function getObjectInfo(obj) {
|
|
6
|
+
print("Reflecting on object");
|
|
7
|
+
return {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"methods": ["method1", "method2"],
|
|
10
|
+
"attributes": ["attr1", "attr2"]
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Test 2: Function reflection
|
|
15
|
+
function getFunctionInfo(func) {
|
|
16
|
+
print("Reflecting on function: " + func);
|
|
17
|
+
return {
|
|
18
|
+
"name": func,
|
|
19
|
+
"arity": 2,
|
|
20
|
+
"returnType": "unknown"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Test 3: Macro-like code generation
|
|
25
|
+
function generateGetter(propertyName) {
|
|
26
|
+
print("Generating getter for: " + propertyName);
|
|
27
|
+
return function() {
|
|
28
|
+
print("Getting property: " + propertyName);
|
|
29
|
+
return "value_of_" + propertyName;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Test 4: AST-like node creation
|
|
34
|
+
function createFunctionNode(name, params, body) {
|
|
35
|
+
print("Creating AST node for function: " + name);
|
|
36
|
+
return {
|
|
37
|
+
"type": "FunctionNode",
|
|
38
|
+
"name": name,
|
|
39
|
+
"params": params,
|
|
40
|
+
"body": body
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Test 5: Code inspection
|
|
45
|
+
function inspectCode(code) {
|
|
46
|
+
print("Inspecting code");
|
|
47
|
+
return {
|
|
48
|
+
"statements": 5,
|
|
49
|
+
"functions": 2,
|
|
50
|
+
"variables": 10
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Test 6: Meta-information tracking
|
|
55
|
+
function trackMetadata(item, metadata) {
|
|
56
|
+
print("Tracking metadata for: " + item);
|
|
57
|
+
return {
|
|
58
|
+
"item": item,
|
|
59
|
+
"metadata": metadata,
|
|
60
|
+
"timestamp": 12345
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Test 7: Compile-time transformation
|
|
65
|
+
function transformAST(node) {
|
|
66
|
+
print("Transforming AST node of type: " + node["type"]);
|
|
67
|
+
return node;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Test suite execution
|
|
71
|
+
print("Phase 6: Metaprogramming Test Suite");
|
|
72
|
+
print("====================================");
|
|
73
|
+
|
|
74
|
+
// Test reflection
|
|
75
|
+
print("\nTesting object reflection:");
|
|
76
|
+
let objInfo = getObjectInfo({});
|
|
77
|
+
print("Object info retrieved");
|
|
78
|
+
|
|
79
|
+
let funcInfo = getFunctionInfo("myFunction");
|
|
80
|
+
print("Function arity: " + funcInfo["arity"]);
|
|
81
|
+
|
|
82
|
+
// Test code generation
|
|
83
|
+
print("\nTesting code generation:");
|
|
84
|
+
let getter = generateGetter("username");
|
|
85
|
+
let value = getter();
|
|
86
|
+
print("Generated getter result: " + value);
|
|
87
|
+
|
|
88
|
+
let getter2 = generateGetter("email");
|
|
89
|
+
let value2 = getter2();
|
|
90
|
+
print("Generated getter result: " + value2);
|
|
91
|
+
|
|
92
|
+
// Test AST node creation
|
|
93
|
+
print("\nTesting AST node creation:");
|
|
94
|
+
let node1 = createFunctionNode("add", ["a", "b"], "return a + b");
|
|
95
|
+
print("Created function node: " + node1["name"]);
|
|
96
|
+
|
|
97
|
+
let node2 = createFunctionNode("multiply", ["x", "y"], "return x * y");
|
|
98
|
+
print("Created function node: " + node2["name"]);
|
|
99
|
+
|
|
100
|
+
// Test code inspection
|
|
101
|
+
print("\nTesting code inspection:");
|
|
102
|
+
let codeInfo = inspectCode("some code here");
|
|
103
|
+
print("Code has " + codeInfo["functions"] + " functions");
|
|
104
|
+
print("Code has " + codeInfo["variables"] + " variables");
|
|
105
|
+
|
|
106
|
+
// Test metadata tracking
|
|
107
|
+
print("\nTesting metadata tracking:");
|
|
108
|
+
let meta1 = trackMetadata("function_add", {"pure": true, "inline": true});
|
|
109
|
+
print("Metadata tracked for: " + meta1["item"]);
|
|
110
|
+
|
|
111
|
+
let meta2 = trackMetadata("variable_counter", {"mutable": true, "scope": "local"});
|
|
112
|
+
print("Metadata tracked for: " + meta2["item"]);
|
|
113
|
+
|
|
114
|
+
// Test AST transformation
|
|
115
|
+
print("\nTesting AST transformation:");
|
|
116
|
+
let originalNode = {
|
|
117
|
+
"type": "BinaryOp",
|
|
118
|
+
"left": "a",
|
|
119
|
+
"right": "b",
|
|
120
|
+
"op": "+"
|
|
121
|
+
};
|
|
122
|
+
let transformedNode = transformAST(originalNode);
|
|
123
|
+
print("Transformed node type: " + transformedNode["type"]);
|
|
124
|
+
|
|
125
|
+
print("\n✓ All metaprogramming tests completed");
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Zexus Phase 7: Optimization Test Suite
|
|
2
|
+
// Tests bytecode compilation, profiling, and optimization passes
|
|
3
|
+
|
|
4
|
+
// Test 1: Constant folding
|
|
5
|
+
function testConstantFolding() {
|
|
6
|
+
let x = 5 + 3; // Should be optimized to 8
|
|
7
|
+
let y = 10 * 2; // Should be optimized to 20
|
|
8
|
+
let z = x + y; // Should be optimized to 28
|
|
9
|
+
return z;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Test 2: Dead code elimination
|
|
13
|
+
function testDeadCodeElimination() {
|
|
14
|
+
let used = 42;
|
|
15
|
+
let unused = 99; // Dead code - not used
|
|
16
|
+
return used;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Test 3: Function inlining
|
|
20
|
+
inline function inlineableFunction(a, b) {
|
|
21
|
+
return a + b;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function testInlining() {
|
|
25
|
+
let result = inlineableFunction(5, 3);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Test 4: Loop unrolling
|
|
30
|
+
function testLoopUnrolling() {
|
|
31
|
+
let sum = 0;
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (i < 4) {
|
|
34
|
+
sum = sum + i;
|
|
35
|
+
i = i + 1;
|
|
36
|
+
}
|
|
37
|
+
return sum; // Could be unrolled: 0+1+2+3=6
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Test 5: Strength reduction
|
|
41
|
+
function testStrengthReduction() {
|
|
42
|
+
let x = 10;
|
|
43
|
+
let y = x * 2; // Could be optimized to x + x
|
|
44
|
+
let z = x * 4; // Could be optimized to x << 2
|
|
45
|
+
return y + z;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Test 6: Function profiling
|
|
49
|
+
function profiledFunction(n) {
|
|
50
|
+
let result = 0;
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (i < n) {
|
|
53
|
+
result = result + i;
|
|
54
|
+
i = i + 1;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Test 7: Hot path optimization
|
|
60
|
+
pure function hotPathFunction(x) {
|
|
61
|
+
if (x > 0) {
|
|
62
|
+
return x * 2; // Hot path - executed frequently
|
|
63
|
+
} else {
|
|
64
|
+
return x * 3; // Cold path - rarely executed
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Test 8: Bytecode representation
|
|
69
|
+
function testBytecodeGeneration() {
|
|
70
|
+
let a = 10;
|
|
71
|
+
let b = 20;
|
|
72
|
+
let c = a + b;
|
|
73
|
+
return c;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Test suite execution
|
|
77
|
+
print("Phase 7: Optimization Test Suite");
|
|
78
|
+
print("=================================");
|
|
79
|
+
|
|
80
|
+
// Test constant folding
|
|
81
|
+
print("\nTesting constant folding:");
|
|
82
|
+
let cf_result = testConstantFolding();
|
|
83
|
+
print("Constant folding result: " + cf_result);
|
|
84
|
+
|
|
85
|
+
// Test dead code elimination
|
|
86
|
+
print("\nTesting dead code elimination:");
|
|
87
|
+
let dce_result = testDeadCodeElimination();
|
|
88
|
+
print("Dead code elimination result: " + dce_result);
|
|
89
|
+
|
|
90
|
+
// Test inlining
|
|
91
|
+
print("\nTesting function inlining:");
|
|
92
|
+
let inline_result = testInlining();
|
|
93
|
+
print("Inlining result: " + inline_result);
|
|
94
|
+
|
|
95
|
+
// Test loop unrolling
|
|
96
|
+
print("\nTesting loop unrolling:");
|
|
97
|
+
let unroll_result = testLoopUnrolling();
|
|
98
|
+
print("Loop unrolling result: " + unroll_result);
|
|
99
|
+
|
|
100
|
+
// Test strength reduction
|
|
101
|
+
print("\nTesting strength reduction:");
|
|
102
|
+
let sr_result = testStrengthReduction();
|
|
103
|
+
print("Strength reduction result: " + sr_result);
|
|
104
|
+
|
|
105
|
+
// Test profiling
|
|
106
|
+
print("\nTesting function profiling:");
|
|
107
|
+
let prof_result1 = profiledFunction(5);
|
|
108
|
+
print("Profiled function(5) = " + prof_result1);
|
|
109
|
+
|
|
110
|
+
let prof_result2 = profiledFunction(10);
|
|
111
|
+
print("Profiled function(10) = " + prof_result2);
|
|
112
|
+
|
|
113
|
+
let prof_result3 = profiledFunction(100);
|
|
114
|
+
print("Profiled function(100) = " + prof_result3);
|
|
115
|
+
|
|
116
|
+
// Test hot path
|
|
117
|
+
print("\nTesting hot path optimization:");
|
|
118
|
+
let hot1 = hotPathFunction(5);
|
|
119
|
+
print("Hot path result (x=5): " + hot1);
|
|
120
|
+
|
|
121
|
+
let hot2 = hotPathFunction(-3);
|
|
122
|
+
print("Cold path result (x=-3): " + hot2);
|
|
123
|
+
|
|
124
|
+
let hot3 = hotPathFunction(7);
|
|
125
|
+
print("Hot path result (x=7): " + hot3);
|
|
126
|
+
|
|
127
|
+
// Test bytecode generation
|
|
128
|
+
print("\nTesting bytecode generation:");
|
|
129
|
+
let bc_result = testBytecodeGeneration();
|
|
130
|
+
print("Bytecode test result: " + bc_result);
|
|
131
|
+
|
|
132
|
+
print("\n✓ All optimization tests completed");
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Zexus Phase 9: Advanced Types Test Suite
|
|
2
|
+
// Tests generics, traits, union types, and type bounds
|
|
3
|
+
|
|
4
|
+
// Test 1: Generic-like function
|
|
5
|
+
function genericContainer(value) {
|
|
6
|
+
return {
|
|
7
|
+
"value": value,
|
|
8
|
+
"get": function() {
|
|
9
|
+
return value;
|
|
10
|
+
},
|
|
11
|
+
"set": function(newValue) {
|
|
12
|
+
value = newValue;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Test 2: Type parameters simulation
|
|
18
|
+
function genericMap(collection, transformer) {
|
|
19
|
+
print("Mapping collection");
|
|
20
|
+
let result = [];
|
|
21
|
+
let i = 0;
|
|
22
|
+
while (i < 3) {
|
|
23
|
+
result[i] = transformer(collection[i]);
|
|
24
|
+
i = i + 1;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Test 3: Trait-like interface - Iterable
|
|
30
|
+
function implementsIterable(obj) {
|
|
31
|
+
print("Checking if object implements Iterable");
|
|
32
|
+
if (obj["__iter__"] != false) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Test 4: Trait-like interface - Comparable
|
|
39
|
+
function implementsComparable(obj) {
|
|
40
|
+
print("Checking if object implements Comparable");
|
|
41
|
+
if (obj["compare"] != false) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Test 5: Trait-like interface - Cloneable
|
|
48
|
+
function implementsCloneable(obj) {
|
|
49
|
+
print("Checking if object implements Cloneable");
|
|
50
|
+
if (obj["clone"] != false) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Test 6: Union type handling
|
|
57
|
+
function unionTypeOperation(value) {
|
|
58
|
+
print("Operating on union type value");
|
|
59
|
+
if (value == 42 || value == "string" || value == true) {
|
|
60
|
+
return "valid union type";
|
|
61
|
+
}
|
|
62
|
+
return "invalid union type";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Test 7: Type bounds
|
|
66
|
+
function boundedGeneric(value, minType, maxType) {
|
|
67
|
+
print("Applying type bounds: " + minType + " to " + maxType);
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Test 8: Variance in types
|
|
72
|
+
function covariantFunction(value) {
|
|
73
|
+
print("Operating on covariant type");
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Test suite execution
|
|
78
|
+
print("Phase 9: Advanced Types Test Suite");
|
|
79
|
+
print("===================================");
|
|
80
|
+
|
|
81
|
+
// Test generics
|
|
82
|
+
print("\nTesting generic containers:");
|
|
83
|
+
let container1 = genericContainer(42);
|
|
84
|
+
print("Container value: " + container1["get"]());
|
|
85
|
+
|
|
86
|
+
container1["set"](99);
|
|
87
|
+
print("Updated container value: " + container1["get"]());
|
|
88
|
+
|
|
89
|
+
let container2 = genericContainer("hello");
|
|
90
|
+
print("String container value: " + container2["get"]());
|
|
91
|
+
|
|
92
|
+
// Test generic mapping
|
|
93
|
+
print("\nTesting generic mapping:");
|
|
94
|
+
let numbers = [1, 2, 3];
|
|
95
|
+
let doubled = genericMap(numbers, function(x) {
|
|
96
|
+
return x * 2;
|
|
97
|
+
});
|
|
98
|
+
print("Doubled numbers: " + doubled);
|
|
99
|
+
|
|
100
|
+
let strings = ["a", "b", "c"];
|
|
101
|
+
let uppercased = genericMap(strings, function(x) {
|
|
102
|
+
return x + "_upper";
|
|
103
|
+
});
|
|
104
|
+
print("Uppercased strings: " + uppercased);
|
|
105
|
+
|
|
106
|
+
// Test traits - Iterable
|
|
107
|
+
print("\nTesting Iterable trait:");
|
|
108
|
+
let iterableObj = {
|
|
109
|
+
"data": [1, 2, 3],
|
|
110
|
+
"__iter__": function() {
|
|
111
|
+
return "iterator";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
let isIter = implementsIterable(iterableObj);
|
|
115
|
+
print("Object is Iterable: " + isIter);
|
|
116
|
+
|
|
117
|
+
// Test traits - Comparable
|
|
118
|
+
print("\nTesting Comparable trait:");
|
|
119
|
+
let comparableObj = {
|
|
120
|
+
"value": 42,
|
|
121
|
+
"compare": function(other) {
|
|
122
|
+
return other;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
let isComp = implementsComparable(comparableObj);
|
|
126
|
+
print("Object is Comparable: " + isComp);
|
|
127
|
+
|
|
128
|
+
// Test traits - Cloneable
|
|
129
|
+
print("\nTesting Cloneable trait:");
|
|
130
|
+
let cloneableObj = {
|
|
131
|
+
"data": "original",
|
|
132
|
+
"clone": function() {
|
|
133
|
+
return "cloned";
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
let isClonable = implementsCloneable(cloneableObj);
|
|
137
|
+
print("Object is Cloneable: " + isClonable);
|
|
138
|
+
|
|
139
|
+
// Test union types
|
|
140
|
+
print("\nTesting union types:");
|
|
141
|
+
unionTypeOperation(42);
|
|
142
|
+
unionTypeOperation("data");
|
|
143
|
+
unionTypeOperation(true);
|
|
144
|
+
unionTypeOperation(3.14);
|
|
145
|
+
|
|
146
|
+
// Test type bounds
|
|
147
|
+
print("\nTesting type bounds:");
|
|
148
|
+
boundedGeneric(50, "int", "int");
|
|
149
|
+
boundedGeneric("text", "string", "string");
|
|
150
|
+
|
|
151
|
+
// Test variance
|
|
152
|
+
print("\nTesting variance:");
|
|
153
|
+
covariantFunction(123);
|
|
154
|
+
covariantFunction("test");
|
|
155
|
+
covariantFunction({});
|
|
156
|
+
|
|
157
|
+
print("\n✓ All advanced type tests completed");
|