mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
Finished up to and including chapter 16
This commit is contained in:
parent
647a095a05
commit
b86985deaf
24 changed files with 1051 additions and 198 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rlox2_frontend::parser::{Expr, Stmt};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{LoxFunction, LoxReference, Value};
|
||||
|
||||
|
|
@ -12,12 +12,16 @@ pub struct LoxClass {
|
|||
|
||||
name: String,
|
||||
|
||||
methods: HashMap<String, Value>,
|
||||
methods: FxHashMap<String, Value>,
|
||||
}
|
||||
|
||||
/// 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>, methods: HashMap<String, Value>, superclass: Option<Rc<LoxClass>>) -> Rc<Self> {
|
||||
pub fn new(
|
||||
name: impl Into<String>,
|
||||
methods: FxHashMap<String, Value>,
|
||||
superclass: Option<Rc<LoxClass>>,
|
||||
) -> Rc<Self> {
|
||||
let name = name.into();
|
||||
let mut methods = methods;
|
||||
|
||||
|
|
@ -42,7 +46,7 @@ impl LoxClass {
|
|||
}
|
||||
|
||||
if let Some(ref superclass) = superclass {
|
||||
let mut new_methods: HashMap<String, Value> = HashMap::new();
|
||||
let mut new_methods: FxHashMap<String, Value> = FxHashMap::default();
|
||||
|
||||
// Rc<LoxFunction> is immutable, so we need to drain, change, and replace
|
||||
for (name, value) in methods {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue