feat: improve inline asm parsing and type safety #265
Merged
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 enhances the inline assembly (
asm) block functionality and strengthens the compiler's type system. By supporting generic expressions as assembly operands and implementing a robust type coercion layer, Wave now allows for more expressive low-level programming (such as syscall wrappers) while maintaining higher safety standards during code generation.Key Changes
1. Advanced Inline ASM Parsing
asmblocks now accept genericExpressionvariants forinandoutclauses. This allows for literals (decimal, hex, binary), variable references, address-of (&x), and dereferences (deref x).parse_asm_operandandparse_asm_inout_clausefor cleaner, more maintainable parsing logic.is_assignablechecks to ensure thatoutoperands are valid L-values (memory locations that can be written to).2. LLVM Codegen & Type Coercion
gen_asm_stmt_irto support multiple assembly outputs by utilizing LLVM struct return types.asm_operand_to_valuenow converts AST expressions to LLVM values while preserving radix information (hex/binary) for literals.coerce_basic_valueandcoerce_to_expectedto handle implicit widening (e.g.,i32toi64) and explicit pointer casting.store_asm_outputcorrectly writes assembly results back to Wave variables, handling necessary pointer-bitcasts.3. Type System & Error Reporting
IntLiteraltoken that stores the raw string representation. This allows the backend to correctly interpret different numeric bases.colorexcrate intofront/errorto provide helpful, color-coded error messages in the terminal.gen_variable_irnow utilizes the coercion engine to ensure initializers are safely promoted to the variable's declared type.4. Testing & Infrastructure
test56.waveto demonstrate new assembly features via type-safe syscall wrappers (syscall4i,syscall4p).test66.wave.test69.wave.test56.waveas a known timeout (due to its server-like nature).Benefits