Skip to content

v1: unblock self-host runtime and fix boolean NOT codegen#132

Merged
egecanakincioglu merged 4 commits into
mainfrom
fix/runtime-file-process-v1.1
Jun 8, 2026
Merged

v1: unblock self-host runtime and fix boolean NOT codegen#132
egecanakincioglu merged 4 commits into
mainfrom
fix/runtime-file-process-v1.1

Conversation

@egecanakincioglu

Copy link
Copy Markdown
Owner

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

  • 7fef0fafix(runtime): implement native File.read lowering for self-host compiler
    • File__read helper: open + lseek(END) + mmap + read + close
  • b2d09e8fix(runtime): implement native File.write lowering for self-host compiler
    • File__write helper: fopen + strlen + write syscall + close
  • ab56310fix(runtime): route Process.exec to native system helper
    • Routes Process.exec → __arimo_system (existing fork+execve+waitpid)
  • c21ea5dfix(codegen): emit boolean NOT as XOR with 1, not bitwise NOT
    • x86 NOT (bitwise complement) → XOR reg, 1 for boolean toggle
    • Fixes while (!done) infinite loop

Validation

Test Result
File.read regression PASS
File.write regression PASS
Process.exec regression PASS
while (!done) regression PASS
S3→S4 build PASS (exit 0)
Unresolved labels 0
S4 --help PASS

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

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.
@egecanakincioglu egecanakincioglu merged commit e7bffb2 into main Jun 8, 2026
1 check failed
@egecanakincioglu egecanakincioglu deleted the fix/runtime-file-process-v1.1 branch June 8, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant