Skip to content

Conversation

@LunaStev
Copy link
Member

This PR significantly enhances the Wave compiler's system-level programming capabilities and matures its build system. By allowing arbitrary numeric values to be cast as pointers, developers can now interact with fixed memory addresses (essential for embedded or OS development). Additionally, the CLI has been expanded to support professional build workflows, including object file generation and linked executable creation.

Key Changes

1. Arbitrary Pointer Literals

  • Flexible Casting: Relaxed the previous restriction that only allowed 0 as a null pointer literal.
  • Implementation: The LLVM backend now parses arbitrary numeric literals in a pointer context and utilizes build_int_to_ptr to safely cast them to the target pointer type.
  • Validation: Added a compile-time check to prevent negative numeric values from being used as pointer literals, ensuring memory safety.

2. Expanded CLI & Build Commands

  • Object File Generation: Added the -o flag to the build command, allowing developers to compile Wave source files into machine-specific object files (.o).
  • Linked Executables: The default build command now orchestrates the full pipeline—compiling to object code and then linking into a final binary stored in the target/ directory.
  • New run Flag: Added the --img flag to the run command to support specialized image-based build-and-run flows.

3. Compilation Pipeline Refactoring

  • Pipeline Orchestration: Implemented object_build_wave_file and build_wave_file to handle the multi-stage compilation process.
  • Enhanced Debugging: The new pipelines include built-in support for debugging artifacts, including:
    • Token lists
    • AST visualizations
    • Machine code hex dumps
  • Library API: Exported compile_and_build and compile_and_build_obj in lib.rs, enabling external tools or scripts to programmatically access Wave's build workflows.

This commit enhances the handling of pointer literals in the LLVM backend
and introduces new CLI capabilities for building object files and
executables.

Changes:
- **Pointer Literal Enhancements**:
  - Relaxed the restriction on pointer literals. Previously, only `0`
    was allowed as a null pointer.
  - Now supports arbitrary numeric literals by parsing them as integers
    and using `build_int_to_ptr` to cast them to the target pointer type.
  - Added a panic check to prevent negative numeric literals from being
    used as pointers.
- **CLI & Command Expansion**:
  - **`run` command**: Added a `--img` flag to trigger an image-based
    build-and-run flow.
  - **`build` command**:
    - Added a `-o` flag to compile source files into machine object
      files (`.o`).
    - The default build command now compiles and links files into a
      final binary inside the `target/` directory.
- **Runner & Pipeline Refactoring**:
  - Implemented `object_build_wave_file` to handle the full compilation
    pipeline (lexing, parsing, IR generation, and object code emission)
    with detailed debug support for tokens, AST, and hex dumps.
  - Implemented `build_wave_file` to orchestrate the linking of
    generated object files into executable binaries.
- **Library API**:
  - Exported `compile_and_build` and `compile_and_build_obj` in `lib.rs`
    to provide programmatic access to the new build workflows.

These changes provide more flexibility for system-level programming and
improve the developer experience when managing build artifacts.
@LunaStev LunaStev merged commit 67f368c into wavefnd:master Jan 19, 2026
3 of 4 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