| Stability | experimental |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
VM.Instruction.Io
Description
This module implements low-level file system interactions (Open, Read, Write, Close). It acts as a bridge between the VM's stack-based memory and the Host OS.
Synopsis
- instOpen :: VirtualMachine ()
- instRead :: VirtualMachine ()
- instWrite :: VirtualMachine ()
- instClose :: VirtualMachine ()
- instInput :: VirtualMachine ()
Documentation
instOpen :: VirtualMachine () Source #
Implements OPEN instruction (Opcode 0xB0).
arg StackTop: Mode (Int) - 0:Read, 1:Write, 2:Append.
arg StackNext: Path (String).
@details Pops path and mode, calls tryOpen, and pushes the resulting FD. Safety: Returns -1 on failure instead of crashing.
instRead :: VirtualMachine () Source #
Implements READ instruction (Opcode 0xB1).
arg StackTop: Size (Int).
arg StackNext: FD (Int).
@details
Reads Size bytes from the file descriptor FD.
Pushes the read content string to the stack.
instWrite :: VirtualMachine () Source #
Implements WRITE instruction (Opcode 0xB2).
arg StackTop: Content (String).
arg StackNext: FD (Int).
@details Writes content to the specified file descriptor. Ignores operation if FD is invalid.
instClose :: VirtualMachine () Source #
Implements CLOSE instruction (Opcode 0xB3).
@arg StackTop: FD (Int).
@details Closes the handle and removes the FD from the VM state map. Safe to call on invalid FD (no-op).
instInput :: VirtualMachine () Source #
Implements INPUT instruction (Opcode 0xB4).
@arg StackTop: FD (Int).
@details Reads a single line from the FD (useful for stdin). Pushes the string content (without newline usually) to stack.