[rlox] summer cleanup (clippy stuff)
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
use crate::bc::Value::{Bool, Number};
|
use crate::bc::Value::{Bool, Number};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::{Debug};
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum Op {
|
pub enum Op {
|
||||||
Return,
|
Return,
|
||||||
@@ -196,10 +197,10 @@ impl fmt::Debug for TraceInfo<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::bc::{Object, Value};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_value_equality() {
|
fn string_value_equality() {
|
||||||
|
use crate::bc::Value;
|
||||||
|
|
||||||
let s1 = "bla5";
|
let s1 = "bla5";
|
||||||
let s2 = "bla6";
|
let s2 = "bla6";
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::convert::identity;
|
|||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::str::CharIndices;
|
use std::str::CharIndices;
|
||||||
|
|
||||||
use crate::bc::{Chunk, Op, Value};
|
use crate::bc::{Chunk, Op};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
@@ -301,7 +301,7 @@ impl<'src> Parser<'src> {
|
|||||||
EqualEqual | BangEqual => Precedence::Equality,
|
EqualEqual | BangEqual => Precedence::Equality,
|
||||||
Greater | GreaterEqual | Less | LessEqual => Precedence::Comparison,
|
Greater | GreaterEqual | Less | LessEqual => Precedence::Comparison,
|
||||||
RightParen => Precedence::None,
|
RightParen => Precedence::None,
|
||||||
_ => panic!("{:?}", ttype),
|
_ => panic!("Undefined precedence: {:?}", ttype),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::bc::{Object, Chunk, Op, TraceInfo, Value};
|
use crate::bc::{Chunk, Op, TraceInfo, Value};
|
||||||
use std::ops::Not;
|
use std::ops::Not;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ pub struct VM {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum VMError {
|
pub enum VMError {
|
||||||
Compile,
|
// Compile,
|
||||||
Runtime(Rc<str>, usize),
|
Runtime(Rc<str>, usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,14 +103,15 @@ impl VM {
|
|||||||
let a = self.pop_num()?;
|
let a = self.pop_num()?;
|
||||||
self.push(Value::from(num + a));
|
self.push(Value::from(num + a));
|
||||||
}
|
}
|
||||||
Value::Obj(ref obj) => {
|
Value::Obj(ref _obj) => {
|
||||||
match b.as_str() {
|
match b.as_str() {
|
||||||
None => Err(self.type_err("String", b)),
|
None => Err(self.type_err("String", b)),
|
||||||
Some(str_b) => {
|
Some(str_b) => {
|
||||||
let a = self.pop()?;
|
let a = self.pop()?;
|
||||||
match a.as_str() {
|
match a.as_str() {
|
||||||
Some(str_a) => {
|
Some(str_a) => {
|
||||||
Ok(self.push(Value::from(str_a.to_owned() + str_b)))
|
self.push(Value::from(str_a.to_owned() + str_b));
|
||||||
|
Ok(())
|
||||||
},
|
},
|
||||||
None => Err(self.type_err("String", a))
|
None => Err(self.type_err("String", a))
|
||||||
}
|
}
|
||||||
@@ -160,9 +161,7 @@ impl VM {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::bc::Op::Equal;
|
|
||||||
use super::{Chunk, Op, Value, VM};
|
use super::{Chunk, Op, Value, VM};
|
||||||
use crate::vm::VMError;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_arithmetic() {
|
fn simple_arithmetic() {
|
||||||
|
|||||||
Reference in New Issue
Block a user