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,61 @@
|
|
|
1
|
+
"""JSON module for Zexus standard library."""
|
|
2
|
+
|
|
3
|
+
import json as json_lib
|
|
4
|
+
from typing import Any, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class JsonModule:
|
|
8
|
+
"""Provides JSON encoding and decoding operations."""
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def parse(text: str) -> Any:
|
|
12
|
+
"""Parse JSON string to object."""
|
|
13
|
+
return json_lib.loads(text)
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def stringify(obj: Any, indent: Optional[int] = None, sort_keys: bool = False) -> str:
|
|
17
|
+
"""Convert object to JSON string."""
|
|
18
|
+
return json_lib.dumps(obj, indent=indent, sort_keys=sort_keys, ensure_ascii=False)
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def load(file_path: str) -> Any:
|
|
22
|
+
"""Load JSON from file."""
|
|
23
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
24
|
+
return json_lib.load(f)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def save(file_path: str, obj: Any, indent: Optional[int] = 2, sort_keys: bool = False) -> None:
|
|
28
|
+
"""Save object to JSON file."""
|
|
29
|
+
with open(file_path, 'w', encoding='utf-8') as f:
|
|
30
|
+
json_lib.dump(obj, f, indent=indent, sort_keys=sort_keys, ensure_ascii=False)
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def validate(text: str) -> bool:
|
|
34
|
+
"""Check if string is valid JSON."""
|
|
35
|
+
try:
|
|
36
|
+
json_lib.loads(text)
|
|
37
|
+
return True
|
|
38
|
+
except (json_lib.JSONDecodeError, ValueError):
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def merge(obj1: dict, obj2: dict) -> dict:
|
|
43
|
+
"""Merge two JSON objects."""
|
|
44
|
+
result = obj1.copy()
|
|
45
|
+
result.update(obj2)
|
|
46
|
+
return result
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def pretty_print(obj: Any, indent: int = 2) -> str:
|
|
50
|
+
"""Pretty print JSON with indentation."""
|
|
51
|
+
return json_lib.dumps(obj, indent=indent, sort_keys=True, ensure_ascii=False)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# Export functions for easy access
|
|
55
|
+
parse = JsonModule.parse
|
|
56
|
+
stringify = JsonModule.stringify
|
|
57
|
+
load = JsonModule.load
|
|
58
|
+
save = JsonModule.save
|
|
59
|
+
validate = JsonModule.validate
|
|
60
|
+
merge = JsonModule.merge
|
|
61
|
+
pretty_print = JsonModule.pretty_print
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"""Math module for Zexus standard library."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import random
|
|
5
|
+
from typing import List
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MathModule:
|
|
9
|
+
"""Provides advanced mathematical operations."""
|
|
10
|
+
|
|
11
|
+
# Constants
|
|
12
|
+
PI = math.pi
|
|
13
|
+
E = math.e
|
|
14
|
+
TAU = math.tau
|
|
15
|
+
INF = math.inf
|
|
16
|
+
NAN = math.nan
|
|
17
|
+
|
|
18
|
+
# Trigonometric functions
|
|
19
|
+
@staticmethod
|
|
20
|
+
def sin(x: float) -> float:
|
|
21
|
+
"""Sine of x radians."""
|
|
22
|
+
return math.sin(x)
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def cos(x: float) -> float:
|
|
26
|
+
"""Cosine of x radians."""
|
|
27
|
+
return math.cos(x)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def tan(x: float) -> float:
|
|
31
|
+
"""Tangent of x radians."""
|
|
32
|
+
return math.tan(x)
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def asin(x: float) -> float:
|
|
36
|
+
"""Arc sine in radians."""
|
|
37
|
+
return math.asin(x)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def acos(x: float) -> float:
|
|
41
|
+
"""Arc cosine in radians."""
|
|
42
|
+
return math.acos(x)
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def atan(x: float) -> float:
|
|
46
|
+
"""Arc tangent in radians."""
|
|
47
|
+
return math.atan(x)
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def atan2(y: float, x: float) -> float:
|
|
51
|
+
"""Arc tangent of y/x in radians."""
|
|
52
|
+
return math.atan2(y, x)
|
|
53
|
+
|
|
54
|
+
# Hyperbolic functions
|
|
55
|
+
@staticmethod
|
|
56
|
+
def sinh(x: float) -> float:
|
|
57
|
+
"""Hyperbolic sine."""
|
|
58
|
+
return math.sinh(x)
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def cosh(x: float) -> float:
|
|
62
|
+
"""Hyperbolic cosine."""
|
|
63
|
+
return math.cosh(x)
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def tanh(x: float) -> float:
|
|
67
|
+
"""Hyperbolic tangent."""
|
|
68
|
+
return math.tanh(x)
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def asinh(x: float) -> float:
|
|
72
|
+
"""Inverse hyperbolic sine."""
|
|
73
|
+
return math.asinh(x)
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def acosh(x: float) -> float:
|
|
77
|
+
"""Inverse hyperbolic cosine."""
|
|
78
|
+
return math.acosh(x)
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def atanh(x: float) -> float:
|
|
82
|
+
"""Inverse hyperbolic tangent."""
|
|
83
|
+
return math.atanh(x)
|
|
84
|
+
|
|
85
|
+
# Power and logarithmic functions
|
|
86
|
+
@staticmethod
|
|
87
|
+
def exp(x: float) -> float:
|
|
88
|
+
"""e raised to power x."""
|
|
89
|
+
return math.exp(x)
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def log(x: float, base: float = math.e) -> float:
|
|
93
|
+
"""Logarithm of x to given base."""
|
|
94
|
+
return math.log(x, base)
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def log10(x: float) -> float:
|
|
98
|
+
"""Base-10 logarithm."""
|
|
99
|
+
return math.log10(x)
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def log2(x: float) -> float:
|
|
103
|
+
"""Base-2 logarithm."""
|
|
104
|
+
return math.log2(x)
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def log1p(x: float) -> float:
|
|
108
|
+
"""Natural logarithm of 1+x."""
|
|
109
|
+
return math.log1p(x)
|
|
110
|
+
|
|
111
|
+
@staticmethod
|
|
112
|
+
def pow(x: float, y: float) -> float:
|
|
113
|
+
"""x raised to power y."""
|
|
114
|
+
return math.pow(x, y)
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def sqrt(x: float) -> float:
|
|
118
|
+
"""Square root."""
|
|
119
|
+
return math.sqrt(x)
|
|
120
|
+
|
|
121
|
+
@staticmethod
|
|
122
|
+
def cbrt(x: float) -> float:
|
|
123
|
+
"""Cube root."""
|
|
124
|
+
return math.copysign(1, x) * abs(x) ** (1/3)
|
|
125
|
+
|
|
126
|
+
# Rounding and absolute functions
|
|
127
|
+
@staticmethod
|
|
128
|
+
def ceil(x: float) -> int:
|
|
129
|
+
"""Ceiling (smallest integer >= x)."""
|
|
130
|
+
return math.ceil(x)
|
|
131
|
+
|
|
132
|
+
@staticmethod
|
|
133
|
+
def floor(x: float) -> int:
|
|
134
|
+
"""Floor (largest integer <= x)."""
|
|
135
|
+
return math.floor(x)
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def trunc(x: float) -> int:
|
|
139
|
+
"""Truncate to integer."""
|
|
140
|
+
return math.trunc(x)
|
|
141
|
+
|
|
142
|
+
@staticmethod
|
|
143
|
+
def round(x: float, ndigits: int = 0) -> float:
|
|
144
|
+
"""Round to n digits."""
|
|
145
|
+
return round(x, ndigits)
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def abs(x: float) -> float:
|
|
149
|
+
"""Absolute value."""
|
|
150
|
+
return abs(x)
|
|
151
|
+
|
|
152
|
+
# Other functions
|
|
153
|
+
@staticmethod
|
|
154
|
+
def factorial(n: int) -> int:
|
|
155
|
+
"""Factorial of n."""
|
|
156
|
+
return math.factorial(n)
|
|
157
|
+
|
|
158
|
+
@staticmethod
|
|
159
|
+
def gcd(a: int, b: int) -> int:
|
|
160
|
+
"""Greatest common divisor."""
|
|
161
|
+
return math.gcd(a, b)
|
|
162
|
+
|
|
163
|
+
@staticmethod
|
|
164
|
+
def lcm(a: int, b: int) -> int:
|
|
165
|
+
"""Least common multiple."""
|
|
166
|
+
return abs(a * b) // math.gcd(a, b) if a and b else 0
|
|
167
|
+
|
|
168
|
+
@staticmethod
|
|
169
|
+
def degrees(x: float) -> float:
|
|
170
|
+
"""Convert radians to degrees."""
|
|
171
|
+
return math.degrees(x)
|
|
172
|
+
|
|
173
|
+
@staticmethod
|
|
174
|
+
def radians(x: float) -> float:
|
|
175
|
+
"""Convert degrees to radians."""
|
|
176
|
+
return math.radians(x)
|
|
177
|
+
|
|
178
|
+
@staticmethod
|
|
179
|
+
def copysign(x: float, y: float) -> float:
|
|
180
|
+
"""Return x with sign of y."""
|
|
181
|
+
return math.copysign(x, y)
|
|
182
|
+
|
|
183
|
+
@staticmethod
|
|
184
|
+
def fmod(x: float, y: float) -> float:
|
|
185
|
+
"""Floating point remainder of x/y."""
|
|
186
|
+
return math.fmod(x, y)
|
|
187
|
+
|
|
188
|
+
@staticmethod
|
|
189
|
+
def modf(x: float) -> tuple:
|
|
190
|
+
"""Return fractional and integer parts."""
|
|
191
|
+
return math.modf(x)
|
|
192
|
+
|
|
193
|
+
@staticmethod
|
|
194
|
+
def isnan(x: float) -> bool:
|
|
195
|
+
"""Check if x is NaN."""
|
|
196
|
+
return math.isnan(x)
|
|
197
|
+
|
|
198
|
+
@staticmethod
|
|
199
|
+
def isinf(x: float) -> bool:
|
|
200
|
+
"""Check if x is infinite."""
|
|
201
|
+
return math.isinf(x)
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def isfinite(x: float) -> bool:
|
|
205
|
+
"""Check if x is finite."""
|
|
206
|
+
return math.isfinite(x)
|
|
207
|
+
|
|
208
|
+
# Statistics functions
|
|
209
|
+
@staticmethod
|
|
210
|
+
def sum(numbers: List[float]) -> float:
|
|
211
|
+
"""Sum of numbers."""
|
|
212
|
+
return sum(numbers)
|
|
213
|
+
|
|
214
|
+
@staticmethod
|
|
215
|
+
def mean(numbers: List[float]) -> float:
|
|
216
|
+
"""Arithmetic mean."""
|
|
217
|
+
return sum(numbers) / len(numbers) if numbers else 0
|
|
218
|
+
|
|
219
|
+
@staticmethod
|
|
220
|
+
def median(numbers: List[float]) -> float:
|
|
221
|
+
"""Median value."""
|
|
222
|
+
sorted_nums = sorted(numbers)
|
|
223
|
+
n = len(sorted_nums)
|
|
224
|
+
if n == 0:
|
|
225
|
+
return 0
|
|
226
|
+
mid = n // 2
|
|
227
|
+
if n % 2 == 0:
|
|
228
|
+
return (sorted_nums[mid - 1] + sorted_nums[mid]) / 2
|
|
229
|
+
return sorted_nums[mid]
|
|
230
|
+
|
|
231
|
+
@staticmethod
|
|
232
|
+
def mode(numbers: List[float]) -> float:
|
|
233
|
+
"""Most common value."""
|
|
234
|
+
if not numbers:
|
|
235
|
+
return 0
|
|
236
|
+
from collections import Counter
|
|
237
|
+
return Counter(numbers).most_common(1)[0][0]
|
|
238
|
+
|
|
239
|
+
@staticmethod
|
|
240
|
+
def variance(numbers: List[float]) -> float:
|
|
241
|
+
"""Population variance."""
|
|
242
|
+
if not numbers:
|
|
243
|
+
return 0
|
|
244
|
+
m = MathModule.mean(numbers)
|
|
245
|
+
return sum((x - m) ** 2 for x in numbers) / len(numbers)
|
|
246
|
+
|
|
247
|
+
@staticmethod
|
|
248
|
+
def stdev(numbers: List[float]) -> float:
|
|
249
|
+
"""Population standard deviation."""
|
|
250
|
+
return math.sqrt(MathModule.variance(numbers))
|
|
251
|
+
|
|
252
|
+
@staticmethod
|
|
253
|
+
def min(numbers: List[float]) -> float:
|
|
254
|
+
"""Minimum value."""
|
|
255
|
+
return min(numbers) if numbers else 0
|
|
256
|
+
|
|
257
|
+
@staticmethod
|
|
258
|
+
def max(numbers: List[float]) -> float:
|
|
259
|
+
"""Maximum value."""
|
|
260
|
+
return max(numbers) if numbers else 0
|
|
261
|
+
|
|
262
|
+
@staticmethod
|
|
263
|
+
def clamp(x: float, min_val: float, max_val: float) -> float:
|
|
264
|
+
"""Clamp x between min and max."""
|
|
265
|
+
return max(min_val, min(max_val, x))
|
|
266
|
+
|
|
267
|
+
@staticmethod
|
|
268
|
+
def lerp(a: float, b: float, t: float) -> float:
|
|
269
|
+
"""Linear interpolation between a and b."""
|
|
270
|
+
return a + (b - a) * t
|
|
271
|
+
|
|
272
|
+
# Random functions
|
|
273
|
+
@staticmethod
|
|
274
|
+
def random() -> float:
|
|
275
|
+
"""Random float in [0, 1)."""
|
|
276
|
+
return random.random()
|
|
277
|
+
|
|
278
|
+
@staticmethod
|
|
279
|
+
def randint(a: int, b: int) -> int:
|
|
280
|
+
"""Random integer in [a, b]."""
|
|
281
|
+
return random.randint(a, b)
|
|
282
|
+
|
|
283
|
+
@staticmethod
|
|
284
|
+
def randrange(start: int, stop: int = None, step: int = 1) -> int:
|
|
285
|
+
"""Random integer from range."""
|
|
286
|
+
if stop is None:
|
|
287
|
+
return random.randrange(start)
|
|
288
|
+
return random.randrange(start, stop, step)
|
|
289
|
+
|
|
290
|
+
@staticmethod
|
|
291
|
+
def choice(seq: List) -> any:
|
|
292
|
+
"""Random element from sequence."""
|
|
293
|
+
return random.choice(seq) if seq else None
|
|
294
|
+
|
|
295
|
+
@staticmethod
|
|
296
|
+
def shuffle(seq: List) -> List:
|
|
297
|
+
"""Shuffle sequence (returns new list)."""
|
|
298
|
+
result = seq.copy()
|
|
299
|
+
random.shuffle(result)
|
|
300
|
+
return result
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
# Export all functions and constants
|
|
304
|
+
PI = MathModule.PI
|
|
305
|
+
E = MathModule.E
|
|
306
|
+
TAU = MathModule.TAU
|
|
307
|
+
INF = MathModule.INF
|
|
308
|
+
NAN = MathModule.NAN
|
|
309
|
+
sin = MathModule.sin
|
|
310
|
+
cos = MathModule.cos
|
|
311
|
+
tan = MathModule.tan
|
|
312
|
+
asin = MathModule.asin
|
|
313
|
+
acos = MathModule.acos
|
|
314
|
+
atan = MathModule.atan
|
|
315
|
+
atan2 = MathModule.atan2
|
|
316
|
+
sinh = MathModule.sinh
|
|
317
|
+
cosh = MathModule.cosh
|
|
318
|
+
tanh = MathModule.tanh
|
|
319
|
+
asinh = MathModule.asinh
|
|
320
|
+
acosh = MathModule.acosh
|
|
321
|
+
atanh = MathModule.atanh
|
|
322
|
+
exp = MathModule.exp
|
|
323
|
+
log = MathModule.log
|
|
324
|
+
log10 = MathModule.log10
|
|
325
|
+
log2 = MathModule.log2
|
|
326
|
+
log1p = MathModule.log1p
|
|
327
|
+
pow = MathModule.pow
|
|
328
|
+
sqrt = MathModule.sqrt
|
|
329
|
+
cbrt = MathModule.cbrt
|
|
330
|
+
ceil = MathModule.ceil
|
|
331
|
+
floor = MathModule.floor
|
|
332
|
+
trunc = MathModule.trunc
|
|
333
|
+
round = MathModule.round
|
|
334
|
+
abs = MathModule.abs
|
|
335
|
+
factorial = MathModule.factorial
|
|
336
|
+
gcd = MathModule.gcd
|
|
337
|
+
lcm = MathModule.lcm
|
|
338
|
+
degrees = MathModule.degrees
|
|
339
|
+
radians = MathModule.radians
|
|
340
|
+
copysign = MathModule.copysign
|
|
341
|
+
fmod = MathModule.fmod
|
|
342
|
+
modf = MathModule.modf
|
|
343
|
+
isnan = MathModule.isnan
|
|
344
|
+
isinf = MathModule.isinf
|
|
345
|
+
isfinite = MathModule.isfinite
|
|
346
|
+
sum = MathModule.sum
|
|
347
|
+
mean = MathModule.mean
|
|
348
|
+
median = MathModule.median
|
|
349
|
+
mode = MathModule.mode
|
|
350
|
+
variance = MathModule.variance
|
|
351
|
+
stdev = MathModule.stdev
|
|
352
|
+
min = MathModule.min
|
|
353
|
+
max = MathModule.max
|
|
354
|
+
clamp = MathModule.clamp
|
|
355
|
+
lerp = MathModule.lerp
|
|
356
|
+
random = MathModule.random
|
|
357
|
+
randint = MathModule.randint
|
|
358
|
+
randrange = MathModule.randrange
|
|
359
|
+
choice = MathModule.choice
|
|
360
|
+
shuffle = MathModule.shuffle
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"""OS module for Zexus standard library."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import platform
|
|
6
|
+
import subprocess
|
|
7
|
+
from typing import Dict, List, Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OSModule:
|
|
11
|
+
"""Provides OS-specific operations."""
|
|
12
|
+
|
|
13
|
+
@staticmethod
|
|
14
|
+
def name() -> str:
|
|
15
|
+
"""Get OS name."""
|
|
16
|
+
return os.name
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def platform_system() -> str:
|
|
20
|
+
"""Get platform system (Linux, Windows, Darwin, etc.)."""
|
|
21
|
+
return platform.system()
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def platform_release() -> str:
|
|
25
|
+
"""Get platform release version."""
|
|
26
|
+
return platform.release()
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def platform_version() -> str:
|
|
30
|
+
"""Get platform version."""
|
|
31
|
+
return platform.version()
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def platform_machine() -> str:
|
|
35
|
+
"""Get machine type."""
|
|
36
|
+
return platform.machine()
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def platform_processor() -> str:
|
|
40
|
+
"""Get processor name."""
|
|
41
|
+
return platform.processor()
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def python_version() -> str:
|
|
45
|
+
"""Get Python version."""
|
|
46
|
+
return platform.python_version()
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def getcwd() -> str:
|
|
50
|
+
"""Get current working directory."""
|
|
51
|
+
return os.getcwd()
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def chdir(path: str) -> None:
|
|
55
|
+
"""Change current working directory."""
|
|
56
|
+
os.chdir(path)
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def getenv(name: str, default: str = "") -> str:
|
|
60
|
+
"""Get environment variable."""
|
|
61
|
+
return os.getenv(name, default)
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def setenv(name: str, value: str) -> None:
|
|
65
|
+
"""Set environment variable."""
|
|
66
|
+
os.environ[name] = value
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def unsetenv(name: str) -> None:
|
|
70
|
+
"""Unset environment variable."""
|
|
71
|
+
if name in os.environ:
|
|
72
|
+
del os.environ[name]
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def listenv() -> Dict[str, str]:
|
|
76
|
+
"""List all environment variables."""
|
|
77
|
+
return dict(os.environ)
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def get_home_dir() -> str:
|
|
81
|
+
"""Get user home directory."""
|
|
82
|
+
return os.path.expanduser("~")
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def get_temp_dir() -> str:
|
|
86
|
+
"""Get temporary directory."""
|
|
87
|
+
import tempfile
|
|
88
|
+
return tempfile.gettempdir()
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def get_username() -> str:
|
|
92
|
+
"""Get current username."""
|
|
93
|
+
return os.getlogin() if hasattr(os, 'getlogin') else os.getenv('USER', os.getenv('USERNAME', 'unknown'))
|
|
94
|
+
|
|
95
|
+
@staticmethod
|
|
96
|
+
def get_hostname() -> str:
|
|
97
|
+
"""Get hostname."""
|
|
98
|
+
return platform.node()
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def get_pid() -> int:
|
|
102
|
+
"""Get current process ID."""
|
|
103
|
+
return os.getpid()
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def get_ppid() -> int:
|
|
107
|
+
"""Get parent process ID."""
|
|
108
|
+
return os.getppid()
|
|
109
|
+
|
|
110
|
+
@staticmethod
|
|
111
|
+
def cpu_count() -> int:
|
|
112
|
+
"""Get number of CPUs."""
|
|
113
|
+
return os.cpu_count() or 1
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def execute(command: str, shell: bool = True, capture_output: bool = True) -> Dict[str, Any]:
|
|
117
|
+
"""Execute shell command."""
|
|
118
|
+
try:
|
|
119
|
+
result = subprocess.run(
|
|
120
|
+
command,
|
|
121
|
+
shell=shell,
|
|
122
|
+
capture_output=capture_output,
|
|
123
|
+
text=True,
|
|
124
|
+
timeout=30
|
|
125
|
+
)
|
|
126
|
+
return {
|
|
127
|
+
'returncode': result.returncode,
|
|
128
|
+
'stdout': result.stdout if capture_output else '',
|
|
129
|
+
'stderr': result.stderr if capture_output else '',
|
|
130
|
+
'success': result.returncode == 0
|
|
131
|
+
}
|
|
132
|
+
except subprocess.TimeoutExpired:
|
|
133
|
+
return {
|
|
134
|
+
'returncode': -1,
|
|
135
|
+
'stdout': '',
|
|
136
|
+
'stderr': 'Command timed out',
|
|
137
|
+
'success': False
|
|
138
|
+
}
|
|
139
|
+
except Exception as e:
|
|
140
|
+
return {
|
|
141
|
+
'returncode': -1,
|
|
142
|
+
'stdout': '',
|
|
143
|
+
'stderr': str(e),
|
|
144
|
+
'success': False
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def path_join(*parts: str) -> str:
|
|
149
|
+
"""Join path components."""
|
|
150
|
+
return os.path.join(*parts)
|
|
151
|
+
|
|
152
|
+
@staticmethod
|
|
153
|
+
def path_split(path: str) -> tuple:
|
|
154
|
+
"""Split path into directory and file."""
|
|
155
|
+
return os.path.split(path)
|
|
156
|
+
|
|
157
|
+
@staticmethod
|
|
158
|
+
def path_dirname(path: str) -> str:
|
|
159
|
+
"""Get directory name from path."""
|
|
160
|
+
return os.path.dirname(path)
|
|
161
|
+
|
|
162
|
+
@staticmethod
|
|
163
|
+
def path_basename(path: str) -> str:
|
|
164
|
+
"""Get base name from path."""
|
|
165
|
+
return os.path.basename(path)
|
|
166
|
+
|
|
167
|
+
@staticmethod
|
|
168
|
+
def path_exists(path: str) -> bool:
|
|
169
|
+
"""Check if path exists."""
|
|
170
|
+
return os.path.exists(path)
|
|
171
|
+
|
|
172
|
+
@staticmethod
|
|
173
|
+
def path_isfile(path: str) -> bool:
|
|
174
|
+
"""Check if path is a file."""
|
|
175
|
+
return os.path.isfile(path)
|
|
176
|
+
|
|
177
|
+
@staticmethod
|
|
178
|
+
def path_isdir(path: str) -> bool:
|
|
179
|
+
"""Check if path is a directory."""
|
|
180
|
+
return os.path.isdir(path)
|
|
181
|
+
|
|
182
|
+
@staticmethod
|
|
183
|
+
def path_abspath(path: str) -> str:
|
|
184
|
+
"""Get absolute path."""
|
|
185
|
+
return os.path.abspath(path)
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def path_realpath(path: str) -> str:
|
|
189
|
+
"""Get real path (resolving symlinks)."""
|
|
190
|
+
return os.path.realpath(path)
|
|
191
|
+
|
|
192
|
+
@staticmethod
|
|
193
|
+
def get_file_size(path: str) -> int:
|
|
194
|
+
"""Get file size in bytes."""
|
|
195
|
+
return os.path.getsize(path)
|
|
196
|
+
|
|
197
|
+
@staticmethod
|
|
198
|
+
def get_file_mtime(path: str) -> float:
|
|
199
|
+
"""Get file modification time."""
|
|
200
|
+
return os.path.getmtime(path)
|
|
201
|
+
|
|
202
|
+
@staticmethod
|
|
203
|
+
def get_file_atime(path: str) -> float:
|
|
204
|
+
"""Get file access time."""
|
|
205
|
+
return os.path.getatime(path)
|
|
206
|
+
|
|
207
|
+
@staticmethod
|
|
208
|
+
def get_file_ctime(path: str) -> float:
|
|
209
|
+
"""Get file creation time."""
|
|
210
|
+
return os.path.getctime(path)
|
|
211
|
+
|
|
212
|
+
@staticmethod
|
|
213
|
+
def get_path_separator() -> str:
|
|
214
|
+
"""Get path separator for current OS."""
|
|
215
|
+
return os.sep
|
|
216
|
+
|
|
217
|
+
@staticmethod
|
|
218
|
+
def get_path_delimiter() -> str:
|
|
219
|
+
"""Get path delimiter for current OS."""
|
|
220
|
+
return os.pathsep
|
|
221
|
+
|
|
222
|
+
@staticmethod
|
|
223
|
+
def get_line_separator() -> str:
|
|
224
|
+
"""Get line separator for current OS."""
|
|
225
|
+
return os.linesep
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# Export functions for easy access
|
|
229
|
+
name = OSModule.name
|
|
230
|
+
platform_system = OSModule.platform_system
|
|
231
|
+
platform_release = OSModule.platform_release
|
|
232
|
+
platform_version = OSModule.platform_version
|
|
233
|
+
platform_machine = OSModule.platform_machine
|
|
234
|
+
platform_processor = OSModule.platform_processor
|
|
235
|
+
python_version = OSModule.python_version
|
|
236
|
+
getcwd = OSModule.getcwd
|
|
237
|
+
chdir = OSModule.chdir
|
|
238
|
+
getenv = OSModule.getenv
|
|
239
|
+
setenv = OSModule.setenv
|
|
240
|
+
unsetenv = OSModule.unsetenv
|
|
241
|
+
listenv = OSModule.listenv
|
|
242
|
+
get_home_dir = OSModule.get_home_dir
|
|
243
|
+
get_temp_dir = OSModule.get_temp_dir
|
|
244
|
+
get_username = OSModule.get_username
|
|
245
|
+
get_hostname = OSModule.get_hostname
|
|
246
|
+
get_pid = OSModule.get_pid
|
|
247
|
+
get_ppid = OSModule.get_ppid
|
|
248
|
+
cpu_count = OSModule.cpu_count
|
|
249
|
+
execute = OSModule.execute
|
|
250
|
+
path_join = OSModule.path_join
|
|
251
|
+
path_split = OSModule.path_split
|
|
252
|
+
path_dirname = OSModule.path_dirname
|
|
253
|
+
path_basename = OSModule.path_basename
|
|
254
|
+
path_exists = OSModule.path_exists
|
|
255
|
+
path_isfile = OSModule.path_isfile
|
|
256
|
+
path_isdir = OSModule.path_isdir
|
|
257
|
+
path_abspath = OSModule.path_abspath
|
|
258
|
+
path_realpath = OSModule.path_realpath
|
|
259
|
+
get_file_size = OSModule.get_file_size
|
|
260
|
+
get_file_mtime = OSModule.get_file_mtime
|
|
261
|
+
get_file_atime = OSModule.get_file_atime
|
|
262
|
+
get_file_ctime = OSModule.get_file_ctime
|
|
263
|
+
get_path_separator = OSModule.get_path_separator
|
|
264
|
+
get_path_delimiter = OSModule.get_path_delimiter
|
|
265
|
+
get_line_separator = OSModule.get_line_separator
|