Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jan 18, 2024
1 parent 9f4ab7f commit 50e4b50
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 113 deletions.
26 changes: 13 additions & 13 deletions crates/dash_compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<'interner> FunctionCompiler<'interner> {
cp: root.cp,
locals,
externals,
source: self.source.into(),
source: self.source,
debug_symbols: root.debug_symbols,
})
}
Expand Down Expand Up @@ -2095,26 +2095,26 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
/// eq (ld _1 ld w)
/// jmpfalsep case_x_cond
/// # code for case w
/// # if there's a break anywhere in here, jump to end of switch
/// # if there's a break anywhere in here, jump to end of switch
/// jmp case_x
///
/// case_x_cond:
/// eq (ld_1 ld x)
/// jmpfalsep case_y_cond
/// case_x_cond:
/// eq (ld_1 ld x)
/// jmpfalsep case_y_cond
/// case_x:
/// # code for case x
/// constant 'case 1'
/// ret
/// jmp case_y
/// constant 'case 1'
/// ret
/// jmp case_y
///
/// case_x_code:
/// ...
/// case_y_cond:
/// eq (ld_1 ld y)
/// jmpfalsep default
/// case y:
/// ...
/// jmp default
/// eq (ld_1 ld y)
/// jmpfalsep default
/// case y:
/// ...
/// jmp default
///
/// default:
/// ...
Expand Down
8 changes: 4 additions & 4 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ mod handlers {
None => throw!(cx, Error, "Static imports are disabled for this context."),
};

cx.set_local(local_id.into(), value.into());
cx.set_local(local_id.into(), value);

Ok(None)
}
Expand Down Expand Up @@ -1445,7 +1445,7 @@ mod handlers {

let frame = cx.active_frame_mut();
match &mut frame.state {
FrameState::Module(exports) => exports.named.push((ident, value.into())),
FrameState::Module(exports) => exports.named.push((ident, value)),
_ => throw!(cx, Error, "Export is only available at the top level in modules"),
}
}
Expand Down Expand Up @@ -1569,7 +1569,7 @@ mod handlers {
let ident = cx.identifier_constant(ident_id.into());

let prop = obj.get_property(&mut cx, ident.into())?;
cx.set_local(id, prop.into());
cx.set_local(id, prop);
}

Ok(None)
Expand All @@ -1587,7 +1587,7 @@ mod handlers {
let i = cx.scope.intern_usize(i.into());

let prop = array.get_property(&mut cx, i.into())?;
cx.set_local(id, prop.into());
cx.set_local(id, prop);
}

Ok(None)
Expand Down
6 changes: 5 additions & 1 deletion crates/dash_vm/src/gc/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl HandleFlags {
}

#[repr(C)]
#[allow(clippy::type_complexity)]
pub struct ObjectVTable {
pub(crate) drop_boxed_gcnode: unsafe fn(*mut GcNode<()>),
pub(crate) trace: unsafe fn(*const (), &mut TraceCtxt<'_>),
Expand Down Expand Up @@ -124,14 +125,17 @@ impl Handle {
}

pub fn vtable(&self) -> &'static ObjectVTable {
unsafe { &(*self.0.as_ptr()).vtable }
unsafe { (*self.0.as_ptr()).vtable }
}

/// Returns the `Persistent<T>` refcount.
pub fn refcount(&self) -> u64 {
unsafe { (*self.0.as_ptr()).refcount.get() }
}

/// # Safety
/// The updated refcount must not be updated to a value such that a drop
/// causes the refcount to drop zero while there are active `Handle`s
pub unsafe fn set_refcount(&self, refcount: u64) {
(*self.0.as_ptr()).refcount.set(refcount);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_vm/src/js_std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ pub fn slice(cx: CallContext) -> Result<Value, Value> {
let this = Value::Object(cx.this.to_object(cx.scope)?);
let len = this.length_of_array_like(cx.scope)?;

let start = match cx.args.get(0) {
let start = match cx.args.first() {
Some(v) => to_slice_index(v.to_int32(cx.scope)? as isize, len),
None => 0,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/dash_vm/src/js_std/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::value::ops::conversions::ValueConversion;
use crate::value::{boxed, Value, ValueContext};

pub fn constructor(cx: CallContext) -> Result<Value, Value> {
let value = cx.args.get(0).unwrap_or_undefined().to_boolean(cx.scope)?;
let value = cx.args.first().unwrap_or_undefined().to_boolean(cx.scope)?;
if cx.is_constructor_call {
let value = boxed::Boolean::new(cx.scope, value);
Ok(Value::Object(cx.scope.register(value).into()))
Ok(Value::Object(cx.scope.register(value)))
} else {
Ok(Value::Boolean(value))
}
Expand Down
54 changes: 27 additions & 27 deletions crates/dash_vm/src/js_std/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::value::{Value, ValueContext};

pub fn abs(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, return NaN.
// 3. If n is -0𝔽, return +0𝔽.
// 4. If n is -∞𝔽, return +∞𝔽.
Expand All @@ -17,7 +17,7 @@ pub fn abs(cx: CallContext) -> Result<Value, Value> {

pub fn acos(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n > 1𝔽, or n < -1𝔽, return NaN.
// 3. If n is 1𝔽, return +0𝔽.
// 4. Return an implementation-approximated Number value representing the result of the inverse cosine of ℝ(n).
Expand All @@ -26,7 +26,7 @@ pub fn acos(cx: CallContext) -> Result<Value, Value> {

pub fn acosh(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN or n is +∞𝔽, return n.
// 3. If n is 1𝔽, return +0𝔽.
// 4. If n < 1𝔽, return NaN.
Expand All @@ -36,7 +36,7 @@ pub fn acosh(cx: CallContext) -> Result<Value, Value> {

pub fn asin(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
// 3. If n > 1𝔽 or n < -1𝔽, return NaN.
// 4. Return an implementation-approximated Number value representing the result of the inverse sine of ℝ(n).
Expand All @@ -45,15 +45,15 @@ pub fn asin(cx: CallContext) -> Result<Value, Value> {

pub fn asinh(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, n is -0𝔽, n is +∞𝔽, or n is -∞𝔽, return n.
// 3. Return an implementation-approximated Number value representing the result of the inverse hyperbolic sine of ℝ(n).
Ok(Value::number(n.asinh()))
}

pub fn atan(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
// 3. If n is +∞𝔽, return an implementation-approximated Number value representing π / 2.
// 4. If n is -∞𝔽, return an implementation-approximated Number value representing -π / 2.
Expand All @@ -63,7 +63,7 @@ pub fn atan(cx: CallContext) -> Result<Value, Value> {

pub fn atanh(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
// 3. If n > 1𝔽 or n < -1𝔽, return NaN.
// 4. If n is 1𝔽, return +∞𝔽.
Expand All @@ -74,7 +74,7 @@ pub fn atanh(cx: CallContext) -> Result<Value, Value> {

pub fn atan2(cx: CallContext) -> Result<Value, Value> {
// 1. Let ny be ? ToNumber(y).
let ny = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let ny = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. Let nx be ? ToNumber(x).
let nx = cx.args.get(1).unwrap_or_undefined().to_number(cx.scope)?;
// ... steps are a little too long to add here ...
Expand All @@ -83,15 +83,15 @@ pub fn atan2(cx: CallContext) -> Result<Value, Value> {

pub fn cbrt(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, n is -0𝔽, n is +∞𝔽, or n is -∞𝔽, return n.
// 3. Return an implementation-approximated Number value representing the result of the cube root of ℝ(n).
Ok(Value::number(n.cbrt()))
}

pub fn ceil(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, n is -0𝔽, n is +∞𝔽, or n is -∞𝔽, return n.
// 3. If n < +0𝔽 and n > -1𝔽, return -0𝔽.
// 4. If n is an integral Number, return n.
Expand All @@ -100,13 +100,13 @@ pub fn ceil(cx: CallContext) -> Result<Value, Value> {
}

pub fn clz32(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)? as u32;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)? as u32;
Ok(Value::number(n.leading_zeros() as f64))
}

pub fn cos(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +∞𝔽, or n is -∞𝔽, return NaN.
// 3. If n is +0𝔽 or n is -0𝔽, return 1𝔽.
// 4. Return an implementation-approximated Number value representing the result of the cosine of ℝ(n).
Expand All @@ -115,7 +115,7 @@ pub fn cos(cx: CallContext) -> Result<Value, Value> {

pub fn cosh(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, return NaN.
// 3. If n is +∞𝔽 or n is -∞𝔽, return +∞𝔽.
// 4. If n is +0𝔽 or n is -0𝔽, return 1𝔽.
Expand All @@ -125,7 +125,7 @@ pub fn cosh(cx: CallContext) -> Result<Value, Value> {

pub fn exp(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN or n is +∞𝔽, return n.
// 3. If n is +0𝔽 or n is -0𝔽, return 1𝔽.
// 4. If n is -∞𝔽, return +0𝔽.
Expand All @@ -135,71 +135,71 @@ pub fn exp(cx: CallContext) -> Result<Value, Value> {

pub fn expm1(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
// 2. If n is NaN, n is +0𝔽, n is -0𝔽, or n is +∞𝔽, return n.
// 3. If n is -∞𝔽, return -1𝔽.
// 4. Return an implementation-approximated Number value representing the result of subtracting 1 from the exponential function of ℝ(n).
Ok(Value::number(n.exp_m1()))
}

pub fn log(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.ln()))
}

pub fn log1p(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.ln_1p()))
}

pub fn log10(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.log10()))
}

pub fn log2(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.log2()))
}

pub fn round(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.round()))
}

pub fn sin(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.sin()))
}

pub fn sinh(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.sinh()))
}

pub fn sqrt(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.sqrt()))
}

pub fn tan(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.tan()))
}

pub fn tanh(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.tanh()))
}

pub fn trunc(cx: CallContext) -> Result<Value, Value> {
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
Ok(Value::number(n.trunc()))
}

pub fn floor(cx: CallContext) -> Result<Value, Value> {
// 1. Let n be ? ToNumber(x).
let n = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let n = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;

// 2. If n is NaN, n is +0𝔽, n is -0𝔽, n is +∞𝔽, or n is -∞𝔽, return n.
if n.is_nan() || n.is_infinite() || n == 0f64 {
Expand Down
4 changes: 2 additions & 2 deletions crates/dash_vm/src/js_std/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::value::primitive::{Number, MAX_SAFE_INTEGERF};
use crate::value::{boxed, Value, ValueContext};

pub fn constructor(cx: CallContext) -> Result<Value, Value> {
let value = cx.args.get(0).unwrap_or_undefined().to_number(cx.scope)?;
let value = cx.args.first().unwrap_or_undefined().to_number(cx.scope)?;
if cx.is_constructor_call {
let value = boxed::Number::new(cx.scope, value);
Ok(Value::Object(cx.scope.register(value).into()))
Ok(Value::Object(cx.scope.register(value)))
} else {
Ok(Value::number(value))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_vm/src/js_std/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::value::{Value, ValueContext};
use std::fmt::Write;

pub fn constructor(cx: CallContext) -> Result<Value, Value> {
let value = cx.args.get(0).unwrap_or_undefined().to_js_string(cx.scope)?;
let value = cx.args.first().unwrap_or_undefined().to_js_string(cx.scope)?;
if cx.is_constructor_call {
let boxed = BoxedString::new(cx.scope, value);
Ok(Value::Object(cx.scope.register(boxed)))
Expand Down
Loading

0 comments on commit 50e4b50

Please sign in to comment.