more const!

This commit is contained in:
Lokathor 2018-12-30 23:29:58 -07:00
parent d0b44e7390
commit d62fbae4f0
5 changed files with 9 additions and 21 deletions

View file

@ -11,7 +11,7 @@ rust:
before_script: before_script:
- rustup component add rust-src - rustup component add rust-src
#- rustup component add clippy --toolchain=nightly - rustup component add clippy --toolchain=nightly
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/cargo-xbuild || cargo install cargo-xbuild) - (test -x $HOME/.cargo/bin/cargo-xbuild || cargo install cargo-xbuild)
- (test -x $HOME/.cargo/bin/cargo-make || cargo install cargo-make) - (test -x $HOME/.cargo/bin/cargo-make || cargo install cargo-make)

View file

@ -15,10 +15,6 @@ publish = false
typenum = "1.10" typenum = "1.10"
gba-proc-macro = "0.5" gba-proc-macro = "0.5"
#[dev-dependencies]
#quickcheck="0.7"
# TODO: F
[profile.release] [profile.release]
lto = true lto = true
panic = "abort" panic = "abort"

View file

@ -118,8 +118,7 @@ impl<T> VolAddress<T> {
/// # Safety /// # Safety
/// ///
/// You must follow the standard safety rules as outlined in the type docs. /// You must follow the standard safety rules as outlined in the type docs.
pub unsafe fn offset(self, offset: isize) -> Self { pub const unsafe fn offset(self, offset: isize) -> Self {
// TODO: const this
VolAddress { VolAddress {
address: NonZeroUsize::new_unchecked(self.address.get().wrapping_add(offset as usize * core::mem::size_of::<T>())), address: NonZeroUsize::new_unchecked(self.address.get().wrapping_add(offset as usize * core::mem::size_of::<T>())),
marker: PhantomData, marker: PhantomData,
@ -135,8 +134,7 @@ impl<T> VolAddress<T> {
/// from the operation or throw a `debug_assert!` or something instead of /// from the operation or throw a `debug_assert!` or something instead of
/// triggering UB. Eventually this will be `const fn`, which will potentially /// triggering UB. Eventually this will be `const fn`, which will potentially
/// let you spot errors without even having to run your program. /// let you spot errors without even having to run your program.
pub fn is_aligned(self) -> bool { pub const fn is_aligned(self) -> bool {
// TODO: const this
self.address.get() % core::mem::align_of::<T>() == 0 self.address.get() % core::mem::align_of::<T>() == 0
} }
@ -276,8 +274,7 @@ impl<T> VolAddressBlock<T> {
/// # Safety /// # Safety
/// ///
/// The slot given must be in bounds. /// The slot given must be in bounds.
pub unsafe fn index_unchecked(self, slot: usize) -> VolAddress<T> { pub const unsafe fn index_unchecked(self, slot: usize) -> VolAddress<T> {
// TODO: const this
self.vol_address.offset(slot as isize) self.vol_address.offset(slot as isize)
} }

View file

@ -2,10 +2,9 @@
#![feature(asm)] #![feature(asm)]
#![feature(const_int_wrapping)] #![feature(const_int_wrapping)]
#![feature(const_int_rotate)] #![feature(const_int_rotate)]
#![feature(min_const_unsafe_fn)]
#![warn(missing_docs)]
#![allow(clippy::cast_lossless)] #![allow(clippy::cast_lossless)]
#![deny(clippy::float_arithmetic)] #![deny(clippy::float_arithmetic)]
#![warn(missing_docs)]
//! This crate helps you write GBA ROMs. //! This crate helps you write GBA ROMs.
//! //!

View file

@ -37,15 +37,13 @@ pub const PALRAM_BG: VolAddressBlock<Color> = unsafe { VolAddressBlock::new_unch
pub const PALRAM_OBJ: VolAddressBlock<Color> = unsafe { VolAddressBlock::new_unchecked(VolAddress::new_unchecked(0x500_0200), 256) }; pub const PALRAM_OBJ: VolAddressBlock<Color> = unsafe { VolAddressBlock::new_unchecked(VolAddress::new_unchecked(0x500_0200), 256) };
/// Obtains the address of the specified 8bpp background palette slot. /// Obtains the address of the specified 8bpp background palette slot.
pub fn index_palram_bg_8bpp(slot: u8) -> VolAddress<Color> { pub const fn index_palram_bg_8bpp(slot: u8) -> VolAddress<Color> {
// TODO: const this
// Note(Lokathor): because of the `u8` limit we can't go out of bounds here. // Note(Lokathor): because of the `u8` limit we can't go out of bounds here.
unsafe { PALRAM_BG.index_unchecked(slot as usize) } unsafe { PALRAM_BG.index_unchecked(slot as usize) }
} }
/// Obtains the address of the specified 8bpp object palette slot. /// Obtains the address of the specified 8bpp object palette slot.
pub fn index_palram_obj_8bpp(slot: u8) -> VolAddress<Color> { pub const fn index_palram_obj_8bpp(slot: u8) -> VolAddress<Color> {
// TODO: const this
// Note(Lokathor): because of the `u8` limit we can't go out of bounds here. // Note(Lokathor): because of the `u8` limit we can't go out of bounds here.
unsafe { PALRAM_OBJ.index_unchecked(slot as usize) } unsafe { PALRAM_OBJ.index_unchecked(slot as usize) }
} }
@ -54,8 +52,7 @@ pub fn index_palram_obj_8bpp(slot: u8) -> VolAddress<Color> {
/// ///
/// Accesses `palbank * 16 + palslot`, if this is out of bounds the computation /// Accesses `palbank * 16 + palslot`, if this is out of bounds the computation
/// will wrap. /// will wrap.
pub fn index_palram_bg_4bpp(palbank: u8, palslot: u8) -> VolAddress<Color> { pub const fn index_palram_bg_4bpp(palbank: u8, palslot: u8) -> VolAddress<Color> {
// TODO: const this
// Note(Lokathor): because of the `u8` limit we can't go out of bounds here. // Note(Lokathor): because of the `u8` limit we can't go out of bounds here.
unsafe { PALRAM_BG.index_unchecked(palbank.wrapping_mul(16).wrapping_add(palslot) as usize) } unsafe { PALRAM_BG.index_unchecked(palbank.wrapping_mul(16).wrapping_add(palslot) as usize) }
} }
@ -64,8 +61,7 @@ pub fn index_palram_bg_4bpp(palbank: u8, palslot: u8) -> VolAddress<Color> {
/// ///
/// Accesses `palbank * 16 + palslot`, if this is out of bounds the computation /// Accesses `palbank * 16 + palslot`, if this is out of bounds the computation
/// will wrap. /// will wrap.
pub fn index_palram_obj_4bpp(palbank: u8, palslot: u8) -> VolAddress<Color> { pub const fn index_palram_obj_4bpp(palbank: u8, palslot: u8) -> VolAddress<Color> {
// TODO: const this
// Note(Lokathor): because of the `u8` limit we can't go out of bounds here. // Note(Lokathor): because of the `u8` limit we can't go out of bounds here.
unsafe { PALRAM_OBJ.index_unchecked(palbank.wrapping_mul(16).wrapping_add(palslot) as usize) } unsafe { PALRAM_OBJ.index_unchecked(palbank.wrapping_mul(16).wrapping_add(palslot) as usize) }
} }