optimize: remove {StepResult,TailResult}::ForceThunk
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
|
||||
use gc_arena::Mutation;
|
||||
|
||||
use crate::{BytecodeReader, ForceInfo, StepResult, Vm, VmContext};
|
||||
use crate::{BytecodeReader, StepResult, Vm, VmContext};
|
||||
|
||||
pub(crate) enum TailResult<'gc> {
|
||||
pub(crate) enum TailResult {
|
||||
YieldFuel(u32),
|
||||
ForceThunk(ForceInfo<'gc>),
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -18,7 +17,7 @@ pub(crate) type OpFn<'gc, C> = extern "rust-preserve-none" fn(
|
||||
&DispatchTable<'gc, C>,
|
||||
u32,
|
||||
u32,
|
||||
) -> TailResult<'gc>;
|
||||
) -> TailResult;
|
||||
|
||||
pub(crate) struct DispatchTable<'gc, C: VmContext>(pub(crate) [OpFn<'gc, C>; 256]);
|
||||
|
||||
@@ -30,7 +29,7 @@ extern "rust-preserve-none" fn op_illegal<'gc, C: VmContext>(
|
||||
_table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
_fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
panic!("illegal opcode at pc = {pc}");
|
||||
}
|
||||
|
||||
@@ -38,7 +37,6 @@ macro_rules! tail_dispatch_after {
|
||||
($result:expr, $new_pc:expr, $vm:ident, $mc:ident, $ctx:ident, $bc:ident, $table:ident, $fuel:ident) => {{
|
||||
match $result {
|
||||
StepResult::Continue => {}
|
||||
StepResult::ForceThunk(info) => return TailResult::ForceThunk(info),
|
||||
StepResult::Done => return TailResult::Done,
|
||||
}
|
||||
let new_pc: u32 = $new_pc;
|
||||
@@ -60,7 +58,7 @@ macro_rules! tail_fn {
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
let result = vm.$name();
|
||||
tail_dispatch_after!(result, pc + 1, vm, mc, ctx, bc, table, fuel)
|
||||
}
|
||||
@@ -74,7 +72,7 @@ macro_rules! tail_fn {
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
let mut reader = BytecodeReader::from_after_op(bc, pc as usize);
|
||||
let result = vm.$name(&mut reader);
|
||||
tail_dispatch_after!(result, reader.pc() as u32, vm, mc, ctx, bc, table, fuel)
|
||||
@@ -89,7 +87,7 @@ macro_rules! tail_fn {
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
let mut reader = BytecodeReader::from_after_op(bc, pc as usize);
|
||||
let result = vm.$name(&mut reader, mc);
|
||||
tail_dispatch_after!(result, reader.pc() as u32, vm, mc, ctx, bc, table, fuel)
|
||||
@@ -104,26 +102,12 @@ macro_rules! tail_fn {
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
let mut reader = BytecodeReader::from_after_op(bc, pc as usize);
|
||||
let result = vm.$name(ctx, &mut reader, mc);
|
||||
tail_dispatch_after!(result, reader.pc() as u32, vm, mc, ctx, bc, table, fuel)
|
||||
}
|
||||
};
|
||||
($name:ident, (mc, inst_start_pc)) => {
|
||||
extern "rust-preserve-none" fn $name<'gc, C: VmContext>(
|
||||
vm: &mut Vm<'gc>,
|
||||
mc: &Mutation<'gc>,
|
||||
ctx: &mut C,
|
||||
bc: &[u8],
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
let result = vm.$name(mc, pc as usize);
|
||||
tail_dispatch_after!(result, pc + 1, vm, mc, ctx, bc, table, fuel)
|
||||
}
|
||||
};
|
||||
($name:ident, (ctx)) => {
|
||||
extern "rust-preserve-none" fn $name<'gc, C: VmContext>(
|
||||
vm: &mut Vm<'gc>,
|
||||
@@ -133,7 +117,7 @@ macro_rules! tail_fn {
|
||||
table: &DispatchTable<'gc, C>,
|
||||
pc: u32,
|
||||
fuel: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
let result = vm.$name(ctx);
|
||||
tail_dispatch_after!(result, pc + 1, vm, mc, ctx, bc, table, fuel)
|
||||
}
|
||||
@@ -181,7 +165,7 @@ tail_fn!(op_gt, (ctx, reader, mc));
|
||||
tail_fn!(op_leq, (ctx, reader, mc));
|
||||
tail_fn!(op_geq, (ctx, reader, mc));
|
||||
tail_fn!(op_concat, (reader, mc));
|
||||
tail_fn!(op_update, (mc, inst_start_pc));
|
||||
tail_fn!(op_update, (reader, mc));
|
||||
|
||||
tail_fn!(op_neg, ());
|
||||
tail_fn!(op_not, ());
|
||||
@@ -303,7 +287,7 @@ pub(crate) fn run_tailcall<'gc, C: VmContext>(
|
||||
ctx: &mut C,
|
||||
bc: &[u8],
|
||||
pc: u32,
|
||||
) -> TailResult<'gc> {
|
||||
) -> TailResult {
|
||||
const FUEL: u32 = 1024;
|
||||
let table = &DispatchTable::<'gc, C>::NEW;
|
||||
let op = bc[pc as usize] as usize;
|
||||
|
||||
Reference in New Issue
Block a user