You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement context manager and decorator support in TechLang
- Added context manager functionality with definitions for built-in context managers like file, timer, transaction, and lock.
- Introduced decorator support allowing function wrapping with additional behavior such as logging, timing, and input validation.
- Created tests for decorators, context managers, and async/await features to ensure proper functionality and integration.
- Enhanced error handling and resource management in context operations.
Decorators modify the function's body by prepending before_body and appending after_body tokens.
1493
+
1494
+
**Context Manager Cleanup:**
1495
+
Exit blocks execute even when errors occur, ensuring resource cleanup.
1496
+
1497
+
**Async Implementation:**
1498
+
Uses Python's `concurrent.futures.ThreadPoolExecutor` for background task execution. Coroutines execute synchronously when awaited, tasks run in thread pool when spawned.
1499
+
1500
+
**Event Loop:**
1501
+
Global event loop manages task lifecycle with states: PENDING → RUNNING → COMPLETED/FAILED/CANCELLED.
1502
+
1503
+
### Known Limitations
1504
+
- Decorators don't support decorator arguments (like `@decorator(arg)`)
1505
+
- Context managers can't return values to the `with` block
1506
+
- Async doesn't support true parallelism (GIL limitations)
1507
+
- No async generators or async iteration
1508
+
- Task cancellation is cooperative, not preemptive
1509
+
1510
+
### Future Enhancements
1511
+
- Decorator arguments: `decorator logger level do ... end`
1512
+
- Context manager `as` binding: `with file "x.txt" as f do ... end`
0 commit comments