updated a bunch of stuff

This commit is contained in:
Moritz Gmeiner 2024-09-01 19:16:30 +02:00
commit 67bb5fe8fd
24 changed files with 683 additions and 702 deletions

View file

@ -10,7 +10,7 @@ use crate::{LoxFunction, LoxReference, Value};
pub struct LoxClass {
superclass: Option<Rc<LoxClass>>,
name: String,
name: Box<str>,
methods: FxHashMap<String, Value>,
}
@ -18,7 +18,7 @@ pub struct LoxClass {
/// Representation of a class in Lox. Always behind an Rc to ensure uniqueness. Should never be handled raw.
impl LoxClass {
pub fn new(
name: impl Into<String>,
name: impl Into<Box<str>>,
methods: FxHashMap<String, Value>,
superclass: Option<Rc<LoxClass>>,
) -> Rc<Self> {
@ -33,10 +33,7 @@ impl LoxClass {
let mut body = init.body().clone();
if let Stmt::Block { ref mut statements } = body {
statements.push(Stmt::return_stmt(Expr::LocalVariable {
name: "this".to_owned(),
level: 1,
}));
statements.push(Stmt::return_stmt(Expr::local_variable("this", 1)));
} else {
panic!("Body of init method of class {name} wasn't a block");
}
@ -130,7 +127,12 @@ impl LoxClass {
impl Display for LoxClass {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "<class {} at {:#X}>", self.name, (self as *const LoxClass) as usize)
write!(
f,
"<class {} at {:#X}>",
self.name,
(self as *const LoxClass) as usize
)
}
}