Skip to content

Commit a4c7b3b

Browse files
committed
Better Return opcode generation
1 parent 01947e0 commit a4c7b3b

File tree

4 files changed

+2
-17
lines changed

4 files changed

+2
-17
lines changed

boa_engine/src/bytecompiler/class.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl ByteCompiler<'_, '_> {
7575
}
7676

7777
compiler.emit_opcode(Opcode::SetReturnValue);
78-
compiler.emit_opcode(Opcode::Return);
7978

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

274273
field_compiler.emit_opcode(Opcode::SetReturnValue);
275-
field_compiler.emit_opcode(Opcode::Return);
276274

277275
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;
278276

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

308306
field_compiler.emit_opcode(Opcode::SetReturnValue);
309-
field_compiler.emit_opcode(Opcode::Return);
310307

311308
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;
312309

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

352349
field_compiler.emit_opcode(Opcode::SetReturnValue);
353-
field_compiler.emit_opcode(Opcode::Return);
354350

355351
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;
356352

boa_engine/src/bytecompiler/function.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
builtins::function::ThisMode,
55
bytecompiler::ByteCompiler,
66
environments::CompileTimeEnvironment,
7-
vm::{CodeBlock, CodeBlockFlags, Opcode},
7+
vm::{CodeBlock, CodeBlockFlags},
88
Context,
99
};
1010
use boa_ast::function::{FormalParameterList, FunctionBody};
@@ -151,15 +151,6 @@ impl FunctionCompiler {
151151

152152
compiler.params = parameters.clone();
153153

154-
if compiler
155-
.bytecode
156-
.last()
157-
.filter(|last| **last == Opcode::Return as u8)
158-
.is_none()
159-
{
160-
compiler.emit_opcode(Opcode::Return);
161-
}
162-
163154
Gc::new(compiler.finish())
164155
}
165156
}

boa_engine/src/bytecompiler/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
14151415
for ret in self.returns_to_patch.clone() {
14161416
self.patch_jump(ret);
14171417
}
1418+
self.emit_opcode(Opcode::Return);
14181419

14191420
let name = self
14201421
.context

boa_engine/src/bytecompiler/statement/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ impl ByteCompiler<'_, '_> {
9090

9191
pub(crate) fn r#return(&mut self) {
9292
let actions = self.return_jump_record_actions();
93-
9493
JumpRecord::new(JumpRecordKind::Return, Self::DUMMY_LABEL, actions)
9594
.perform_actions(u32::MAX, self);
96-
97-
self.emit_opcode(Opcode::Return);
9895
}
9996

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

0 commit comments

Comments
 (0)