implement Assert
This commit is contained in:
@@ -185,7 +185,7 @@ tail_fn!(op_coerce_to_string, (reader, mc));
|
||||
tail_fn!(op_concat_strings, (ctx, reader, mc));
|
||||
tail_fn!(op_resolve_path, (ctx));
|
||||
|
||||
tail_fn!(op_assert, (reader));
|
||||
tail_fn!(op_assert, (ctx, reader, mc));
|
||||
|
||||
tail_fn!(op_push_with, (ctx, reader, mc));
|
||||
tail_fn!(op_pop_with, ());
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use fix_error::Error;
|
||||
use gc_arena::Mutation;
|
||||
|
||||
use crate::value::*;
|
||||
use crate::{BytecodeReader, Step};
|
||||
use crate::{BytecodeReader, Step, VmRuntimeCtx};
|
||||
|
||||
impl<'gc> crate::Vm<'gc> {
|
||||
#[inline(always)]
|
||||
@@ -20,7 +23,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
pub(crate) fn op_jump_if_true(
|
||||
&mut self,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
mc: &Mutation<'gc>,
|
||||
) -> Step {
|
||||
let offset = reader.read_i32();
|
||||
let cond = self.force_and_retry::<StrictValue>(reader, mc)?;
|
||||
@@ -38,9 +41,20 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_assert(&mut self, reader: &mut BytecodeReader<'_>) -> Step {
|
||||
let _raw_idx = reader.read_u32();
|
||||
pub(crate) fn op_assert(
|
||||
&mut self,
|
||||
ctx: &mut impl VmRuntimeCtx,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &Mutation<'gc>,
|
||||
) -> Step {
|
||||
let raw_id = reader.read_string_id();
|
||||
let raw = ctx.resolve_string(raw_id);
|
||||
let _span_id = reader.read_u32();
|
||||
todo!("implement Assert (force TOS)");
|
||||
let assertion = self.force_and_retry::<bool>(reader, mc)?;
|
||||
if !assertion {
|
||||
// FIXME: use catchable error
|
||||
return self.finish_err(Error::eval_error(format!("assertion '{raw}' failed")));
|
||||
}
|
||||
Step::Continue(())
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -697,7 +697,7 @@ impl<'gc> Vm<'gc> {
|
||||
CoerceToString => self.op_coerce_to_string(&mut reader, mc),
|
||||
ResolvePath => self.op_resolve_path(ctx),
|
||||
|
||||
Assert => self.op_assert(&mut reader),
|
||||
Assert => self.op_assert(ctx, &mut reader, mc),
|
||||
|
||||
PushWith => self.op_push_with(ctx, &mut reader, mc),
|
||||
PopWith => self.op_pop_with(),
|
||||
|
||||
Reference in New Issue
Block a user