Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 24, 2023
1 parent d649272 commit e81eb6d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 38 deletions.
4 changes: 2 additions & 2 deletions valuescript_common/src/instruction_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl InstructionByte {
pub fn from_byte(byte: u8) -> InstructionByte {
use InstructionByte::*;

return match byte {
match byte {
0x00 => End,
0x01 => Mov,
0x02 => OpInc,
Expand Down Expand Up @@ -125,6 +125,6 @@ impl InstructionByte {
0x39 => YieldStar,

_ => panic!("Unrecognized instruction: {}", byte),
};
}
}
}
9 changes: 2 additions & 7 deletions valuescript_compiler/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ impl std::fmt::Display for LabelRef {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub enum Value {
#[default]
Void,
Undefined,
Null,
Expand All @@ -352,12 +353,6 @@ pub enum Value {
Builtin(Builtin),
}

impl Default for Value {
fn default() -> Self {
Value::Void
}
}

#[derive(Debug, Clone)]
pub struct Number(pub f64);

Expand Down
4 changes: 2 additions & 2 deletions valuescript_compiler/src/assembly_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,11 @@ pub fn parse_module(content: &str) -> Module {
}

fn is_leading_identifier_char(c: char) -> bool {
c == '_' || ('a'..='z').contains(&c) || ('A'..='Z').contains(&c)
c == '_' || c.is_ascii_alphabetic()
}

fn is_identifier_char(c: char) -> bool {
c == '_' || ('0'..='9').contains(&c) || ('a'..='z').contains(&c) || ('A'..='Z').contains(&c)
c == '_' || c.is_ascii_alphanumeric()
}

fn advance_chars(iter: &mut std::iter::Peekable<std::str::Chars>, len: usize) {
Expand Down
9 changes: 2 additions & 7 deletions valuescript_compiler/src/optimization/kal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use super::try_to_kal::TryToKal;
* change program behavior due to believing false things), whereas sometimes type systems (notably
* TypeScript) are not.
*/
#[derive(Clone)]
#[derive(Clone, Default)]
pub enum Kal {
#[default]
Unknown,
Void,
Undefined,
Expand All @@ -50,12 +51,6 @@ pub enum Kal {
Builtin(Builtin),
}

impl Default for Kal {
fn default() -> Self {
Kal::Unknown
}
}

#[derive(Clone)]
pub struct Array {
pub values: Vec<Kal>,
Expand Down
4 changes: 2 additions & 2 deletions valuescript_compiler/src/target_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TargetAccessor {
) -> TargetAccessor {
use swc_ecma_ast::Expr::*;

return match expr {
match expr {
Ident(ident) => TargetAccessor::compile_ident(ec, &CrateIdent::from_swc_ident(ident)),
This(this) => TargetAccessor::compile_ident(ec, &CrateIdent::this(this.span)),
Member(member) => {
Expand Down Expand Up @@ -98,7 +98,7 @@ impl TargetAccessor {

TargetAccessor::make_bad(ec)
}
};
}
}

pub fn compile_ident(ec: &mut ExpressionCompiler, ident: &CrateIdent) -> TargetAccessor {
Expand Down
2 changes: 1 addition & 1 deletion valuescript_vm/src/builtins/number_builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub static PARSE_INT: NativeFunction = native_fn(|_this, params| {
let string_value = value.to_string().trim_start().to_string();
let radix = params.get(1).and_then(|v| v.to_index()).unwrap_or(10);

if radix < 2 || radix > 36 {
if !(2..=36).contains(&radix) {
return Ok(Val::Number(f64::NAN));
}

Expand Down
4 changes: 2 additions & 2 deletions valuescript_vm/src/bytecode_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl BytecodeDecoder {
}

pub fn decode_val(&mut self, registers: &mut Vec<Val>) -> Val {
return match self.decode_type() {
match self.decode_type() {
BytecodeType::End => panic!("Cannot decode end"),
BytecodeType::Void => Val::Void,
BytecodeType::Undefined => Val::Undefined,
Expand Down Expand Up @@ -153,7 +153,7 @@ impl BytecodeDecoder {
BytecodeType::BigInt => self.decode_bigint().to_val(),
BytecodeType::GeneratorFunction => self.decode_function(true),
BytecodeType::Unrecognized => panic!("Unrecognized bytecode type at {}", self.pos - 1),
};
}
}

pub fn decode_vec_val(&mut self, registers: &mut Vec<Val>) -> Vec<Val> {
Expand Down
4 changes: 2 additions & 2 deletions valuescript_vm/src/number_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static TO_FIXED: NativeFunction = native_fn(|this, params| {

precision = f64::floor(precision);

if precision < 1.0 || precision > 100.0 {
if !(1.0..=100.0).contains(&precision) {
return Err("precision must be between 1 and 100".to_range_error());
}

Expand All @@ -59,7 +59,7 @@ static TO_EXPONENTIAL: NativeFunction = native_fn(|this, params| {
let mut precision = p.to_number();
precision = f64::floor(precision);

if precision < 0.0 || precision > 100.0 {
if !(0.0..=100.0).contains(&precision) {
return Err("precision must be between 0 and 100".to_range_error());
}

Expand Down
17 changes: 6 additions & 11 deletions valuescript_vm/src/vs_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use crate::vs_function::VsFunction;
use crate::vs_object::VsObject;
use crate::vs_symbol::{symbol_to_name, VsSymbol};

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub enum Val {
#[default]
Void,
Undefined,
Null,
Expand All @@ -37,12 +38,6 @@ pub enum Val {
CopyCounter(Box<CopyCounter>),
}

impl Default for Val {
fn default() -> Self {
Val::Void
}
}

#[derive(PartialEq, Debug)]
pub enum VsType {
Undefined,
Expand Down Expand Up @@ -222,7 +217,7 @@ impl ValTrait for Val {
fn to_index(&self) -> Option<usize> {
use Val::*;

return match self {
match self {
Void => panic!("Shouldn't happen"),
Undefined => None,
Null => None,
Expand All @@ -241,7 +236,7 @@ impl ValTrait for Val {
Static(val) => val.to_index(),
Dynamic(val) => val.to_index(),
CopyCounter(_) => None,
};
}
}

fn is_primitive(&self) -> bool {
Expand Down Expand Up @@ -291,7 +286,7 @@ impl ValTrait for Val {
fn is_nullish(&self) -> bool {
use Val::*;

return match self {
match self {
Void => panic!("Shouldn't happen"), // TODO: Or just true?
Undefined => true,
Null => true,
Expand All @@ -307,7 +302,7 @@ impl ValTrait for Val {
Static(_) => false,
Dynamic(val) => val.is_nullish(),
CopyCounter(_) => false,
};
}
}

fn bind(&self, params: Vec<Val>) -> Option<Val> {
Expand Down
4 changes: 2 additions & 2 deletions vstc/src/run_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ fn format_from_path(file_path: &String) -> RunFormat {
.and_then(OsStr::to_str)
.unwrap_or("");

return match ext {
match ext {
"ts" => RunFormat::TypeScript,
"mts" => RunFormat::TypeScript,
"js" => RunFormat::TypeScript,
"mjs" => RunFormat::TypeScript,
"vsm" => RunFormat::Assembly,
"vsb" => RunFormat::Bytecode,
_ => std::panic!("Unrecognized file extension \"{}\"", ext),
};
}
}

fn to_bytecode(format: RunFormat, file_path: &String) -> Bytecode {
Expand Down

0 comments on commit e81eb6d

Please sign in to comment.