Open
Conversation
Implements the Python context manager protocol (`__enter__`/`__exit__`) and the `open()` builtin function for sandboxed file I/O via OsCall. The `with` statement compiles to bytecode using existing opcodes (Dup, CallAttr, exception table entries) with FinallyTarget integration for return/break/continue. The `open()` builtin yields OsCall(FileOpen) to the host, which returns file content as MontyObject::FileData. A new FileObject heap type provides read(), readline(), write(), close(), and the context manager methods. Key changes: - Parser: parse `with` statements, desugar multiple items to nested nodes - Compiler: compile_with() emits setup/body/normal-exit/exception-handler bytecode - Builtins: BuiltinsFunctions::call() returns CallResult (was Value) for OsCall support - New types: FileObject, OsFunction::FileOpen/FileClose, MontyObject::FileData - Test infra: virtual open() for CPython test compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Results 📊❌ Patch coverage is 59.24%. Project has 4131 uncovered lines. Files with missing lines (8)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 86.24% 85.81% -0.43%
==========================================
Files 108 110 +2
Lines 28651 29106 +455
Branches 61876 62908 +1032
==========================================
+ Hits 24709 24975 +266
- Misses 3942 4131 +189
- Partials 1845 1880 +35Generated by Codecov Action |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the Python context manager protocol (
__enter__/__exit__) and theopen()builtin function for sandboxed file I/O via OsCall.The
withstatement compiles to bytecode using existing opcodes (Dup, CallAttr, exception table entries) with FinallyTarget integration for return/break/continue. Theopen()builtin yields OsCall(FileOpen) to the host, which returns file content as MontyObject::FileData. A new FileObject heap type provides read(), readline(), write(), close(), and the context manager methods.Key changes:
withstatements, desugar multiple items to nested nodes