<commit_before>use ForthResult;
use error::Error::UnknownWord;
use stack::Stack;
use std::rc::Rc;
use std::result::Result::{Ok, Err};
use word::Word;
use word::WordKind::{Builtin, Words};

#[deriving(Default)]
pub struct State {
    stack: Stack,
    dict: Vec<Rc<Word>>,
}

impl State {
    pub fn new() -> State {
        State {
            stack: Stack::new(),
            dict: Vec::new(),
        }
    }

    pub fn add_word(&mut self, word: Word) {
        self.dict.push(Rc::new(word));
    }

    pub fn run_word(&mut self, command: &str) -> ForthResult {
        let mut next = None;
        for word in self.dict.iter() {
            if command == word.command {
                next = Some(word.clone());
                break;
            }
        }
        match next {
            Some(word) => {
                match word.kind {
                    Builtin(ref f) => try!((*f)(&mut self.stack)),
                    Words(ref ws) => for w in ws.iter() {
                        try!(self.run_word(w.as_slice()))
                    },
                }
            },
            None => {
                match command.parse() {
                    Some(i) => self.stack.push(i),
                    None => return Err(UnknownWord),
                }
            },
        }
        Ok(())<commit_msg>Remove need for Rc pointer in State<commit_after>use ForthResult;
use error::Error::UnknownWord;
use stack::Stack;
use std::result::Result::{Ok, Err};
use word::Word;
use word::WordKind::{Builtin, Words};

#[deriving(Default)]
pub struct State {
    stack: Stack,
    dict: Vec<Word>,
}

impl State {
    pub fn new() -> State {
        State {
            stack: Stack::new(),
            dict: Vec::new(),
        }
    }

    pub fn add_word(&mut self, word: Word) {
        self.dict.push(word);
    }

    fn real_run_word(dict: &Vec<Word>, stack: &mut Stack,
                     command: &str) -> ForthResult {
        for word in dict.iter() {
            if command == word.command {
                match word.kind {
                    Builtin(ref f) => try!((*f)(stack)),
                    Words(ref ws) => for w in ws.iter() {
                        try!(State::real_run_word(dict, stack, w.as_slice()));
                    },
                }
                return Ok(());
            }
        }
        let i = try!(command.parse().ok_or(UnknownWord));
        stack.push(i);
        Ok(())
    }

    pub fn run_word(&mut self, command: &str) -> ForthResult {
        State::real_run_word(&self.dict, &mut self.stack, command)
{'fraction_non_alphanumeric': 0.14819136522753792, 'fraction_numerical': 0.0, 'mean_word_length': 1.5465346534653466, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676383', 'n_tokens_mistral': 785, 'n_tokens_neox': 757, 'n_words': 181}