mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
updated a bunch of stuff
This commit is contained in:
parent
660464638f
commit
67bb5fe8fd
24 changed files with 683 additions and 702 deletions
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue