Skip to content

Commit

Permalink
Better Return opcode generation
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jul 20, 2023
1 parent 01947e0 commit a4c7b3b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 17 deletions.
4 changes: 0 additions & 4 deletions boa_engine/src/bytecompiler/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl ByteCompiler<'_, '_> {
}

compiler.emit_opcode(Opcode::SetReturnValue);
compiler.emit_opcode(Opcode::Return);

let code = Gc::new(compiler.finish());
let index = self.functions.len() as u32;
Expand Down Expand Up @@ -272,7 +271,6 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();

field_compiler.emit_opcode(Opcode::SetReturnValue);
field_compiler.emit_opcode(Opcode::Return);

field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

Expand Down Expand Up @@ -306,7 +304,6 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();

field_compiler.emit_opcode(Opcode::SetReturnValue);
field_compiler.emit_opcode(Opcode::Return);

field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

Expand Down Expand Up @@ -350,7 +347,6 @@ impl ByteCompiler<'_, '_> {
field_compiler.pop_compile_environment();

field_compiler.emit_opcode(Opcode::SetReturnValue);
field_compiler.emit_opcode(Opcode::Return);

field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

Expand Down
11 changes: 1 addition & 10 deletions boa_engine/src/bytecompiler/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
builtins::function::ThisMode,
bytecompiler::ByteCompiler,
environments::CompileTimeEnvironment,
vm::{CodeBlock, CodeBlockFlags, Opcode},
vm::{CodeBlock, CodeBlockFlags},
Context,
};
use boa_ast::function::{FormalParameterList, FunctionBody};
Expand Down Expand Up @@ -151,15 +151,6 @@ impl FunctionCompiler {

compiler.params = parameters.clone();

if compiler
.bytecode
.last()
.filter(|last| **last == Opcode::Return as u8)
.is_none()
{
compiler.emit_opcode(Opcode::Return);
}

Gc::new(compiler.finish())
}
}
1 change: 1 addition & 0 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
for ret in self.returns_to_patch.clone() {
self.patch_jump(ret);
}
self.emit_opcode(Opcode::Return);

let name = self
.context
Expand Down
3 changes: 0 additions & 3 deletions boa_engine/src/bytecompiler/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ impl ByteCompiler<'_, '_> {

pub(crate) fn r#return(&mut self) {
let actions = self.return_jump_record_actions();

JumpRecord::new(JumpRecordKind::Return, Self::DUMMY_LABEL, actions)
.perform_actions(u32::MAX, self);

self.emit_opcode(Opcode::Return);
}

fn return_jump_record_actions(&self) -> Vec<JumpRecordAction> {
Expand Down

0 comments on commit a4c7b3b

Please sign in to comment.