better type assertion ergonomic
This commit is contained in:
@@ -3,7 +3,7 @@ use gc_arena::Gc;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
AttrKeyData, AttrSet, BytecodeReader, List, NixString, OperandData, StepResult, Value,
|
||||
AttrKeyData, AttrSet, BytecodeReader, List, NixString, OperandData, Step, Value,
|
||||
};
|
||||
|
||||
impl<'gc> crate::Vm<'gc> {
|
||||
@@ -13,7 +13,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
ctx: &mut impl crate::VmContext,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
) -> StepResult {
|
||||
) -> Step {
|
||||
let count = reader.read_u32() as usize;
|
||||
let mut entries: SmallVec<[AttrEntry; 4]> = SmallVec::with_capacity(count);
|
||||
for _ in 0..count {
|
||||
@@ -37,14 +37,14 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}
|
||||
kv.sort_by_key(|(k, _)| *k);
|
||||
let attrs = Gc::new(mc, AttrSet::from_sorted_unchecked(kv));
|
||||
self.push_stack(Value::new_gc(attrs));
|
||||
StepResult::Continue
|
||||
self.push(Value::new_gc(attrs));
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_make_empty_attrs(&mut self) -> StepResult {
|
||||
self.push_stack(self.empty_attrs);
|
||||
StepResult::Continue
|
||||
pub(crate) fn op_make_empty_attrs(&mut self) -> Step {
|
||||
self.push(self.empty_attrs);
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -53,7 +53,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
ctx: &mut impl crate::VmContext,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
) -> StepResult {
|
||||
) -> Step {
|
||||
let _span_id = reader.read_u32();
|
||||
let key = reader.read_string_id();
|
||||
|
||||
@@ -61,7 +61,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
return step;
|
||||
}
|
||||
|
||||
let attrs = self.peek_stack(0).restrict().expect("forced");
|
||||
let attrs = self.peek(0).restrict().expect("forced");
|
||||
let Some(attrset) = attrs.as_gc::<AttrSet>() else {
|
||||
return self.finish_err(Error::eval_error(
|
||||
"value is not a set while a set was expected",
|
||||
@@ -70,7 +70,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
|
||||
match attrset.lookup(key) {
|
||||
Some(v) => {
|
||||
self.replace_stack(0, v);
|
||||
self.replace(0, v);
|
||||
}
|
||||
None => loop {
|
||||
let byte = reader.bytecode()[reader.pc()];
|
||||
@@ -80,7 +80,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
reader.set_pc(reader.pc() + 1 + 4);
|
||||
} else if byte == fix_codegen::Op::JumpIfSelectSucceeded as u8 {
|
||||
reader.set_pc(reader.pc() + 1 + 4);
|
||||
let _ = self.pop_stack();
|
||||
let _ = self.pop();
|
||||
break;
|
||||
} else {
|
||||
let name = ctx.resolve_string(key);
|
||||
@@ -89,7 +89,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
}
|
||||
},
|
||||
}
|
||||
StepResult::Continue
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -98,7 +98,7 @@ impl<'gc> crate::Vm<'gc> {
|
||||
ctx: &mut impl crate::VmContext,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
) -> StepResult {
|
||||
) -> Step {
|
||||
let _span_id = reader.read_u32();
|
||||
|
||||
if let Some(step) = self.try_force(0, reader, mc) {
|
||||
@@ -129,28 +129,28 @@ impl<'gc> crate::Vm<'gc> {
|
||||
match attrset.lookup(key_sid) {
|
||||
Some(v) => {
|
||||
self.stack.truncate(self.stack.len() - 2);
|
||||
self.push_stack(v);
|
||||
self.push(v);
|
||||
}
|
||||
None => {
|
||||
let name = ctx.resolve_string(key_sid);
|
||||
return self.finish_err(Error::eval_error(format!("attribute '{name}' missing")));
|
||||
}
|
||||
}
|
||||
StepResult::Continue
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_jump_if_select_succeeded(
|
||||
&mut self,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
) -> StepResult {
|
||||
) -> Step {
|
||||
let offset = reader.read_i32();
|
||||
reader.set_pc(((reader.pc() as isize) + (offset as isize)) as usize);
|
||||
StepResult::Continue
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_has_attr(&mut self, reader: &mut BytecodeReader<'_>) -> StepResult {
|
||||
pub(crate) fn op_has_attr(&mut self, reader: &mut BytecodeReader<'_>) -> Step {
|
||||
let _n = reader.read_u16() as usize;
|
||||
todo!("HasAttr");
|
||||
}
|
||||
@@ -161,21 +161,21 @@ impl<'gc> crate::Vm<'gc> {
|
||||
ctx: &mut impl crate::VmContext,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
) -> StepResult {
|
||||
) -> Step {
|
||||
let count = reader.read_u32() as usize;
|
||||
let mut items: SmallVec<[Value; 4]> = SmallVec::with_capacity(count);
|
||||
for _ in 0..count {
|
||||
items.push(reader.read_operand_data(ctx).resolve(mc, self));
|
||||
}
|
||||
let list = Gc::new(mc, List { inner: items });
|
||||
self.push_stack(Value::new_gc(list));
|
||||
StepResult::Continue
|
||||
self.push(Value::new_gc(list));
|
||||
Step::Continue
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_make_empty_list(&mut self) -> StepResult {
|
||||
self.push_stack(self.empty_list);
|
||||
StepResult::Continue
|
||||
pub(crate) fn op_make_empty_list(&mut self) -> Step {
|
||||
self.push(self.empty_list);
|
||||
Step::Continue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user