Browse Source

VM Tidy Up (#1610)

* - add trace to VSCode launch
- comment out pushUndefined and Return
- Move call frame to its own file
- heading for code blocks needed to be on its own line
- Show the difference between the VM starting up and a new Call frame being ran

* add back in return opCodes

* Update boa/src/vm/mod.rs

Co-authored-by: João Borges <rageknify@gmail.com>
pull/1636/head
Jason Williams 3 years ago committed by GitHub
parent
commit
1a257b52ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .vscode/launch.json
  2. 1
      boa/src/bytecompiler.rs
  3. 17
      boa/src/vm/call_frame.rs
  4. 2
      boa/src/vm/code_block.rs
  5. 24
      boa/src/vm/mod.rs

2
.vscode/launch.json vendored

@ -28,7 +28,7 @@
"vm"
]
},
"args": ["${workspaceFolder}/tests/js/test.js"],
"args": ["-t", "${workspaceFolder}/tests/js/test.js"],
"sourceLanguages": ["rust"]
}
]

1
boa/src/bytecompiler.rs

@ -868,6 +868,7 @@ impl ByteCompiler {
compiler.code_block.params = paramaters.to_owned().into_boxed_slice();
// TODO These are redundant if a function returns so may need to check if a function returns and adding these if it doesn't
compiler.emit(Opcode::PushUndefined, &[]);
compiler.emit(Opcode::Return, &[]);

17
boa/src/vm/call_frame.rs

@ -0,0 +1,17 @@
//! CallFrame
//! This module will provides everything needed to implement the CallFrame
use super::CodeBlock;
use crate::{environment::lexical_environment::Environment, JsValue};
use gc::Gc;
#[derive(Debug)]
pub struct CallFrame {
pub(crate) prev: Option<Box<Self>>,
pub(crate) code: Gc<CodeBlock>,
pub(crate) pc: usize,
pub(crate) fp: usize,
pub(crate) exit_on_return: bool,
pub(crate) this: JsValue,
pub(crate) environment: Environment,
}

2
boa/src/vm/code_block.rs

@ -218,7 +218,7 @@ impl CodeBlock {
impl std::fmt::Display for CodeBlock {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
writeln!(
f,
"----------------- name '{}' (length: {}) ------------------",
self.name, self.length

24
boa/src/vm/mod.rs

@ -2,18 +2,18 @@
//! This module will provide an instruction set for the AST to use, various traits,
//! plus an interpreter to execute those instructions
use crate::environment::lexical_environment::Environment;
use crate::{
builtins::Array, environment::lexical_environment::VariableScope, symbol::WellKnownSymbols,
BoaProfiler, Context, JsResult, JsValue,
};
mod call_frame;
mod code_block;
mod opcode;
pub use call_frame::CallFrame;
pub use code_block::CodeBlock;
pub use code_block::JsVmFunction;
use gc::Gc;
pub use opcode::Opcode;
use std::{convert::TryInto, mem::size_of, time::Instant};
@ -22,18 +22,6 @@ use self::code_block::Readable;
#[cfg(test)]
mod tests;
#[derive(Debug)]
pub struct CallFrame {
pub(crate) prev: Option<Box<Self>>,
pub(crate) code: Gc<CodeBlock>,
pub(crate) pc: usize,
pub(crate) fp: usize,
pub(crate) exit_on_return: bool,
pub(crate) this: JsValue,
pub(crate) environment: Environment,
}
/// Virtual Machine.
#[derive(Debug)]
pub struct Vm {
@ -515,11 +503,17 @@ impl Context {
const OPERAND_COLUMN_WIDTH: usize = COLUMN_WIDTH;
const NUMBER_OF_COLUMNS: usize = 4;
let msg = if self.vm.frame().exit_on_return {
" VM Start"
} else {
" Call Frame "
};
if self.vm.trace {
println!("{}\n", self.vm.frame().code);
println!(
"{:-^width$}",
" Vm Start ",
msg,
width = COLUMN_WIDTH * NUMBER_OF_COLUMNS - 10
);
println!(

Loading…
Cancel
Save