refactor: split VmContext

This commit is contained in:
2026-04-25 17:54:59 +08:00
parent 468269c20d
commit 4f3cd0ef4c
9 changed files with 243 additions and 215 deletions
+12 -15
View File
@@ -3,13 +3,13 @@ use std::cmp::Ordering;
use gc_arena::{Gc, Mutation};
use crate::value::*;
use crate::{BytecodeReader, NixNum, Step, VmContextExt, VmError};
use crate::{BytecodeReader, NixNum, Step, VmError, VmRuntimeCtx, VmRuntimeCtxExt as _};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_add(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -82,7 +82,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_eq(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -98,7 +98,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_neq(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -114,7 +114,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_lt(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -124,7 +124,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_gt(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -134,7 +134,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_leq(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -144,7 +144,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_geq(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -153,7 +153,7 @@ impl<'gc> crate::Vm<'gc> {
fn compare_values(
&mut self,
ctx: &impl crate::VmContext,
ctx: &impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
pred: fn(Ordering) -> bool,
@@ -202,7 +202,7 @@ impl<'gc> crate::Vm<'gc> {
pub(crate) fn values_equal(
&mut self,
ctx: &impl crate::VmContext,
ctx: &impl VmRuntimeCtx,
lhs: StrictValue<'gc>,
rhs: StrictValue<'gc>,
) -> crate::VmResult<bool> {
@@ -257,7 +257,7 @@ impl<'gc> crate::Vm<'gc> {
fn compare_values_inner(
&mut self,
ctx: &impl crate::VmContext,
ctx: &impl VmRuntimeCtx,
pred: fn(Ordering) -> bool,
lhs: StrictValue<'gc>,
rhs: StrictValue<'gc>,
@@ -276,10 +276,7 @@ impl<'gc> crate::Vm<'gc> {
self.push(Value::new_inline(pred(ord)));
return Ok(());
}
if let (Some(a), Some(b)) = (
VmContextExt::get_string(ctx, lhs),
VmContextExt::get_string(ctx, rhs),
) {
if let (Some(a), Some(b)) = (ctx.get_string(lhs), ctx.get_string(rhs)) {
self.push(Value::new_inline(pred(a.cmp(b))));
return Ok(());
}
+3 -3
View File
@@ -1,7 +1,7 @@
use fix_builtins::BuiltinId;
use num_enum::TryFromPrimitive;
use crate::{BytecodeReader, PrimOp, Step, Value};
use crate::{BytecodeReader, PrimOp, Step, Value, VmRuntimeCtx};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
@@ -42,7 +42,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_concat_strings(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
_mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -57,7 +57,7 @@ impl<'gc> crate::Vm<'gc> {
}
#[inline(always)]
pub(crate) fn op_resolve_path(&mut self, _ctx: &mut impl crate::VmContext) -> Step {
pub(crate) fn op_resolve_path(&mut self, _ctx: &mut impl VmRuntimeCtx) -> Step {
todo!("implement ResolvePath");
}
}
+6 -4
View File
@@ -2,13 +2,15 @@ use fix_error::Error;
use gc_arena::{Gc, Mutation, RefLock};
use crate::value::*;
use crate::{BytecodeReader, CallFrame, Closure, Env, Step, ThunkState, VmContextExt};
use crate::{
BytecodeReader, CallFrame, Closure, Env, Step, ThunkState, VmRuntimeCtx, VmRuntimeCtxExt,
};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_call(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
@@ -45,14 +47,14 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_return(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
self.handle_return(reader, ctx, mc)
}
pub(crate) fn handle_return<C: crate::VmContext>(
pub(crate) fn handle_return<C: VmRuntimeCtx>(
&mut self,
reader: &mut BytecodeReader<'_>,
ctx: &C,
+10 -9
View File
@@ -5,14 +5,15 @@ use smallvec::SmallVec;
use crate::value::NixType;
use crate::{
AttrKeyData, AttrSet, BytecodeReader, List, OperandData, Step, StrictValue, Value, VmContextExt,
AttrKeyData, AttrSet, BytecodeReader, List, OperandData, Step, StrictValue, Value,
VmRuntimeCtx, VmRuntimeCtxExt,
};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_make_attrs(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -52,7 +53,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_select_static(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -73,7 +74,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_select_dynamic(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -102,7 +103,7 @@ impl<'gc> crate::Vm<'gc> {
fn select_skip(
&mut self,
key: StringId,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
) -> Step {
use fix_codegen::Op::*;
@@ -168,7 +169,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_has_attr_path_static(
&mut self,
_ctx: &mut impl crate::VmContext,
_ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -192,7 +193,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_has_attr_path_dynamic(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -255,7 +256,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_has_attr_dynamic(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -288,7 +289,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_make_list(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
+3 -3
View File
@@ -3,13 +3,13 @@ use fix_error::Error;
use gc_arena::Gc;
use crate::value::*;
use crate::{BytecodeReader, CallFrame, Step, WithEnv};
use crate::{BytecodeReader, CallFrame, Step, VmRuntimeCtx, WithEnv};
impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_push_with(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {
@@ -49,7 +49,7 @@ impl<'gc> crate::Vm<'gc> {
#[inline(always)]
pub(crate) fn op_lookup_with(
&mut self,
ctx: &mut impl crate::VmContext,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &gc_arena::Mutation<'gc>,
) -> Step {