pub fn eval(&mut self, line: String) -> Result<Return, ContextErr> {
        // a) Skip leading spaces and parse a name (see 3.4.1);
        for word_str in line.split_whitespace() {
            match self.fsm {
                Fsm::Execute => {
                    match word_str {
                        "bye" => {
                            return Ok(Return::Shutdown);
                        }
                        "yield" => {
                            todo!("There's a bug where yielding doesn't resume. It just chops off other stuff.");
                            return Ok(Return::Yielding);
                        }
                        "var" => {
                            // https://forth-standard.org/standard/core/VARIABLE
                            // Idea: if you ever need to extend this, consider a FSM to wait for another input
                            self.fsm = Fsm::GetVariable;
                        }
                        _ => {
                            // b) Search the dictionary name space (see 3.4.2).
                            let word = match self.find_word(word_str) {
                                Some(word) => word,
                                None => {
                                    let i = self.convert_to_number(word_str)?;

                                    Rc::new(Word::Data(i))
                                }
                            };

                            match self.mode {
                                Mode::Interpreting => {
                                    self.run_word(word)?;
                                }
                                Mode::Compiling => {
                                    todo!("Compiling");
                                }
                            }
                        }
                    }
                }
                Fsm::GetVariable => {
                    // add a value to the dict without a key.
                    let addr = self
                        .dictionary
                        .insert(None, Rc::new(Word::Data(Datum::default())))?;

                    self.dictionary
                        .insert(Some(word_str.into()), Rc::new(Word::Data(addr as Datum)))?;

                    // Switch back to execution mode
                    self.fsm = Fsm::Execute;
                }
            }
        }

        Ok(Return::Ok)
    }
/// Evaluates a line of code. By default, tokens are separated by whitespace.
Evaluates a line of code. By default, tokens are separated by whitespace.
Evaluates a line of code . By default tokens are separated by whitespace .
pub fn eval(&mut self, line: String) -> Result<Return, ContextErr> {
        // a) Skip leading spaces and parse a name (see 3.4.1);
        for word_str in line.split_whitespace() {
            match self.fsm {
                Fsm::Execute => {
                    match word_str {
                        "bye" => {
                            return Ok(Return::Shutdown);
                        }
                        "yield" => {
                            todo!("There's a bug where yielding doesn't resume. It just chops off other stuff.");
                            return Ok(Return::Yielding);
                        }
                        "var" => {
                            // https://forth-standard.org/standard/core/VARIABLE
                            // Idea: if you ever need to extend this, consider a FSM to wait for another input
                            self.fsm = Fsm::GetVariable;
                        }
                        _ => {
                            // b) Search the dictionary name space (see 3.4.2).
                            let word = match self.find_word(word_str) {
                                Some(word) => word,
                                None => {
                                    let i = self.convert_to_number(word_str)?;
                                    Rc::new(Word::Data(i))
                                }
                            };
                            match self.mode {
                                Mode::Interpreting => {
                                    self.run_word(word)?;
                                }
                                Mode::Compiling => {
                                    todo!("Compiling");
                                }
                            }
                        }
                    }
                }
                Fsm::GetVariable => {
                    // add a value to the dict without a key.
                    let addr = self
                        .dictionary
                        .insert(None, Rc::new(Word::Data(Datum::default())))?;
                    self.dictionary
                        .insert(Some(word_str.into()), Rc::new(Word::Data(addr as Datum)))?;
                    // Switch back to execution mode
                    self.fsm = Fsm::Execute;
                }
            }
        }
        Ok(Return::Ok)
    }
pub fn eval ( & mut self , line : String ) -> Result < Return , ContextErr > { // a) Skip leading spaces and parse a name (see 3.4.1); for word_str in line . split_whitespace ( ) { match self . fsm { Fsm :: Execute => { match word_str { " " => { return Ok ( Return :: Shutdown ) ; } " " => { todo ! ( " " ) ; return Ok ( Return :: Yielding ) ; } " " => { // https://forth-standard.org/standard/core/VARIABLE // Idea: if you ever need to extend this, consider a FSM to wait for another input self . fsm = Fsm :: GetVariable ; } _ => { // b) Search the dictionary name space (see 3.4.2). let word = match self . find_word ( word_str ) { Some ( word ) => word , None => { let i = self . convert_to_number ( word_str ) ? ; Rc :: new ( Word :: Data ( i ) ) } } ; match self . mode { Mode :: Interpreting => { self . run_word ( word ) ? ; } Mode :: Compiling => { todo ! ( " " ) ; } } } } } Fsm :: GetVariable => { // add a value to the dict without a key. let addr = self . dictionary . insert ( None , Rc :: new ( Word :: Data ( Datum :: default ( ) ) ) ) ? ; self . dictionary . insert ( Some ( word_str . into ( ) ) , Rc :: new ( Word :: Data ( addr as Datum ) ) ) ? ; // Switch back to execution mode self . fsm = Fsm :: Execute ; } } } Ok ( Return :: Ok ) }
Evaluates a line of code.
Evaluates a line of code .
&mut self
line
String
&mut self
line
String