refactor: abstract VM

This commit is contained in:
2026-05-16 19:51:38 +08:00
parent 21899f7380
commit 29fab93cd1
42 changed files with 1823 additions and 1410 deletions
-46
View File
@@ -1,46 +0,0 @@
use fix_error::Error;
use gc_arena::Mutation;
use crate::bytecode_reader::BytecodeReader;
use crate::instructions::misc::canon_path_str;
use crate::value::*;
use crate::{Step, Vm, VmRuntimeCtx, VmRuntimeCtxExt};
impl<'gc> Vm<'gc> {
pub(crate) fn primop_to_path(
&mut self,
ctx: &mut impl VmRuntimeCtx,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
// coerce to path THEN TO STRING
let val = self.force_and_retry::<StrictValue>(reader, mc)?;
if let Some(Path(s)) = val.as_inline::<Path>() {
return self.return_from_primop(Value::new_inline(s), reader);
}
let Some(s) = ctx.get_string(val) else {
return self.finish_err(Error::eval_error(format!(
"cannot coerce {} to a path",
val.ty()
)));
};
if !s.starts_with('/') {
return self.finish_err(Error::eval_error(format!(
"string '{s}' doesn't represent an absolute path"
)));
}
let canon = canon_path_str(s);
let sid = ctx.intern_string(canon);
self.return_from_primop(Value::new_inline(sid), reader)
}
pub(crate) fn primop_is_path(
&mut self,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
let val = self.force_and_retry::<StrictValue>(reader, mc)?;
let is_path = val.is::<Path>();
self.return_from_primop(Value::new_inline(is_path), reader)
}
}