Просмотр исходного кода

Fix compiler warnings

Some minor stuff, mostly. The features have been stable since 1.20
Corey Richardson 8 лет назад
Родитель
Сommit
959fed1d84
9 измененных файлов с 17 добавлено и 22 удалено
  1. 1 0
      Cargo.toml
  2. 1 1
      src/lang/parser.rs
  3. 3 2
      src/lang/tokenizer.rs
  4. 1 2
      src/lib.rs
  5. 1 2
      src/main.rs
  6. 2 2
      src/proto.rs
  7. 2 2
      src/synth/math.rs
  8. 2 0
      src/synth/mod.rs
  9. 4 11
      src/synth/noise.rs

+ 1 - 0
Cargo.toml

@@ -6,3 +6,4 @@ authors = ["Graham Northup <grissess@nexusg.org>"]
 [dependencies]
 byteorder = "1.1.0"
 rand = "0.3"
+unicode-xid = "0.1.0"

+ 1 - 1
src/lang/parser.rs

@@ -169,7 +169,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
         };
 
         let tp = self.token.to_type();
-        self.expect(tp);
+        self.expect(tp)?;
         ret
     }
 }

+ 3 - 2
src/lang/tokenizer.rs

@@ -2,6 +2,7 @@ use std::collections::HashMap;
 use std::error::Error;
 use std::fmt;
 use super::*;
+use unicode_xid::UnicodeXID;
 
 pub struct Lexemes {
     radix_point: char,
@@ -368,7 +369,7 @@ impl<T: Iterator<Item=char>> Tokenizer<T> {
         }
 
         /* Identifiers */
-        if cc.is_xid_start() {
+        if UnicodeXID::is_xid_start(cc) {
             let mut buffer = String::new();
             buffer.push(cc);
 
@@ -379,7 +380,7 @@ impl<T: Iterator<Item=char>> Tokenizer<T> {
                 }
                 let ncc = nc.unwrap();
 
-                if ncc.is_xid_continue() {
+                if UnicodeXID::is_xid_continue(ncc) {
                     buffer.push(ncc);
                 } else {
                     self.push_back(ncc);

+ 1 - 2
src/lib.rs

@@ -1,9 +1,8 @@
-#![feature(associated_consts)]
 #![feature(unicode)]
-#![feature(drop_types_in_const)]
 
 extern crate byteorder;
 extern crate rand;
+extern crate unicode_xid;
 
 pub mod types;
 pub use types::*;

+ 1 - 2
src/main.rs

@@ -1,7 +1,6 @@
 use std::io;
 use std::io::*;
 
-extern crate rand;
 extern crate synfone;
 use synfone::synth::*;
 use synfone::lang::*;
@@ -30,7 +29,7 @@ fn main() {
         outbuf.reserve_exact(buf.size() - curlen);
         unsafe { outbuf.set_len(buf.size()); }
         buf.bytes(&mut outbuf);
-        out.write_all(&outbuf);
+        out.write_all(&outbuf).expect("failed to write to stdout");
         counter += buf.len();
     }
 }

+ 2 - 2
src/proto.rs

@@ -19,14 +19,14 @@ pub enum Command {
 impl Command {
     const SIZE: usize = 36;
 
-    fn duration(&self) -> Option<Duration> {
+    pub fn duration(&self) -> Option<Duration> {
         match *self {
             Command::Play{sec, usec, ..} => Some(Duration::new(sec as u64, usec * 1000)),
             _ => None,
         }
     }
 
-    fn pitch(&self) -> Option<Pitch> {
+    pub fn pitch(&self) -> Option<Pitch> {
         match *self {
             Command::Play{freq, ..} => Some(Pitch::Freq(freq as f32)),
             _ => None,

+ 2 - 2
src/synth/math.rs

@@ -108,7 +108,7 @@ pub struct NegateFactory;
 
 impl GeneratorFactory for NegateFactory {
     fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
-        let mut gen = params.remove_param("value", 0)?.as_gen()?;
+        let gen = params.remove_param("value", 0)?.as_gen()?;
         let len = gen.buffer().len();
         Ok(Box::new(Negate {
             value: gen,
@@ -150,7 +150,7 @@ pub struct ReciprocateFactory;
 
 impl GeneratorFactory for ReciprocateFactory {
     fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
-        let mut gen = params.remove_param("value", 0)?.as_gen()?;
+        let gen = params.remove_param("value", 0)?.as_gen()?;
         let len = gen.buffer().len();
         Ok(Box::new(Reciprocate {
             value: gen,

+ 2 - 0
src/synth/mod.rs

@@ -1,3 +1,5 @@
+#![allow(non_upper_case_globals)]
+
 use std::{iter, cmp, slice, mem, fmt};
 use std::fmt::Debug;
 use std::error::Error;

+ 4 - 11
src/synth/noise.rs

@@ -2,7 +2,6 @@ use std::mem;
 use super::*;
 
 use ::rand::{XorShiftRng, Rng, SeedableRng};
-use ::rand::os::OsRng;
 
 #[derive(Debug)]
 pub struct Noise {
@@ -11,7 +10,7 @@ pub struct Noise {
 }
 
 impl Generator for Noise {
-    fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer {
+    fn eval<'a>(&'a mut self, _params: &Parameters) -> &'a SampleBuffer {
         self.buf.rate = Rate::Sample;
 
         for i in 0..self.buf.len() {
@@ -26,23 +25,17 @@ impl Generator for Noise {
     }
 }
 
-static mut _rand_gen: Option<OsRng> = None;
-
 pub struct NoiseFactory;
 
 impl GeneratorFactory for NoiseFactory {
     fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
-        if unsafe { &_rand_gen }.is_none() {
-            unsafe {_rand_gen = Some(OsRng::new().expect("Couldn't initialize OS random")); }
-        }
-
-        let mut seed: [u32; 4] = Default::default();
+        let mut seed: [u32; 4] = ::rand::random();
         for i in seed.iter_mut() {
-            *i = unsafe { &mut _rand_gen }.as_mut().unwrap().next_u32();
+            *i = ::rand::random()
         }
 
         Ok(Box::new(Noise {
-            rng: XorShiftRng::from_seed(seed),
+            rng: XorShiftRng::from_seed(::rand::random()),
             buf: SampleBuffer::new(params.env.default_buffer_size),
         }))
     }