From d4b31544fcd3cd87077d6b5b32685dc885cd8d33 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 8 Jan 2018 19:54:41 +0800 Subject: change size_of consts to macros to support stable rustc --- src/apu.rs | 29 +++++++++++++++-------------- src/bin.rs | 2 +- src/lib.rs | 1 - src/memory.rs | 38 +++++++++++++++++++++----------------- src/mos6502.rs | 8 +++++--- src/ppu.rs | 14 +++++++------- src/utils.rs | 3 +-- 7 files changed, 50 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/apu.rs b/src/apu.rs index 7777f68..f801ffb 100644 --- a/src/apu.rs +++ b/src/apu.rs @@ -720,18 +720,19 @@ pub struct APU<'a> { spkr: &'a mut Speaker, } -const APU_IGNORED_SIZE: usize = - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::() + - size_of::<&Speaker>(); +macro_rules! APU_IGNORED_SIZE { + () => (size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::() + + size_of::<&Speaker>()) +} impl<'a> APU<'a> { pub fn new(spkr: &'a mut Speaker) -> Self { @@ -752,7 +753,7 @@ impl<'a> APU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, APU_IGNORED_SIZE, reader) && + load_prefix(self, APU_IGNORED_SIZE!(), reader) && self.pulse1.load(reader) && self.pulse2.load(reader) && self.triangle.load(reader) && @@ -766,7 +767,7 @@ impl<'a> APU<'a> { } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, APU_IGNORED_SIZE, writer) && + save_prefix(self, APU_IGNORED_SIZE!(), writer) && self.pulse1.save(writer) && self.pulse2.save(writer) && self.triangle.save(writer) && diff --git a/src/bin.rs b/src/bin.rs index 07f8487..3ea5e21 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -4,7 +4,7 @@ extern crate core; use std::fs::File; use std::sync::{Mutex, Condvar}; use std::io::{Read, Write}; -use std::intrinsics::transmute; +use std::mem::transmute; use std::process::exit; use std::cell::Cell; diff --git a/src/lib.rs b/src/lib.rs index 8a634e9..53e1121 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(const_size_of)] //extern crate core; mod utils; mod memory; diff --git a/src/memory.rs b/src/memory.rs index f199317..46a9464 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -31,11 +31,12 @@ pub struct CPUBus<'a> { apu: *mut APU<'a>, } -const CPUBUS_IGNORED_SIZE: usize = - size_of::>() + - size_of::<*mut CPU>() + - size_of::<*mut PPU>() + - size_of::<*mut APU>(); +macro_rules! CPUBUS_IGNORED_SIZE { + () => (size_of::>() + + size_of::<*mut CPU>() + + size_of::<*mut PPU>() + + size_of::<*mut APU>()) +} impl<'a> CPUBus<'a> { pub fn new() -> Self { @@ -49,12 +50,12 @@ impl<'a> CPUBus<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPUBUS_IGNORED_SIZE, reader) && + load_prefix(self, CPUBUS_IGNORED_SIZE!(), reader) && self.ppu_sampler.borrow_mut().load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPUBUS_IGNORED_SIZE, writer) && + save_prefix(self, CPUBUS_IGNORED_SIZE!(), writer) && self.ppu_sampler.borrow().save(writer) } @@ -126,11 +127,12 @@ pub struct CPUMemory<'a> { ctl2: Option<&'a Controller> } -const CPUMEM_IGNORED_SIZE: usize = - size_of::() + - size_of::<&RefMapper>() + - size_of::>() + - size_of::>(); +macro_rules! CPUMEM_IGNORED_SIZE { + () => (size_of::() + + size_of::<&RefMapper>() + + size_of::>() + + size_of::>()) +} impl<'a> CPUMemory<'a> { pub fn new(mapper: &'a RefMapper<'a>, @@ -142,12 +144,12 @@ impl<'a> CPUMemory<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPUMEM_IGNORED_SIZE, reader) && + load_prefix(self, CPUMEM_IGNORED_SIZE!(), reader) && self.bus.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPUMEM_IGNORED_SIZE, writer) && + save_prefix(self, CPUMEM_IGNORED_SIZE!(), writer) && self.bus.save(writer) } @@ -282,7 +284,9 @@ pub struct PPUMemory<'a> { mapper: &'a RefMapper<'a> } -const PPUMEM_IGNORED_SIZE: usize = size_of::<&RefMapper>(); +macro_rules! PPUMEM_IGNORED_SIZE { + () => (size_of::<&RefMapper>()) +} impl<'a> PPUMemory<'a> { pub fn new(mapper: &'a RefMapper<'a>) -> Self { @@ -294,11 +298,11 @@ impl<'a> PPUMemory<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, PPUMEM_IGNORED_SIZE, reader) + load_prefix(self, PPUMEM_IGNORED_SIZE!(), reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, PPUMEM_IGNORED_SIZE, writer) + save_prefix(self, PPUMEM_IGNORED_SIZE!(), writer) } } diff --git a/src/mos6502.rs b/src/mos6502.rs index e8c471f..a97ece1 100644 --- a/src/mos6502.rs +++ b/src/mos6502.rs @@ -615,7 +615,9 @@ pub struct CPU<'a> { /*-- end sub-state --*/ } -const CPU_IGNORED_SIZE: usize = size_of::(); +macro_rules! CPU_IGNORED_SIZE { + () => (size_of::()) +} macro_rules! make_int { ($f:ident, $v: expr) => ( @@ -668,12 +670,12 @@ impl<'a> CPU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPU_IGNORED_SIZE, reader) && + load_prefix(self, CPU_IGNORED_SIZE!(), reader) && self.mem.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPU_IGNORED_SIZE, writer) && + save_prefix(self, CPU_IGNORED_SIZE!(), writer) && self.mem.save(writer) } diff --git a/src/ppu.rs b/src/ppu.rs index 0edafba..40d0493 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use memory::{VMem, PPUMemory, CPUBus}; -use core::intrinsics::transmute; -use core::mem::size_of; +use core::mem::{size_of, transmute}; use utils::{Read, Write, load_prefix, save_prefix}; pub trait Screen { @@ -62,9 +61,10 @@ pub struct PPU<'a> { pub scr: &'a mut Screen, } -const PPU_IGNORED_SIZE: usize = - size_of::() + - size_of::<&mut Screen>(); +macro_rules! PPU_IGNORED_SIZE { + () => (size_of::() + + size_of::<&mut Screen>()) +} impl<'a> PPU<'a> { #[inline] @@ -491,12 +491,12 @@ impl<'a> PPU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, PPU_IGNORED_SIZE, reader) && + load_prefix(self, PPU_IGNORED_SIZE!(), reader) && self.mem.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, PPU_IGNORED_SIZE, writer) && + save_prefix(self, PPU_IGNORED_SIZE!(), writer) && self.mem.save(writer) } diff --git a/src/utils.rs b/src/utils.rs index ea20ac9..2a7827f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,4 @@ -use core::intrinsics::transmute; -use core::mem::size_of; +use core::mem::{transmute, size_of}; use core::slice::{from_raw_parts_mut, from_raw_parts}; pub struct Sampler { -- cgit v1.2.3-70-g09d2