diff options
Diffstat (limited to 'src/runtime.rs')
| -rw-r--r-- | src/runtime.rs | 26 | 
1 files changed, 19 insertions, 7 deletions
diff --git a/src/runtime.rs b/src/runtime.rs index b041561..46b2d9f 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -1,6 +1,5 @@  use std::{collections::{LinkedList, BTreeMap}, cmp::Ordering, sync::Arc, iter::{Copied, Rev}}; -use boa_interner::Sym;  use ion_rs::SymbolTable;  use crate::ion::{IonReader, IonValue}; @@ -268,7 +267,6 @@ pub struct Function {      pub(crate) expected_stack_depth: usize,  } -pub type FnRef = usize;  pub type ByteCode = Vec<u8>;  struct Stack(Vec<u8>); @@ -290,7 +288,17 @@ impl  Runtime {          }      } -    pub fn invoke(&mut self, fnref: FnRef, arguments: Vec<IonValue>) -> Vec<IonValue> { +    pub fn to_symbol_id<S>(&self, s: S) -> Option<usize> +    where S: AsRef<str> +    { +        self.symbols.sid_for(&s) +    } + +    pub fn resolve_symbol(&self, id: usize) -> Option<&str> { +        self.symbols.text_for(id) +    } + +    pub fn invoke(&mut self, fnref: usize, arguments: Vec<IonValue>) -> Vec<IonValue> {          let func = *self.functions.get(&fnref).expect("Undefined function");          let mut frame = StackFrame::new(self.bytecode.clone(), &func, arguments);          loop { @@ -310,11 +318,15 @@ impl  Runtime {          }          let op = frame.next_byte(); -        for x in &frame.stack.0 { -            print!(" {x:02X}"); + +        #[cfg(debugger)] +        { +            for x in &frame.stack.0 { +                print!(" {x:02X}"); +            } +            println!(); +            println!("PC: {:02X}, OP: {:02X}", frame.pc - 1, op);          } -        println!(); -        println!("PC: {:02X}, OP: {:02X}", frame.pc - 1, op);          match op {              0x01 => { // OpType::Jump  | 
