Skip to content

Conversation

@LunaStev
Copy link
Member

This PR introduces the unary negation operator (-) to allow negative expressions beyond just literals, integrates let and const into the statement parser, and significantly expands the standard library with low-level Linux syscalls and networking capabilities. These updates bridge the gap between high-level language ergonomics and low-level system programming.

Key Changes

1. Unary Negation Support (-)

The compiler now supports negating any numeric expression, not just constant literals (e.g., -(a + b)).

  • AST & Type System: Added Operator::Neg and updated type inference logic to ensure negation applies to numeric types while the logical NOT (!) operator correctly yields a boolean.
  • Parser: Refactored the unary expression engine to handle the - prefix for general expressions.
  • LLVM Codegen: Implemented IR generation for negation using 0 - x logic for integers (build_int_sub) and 0.0 - x for floats (build_float_sub).

2. Parser Enhancements

  • Declaration Statements: Formally integrated let and const keywords into the statement parsing loop. This allows for immutable local bindings and constant declarations in a way that matches industry-standard syntax.

3. Standard Library (std) Expansion

  • Linux Syscalls: Added std/sys/linux/syscall.wave. This module leverages Wave's inline assembly to implement the socket syscall directly.
  • Networking: Added std/net/udp.wave, providing a higher-level abstraction for creating UDP sockets using the underlying syscalls.
  • FFI & C ABI: Introduced std/libc/c.wave as a foundational module for maintaining C ABI compatibility and FFI documentation.
  • Manifest Update: Updated std/manifest.json to register the new sys, net, and libc namespaces.

…scalls

This commit introduces the unary negation operator (`-`) for expressions,
enables `let` and `const` statement parsing, and expands the standard
library with Linux syscalls and networking modules.

Changes:
- **Unary Negation Support**:
  - **AST**: Added `Operator::Neg` to represent the unary minus operator.
  - **Parser**: Refactored unary expression parsing to allow the `-`
    operator on general expressions, not just numeric literals.
  - **Type Inference**: Implemented `get_wave_type` for unary expressions,
    ensuring `-` applies to numeric types and `!` results in a boolean.
  - **Codegen**: Implemented LLVM IR generation for `Neg` using
    `build_int_sub` and `build_float_sub` (subtracting from zero).
- **Parser Enhancements**:
  - Registered `let` and `const` keywords in the statement parser to
    support local variable and constant declarations.
- **Standard Library Expansion**:
  - **Syscalls**: Added `std/sys/linux/syscall.wave` implementing the
    `socket` syscall using inline assembly.
  - **Networking**: Added `std/net/udp.wave` to provide basic UDP
    socket creation.
  - **FFI/Libc**: Added `std/libc/c.wave` as a placeholder/documentation
    module for C ABI compatibility.
  - **Manifest**: Updated `std/manifest.json` to include the new `sys`,
    `net`, and `libc` modules.

These updates bridge the gap between high-level syntax (let/const) and
low-level system capabilities (syscalls/FFI).

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Jan 15, 2026
@LunaStev LunaStev added this to Wave Jan 15, 2026
@LunaStev LunaStev merged commit fd6934e into wavefnd:master Jan 15, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in Wave Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant