Skip to content

Conversation

@LunaStev
Copy link
Member

This PR transforms Wave into a systems-level programming language by implementing a comprehensive Linux x86_64 system interface. It includes a full suite of syscall wrappers, low-level memory/file-system management, and high-level networking abstractions for TCP and UDP.

Key Changes

1. Lexer & Frontend Enhancements

  • Hex Escapes: Added support for \xHH escape sequences in string literals, enabling the inclusion of raw binary data within strings.
  • Trivia Handling: Unified whitespace and comment skipping into a centralized skip_trivia method, improving the robustness of tokenization across complex multi-line comments.
  • Input Parsing: Formally integrated the input statement into the parser and fixed scanf mapping to correctly handle 8-bit integers as characters (%c).

2. Backend & Type System Improvements

  • Syscall Coercion: Implemented a specialized implicit coercion rule between Pointer and Int64 types specifically for functions prefixed with syscall. This facilitates the passing of raw memory addresses directly to system registers without manual casting.
  • x86_64 Calling Convention: The backend now correctly maps Wave arguments to the standard Linux x86_64 syscall registers (rax, rdi, rsi, rdx, r10, r8, r9).

3. Standard Library: std::sys::linux

  • Core Syscalls: Implemented syscall0 through syscall6 using inline assembly.
  • File System (fs): Added raw wrappers for open, read, write, close, lseek, and stat.
  • Memory Management: Implemented mmap, munmap, and brk for manual control over virtual memory and heap allocation.
  • Time & Sockets: Added nanosleep, clock_gettime, and a full set of socket constants and API wrappers (AF_INET, SOCK_STREAM, etc.).

4. Standard Library: std::net

Built upon the raw syscalls, these modules provide ergonomic, synchronous networking:

  • tcp: High-level TcpListener and TcpStream for reliable stream-based communication.
  • udp: UdpSocket for datagram-based network logic.

This commit establishes a comprehensive low-level system interface for
the Wave language on Linux x86_64. It includes a full suite of syscall
wrappers, foundational system modules (FS, Memory, Time), and high-level
networking abstractions (TCP/UDP).

Changes:
- **Lexer Enhancements**:
  - Added support for hex escape sequences (`\xHH`) in string literals.
  - Unified whitespace and comment skipping into a new `skip_trivia`
    method, ensuring robust tokenization across multi-line comments.
  - Refactored `next_token` for better control flow and readability.
- **Parser & Backend**:
  - Added support for the `input` statement in the parser.
  - Implemented implicit coercion between `Pointer` and `Int64` types
    specifically for functions starting with `syscall`, facilitating
    the passing of raw addresses to system registers.
  - Updated `scanf` format generation to correctly map 8-bit integers to `%c`.
- **System Standard Library (`std::sys::linux`)**:
  - **`syscall`**: Implemented `syscall0` through `syscall6` using
    inline assembly following the x86_64 calling convention.
  - **`fs`**: Added raw wrappers for `open`, `close`, `read`, `write`,
    `lseek`, `stat`, and directory operations.
  - **`socket`**: Defined core socket constants (AF_INET, SOCK_STREAM, etc.)
    and raw wrappers for the Linux socket API.
  - **`memory`**: Added `mmap`, `munmap`, and `brk` for manual virtual
    memory management.
  - **`time`**: Added `nanosleep` and `clock_gettime` with `TimeSpec` support.
- **Networking Standard Library (`std::net`)**:
  - **`tcp`**: Implemented `TcpListener` and `TcpStream` providing a
    synchronous, stream-based networking API.
  - **`udp`**: Implemented `UdpSocket` for datagram-based communication.

These additions provide Wave with the necessary primitives to perform
low-level systems programming and network communication directly.
@LunaStev LunaStev self-assigned this Jan 23, 2026
@LunaStev LunaStev merged commit 28d479e into wavefnd:master Jan 23, 2026
2 checks passed
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