Skip to content

Commit 7a38fcf

Browse files
committed
interpreter: Remove fmt::Display impls which didn't make sense
Also refactor uses of `todo!()` to use variables directly in their format strings.
1 parent 8790238 commit 7a38fcf

File tree

6 files changed

+19
-38
lines changed

6 files changed

+19
-38
lines changed

jakescript-cli/src/repl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
match it.vm().execution_state() {
3333
ExecutionState::Advance => {}
3434
ExecutionState::Exception(ex) => {
35-
eprintln!("Exception: {ex}");
35+
eprintln!("Exception: {ex:?}");
3636
self.input_buf.clear();
3737
return Result::ExitWithRuntimeError;
3838
}
@@ -86,7 +86,7 @@ where
8686
continue;
8787
}
8888
};
89-
eprintln!("{value}");
89+
eprintln!("{value:?}");
9090
}
9191
}
9292

jakescript/src/interpreter/expression.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Eval for NewExpression {
7777
type Output = Value;
7878

7979
fn eval(&self, _: &mut Interpreter) -> Result<Self::Output> {
80-
todo!("NewExpression::eval: {:#?}", self)
80+
todo!("NewExpression::eval: {self:#?}")
8181
}
8282
}
8383

@@ -114,7 +114,7 @@ impl Eval for AssignmentExpression {
114114
compute_updated,
115115
map_err,
116116
),
117-
lhs => todo!("AssignmentExpression::eval: base_value={:?}", lhs),
117+
lhs => todo!("AssignmentExpression::eval: base_value={lhs:?}"),
118118
}
119119
}
120120
Expression::Member(MemberExpression::ComputedMemberAccess(lhs_node)) => {
@@ -127,14 +127,14 @@ impl Eval for AssignmentExpression {
127127
// FIXME: Remove this restriction as I think it's actually OK to key
128128
// an object property by the empty
129129
// string.
130-
todo!("AssignmentExpression::eval: prop_name={}", prop_value)
130+
todo!("AssignmentExpression::eval: prop_name={prop_value:?}")
131131
});
132132
it.update_object_property(lhs_ref, &prop_key, compute_updated, map_err)
133133
}
134-
lhs => todo!("AssignmentExpression::eval: base_value={:?}", lhs),
134+
lhs => todo!("AssignmentExpression::eval: base_value={lhs:?}"),
135135
}
136136
}
137-
lhs => todo!("AssignmentExpression::eval: lhs={:#?}", lhs),
137+
lhs => todo!("AssignmentExpression::eval: lhs={lhs:#?}"),
138138
}
139139
}
140140
}
@@ -235,10 +235,10 @@ impl Eval for UpdateExpression {
235235
compute_updated,
236236
map_err,
237237
),
238-
operand => todo!("UpdateExpression::eval: operand={:?}", operand),
238+
operand => todo!("UpdateExpression::eval: operand={operand:?}"),
239239
}
240240
}
241-
operand => todo!("UpdateExpression::eval: operand={:#?}", operand),
241+
operand => todo!("UpdateExpression::eval: operand={operand:#?}"),
242242
}
243243
}
244244
}
@@ -270,7 +270,7 @@ impl Eval for MemberAccessExpression {
270270
.unwrap_or_default();
271271
Ok(value)
272272
}
273-
base_value => todo!("PropertyAccessExpression::eval: base={:?}", base_value),
273+
base_value => todo!("PropertyAccessExpression::eval: base={base_value:?}"),
274274
}
275275
}
276276
}
@@ -282,12 +282,12 @@ impl Eval for ComputedMemberAccessExpression {
282282
let base_value = self.base.eval(it)?;
283283
let (base_refr, base_obj) = match base_value {
284284
Value::Object(base_refr) => (base_refr, it.vm().heap().resolve(base_refr)),
285-
base_value => todo!("ComputedPropertyExpression::eval: base={:?}", base_value),
285+
base_value => todo!("ComputedPropertyExpression::eval: base={base_value:?}"),
286286
};
287287
let property_value = self.member.eval(it)?;
288288
let property = match property_value {
289289
Value::Number(Number::Int(n)) => PropertyKey::from(n),
290-
property => todo!("ComputedPropertyExpression::eval: property={:?}", property),
290+
property => todo!("ComputedPropertyExpression::eval: property={property:?}"),
291291
};
292292
let value = base_obj
293293
.as_ref()
@@ -321,7 +321,7 @@ impl Eval for FunctionCallExpression {
321321
};
322322
let receiver = match receiver {
323323
Some(Value::Object(receiver)) => Some(receiver),
324-
Some(receiver) => todo!("FunctionCallExpression: receiver={:?}", receiver),
324+
Some(receiver) => todo!("FunctionCallExpression: receiver={receiver:?}"),
325325
None => None,
326326
};
327327

jakescript/src/interpreter/heap.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,14 @@ impl Heap {
3535
#[derive(Clone, Copy, Eq, PartialEq)]
3636
pub struct Reference(usize);
3737

38-
impl fmt::Display for Reference {
38+
impl fmt::Debug for Reference {
3939
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4040
// Note: 6 includes the 2 chars for the "0x" prefix, so only 4 actual digits are
4141
// displayed.
4242
write!(f, "{:#06x}", self.0)
4343
}
4444
}
4545

46-
impl fmt::Debug for Reference {
47-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48-
fmt::Display::fmt(self, f)
49-
}
50-
}
51-
5246
#[derive(Clone)]
5347
pub struct ObjectRef {
5448
obj: Rc<RefCell<Object>>,

jakescript/src/interpreter/value.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ impl Value {
1818
}
1919
}
2020

21-
impl fmt::Display for Value {
22-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23-
match self {
24-
Self::Boolean(value) => write!(f, "{value}"),
25-
Self::Number(value) => write!(f, "{value}"),
26-
Self::Object(value) => write!(f, "{value}"),
27-
Self::Null => f.write_str("null"),
28-
Self::Undefined => f.write_str("undefined"),
29-
}
30-
}
31-
}
32-
3321
#[derive(Copy, Clone, Debug)]
3422
pub enum Number {
3523
Float(f64),
@@ -166,21 +154,21 @@ impl Number {
166154
///
167155
/// Always panics.
168156
pub fn checked_shl(self, rhs: Self) -> Option<Self> {
169-
todo!("Number::checked_shl: lhs={}, rhs={}", self, rhs)
157+
todo!("Number::checked_shl: lhs={self}, rhs={rhs}")
170158
}
171159

172160
/// # Panics
173161
///
174162
/// Always panics.
175163
pub fn checked_shr_signed(self, rhs: Self) -> Option<Self> {
176-
todo!("Number::checked_shr_signed: lhs={}, rhs={}", self, rhs)
164+
todo!("Number::checked_shr_signed: lhs={self}, rhs={rhs}")
177165
}
178166

179167
/// # Panics
180168
///
181169
/// Always panics.
182170
pub fn checked_shr_unsigned(self, rhs: Self) -> Option<Self> {
183-
todo!("Number::checked_shr_unsigned: lhs={}, rhs={}", self, rhs)
171+
todo!("Number::checked_shr_unsigned: lhs={self}, rhs={rhs}")
184172
}
185173
}
186174

jakescript/src/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<I: FallibleIterator<Item = char, Error = io::Error>> Lexer<I> {
5757
Element::new_token(it, loc)
5858
} else {
5959
let ch = self.source.peek()?.unwrap();
60-
todo!("Lexer::parse_element: ch={}", ch)
60+
todo!("Lexer::parse_element: ch={ch}")
6161
})
6262
}
6363

jakescript/src/parser/expression.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ impl<I: FallibleIterator<Item = Element, Error = lexer::Error>> Parser<I> {
284284
Expression::IdentifierReference(member_expr) => member_expr.identifier,
285285
member_expr => todo!(
286286
"Unsupported member access expression (only simple `a.b` expressions are \
287-
supported): {:?}",
288-
member_expr
287+
supported): {member_expr:?}"
289288
),
290289
};
291290
Ok(MemberAccessExpression {

0 commit comments

Comments
 (0)