feat(std): expand system modules and modernize standard library syntax#312
Merged
Conversation
…` APIs This commit expands the Wave standard library by adding missing system modules (`io`, `fs`, `bytes`, `process`) to the `std` manifest and introduces multiple low-level utility functions across the library. It also updates variable declarations from `var` to `let mut` for consistency with recent language changes. [Details] - **`std::manifest.json` & `README.md`**: Added `io`, `fs`, `bytes`, and `process` modules. - **`std::mem`**: - Replaced `var` with `let mut` across memory allocation and operation functions. - Added new memory alignment utilities (`mem_is_aligned`, `mem_alloc_aligned`, `mem_free_aligned`). - Added page size management functions (`mem_page_size`, `mem_alloc_pages`, `mem_free_pages`). - Added bounds-checked memory operations (`mem_copy_checked`, `mem_move_checked`, `mem_set_checked`). - Introduced new memory error constants (`MEM_ERR_INVALID`, `MEM_ERR_NO_SPACE`). - **`std::math::bits`**: Added 64-bit bitwise operations: `is_pow2_i64`, `align_down_i64`, `align_up_i64`, `popcount64`, `ctz64`, `ilog2_floor64`, `ilog2_ceil64`, and byte-swapping functions (`bswap32`, `bswap64`). - **`std::sys` (Linux & macOS)**: - Added extensive file system syscall constants (e.g., `FS_O_RDONLY`, `FS_SEEK_SET`) and functions (`dup`, `dup2`, `pipe`, `fsync`, `fcntl`). - Added socket options and poll constants (`SO_REUSEPORT`, `POLLIN`, `POLLOUT`), along with `getsockopt` and `poll` syscalls. - **`std::net`**: Added non-blocking socket utilities (`tcp_stream_set_nonblock`, `udp_set_nonblock`, etc.). - **`std::buffer`, `std::env`, `std::path`, `std::string`, `std::time`**: Refactored `var` to `let mut` to align with the latest Wave syntax. Signed-off-by: LunaStev <luna@lunastev.org>
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.
This PR significantly expands the Wave standard library by introducing several new system-level modules and a wide array of utility functions. Additionally, it performs a codebase-wide modernization of the library by transitioning from the legacy
varkeyword to the currentlet mutsyntax for mutable variable declarations.Key Changes
1. New Standard Library Modules
Added the following modules to the
stdmanifest and established their foundational APIs:std::io: Core input/output primitives.std::fs: High-level file system operations.std::bytes: Byte buffer and slice manipulation.std::process: Process management and environment interaction.2. Advanced Memory Management (
std::mem)mem_is_aligned,mem_alloc_aligned, andmem_free_aligned. Introduced page-level allocation support withmem_page_size,mem_alloc_pages, andmem_free_pages.mem_copy_checked,mem_move_checked, andmem_set_checked.MEM_ERR_INVALID,MEM_ERR_NO_SPACE) for more granular failure reporting.3. 64-bit Bitwise & Math Utilities (
std::math::bits)is_pow2_i64,align_down_i64,align_up_i64,popcount64,ctz64, and integer logarithm functions (ilog2_floor64,ilog2_ceil64).bswap32,bswap64) for endianness conversion.4. System & Networking Extensions (
std::sys,std::net)std::sys(Linux/macOS) with extensive file system constants (e.g.,O_RDONLY,SEEK_SET) and polling constants (POLLIN,POLLOUT).dup,dup2,pipe,fsync,fcntl,poll, andgetsockopt.std::netmodule, includingtcp_stream_set_nonblockandudp_set_nonblock.5. Syntax Modernization
varkeyword withlet mutfor mutable bindings. This ensures the standard library remains the gold standard for idiomatic Wave code.Rationale
These additions provide the necessary building blocks for developing complex, high-performance systems applications in Wave. By providing native support for aligned memory, non-blocking networking, and process management, we reduce the need for developers to write manual
extern(c)wrappers for common POSIX tasks.