use bumpalo::Bump;
#[derive(Debug)]
pub(crate) struct InstructionEmitter {
bump: Bump,
}
impl InstructionEmitter {
pub fn new() -> InstructionEmitter {
let bump = Bump::new();
InstructionEmitter { bump }
}
#[cfg_attr(feature = "xxx-unstable-internal-use-only", allow(dead_code))]
pub fn each_instruction_sequence<F>(&mut self, f: F)
where
F: FnMut(&[u8]),
{
unsafe {
self.bump.each_allocated_chunk(f);
}
}
pub fn reset(&mut self) {
self.bump.reset();
}
}
macro_rules! define_change_list_instructions {
( $(
$( #[$attr:meta] )*
$name:ident (
$($immediate:ident),*
) = $discriminant:expr,
)* ) => {
impl InstructionEmitter {
$(
$( #[$attr] )*
#[inline]
pub fn $name(&self $(, $immediate: u32)*) {
self.bump.alloc_with(|| [$discriminant $(, $immediate )* ]);
}
)*
}
}
}
define_change_list_instructions! {
set_text(pointer, length) = 0,
remove_self_and_next_siblings() = 1,
replace_with() = 2,
set_attribute(attribute_key, value_key) = 3,
remove_attribute(attribute_key) = 4,
push_reverse_child(n) = 5,
pop_push_child(n) = 6,
pop() = 7,
append_child() = 8,
create_text_node(pointer, length) = 9,
create_element(tag_name_key) = 10,
new_event_listener(event_key, a, b) = 11,
update_event_listener(event_key, a, b) = 12,
remove_event_listener(event_key) = 13,
add_cached_string(pointer, length, key) = 14,
drop_cached_string(key) = 15,
create_element_ns(tag_name_key, namespace_key) = 16,
save_children_to_temporaries(temp_base, start, end) = 17,
push_child(n) = 18,
push_temporary(temp) = 19,
insert_before() = 20,
pop_push_reverse_child(n) = 21,
remove_child(n) = 22,
set_class(class) = 23,
save_template(id) = 24,
push_template(id) = 25,
}