Skip to content

Commit

Permalink
Fixed compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored and jedel1043 committed Jan 29, 2023
1 parent ea10b81 commit 1c52137
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ impl Context<'_> {
ContextBuilder::default()
}

/// Evaluates the given code by compiling down to bytecode, then interpreting the bytecode into a value
/// Evaluates the given script by compiling down to bytecode, then interpreting the bytecode
/// into a value.
///
/// # Examples
/// ```
/// # use boa_engine::Context;
/// let mut context = Context::default();
///
/// let value = context.eval("1 + 3").unwrap();
/// let value = context.eval_script("1 + 3").unwrap();
///
/// assert!(value.is_number());
/// assert_eq!(value.as_number().unwrap(), 4.0);
Expand All @@ -166,9 +167,10 @@ impl Context<'_> {
where
S: AsRef<[u8]>,
{
let main_timer = Profiler::global().start_event("Evaluation", "Main");
let main_timer = Profiler::global().start_event("Script evaluation", "Main");

let statement_list = Parser::new(src.as_ref()).parse_script(&mut self.interner)?;

let statement_list = self.parse_script(src)?;
let code_block = self.compile_script(&statement_list)?;
let result = self.execute(code_block);

Expand Down Expand Up @@ -229,10 +231,11 @@ impl Context<'_> {
let mut parser = Parser::new(src.as_ref());
parser.parse_module(&mut self.interner)
}

/// Compile the AST into a `CodeBlock` ready to be executed by the VM.
/// Compile the script AST into a `CodeBlock` ready to be executed by the VM.
pub fn compile_script(&mut self, statement_list: &StatementList) -> JsResult<Gc<CodeBlock>> {
let _timer = Profiler::global().start_event("Compilation", "Main");
let _timer = Profiler::global().start_event("Script compilation", "Main");

let mut compiler = ByteCompiler::new(Sym::MAIN, statement_list.strict(), false, self);
compiler.create_script_decls(statement_list, false);
compiler.compile_statement_list(statement_list, true, false)?;
Expand All @@ -242,6 +245,7 @@ impl Context<'_> {
/// Compile the module AST into a `CodeBlock` ready to be executed by the VM.
pub fn compile_module(&mut self, statement_list: &ModuleItemList) -> JsResult<Gc<CodeBlock>> {
let _timer = Profiler::global().start_event("Module compilation", "Main");

let mut compiler = ByteCompiler::new(Sym::MAIN, true, false, self);
compiler.create_module_decls(statement_list, false);
compiler.compile_module_item_list(statement_list, false)?;
Expand Down

0 comments on commit 1c52137

Please sign in to comment.