ConcatStrings

This commit is contained in:
2026-05-02 23:39:40 +08:00
parent 4f7d94f41b
commit f666bb498f
6 changed files with 68 additions and 20 deletions
+2 -1
View File
@@ -291,7 +291,7 @@ impl<'a, Ctx: DisassemblerContext> Disassembler<'a, Ctx> {
Op::Call => {
self.read_operand_data();
("Call", "arg=?".into())
},
}
Op::DispatchPrimOp => {
let id = BuiltinId::try_from_primitive(self.read_u8()).expect("invalid builtin id");
("DispatchPrimOp", format!("id={id:?}"))
@@ -419,6 +419,7 @@ impl<'a, Ctx: DisassemblerContext> Disassembler<'a, Ctx> {
let force = self.read_u8();
("ConcatStrings", format!("count={} force={}", count, force))
}
Op::CoerceToString => ("CoerceToString", String::new()),
Op::ResolvePath => ("ResolvePath", String::new()),
Op::Assert => {
let raw_idx = self.read_u32();
+17 -11
View File
@@ -77,6 +77,8 @@ pub enum Op {
JumpIfTrue,
Jump,
CoerceToString,
ConcatStrings,
ResolvePath,
@@ -250,6 +252,11 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
self.ctx.get_code_mut().push(op as u8);
}
#[inline]
fn emit_bool(&mut self, val: bool) {
self.emit_u8(u8::from(val));
}
#[inline]
fn emit_u8(&mut self, val: u8) {
self.ctx.get_code_mut().push(val);
@@ -615,17 +622,16 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
);
}
&Ir::ConcatStrings {
parts: _,
force_string: _,
ref parts,
force_string,
} => {
todo!("redesign ConcatStrings");
// self.emit_op(Op::ConcatStrings);
// self.emit_u16(parts.len() as u16);
// self.emit_u8(if force_string { 1 } else { 0 });
// for &part in parts.iter() {
// let operand = self.inline_maybe_thunk(part);
// self.emit_inline_operand(operand);
// }
for &part in parts.iter() {
self.emit_expr(part);
self.emit_op(Op::CoerceToString);
}
self.emit_op(Op::ConcatStrings);
self.emit_u16(parts.len() as u16);
self.emit_bool(force_string);
}
&Ir::HasAttr { lhs, ref rhs } => {
self.emit_has_attr(lhs, rhs);
@@ -842,7 +848,7 @@ impl<'a, Ctx: BytecodeContext> BytecodeEmitter<'a, Ctx> {
self.emit_u32(total_slots as u32);
self.emit_u16(required.len() as u16);
self.emit_u16(optional.len() as u16);
self.emit_u8(if *ellipsis { 1 } else { 0 });
self.emit_bool(*ellipsis);
for &(sym, _) in required.iter() {
self.emit_str_id(sym);