implement Assert
This commit is contained in:
@@ -645,10 +645,10 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
|
|||||||
let raw_idx = self.ctx.intern_string(assertion_raw);
|
let raw_idx = self.ctx.intern_string(assertion_raw);
|
||||||
let span_id = self.ctx.register_span(*span);
|
let span_id = self.ctx.register_span(*span);
|
||||||
self.emit_expr(*assertion);
|
self.emit_expr(*assertion);
|
||||||
self.emit_expr(*expr);
|
|
||||||
self.emit_op(Op::Assert);
|
self.emit_op(Op::Assert);
|
||||||
self.emit_str_id(raw_idx);
|
self.emit_str_id(raw_idx);
|
||||||
self.emit_u32(span_id);
|
self.emit_u32(span_id);
|
||||||
|
self.emit_expr(*expr);
|
||||||
}
|
}
|
||||||
&Ir::ReplBinding(name) => {
|
&Ir::ReplBinding(name) => {
|
||||||
self.emit_op(Op::LoadReplBinding);
|
self.emit_op(Op::LoadReplBinding);
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ tail_fn!(op_coerce_to_string, (reader, mc));
|
|||||||
tail_fn!(op_concat_strings, (ctx, reader, mc));
|
tail_fn!(op_concat_strings, (ctx, reader, mc));
|
||||||
tail_fn!(op_resolve_path, (ctx));
|
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_push_with, (ctx, reader, mc));
|
||||||
tail_fn!(op_pop_with, ());
|
tail_fn!(op_pop_with, ());
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
use fix_error::Error;
|
||||||
|
use gc_arena::Mutation;
|
||||||
|
|
||||||
use crate::value::*;
|
use crate::value::*;
|
||||||
use crate::{BytecodeReader, Step};
|
use crate::{BytecodeReader, Step, VmRuntimeCtx};
|
||||||
|
|
||||||
impl<'gc> crate::Vm<'gc> {
|
impl<'gc> crate::Vm<'gc> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@@ -20,7 +23,7 @@ impl<'gc> crate::Vm<'gc> {
|
|||||||
pub(crate) fn op_jump_if_true(
|
pub(crate) fn op_jump_if_true(
|
||||||
&mut self,
|
&mut self,
|
||||||
reader: &mut BytecodeReader<'_>,
|
reader: &mut BytecodeReader<'_>,
|
||||||
mc: &gc_arena::Mutation<'gc>,
|
mc: &Mutation<'gc>,
|
||||||
) -> Step {
|
) -> Step {
|
||||||
let offset = reader.read_i32();
|
let offset = reader.read_i32();
|
||||||
let cond = self.force_and_retry::<StrictValue>(reader, mc)?;
|
let cond = self.force_and_retry::<StrictValue>(reader, mc)?;
|
||||||
@@ -38,9 +41,20 @@ impl<'gc> crate::Vm<'gc> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn op_assert(&mut self, reader: &mut BytecodeReader<'_>) -> Step {
|
pub(crate) fn op_assert(
|
||||||
let _raw_idx = reader.read_u32();
|
&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();
|
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),
|
CoerceToString => self.op_coerce_to_string(&mut reader, mc),
|
||||||
ResolvePath => self.op_resolve_path(ctx),
|
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),
|
PushWith => self.op_push_with(ctx, &mut reader, mc),
|
||||||
PopWith => self.op_pop_with(),
|
PopWith => self.op_pop_with(),
|
||||||
|
|||||||
Reference in New Issue
Block a user