added type Attrs = FxHashMap<SmolStr, Value>

This commit is contained in:
Moritz Gmeiner 2024-09-03 16:53:46 +02:00
commit 943528a0db
4 changed files with 14 additions and 9 deletions

View file

@ -2,9 +2,9 @@ use std::fmt::Display;
use std::rc::Rc;
use rlox2_frontend::parser::{Expr, Stmt};
use rustc_hash::FxHashMap;
use smol_str::SmolStr;
use crate::value::Attrs;
use crate::{LoxFunction, LoxReference, Value};
#[derive(Debug, Clone)]
@ -13,7 +13,7 @@ pub struct LoxClass {
name: SmolStr,
methods: FxHashMap<String, Value>,
methods: Attrs,
}
/// Representation of a class in Lox. Always behind an Rc to ensure uniqueness. Should never be
@ -21,7 +21,7 @@ pub struct LoxClass {
impl LoxClass {
pub fn new(
name: impl Into<SmolStr>,
methods: FxHashMap<String, Value>,
methods: Attrs,
superclass: Option<Rc<LoxClass>>,
) -> Rc<Self> {
let name = name.into();
@ -41,11 +41,12 @@ impl LoxClass {
}
let new_init = Value::function(LoxFunction::new(name, closure, param_names, body));
methods.insert("init".to_owned(), new_init);
methods.insert("init".into(), new_init);
}
if let Some(ref superclass) = superclass {
let mut new_methods: FxHashMap<String, Value> = FxHashMap::default();
let mut new_methods = Attrs::default();
// Rc<LoxFunction> is immutable, so we need to drain, change, and replace
for (name, value) in methods {