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.
Files changed (227) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +2513 -0
  3. package/bin/zexus +2 -0
  4. package/bin/zpics +2 -0
  5. package/bin/zpm +2 -0
  6. package/bin/zx +2 -0
  7. package/bin/zx-deploy +2 -0
  8. package/bin/zx-dev +2 -0
  9. package/bin/zx-run +2 -0
  10. package/package.json +66 -0
  11. package/scripts/README.md +24 -0
  12. package/scripts/postinstall.js +44 -0
  13. package/shared_config.json +24 -0
  14. package/src/README.md +1525 -0
  15. package/src/tests/run_zexus_tests.py +117 -0
  16. package/src/tests/test_all_phases.zx +346 -0
  17. package/src/tests/test_blockchain_features.zx +306 -0
  18. package/src/tests/test_complexity_features.zx +321 -0
  19. package/src/tests/test_core_integration.py +185 -0
  20. package/src/tests/test_phase10_ecosystem.zx +177 -0
  21. package/src/tests/test_phase1_modifiers.zx +87 -0
  22. package/src/tests/test_phase2_plugins.zx +80 -0
  23. package/src/tests/test_phase3_security.zx +97 -0
  24. package/src/tests/test_phase4_vfs.zx +116 -0
  25. package/src/tests/test_phase5_types.zx +117 -0
  26. package/src/tests/test_phase6_metaprogramming.zx +125 -0
  27. package/src/tests/test_phase7_optimization.zx +132 -0
  28. package/src/tests/test_phase9_advanced_types.zx +157 -0
  29. package/src/tests/test_security_features.py +419 -0
  30. package/src/tests/test_security_features.zx +276 -0
  31. package/src/tests/test_simple_zx.zx +1 -0
  32. package/src/tests/test_verification_simple.zx +69 -0
  33. package/src/zexus/__init__.py +28 -0
  34. package/src/zexus/__main__.py +5 -0
  35. package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
  36. package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
  37. package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
  38. package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
  39. package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
  40. package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
  41. package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
  42. package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
  43. package/src/zexus/__pycache__/ecosystem.cpython-312.pyc +0 -0
  44. package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
  45. package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
  46. package/src/zexus/__pycache__/hybrid_orchestrator.cpython-312.pyc +0 -0
  47. package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
  48. package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
  49. package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
  50. package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
  51. package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
  52. package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
  53. package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
  54. package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
  55. package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
  56. package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
  57. package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
  58. package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
  59. package/src/zexus/__pycache__/virtual_filesystem.cpython-312.pyc +0 -0
  60. package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  61. package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
  62. package/src/zexus/advanced_types.py +401 -0
  63. package/src/zexus/blockchain/__init__.py +40 -0
  64. package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
  65. package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
  66. package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
  67. package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
  68. package/src/zexus/blockchain/crypto.py +463 -0
  69. package/src/zexus/blockchain/ledger.py +255 -0
  70. package/src/zexus/blockchain/transaction.py +267 -0
  71. package/src/zexus/builtin_modules.py +284 -0
  72. package/src/zexus/builtin_plugins.py +317 -0
  73. package/src/zexus/capability_system.py +372 -0
  74. package/src/zexus/cli/__init__.py +2 -0
  75. package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
  76. package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
  77. package/src/zexus/cli/main.py +707 -0
  78. package/src/zexus/cli/zpm.py +203 -0
  79. package/src/zexus/compare_interpreter_compiler.py +146 -0
  80. package/src/zexus/compiler/__init__.py +169 -0
  81. package/src/zexus/compiler/__pycache__/__init__.cpython-312.pyc +0 -0
  82. package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
  83. package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
  84. package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  85. package/src/zexus/compiler/bytecode.py +266 -0
  86. package/src/zexus/compiler/compat_runtime.py +277 -0
  87. package/src/zexus/compiler/lexer.py +257 -0
  88. package/src/zexus/compiler/parser.py +779 -0
  89. package/src/zexus/compiler/semantic.py +118 -0
  90. package/src/zexus/compiler/zexus_ast.py +454 -0
  91. package/src/zexus/complexity_system.py +575 -0
  92. package/src/zexus/concurrency_system.py +493 -0
  93. package/src/zexus/config.py +201 -0
  94. package/src/zexus/crypto_bridge.py +19 -0
  95. package/src/zexus/dependency_injection.py +423 -0
  96. package/src/zexus/ecosystem.py +434 -0
  97. package/src/zexus/environment.py +101 -0
  98. package/src/zexus/environment_manager.py +119 -0
  99. package/src/zexus/error_reporter.py +314 -0
  100. package/src/zexus/evaluator/__init__.py +12 -0
  101. package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
  102. package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
  103. package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
  104. package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
  105. package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
  106. package/src/zexus/evaluator/__pycache__/integration.cpython-312.pyc +0 -0
  107. package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
  108. package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
  109. package/src/zexus/evaluator/bytecode_compiler.py +700 -0
  110. package/src/zexus/evaluator/core.py +891 -0
  111. package/src/zexus/evaluator/expressions.py +827 -0
  112. package/src/zexus/evaluator/functions.py +3989 -0
  113. package/src/zexus/evaluator/integration.py +396 -0
  114. package/src/zexus/evaluator/statements.py +4303 -0
  115. package/src/zexus/evaluator/utils.py +126 -0
  116. package/src/zexus/evaluator_original.py +2041 -0
  117. package/src/zexus/external_bridge.py +16 -0
  118. package/src/zexus/find_affected_imports.sh +155 -0
  119. package/src/zexus/hybrid_orchestrator.py +152 -0
  120. package/src/zexus/input_validation.py +259 -0
  121. package/src/zexus/lexer.py +571 -0
  122. package/src/zexus/logging.py +89 -0
  123. package/src/zexus/lsp/__init__.py +9 -0
  124. package/src/zexus/lsp/completion_provider.py +207 -0
  125. package/src/zexus/lsp/definition_provider.py +22 -0
  126. package/src/zexus/lsp/hover_provider.py +71 -0
  127. package/src/zexus/lsp/server.py +269 -0
  128. package/src/zexus/lsp/symbol_provider.py +31 -0
  129. package/src/zexus/metaprogramming.py +321 -0
  130. package/src/zexus/module_cache.py +89 -0
  131. package/src/zexus/module_manager.py +107 -0
  132. package/src/zexus/object.py +973 -0
  133. package/src/zexus/optimization.py +424 -0
  134. package/src/zexus/parser/__init__.py +31 -0
  135. package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
  136. package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
  137. package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
  138. package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
  139. package/src/zexus/parser/integration.py +86 -0
  140. package/src/zexus/parser/parser.py +3977 -0
  141. package/src/zexus/parser/strategy_context.py +7254 -0
  142. package/src/zexus/parser/strategy_structural.py +1033 -0
  143. package/src/zexus/persistence.py +391 -0
  144. package/src/zexus/plugin_system.py +290 -0
  145. package/src/zexus/policy_engine.py +365 -0
  146. package/src/zexus/profiler/__init__.py +5 -0
  147. package/src/zexus/profiler/profiler.py +233 -0
  148. package/src/zexus/purity_system.py +398 -0
  149. package/src/zexus/runtime/__init__.py +20 -0
  150. package/src/zexus/runtime/async_runtime.py +324 -0
  151. package/src/zexus/search_old_imports.sh +65 -0
  152. package/src/zexus/security.py +1407 -0
  153. package/src/zexus/stack_trace.py +233 -0
  154. package/src/zexus/stdlib/__init__.py +27 -0
  155. package/src/zexus/stdlib/blockchain.py +341 -0
  156. package/src/zexus/stdlib/compression.py +167 -0
  157. package/src/zexus/stdlib/crypto.py +124 -0
  158. package/src/zexus/stdlib/datetime.py +163 -0
  159. package/src/zexus/stdlib/db_mongo.py +199 -0
  160. package/src/zexus/stdlib/db_mysql.py +162 -0
  161. package/src/zexus/stdlib/db_postgres.py +163 -0
  162. package/src/zexus/stdlib/db_sqlite.py +133 -0
  163. package/src/zexus/stdlib/encoding.py +230 -0
  164. package/src/zexus/stdlib/fs.py +195 -0
  165. package/src/zexus/stdlib/http.py +219 -0
  166. package/src/zexus/stdlib/http_server.py +248 -0
  167. package/src/zexus/stdlib/json_module.py +61 -0
  168. package/src/zexus/stdlib/math.py +360 -0
  169. package/src/zexus/stdlib/os_module.py +265 -0
  170. package/src/zexus/stdlib/regex.py +148 -0
  171. package/src/zexus/stdlib/sockets.py +253 -0
  172. package/src/zexus/stdlib/test_framework.zx +208 -0
  173. package/src/zexus/stdlib/test_runner.zx +119 -0
  174. package/src/zexus/stdlib_integration.py +341 -0
  175. package/src/zexus/strategy_recovery.py +256 -0
  176. package/src/zexus/syntax_validator.py +356 -0
  177. package/src/zexus/testing/zpics.py +407 -0
  178. package/src/zexus/testing/zpics_runtime.py +369 -0
  179. package/src/zexus/type_system.py +374 -0
  180. package/src/zexus/validation_system.py +569 -0
  181. package/src/zexus/virtual_filesystem.py +355 -0
  182. package/src/zexus/vm/__init__.py +8 -0
  183. package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
  184. package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
  185. package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
  186. package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
  187. package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
  188. package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
  189. package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
  190. package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
  191. package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
  192. package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
  193. package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
  194. package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
  195. package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
  196. package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
  197. package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
  198. package/src/zexus/vm/async_optimizer.py +420 -0
  199. package/src/zexus/vm/bytecode.py +428 -0
  200. package/src/zexus/vm/bytecode_converter.py +297 -0
  201. package/src/zexus/vm/cache.py +532 -0
  202. package/src/zexus/vm/jit.py +720 -0
  203. package/src/zexus/vm/memory_manager.py +520 -0
  204. package/src/zexus/vm/memory_pool.py +511 -0
  205. package/src/zexus/vm/optimizer.py +478 -0
  206. package/src/zexus/vm/parallel_vm.py +899 -0
  207. package/src/zexus/vm/peephole_optimizer.py +452 -0
  208. package/src/zexus/vm/profiler.py +527 -0
  209. package/src/zexus/vm/register_allocator.py +462 -0
  210. package/src/zexus/vm/register_vm.py +520 -0
  211. package/src/zexus/vm/ssa_converter.py +757 -0
  212. package/src/zexus/vm/vm.py +1392 -0
  213. package/src/zexus/zexus_ast.py +1782 -0
  214. package/src/zexus/zexus_token.py +253 -0
  215. package/src/zexus/zpm/__init__.py +15 -0
  216. package/src/zexus/zpm/installer.py +116 -0
  217. package/src/zexus/zpm/package_manager.py +208 -0
  218. package/src/zexus/zpm/publisher.py +98 -0
  219. package/src/zexus/zpm/registry.py +110 -0
  220. package/src/zexus.egg-info/PKG-INFO +2235 -0
  221. package/src/zexus.egg-info/SOURCES.txt +876 -0
  222. package/src/zexus.egg-info/dependency_links.txt +1 -0
  223. package/src/zexus.egg-info/entry_points.txt +3 -0
  224. package/src/zexus.egg-info/not-zip-safe +1 -0
  225. package/src/zexus.egg-info/requires.txt +14 -0
  226. package/src/zexus.egg-info/top_level.txt +2 -0
  227. package/zexus.json +14 -0
@@ -0,0 +1,396 @@
1
+ """
2
+ Integration layer connecting all 10 phases to the evaluator.
3
+
4
+ This module provides hooks and integration points for:
5
+ - Phase 1: Modifiers
6
+ - Phase 2: Plugin System
7
+ - Phase 3: Capability-Based Security
8
+ - Phase 4: Virtual Filesystem
9
+ - Phase 5: Type System
10
+ - Phase 6: Metaprogramming
11
+ - Phase 7: Optimization
12
+ - Phase 9: Advanced Types
13
+ - Phase 10: Ecosystem
14
+ """
15
+
16
+ from typing import Any, Dict, Optional, List, Callable
17
+ from ..plugin_system import PluginManager
18
+ from ..capability_system import CapabilityManager, DenyAllPolicy
19
+ from ..virtual_filesystem import VirtualFileSystemManager, SandboxBuilder
20
+ from ..type_system import TypeChecker, TypeInferencer
21
+ from ..metaprogramming import MetaRegistry, apply_all_macros
22
+ from ..optimization import BytecodeCompiler, OptimizationFramework
23
+ from ..advanced_types import TraitRegistry
24
+ from ..ecosystem import EcosystemManager
25
+
26
+
27
+ class EvaluatorIntegration:
28
+ """Central integration point for all 10 phases."""
29
+
30
+ def __init__(self):
31
+ """Initialize all phase systems."""
32
+ self.plugin_manager: PluginManager = PluginManager()
33
+ self.capability_manager: CapabilityManager = CapabilityManager()
34
+ self.vfs_manager: VirtualFileSystemManager = VirtualFileSystemManager()
35
+ self.type_checker: TypeChecker = TypeChecker()
36
+ self.type_inferencer: TypeInferencer = TypeInferencer()
37
+ self.meta_registry: MetaRegistry = MetaRegistry()
38
+ self.optimizer: OptimizationFramework = OptimizationFramework()
39
+ self.trait_registry: TraitRegistry = TraitRegistry()
40
+ self.ecosystem: EcosystemManager = EcosystemManager()
41
+
42
+ # Execution context
43
+ self.current_sandbox: Optional[SandboxBuilder] = None
44
+ self.current_capabilities: set = set()
45
+
46
+ def setup_default_security(self):
47
+ """Setup default security policy (untrusted code)."""
48
+ from ..capability_system import AllowAllPolicy
49
+ self.capability_manager.set_policy(DenyAllPolicy())
50
+
51
+ def setup_trusted_execution(self):
52
+ """Setup trusted execution context (no restrictions)."""
53
+ from ..capability_system import AllowAllPolicy
54
+ self.capability_manager.set_policy(AllowAllPolicy())
55
+
56
+
57
+ # Global integration instance
58
+ _global_integration: Optional[EvaluatorIntegration] = None
59
+
60
+
61
+ def get_integration() -> EvaluatorIntegration:
62
+ """Get or create global integration instance."""
63
+ global _global_integration
64
+ if _global_integration is None:
65
+ _global_integration = EvaluatorIntegration()
66
+ _global_integration.setup_default_security()
67
+ return _global_integration
68
+
69
+
70
+ # ============================================================================
71
+ # PHASE 1: MODIFIER SUPPORT
72
+ # ============================================================================
73
+
74
+ class ModifierHandler:
75
+ """Handle modifier-based behavior during evaluation."""
76
+
77
+ @staticmethod
78
+ def apply_modifiers(node: Any, evaluator_method: Callable, *args, **kwargs) -> Any:
79
+ """Apply modifier effects to evaluation."""
80
+ if not hasattr(node, 'modifiers'):
81
+ return evaluator_method(*args, **kwargs)
82
+
83
+ modifiers = node.modifiers if hasattr(node, 'modifiers') else []
84
+ result = evaluator_method(*args, **kwargs)
85
+
86
+ # INLINE modifier: Mark for inlining
87
+ if 'inline' in modifiers or 'INLINE' in modifiers:
88
+ if hasattr(result, '__dict__'):
89
+ result.is_inline = True
90
+
91
+ # ASYNC modifier: Mark for async execution
92
+ if 'async' in modifiers or 'ASYNC' in modifiers:
93
+ if hasattr(result, '__dict__'):
94
+ result.is_async = True
95
+
96
+ # SECURE modifier: Require security check
97
+ if 'secure' in modifiers or 'SECURE' in modifiers:
98
+ if hasattr(result, '__dict__'):
99
+ result.is_secure = True
100
+
101
+ # PURE modifier: No side effects
102
+ if 'pure' in modifiers or 'PURE' in modifiers:
103
+ if hasattr(result, '__dict__'):
104
+ result.is_pure = True
105
+
106
+ return result
107
+
108
+
109
+ # ============================================================================
110
+ # PHASE 2: PLUGIN HOOKS
111
+ # ============================================================================
112
+
113
+ class PluginHookHandler:
114
+ """Trigger plugin hooks at evaluation points."""
115
+
116
+ @staticmethod
117
+ def before_action_call(action_name: str, args: Dict[str, Any]):
118
+ """Trigger hook before action call."""
119
+ integration = get_integration()
120
+ integration.plugin_manager.call_hooks(
121
+ "action.before_call",
122
+ {"action": action_name, "args": args}
123
+ )
124
+
125
+ @staticmethod
126
+ def after_action_call(action_name: str, result: Any):
127
+ """Trigger hook after action call."""
128
+ integration = get_integration()
129
+ integration.plugin_manager.call_hooks(
130
+ "action.after_call",
131
+ {"action": action_name, "result": result}
132
+ )
133
+
134
+ @staticmethod
135
+ def on_function_definition(func_name: str, func_obj: Any):
136
+ """Trigger hook on function definition."""
137
+ integration = get_integration()
138
+ integration.plugin_manager.call_hooks(
139
+ "function.definition",
140
+ {"name": func_name, "function": func_obj}
141
+ )
142
+
143
+ @staticmethod
144
+ def on_variable_assignment(var_name: str, value: Any):
145
+ """Trigger hook on variable assignment."""
146
+ integration = get_integration()
147
+ integration.plugin_manager.call_hooks(
148
+ "variable.assignment",
149
+ {"name": var_name, "value": value}
150
+ )
151
+
152
+
153
+ # ============================================================================
154
+ # PHASE 3: CAPABILITY CHECKING
155
+ # ============================================================================
156
+
157
+ class CapabilityChecker:
158
+ """Check capabilities during evaluation."""
159
+
160
+ @staticmethod
161
+ def check_io_read(context: str = "default") -> bool:
162
+ """Check if IO read capability is available."""
163
+ integration = get_integration()
164
+ allowed, reason = integration.capability_manager.check_capability(
165
+ context, "io.read"
166
+ )
167
+ return allowed
168
+
169
+ @staticmethod
170
+ def check_io_write(context: str = "default") -> bool:
171
+ """Check if IO write capability is available."""
172
+ integration = get_integration()
173
+ allowed, reason = integration.capability_manager.check_capability(
174
+ context, "io.write"
175
+ )
176
+ return allowed
177
+
178
+ @staticmethod
179
+ def check_network(context: str = "default") -> bool:
180
+ """Check if network capability is available."""
181
+ integration = get_integration()
182
+ allowed, reason = integration.capability_manager.check_capability(
183
+ context, "network.tcp"
184
+ )
185
+ return allowed
186
+
187
+ @staticmethod
188
+ def require_capability(capability: str, context: str = "default"):
189
+ """Require a capability, raise if not available."""
190
+ integration = get_integration()
191
+ integration.capability_manager.require_capability(context, capability)
192
+
193
+
194
+ # ============================================================================
195
+ # PHASE 4: VIRTUAL FILESYSTEM
196
+ # ============================================================================
197
+
198
+ class VirtualFilesystemHandler:
199
+ """Handle filesystem access through VFS."""
200
+
201
+ @staticmethod
202
+ def resolve_file_path(virtual_path: str, context: str = "default") -> Optional[str]:
203
+ """Resolve virtual path to real path with access check."""
204
+ integration = get_integration()
205
+ vfs = integration.vfs_manager.get_sandbox_filesystem(context)
206
+
207
+ if vfs is None:
208
+ return virtual_path # No VFS, use path directly
209
+
210
+ try:
211
+ return vfs.resolve_path(virtual_path)
212
+ except PermissionError:
213
+ return None
214
+
215
+ @staticmethod
216
+ def check_file_access(virtual_path: str, operation: str = "read", context: str = "default") -> bool:
217
+ """Check if file access is allowed."""
218
+ integration = get_integration()
219
+ vfs = integration.vfs_manager.get_sandbox_filesystem(context)
220
+
221
+ if vfs is None:
222
+ return True # No VFS, allow access
223
+
224
+ operation_upper = operation.upper()
225
+ if operation_upper == "READ":
226
+ return vfs.can_read(virtual_path)
227
+ elif operation_upper == "WRITE":
228
+ return vfs.can_write(virtual_path)
229
+ return False
230
+
231
+
232
+ # ============================================================================
233
+ # PHASE 5: TYPE SYSTEM
234
+ # ============================================================================
235
+
236
+ class TypeSystemHandler:
237
+ """Handle type checking and inference."""
238
+
239
+ @staticmethod
240
+ def infer_type(value: Any) -> str:
241
+ """Infer type of a value."""
242
+ integration = get_integration()
243
+ type_spec = integration.type_inferencer.infer_type(value)
244
+ return str(type_spec)
245
+
246
+ @staticmethod
247
+ def check_type(value: Any, type_spec: Any) -> bool:
248
+ """Check if value matches type specification."""
249
+ integration = get_integration()
250
+ matches, reason = integration.type_checker.check_type(value, type_spec)
251
+ return matches
252
+
253
+ @staticmethod
254
+ def validate_call(func_sig: Any, args: Dict[str, Any]) -> bool:
255
+ """Validate function call against signature."""
256
+ if hasattr(func_sig, 'validate_call'):
257
+ integration = get_integration()
258
+ valid, errors = func_sig.validate_call(args, integration.type_checker)
259
+ return valid
260
+ return True
261
+
262
+
263
+ # ============================================================================
264
+ # PHASE 6: METAPROGRAMMING
265
+ # ============================================================================
266
+
267
+ class MetaprogrammingHandler:
268
+ """Handle metaprogramming features."""
269
+
270
+ @staticmethod
271
+ def apply_macros(ast_node: Any) -> Any:
272
+ """Apply registered macros to AST."""
273
+ integration = get_integration()
274
+ return integration.meta_registry.apply_macros(ast_node)
275
+
276
+ @staticmethod
277
+ def register_macro(name: str, pattern: str, transformer: Callable):
278
+ """Register a macro."""
279
+ from ..metaprogramming import Macro
280
+ integration = get_integration()
281
+ macro = Macro(name, pattern, transformer)
282
+ integration.meta_registry.register_macro(macro)
283
+
284
+ @staticmethod
285
+ def reflect_on(obj: Any) -> Dict[str, Any]:
286
+ """Get reflection metadata about object."""
287
+ integration = get_integration()
288
+ return integration.meta_registry.reflect(obj)
289
+
290
+
291
+ # ============================================================================
292
+ # PHASE 7: OPTIMIZATION
293
+ # ============================================================================
294
+
295
+ class OptimizationHandler:
296
+ """Handle bytecode compilation and optimization."""
297
+
298
+ @staticmethod
299
+ def profile_function_call(func_name: str, duration: float):
300
+ """Record function call for profiling."""
301
+ integration = get_integration()
302
+ integration.optimizer.compiler.compiled_functions.setdefault(func_name, None)
303
+ profile = integration.optimizer.create_profile(func_name)
304
+ profile.record_call(duration)
305
+
306
+
307
+ # ============================================================================
308
+ # PHASE 9: ADVANCED TYPES
309
+ # ============================================================================
310
+
311
+ class AdvancedTypeHandler:
312
+ """Handle advanced type features."""
313
+
314
+ @staticmethod
315
+ def check_trait(obj: Any, trait_name: str) -> bool:
316
+ """Check if object implements a trait."""
317
+ integration = get_integration()
318
+ trait = integration.trait_registry.get_trait(trait_name)
319
+
320
+ if trait is None:
321
+ return False
322
+
323
+ valid, _ = trait.validate_implementation(obj)
324
+ return valid
325
+
326
+
327
+ # ============================================================================
328
+ # PHASE 10: ECOSYSTEM
329
+ # ============================================================================
330
+
331
+ class EcosystemHandler:
332
+ """Handle ecosystem features."""
333
+
334
+ @staticmethod
335
+ def install_package(name: str, version: str = "*") -> bool:
336
+ """Install a package."""
337
+ integration = get_integration()
338
+ pm = integration.ecosystem.get_package_manager()
339
+ return pm.install(name, version)
340
+
341
+ @staticmethod
342
+ def is_package_installed(name: str) -> bool:
343
+ """Check if package is installed."""
344
+ integration = get_integration()
345
+ pm = integration.ecosystem.get_package_manager()
346
+ return pm.is_installed(name)
347
+
348
+ @staticmethod
349
+ def get_marketplace_plugins(category: str = None) -> List[str]:
350
+ """Get plugins from marketplace."""
351
+ integration = get_integration()
352
+ marketplace = integration.ecosystem.get_marketplace()
353
+
354
+ if category:
355
+ plugins = marketplace.search_by_category(category)
356
+ else:
357
+ plugins = marketplace.get_trending()
358
+
359
+ return [p.name for p in plugins]
360
+
361
+
362
+ # ============================================================================
363
+ # COMPREHENSIVE EVALUATION CONTEXT
364
+ # ============================================================================
365
+
366
+ class EvaluationContext:
367
+ """Complete evaluation context with all phases integrated."""
368
+
369
+ def __init__(self, context_name: str = "default"):
370
+ """Initialize evaluation context."""
371
+ self.name = context_name
372
+ self.integration = get_integration()
373
+
374
+ # Phase handlers
375
+ self.modifiers = ModifierHandler()
376
+ self.plugins = PluginHookHandler()
377
+ self.capabilities = CapabilityChecker()
378
+ self.vfs = VirtualFilesystemHandler()
379
+ self.types = TypeSystemHandler()
380
+ self.metaprogramming = MetaprogrammingHandler()
381
+ self.optimization = OptimizationHandler()
382
+ self.advanced_types = AdvancedTypeHandler()
383
+ self.ecosystem = EcosystemHandler()
384
+
385
+ def setup_for_untrusted_code(self):
386
+ """Setup context for untrusted code execution."""
387
+ # Use deny-all policy
388
+ self.integration.capability_manager.set_policy(DenyAllPolicy())
389
+
390
+ def setup_for_trusted_code(self):
391
+ """Setup context for trusted code execution."""
392
+ from ..capability_system import AllowAllPolicy
393
+ self.integration.capability_manager.set_policy(AllowAllPolicy())
394
+
395
+ def __repr__(self) -> str:
396
+ return f"EvaluationContext({self.name})"