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,324 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Async Runtime System for Zexus
|
|
3
|
+
Provides EventLoop, Task management, and async execution coordination
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import threading
|
|
7
|
+
import queue
|
|
8
|
+
import time
|
|
9
|
+
from collections import deque
|
|
10
|
+
from typing import Any, Callable, Optional, List, Dict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Task:
|
|
14
|
+
"""
|
|
15
|
+
Represents an async task in the event loop
|
|
16
|
+
Wraps a coroutine with metadata and state management
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
# Task states
|
|
20
|
+
PENDING = "PENDING"
|
|
21
|
+
RUNNING = "RUNNING"
|
|
22
|
+
COMPLETED = "COMPLETED"
|
|
23
|
+
FAILED = "FAILED"
|
|
24
|
+
CANCELLED = "CANCELLED"
|
|
25
|
+
|
|
26
|
+
_task_id_counter = 0
|
|
27
|
+
_lock = threading.Lock()
|
|
28
|
+
|
|
29
|
+
def __init__(self, coroutine, name=None, priority=0):
|
|
30
|
+
"""
|
|
31
|
+
Create a new task
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
coroutine: The coroutine/generator to execute
|
|
35
|
+
name: Optional task name for debugging
|
|
36
|
+
priority: Task priority (higher = more priority)
|
|
37
|
+
"""
|
|
38
|
+
with Task._lock:
|
|
39
|
+
Task._task_id_counter += 1
|
|
40
|
+
self.id = Task._task_id_counter
|
|
41
|
+
|
|
42
|
+
self.coroutine = coroutine
|
|
43
|
+
self.name = name or f"Task-{self.id}"
|
|
44
|
+
self.priority = priority
|
|
45
|
+
self.state = Task.PENDING
|
|
46
|
+
self.result = None
|
|
47
|
+
self.error = None
|
|
48
|
+
self.cancelled = False
|
|
49
|
+
self.dependencies = [] # Other tasks this task depends on
|
|
50
|
+
self.dependents = [] # Tasks that depend on this task
|
|
51
|
+
self.awaiting_promise = None # Promise this task is currently waiting for
|
|
52
|
+
|
|
53
|
+
def cancel(self):
|
|
54
|
+
"""Cancel the task"""
|
|
55
|
+
if self.state in (Task.PENDING, Task.RUNNING):
|
|
56
|
+
self.state = Task.CANCELLED
|
|
57
|
+
self.cancelled = True
|
|
58
|
+
return True
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
def is_complete(self):
|
|
62
|
+
"""Check if task is complete (success, failure, or cancelled)"""
|
|
63
|
+
return self.state in (Task.COMPLETED, Task.FAILED, Task.CANCELLED)
|
|
64
|
+
|
|
65
|
+
def is_ready(self):
|
|
66
|
+
"""Check if task is ready to run (all dependencies complete)"""
|
|
67
|
+
if self.cancelled:
|
|
68
|
+
return False
|
|
69
|
+
return all(dep.is_complete() for dep in self.dependencies)
|
|
70
|
+
|
|
71
|
+
def add_dependency(self, task):
|
|
72
|
+
"""Add a task dependency"""
|
|
73
|
+
if task not in self.dependencies:
|
|
74
|
+
self.dependencies.append(task)
|
|
75
|
+
task.dependents.append(self)
|
|
76
|
+
|
|
77
|
+
def __lt__(self, other):
|
|
78
|
+
"""Compare tasks by priority (for priority queue)"""
|
|
79
|
+
return self.priority > other.priority
|
|
80
|
+
|
|
81
|
+
def __repr__(self):
|
|
82
|
+
return f"Task({self.name}, state={self.state}, priority={self.priority})"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class EventLoop:
|
|
86
|
+
"""
|
|
87
|
+
Event loop for managing async task execution
|
|
88
|
+
Provides task scheduling, execution, and coordination
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def __init__(self):
|
|
92
|
+
"""Initialize the event loop"""
|
|
93
|
+
self.task_queue = deque() # Tasks ready to run
|
|
94
|
+
self.waiting_tasks = {} # Tasks waiting for promises: {promise_id: [tasks]}
|
|
95
|
+
self.all_tasks = {} # All tasks by ID
|
|
96
|
+
self.running = False
|
|
97
|
+
self.current_task = None
|
|
98
|
+
self.lock = threading.Lock()
|
|
99
|
+
|
|
100
|
+
def create_task(self, coroutine, name=None, priority=0):
|
|
101
|
+
"""
|
|
102
|
+
Create and schedule a new task
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
coroutine: The coroutine to execute
|
|
106
|
+
name: Optional task name
|
|
107
|
+
priority: Task priority
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
Task: The created task
|
|
111
|
+
"""
|
|
112
|
+
task = Task(coroutine, name, priority)
|
|
113
|
+
with self.lock:
|
|
114
|
+
self.all_tasks[task.id] = task
|
|
115
|
+
self._schedule_task(task)
|
|
116
|
+
return task
|
|
117
|
+
|
|
118
|
+
def _schedule_task(self, task):
|
|
119
|
+
"""Add a task to the ready queue if it's ready to run"""
|
|
120
|
+
if task.is_ready() and not task.is_complete():
|
|
121
|
+
# Insert task in priority order
|
|
122
|
+
inserted = False
|
|
123
|
+
for i, queued_task in enumerate(self.task_queue):
|
|
124
|
+
if task.priority > queued_task.priority:
|
|
125
|
+
self.task_queue.insert(i, task)
|
|
126
|
+
inserted = True
|
|
127
|
+
break
|
|
128
|
+
|
|
129
|
+
if not inserted:
|
|
130
|
+
self.task_queue.append(task)
|
|
131
|
+
|
|
132
|
+
def _run_task_step(self, task):
|
|
133
|
+
"""
|
|
134
|
+
Run one step of a task's coroutine
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
(is_done, value): Whether task is complete and the yielded/returned value
|
|
138
|
+
"""
|
|
139
|
+
try:
|
|
140
|
+
task.state = Task.RUNNING
|
|
141
|
+
self.current_task = task
|
|
142
|
+
|
|
143
|
+
# Check if task has a coroutine (might be a Coroutine object)
|
|
144
|
+
if hasattr(task.coroutine, 'resume'):
|
|
145
|
+
# It's a Coroutine object
|
|
146
|
+
is_done, value = task.coroutine.resume()
|
|
147
|
+
|
|
148
|
+
if is_done:
|
|
149
|
+
task.state = Task.COMPLETED
|
|
150
|
+
task.result = value
|
|
151
|
+
return (True, value)
|
|
152
|
+
else:
|
|
153
|
+
# Yielded a value (might be a Promise)
|
|
154
|
+
return (False, value)
|
|
155
|
+
else:
|
|
156
|
+
# It's a generator
|
|
157
|
+
value = next(task.coroutine)
|
|
158
|
+
return (False, value)
|
|
159
|
+
|
|
160
|
+
except StopIteration as e:
|
|
161
|
+
# Coroutine completed
|
|
162
|
+
task.state = Task.COMPLETED
|
|
163
|
+
task.result = e.value if hasattr(e, 'value') else None
|
|
164
|
+
return (True, task.result)
|
|
165
|
+
|
|
166
|
+
except Exception as e:
|
|
167
|
+
# Coroutine error
|
|
168
|
+
task.state = Task.FAILED
|
|
169
|
+
task.error = e
|
|
170
|
+
return (True, None)
|
|
171
|
+
|
|
172
|
+
finally:
|
|
173
|
+
self.current_task = None
|
|
174
|
+
|
|
175
|
+
def _handle_task_yield(self, task, yielded_value):
|
|
176
|
+
"""
|
|
177
|
+
Handle a value yielded by a task
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
task: The task that yielded
|
|
181
|
+
yielded_value: The value that was yielded
|
|
182
|
+
"""
|
|
183
|
+
# Check if it's a Promise
|
|
184
|
+
if hasattr(yielded_value, 'type') and yielded_value.type() == "PROMISE":
|
|
185
|
+
promise = yielded_value
|
|
186
|
+
|
|
187
|
+
# If promise is already resolved, reschedule task immediately
|
|
188
|
+
if promise.is_resolved():
|
|
189
|
+
with self.lock:
|
|
190
|
+
self._schedule_task(task)
|
|
191
|
+
else:
|
|
192
|
+
# Add task to waiting list for this promise
|
|
193
|
+
promise_id = id(promise)
|
|
194
|
+
|
|
195
|
+
with self.lock:
|
|
196
|
+
if promise_id not in self.waiting_tasks:
|
|
197
|
+
self.waiting_tasks[promise_id] = []
|
|
198
|
+
|
|
199
|
+
self.waiting_tasks[promise_id].append(task)
|
|
200
|
+
task.awaiting_promise = promise
|
|
201
|
+
|
|
202
|
+
# Set up promise callback to reschedule task when resolved
|
|
203
|
+
def on_promise_resolved(value):
|
|
204
|
+
with self.lock:
|
|
205
|
+
if promise_id in self.waiting_tasks:
|
|
206
|
+
waiting = self.waiting_tasks.pop(promise_id)
|
|
207
|
+
for waiting_task in waiting:
|
|
208
|
+
waiting_task.awaiting_promise = None
|
|
209
|
+
self._schedule_task(waiting_task)
|
|
210
|
+
|
|
211
|
+
promise.then(on_promise_resolved)
|
|
212
|
+
promise.catch(on_promise_resolved)
|
|
213
|
+
else:
|
|
214
|
+
# Unknown yield value, reschedule task
|
|
215
|
+
with self.lock:
|
|
216
|
+
self._schedule_task(task)
|
|
217
|
+
|
|
218
|
+
def _complete_task(self, task):
|
|
219
|
+
"""Handle task completion and notify dependents"""
|
|
220
|
+
with self.lock:
|
|
221
|
+
# Schedule dependent tasks that are now ready
|
|
222
|
+
for dependent in task.dependents:
|
|
223
|
+
if dependent.is_ready():
|
|
224
|
+
self._schedule_task(dependent)
|
|
225
|
+
|
|
226
|
+
def run_until_complete(self, coroutine):
|
|
227
|
+
"""
|
|
228
|
+
Run the event loop until the given coroutine completes
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
coroutine: The main coroutine to execute
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
The result of the coroutine
|
|
235
|
+
"""
|
|
236
|
+
# Create main task
|
|
237
|
+
main_task = self.create_task(coroutine, name="main", priority=100)
|
|
238
|
+
|
|
239
|
+
self.running = True
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
while self.running:
|
|
243
|
+
# Check if main task is complete
|
|
244
|
+
if main_task.is_complete():
|
|
245
|
+
if main_task.state == Task.FAILED:
|
|
246
|
+
raise main_task.error
|
|
247
|
+
return main_task.result
|
|
248
|
+
|
|
249
|
+
# Get next task from queue
|
|
250
|
+
with self.lock:
|
|
251
|
+
if not self.task_queue:
|
|
252
|
+
# No tasks ready - check if any tasks are waiting
|
|
253
|
+
if not self.waiting_tasks:
|
|
254
|
+
# No waiting tasks either - we're done
|
|
255
|
+
break
|
|
256
|
+
|
|
257
|
+
# Wait a bit for promises to resolve
|
|
258
|
+
time.sleep(0.001)
|
|
259
|
+
continue
|
|
260
|
+
|
|
261
|
+
task = self.task_queue.popleft()
|
|
262
|
+
|
|
263
|
+
# Run one step of the task
|
|
264
|
+
is_done, value = self._run_task_step(task)
|
|
265
|
+
|
|
266
|
+
if is_done:
|
|
267
|
+
# Task completed
|
|
268
|
+
self._complete_task(task)
|
|
269
|
+
else:
|
|
270
|
+
# Task yielded a value
|
|
271
|
+
self._handle_task_yield(task, value)
|
|
272
|
+
|
|
273
|
+
# If we exit the loop without completing main task, check its state
|
|
274
|
+
if main_task.state == Task.FAILED:
|
|
275
|
+
raise main_task.error
|
|
276
|
+
elif main_task.state == Task.CANCELLED:
|
|
277
|
+
raise Exception("Main task was cancelled")
|
|
278
|
+
|
|
279
|
+
return main_task.result
|
|
280
|
+
|
|
281
|
+
finally:
|
|
282
|
+
self.running = False
|
|
283
|
+
|
|
284
|
+
def stop(self):
|
|
285
|
+
"""Stop the event loop"""
|
|
286
|
+
self.running = False
|
|
287
|
+
|
|
288
|
+
def get_task_count(self):
|
|
289
|
+
"""Get count of tasks in various states"""
|
|
290
|
+
with self.lock:
|
|
291
|
+
return {
|
|
292
|
+
'total': len(self.all_tasks),
|
|
293
|
+
'ready': len(self.task_queue),
|
|
294
|
+
'waiting': sum(len(tasks) for tasks in self.waiting_tasks.values())
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
# Global event loop instance
|
|
299
|
+
_global_event_loop = None
|
|
300
|
+
_global_event_loop_lock = threading.Lock()
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def get_event_loop():
|
|
304
|
+
"""Get the global event loop instance"""
|
|
305
|
+
global _global_event_loop
|
|
306
|
+
|
|
307
|
+
with _global_event_loop_lock:
|
|
308
|
+
if _global_event_loop is None:
|
|
309
|
+
_global_event_loop = EventLoop()
|
|
310
|
+
|
|
311
|
+
return _global_event_loop
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def set_event_loop(loop):
|
|
315
|
+
"""Set the global event loop instance"""
|
|
316
|
+
global _global_event_loop
|
|
317
|
+
|
|
318
|
+
with _global_event_loop_lock:
|
|
319
|
+
_global_event_loop = loop
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def new_event_loop():
|
|
323
|
+
"""Create a new event loop"""
|
|
324
|
+
return EventLoop()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# search_old_imports.sh
|
|
3
|
+
echo "🔍 Searching for files that need import updates..."
|
|
4
|
+
echo "================================================"
|
|
5
|
+
|
|
6
|
+
# Search patterns
|
|
7
|
+
patterns=(
|
|
8
|
+
"from.*\.evaluator"
|
|
9
|
+
"import.*evaluator"
|
|
10
|
+
"from evaluator import"
|
|
11
|
+
"eval_node"
|
|
12
|
+
"evaluate\("
|
|
13
|
+
"Environment.*from.*evaluator"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
for pattern in "${patterns[@]}"; do
|
|
17
|
+
echo ""
|
|
18
|
+
echo "📌 Searching for: $pattern"
|
|
19
|
+
echo "--------------------------------"
|
|
20
|
+
grep -r "$pattern" . --include="*.py" 2>/dev/null | \
|
|
21
|
+
grep -v "__pycache__" | \
|
|
22
|
+
grep -v "evaluator/" | \
|
|
23
|
+
grep -v "evaluator_original.py" | \
|
|
24
|
+
head -20
|
|
25
|
+
done
|
|
26
|
+
|
|
27
|
+
# Specifically check known problematic files
|
|
28
|
+
echo ""
|
|
29
|
+
echo "📋 Checking specific known files:"
|
|
30
|
+
echo "================================="
|
|
31
|
+
files_to_check=(
|
|
32
|
+
"cli/main.py"
|
|
33
|
+
"hybrid_orchestrator.py"
|
|
34
|
+
"__main__.py"
|
|
35
|
+
"compare_interpreter_compiler.py"
|
|
36
|
+
"syntax_validator.py"
|
|
37
|
+
"strategy_recovery.py"
|
|
38
|
+
"compiler/compat_runtime.py"
|
|
39
|
+
"vm/vm.py"
|
|
40
|
+
"vm/jit.py"
|
|
41
|
+
"parser/parser.py"
|
|
42
|
+
"embedding/__init__.py"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
for file in "${files_to_check[@]}"; do
|
|
46
|
+
if [ -f "$file" ]; then
|
|
47
|
+
echo ""
|
|
48
|
+
echo "🔎 $file:"
|
|
49
|
+
if grep -q "evaluator" "$file"; then
|
|
50
|
+
echo " ⚠️ Contains 'evaluator' references:"
|
|
51
|
+
grep -n "evaluator" "$file" | head -5
|
|
52
|
+
else
|
|
53
|
+
echo " ✅ No evaluator references found"
|
|
54
|
+
fi
|
|
55
|
+
fi
|
|
56
|
+
done
|
|
57
|
+
|
|
58
|
+
# Check for eval_node function calls
|
|
59
|
+
echo ""
|
|
60
|
+
echo "🔍 Searching for eval_node function calls (should be replaced with evaluate):"
|
|
61
|
+
echo "============================================================================"
|
|
62
|
+
grep -r "eval_node" . --include="*.py" 2>/dev/null | \
|
|
63
|
+
grep -v "__pycache__" | \
|
|
64
|
+
grep -v "evaluator/" | \
|
|
65
|
+
grep -v "evaluator_original.py"
|