Skip to content

Conversation

@LunaStev
Copy link
Member

This PR implements foundational literal support for character and boolean types, alongside significant improvements to numeric literal parsing. These changes bring Wave's literal handling closer to industry standards, supporting common escape sequences and proper hexadecimal representation.

Key Changes

1. Lexer Enhancements

  • Character Literals: Implemented single-quoted character parsing ('a').
    • Supported escape sequences: \n, \t, \r, \\, \', \".
    • Added validation for literal termination.
  • Boolean Literals: Recognized true and false as dedicated keywords rather than mere identifiers.
  • Numeric Parsing Refactor:
    • Improved hexadecimal handling (properly parsing the 0x prefix).
    • Refactored digit accumulation logic for better separation between integers, hexadecimals, and floats.
    • Removed redundant string manipulations during numeric tokenization.

2. AST & Type System

  • Extended Literal enum in the AST to include:
    • Literal::Bool(bool)
    • Literal::Char(char)
    • Literal::Byte(u8)
  • Updated the parser to map new tokens to these AST variants.

3. LLVM Code Generation

  • Implemented IR generation for new types:
    • Bool: Generates i1 constant (0 or 1).
    • Char/Byte: Generates i8 constant based on ASCII/byte values.
  • Enhanced variable initialization to support these literals during store operations.

4. Backend & Tooling

  • Clang Integration: Added the -Wno-override-module flag to suppress non-critical warnings during the compilation of generated IR.
  • Cleanup: Removed duplicate stdin pipe declarations in the backend runner.

Example Usage

var is_active: bool = true;
var symbol: char = 'W';
var line_feed: char = '\n';
var color_mask: i32 = 0xFF; // Hexadecimal support

Verification Results

  • Test Case: test71.wave was added/updated to verify:
    • Correct assignment and usage of i32, u32, f32.
    • String and boolean literal consistency.
    • char and byte type compatibility.
    • Pointer and array initialization using the new literal logic.

Implement character literals, boolean literals, and improve numeric
literal parsing with proper hexadecimal support.

Changes:
- Add char literal tokenization in lexer:
  - Parse single-quoted characters ('A', 'x', etc.)
  - Support escape sequences (\n, \t, \r, \\, \', \")
  - Validate proper char literal termination
  - Add TokenType::CharLiteral(char) variant
- Add boolean literal keywords:
  - Recognize "true" and "false" as language keywords
  - Add TokenType::BoolLiteral(bool) variant
  - Parse directly to boolean values in lexer
- Refactor numeric literal parsing:
  - Fix hexadecimal literal handling (0x prefix)
  - Separate hex, decimal, and float parsing logic
  - Remove intermediate string manipulation
  - Handle digit accumulation character-by-character
  - Properly consume digits after decimal point
- Extend AST literal types:
  - Add Literal::Bool(bool) for boolean values
  - Add Literal::Char(char) for character values
  - Add Literal::Byte(u8) for byte values (alias for char)
- Implement LLVM IR generation for new literals:
  - Bool: Generate i1 const_int (0 or 1)
  - Char: Generate i8 const_int with ASCII value
  - Byte: Generate i8 const_int with byte value
- Add variable initialization support in codegen:
  - Handle Bool, Char, Byte literals in store operations
  - Convert literal values to appropriate LLVM types
  - Support initialization with literal values
- Fix clang warning suppression:
  - Add -Wno-override-module flag to silence module warnings
  - Remove duplicate stdin pipe declaration
- Update test suite:
  - test71.wave: Demonstrate all supported type literals
  - Show i32, u32, f32, str, bool, byte, char, ptr, array usage

Example usage:
  var flag: bool = true;
  var letter: char = 'A';
  var newline: char = '\n';
  var hex: i32 = 0xFF;

This completes Wave's basic literal support with industry-standard
syntax for characters, booleans, and hexadecimal numbers.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Dec 22, 2025
@LunaStev LunaStev merged commit 273b5f5 into wavefnd:master Dec 22, 2025
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