-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: pull out Interpreter struct
- Loading branch information
1 parent
cd302bd
commit d92c247
Showing
5 changed files
with
80 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use super::runtime::Runtime; | ||
use super::stack::{CallStack, DataStack, Op, Prog}; | ||
use super::EditorError; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct Interpreter { | ||
call_stack: CallStack, | ||
data_stack: DataStack, | ||
} | ||
|
||
impl Interpreter { | ||
pub fn new() -> Interpreter { | ||
Interpreter::default() | ||
} | ||
|
||
/// Execute the program. Returns `Ok(true)` if it halted from a `Block` op, | ||
/// and `Ok(false)` if it halted from hitting the end of the program. | ||
pub fn execute(&mut self, r: &mut Runtime, prog: Prog) -> Result<bool, EditorError> { | ||
self.call_stack.push(prog); | ||
while let Some(op) = self.call_stack.pop() { | ||
if op == Op::Block { | ||
return Ok(true); | ||
} else { | ||
self.call(r, op)?; | ||
} | ||
} | ||
Ok(false) | ||
} | ||
|
||
fn call(&mut self, r: &mut Runtime, op: Op) -> Result<(), EditorError> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters