aboutsummaryrefslogtreecommitdiffstats
path: root/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm.rs')
-rw-r--r--src/vm.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/vm.rs b/src/vm.rs
index 5c42805..5a7b471 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -122,10 +122,6 @@ impl VM {
(b, a) // this matches the order they were on the stack
}
- fn _peek_up(&self, amount: usize) -> Option<&Value> {
- self.stack.get(self.stack.len() - amount)
- }
-
fn frame(&self) -> &Frame {
let last = self.frames.len() - 1;
&self.frames[last]
@@ -141,8 +137,8 @@ impl VM {
self.frame().block.borrow().ops[ip].clone()
}
+ /// Stop the program, violently
fn crash_and_burn(&self) -> ! {
- println!("\n\n !!!POPPING EMPTY STACK - DUMPING EVERYTHING!!!\n");
self.print_stack();
println!("\n");
self.frame().block.borrow().debug_print();
@@ -162,6 +158,7 @@ impl VM {
}
}
+ /// Runs a single operation on the VM
fn eval_op(&mut self, op: Op) -> Result<OpResult, Error> {
match op {
Op::Illegal => {
@@ -427,6 +424,7 @@ impl VM {
self.frame().block.borrow().ops[self.frame().ip]);
}
+ // Initalizes the VM for running. Run cannot be called before this.
pub(crate) fn init(&mut self, prog: &Prog) {
let block = Rc::clone(&prog.blocks[0]);
self.blobs = prog.blobs.clone();
@@ -443,6 +441,7 @@ impl VM {
});
}
+ /// Simulates the program.
pub fn run(&mut self) -> Result<OpResult, Error> {
if self.print_blocks {
println!("\n [[{}]]\n", "RUNNING".red());
@@ -461,6 +460,7 @@ impl VM {
}
}
+ /// Checks the current operation for type errors.
fn check_op(&mut self, op: Op) -> Result<(), Error> {
match op {
Op::Unreachable => {}
@@ -702,6 +702,7 @@ impl VM {
errors
}
+ // Checks the program for type errors.
pub(crate) fn typecheck(&mut self, prog: &Prog) -> Result<(), Vec<Error>> {
let mut errors = Vec::new();