tdp2110 / crafting-interpreters-rs

Crafting Interpreters in Rust
Boost Software License 1.0
259 stars 12 forks source link

DRY up `interp.member.get()` calls in treewalk_interpreter.rs #35

Closed tdp2110 closed 2 years ago

tdp2110 commented 3 years ago

We have many examples in treewalk_interpreter.rs that look like

            match interpreter.lox_functions.get(initializer_id) {
                Some(initializer) => Some(initializer.clone()),
                None => panic!(
                    "Internal interpreter error! couldn't find an initializer method with id {}.",
                    initializer_id
                ),
            },

We should pull these out into functions like

fn get_lox_function(&self, id: i64) -> &LoxFunction
{
  match self.lox_functions.get(id) {
    Some(func) => func,
    None => panic!(
                    "Internal interpreter error! couldn't find an initializer method with id {}.",
                    id
                ),
  }
}
tdp2110 commented 2 years ago

fixed in 38b1e25, 94d8579, 0e9b03b