v1: unblock self-host runtime and fix boolean NOT codegen#132
Merged
Conversation
Add File__read runtime helper in IRLower: - Route File.read() → File__read in lowerStaticCall - generateFileRead: open + lseek(END) + mmap + read + close - Uses existing syscall primitives (open/read/close/lseek/mmap) - Returns PTR to null-terminated file contents - Empty string on any error (file not found, read failure, etc.) Fixes File__read unresolved label in S3→S4 self-host build.
…iler Add File__write runtime helper in IRLower: - Route File.write() → File__write in lowerStaticCall - generateFileWrite: fopen(path, w) + strlen + write syscall + close - Uses existing __arimo_fopen (write-truncate mode) and __arimo_strlen - Void return, silent on error (closes fd if opened) Fixes File__write unresolved label in S3→S4 self-host build.
Route Process.exec(cmd) → __arimo_system in lowerStaticCall. __arimo_system already fully implemented via generateSystem(): fork+execve+waitpid, delegates to /bin/sh -c. No new helper needed. 6-line routing addition. Fixes Process__exec unresolved label in S3→S4 self-host build.
The IROpcode.NOT handler in IRToX64 (both safe and old paths) used
the x86 NOT instruction (bitwise complement). For boolean values (0/1),
bitwise NOT produces -1/-2 which are never equal to 0, causing
while (!done) conditions to never exit.
Fix: emit XOR reg, 1 for boolean NOT. Toggles between 0 and 1 correctly.
Minimal reproducer:
Boolean done = false;
while (!done) { ... done = true; }
Previously infinite loop; now exits correctly.
Fixes S4 lexer hang — lexer was trapped in infinite while loop
during tokenization.
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.
Summary
Implements native lowering for File.read, File.write, and Process.exec. Fixes boolean NOT codegen to use XOR 1 instead of x86 bitwise NOT. S3→S4 now builds successfully with 0 unresolved labels.
Commits
fix(runtime): implement native File.read lowering for self-host compilerfix(runtime): implement native File.write lowering for self-host compilerfix(runtime): route Process.exec to native system helperfix(codegen): emit boolean NOT as XOR with 1, not bitwise NOTValidation
Known Remaining Blocker
S4 hello compile reaches parsing (~50 tokens) but crashes with SIGSEGV. Field offsets confirmed correct. Current suspicion: SafeRegAlloc/IRToX64 emission bug in large parser functions (Parser__parsePrimary: 232 slots, Parser__parseStmt: 323 slots). This is not fixed in this PR and must be handled separately.
🤖 Generated with Claude Code