ConcatStrings
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use fix_builtins::BuiltinId;
|
||||
use fix_common::StringId;
|
||||
use num_enum::TryFromPrimitive;
|
||||
|
||||
use crate::value::{NixString, StrictValue};
|
||||
use crate::{BytecodeReader, PrimOp, Step, Value, VmRuntimeCtx};
|
||||
|
||||
impl<'gc> crate::Vm<'gc> {
|
||||
@@ -34,6 +36,21 @@ impl<'gc> crate::Vm<'gc> {
|
||||
todo!("LoadScopedBinding");
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_coerce_to_string(
|
||||
&mut self,
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
mc: &gc_arena::Mutation<'gc>,
|
||||
) -> Step {
|
||||
let val = self.try_force::<StrictValue>(reader, mc)?;
|
||||
if val.is::<StringId>() || val.is::<NixString>() {
|
||||
self.push(val.relax());
|
||||
} else {
|
||||
todo!("coerce other types to string: {:?}", val.ty());
|
||||
}
|
||||
Step::Continue(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn op_concat_strings(
|
||||
&mut self,
|
||||
@@ -41,14 +58,30 @@ impl<'gc> crate::Vm<'gc> {
|
||||
reader: &mut BytecodeReader<'_>,
|
||||
_mc: &gc_arena::Mutation<'gc>,
|
||||
) -> Step {
|
||||
let _parts_count = reader.read_u16() as usize;
|
||||
use crate::VmRuntimeCtxExt;
|
||||
|
||||
let count = reader.read_u16() as usize;
|
||||
let _force_string = reader.read_u8() != 0;
|
||||
let mut _operands: smallvec::SmallVec<[crate::OperandData; 4]> =
|
||||
smallvec::SmallVec::with_capacity(_parts_count);
|
||||
for _ in 0.._parts_count {
|
||||
_operands.push(reader.read_operand_data(ctx));
|
||||
|
||||
let mut total_len = 0;
|
||||
for i in 0..count {
|
||||
let val = self.peek_forced(count - 1 - i);
|
||||
let s = ctx.get_string(val).expect("coerced");
|
||||
total_len += s.len();
|
||||
}
|
||||
todo!("implement ConcatStrings (force parts, coerce to string, concatenate)");
|
||||
|
||||
let mut result = String::with_capacity(total_len);
|
||||
for i in 0..count {
|
||||
let val = self.peek_forced(count - 1 - i);
|
||||
let s = ctx.get_string(val).expect("coerced");
|
||||
result.push_str(s);
|
||||
}
|
||||
|
||||
self.stack.truncate(self.stack.len() - count);
|
||||
|
||||
let sid = ctx.intern_string(result);
|
||||
self.push(Value::new_inline(sid));
|
||||
Step::Continue(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
Reference in New Issue
Block a user