Repository navigation
Add u8 type, i8 comparisons, and byte casts - #76
Merged
Merged
Conversation
Add `u8` as a source-level type. The internal `UInt8` type already existed, so this wires it through the lexer and parser and adds casts between u8 and i32/u32 on every backend. Like i8, u8 has no arithmetic and plain integer literals still infer as i32, so values are made with `as u8`. Add ordered comparisons for i8 and casts between i8 and u8/u32. Fix a register VM bug this exposed: Load8 zero-extends but the i32->i8 cast sign-extends, so a negative i8 read from memory never compared equal to a cast one. Loads of i8 now sign-extend afterwards. i8 is held sign-extended and u8 zero-extended on the register VM. The stack VM's Load8 sign-extends, so it keeps both byte types sign-extended and masks u8 when widening. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Summary
u8is now a source-level type. The internalUInt8type already existed; this adds theu8keyword, parsing, and casts betweenu8andi32/u32on the Cranelift JIT, LLVM JIT, register VM, and stack VM. Likei8,u8has casts and equality but no arithmetic, and plain integer literals still infer asi32, so values are made withas u8.i8gains ordered comparisons (<,>,<=,>=) and casts to and fromu8andu32.i8tou32sign-extends to 32 bits, so-1 as i8becomes the maximumu32.Load8zero-extends while thei32toi8cast sign-extends, so a negativei8read from memory never compared equal to a cast one, and would have ordered wrongly. Loads ofi8now sign-extend afterwards. The register VM holdsi8sign-extended andu8zero-extended. The stack VM'sLoad8sign-extends, so it keeps both byte types sign-extended and masksu8when widening.u8added to the grammar and both type tables in the language guide, which now also say thati8andu8have no arithmetic.Notes
u8is now a reserved word, so a program that usedu8as an identifier will stop parsing.u8has no ordered comparisons yet. The stack VM would need to switchu8to a zero-extended form first.i32aborts on the VM. This predates the change but is easier to hit withu8.Test plan
tests/cases/int_types_u8.lyteandtests/cases/int_types_i8_compare.lyte. The latter checks that a negativei8loaded from an array compares equal to and orders against cast values, which fails onmainfor the VM.tests/cases/slices/empty_string_bytecode.lyteregenerated for the extra sign-extension instruction afteri8loads.cargo test --workspace --features llvmpasses on all five backends: jit, vm, asm, stack, llvm (built withLLVM_SYS_191_PREFIX=/opt/homebrew/opt/llvm@19).🤖 Generated with Claude Code