Make some stuff Copy
This commit is contained in:
parent
d33e4a6b3e
commit
0416c30e67
@ -38,8 +38,12 @@ impl Driver for Br {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> {
|
||||
let mut data: Vec<_> = list.iter().chain(std::iter::once(default)).collect();
|
||||
fn to_ordered_table(list: &[Br], default: Br) -> Vec<Br> {
|
||||
let mut data: Vec<_> = list
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(std::iter::once(default))
|
||||
.collect();
|
||||
|
||||
data.sort_by_key(|v| v.target());
|
||||
data.dedup_by_key(|v| v.target());
|
||||
@ -48,7 +52,7 @@ fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> {
|
||||
|
||||
fn write_search_layer(
|
||||
range: Range<usize>,
|
||||
list: &[&Br],
|
||||
list: &[Br],
|
||||
mng: &mut Manager,
|
||||
w: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
|
@ -11,7 +11,7 @@ struct Visit {
|
||||
}
|
||||
|
||||
impl Visit {
|
||||
fn set_branch(&mut self, br: &Br) {
|
||||
fn set_branch(&mut self, br: Br) {
|
||||
if br.target() != 0 {
|
||||
self.has_branch = true;
|
||||
}
|
||||
@ -19,7 +19,7 @@ impl Visit {
|
||||
}
|
||||
|
||||
impl Visitor for Visit {
|
||||
fn visit_br(&mut self, stat: &Br) {
|
||||
fn visit_br(&mut self, stat: Br) {
|
||||
self.set_branch(stat);
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ impl Visitor for Visit {
|
||||
return;
|
||||
}
|
||||
|
||||
for target in table.data() {
|
||||
for &target in table.data() {
|
||||
self.set_branch(target);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ impl Visitor for Visit {
|
||||
self.local_set.insert(("store", name));
|
||||
}
|
||||
|
||||
fn visit_value(&mut self, v: &Value) {
|
||||
fn visit_value(&mut self, v: Value) {
|
||||
let name = match v {
|
||||
Value::I64(0) => "ZERO",
|
||||
Value::I64(1) => "ONE",
|
||||
|
@ -47,8 +47,12 @@ impl Driver for Br {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> {
|
||||
let mut data: Vec<_> = list.iter().chain(std::iter::once(default)).collect();
|
||||
fn to_ordered_table(list: &[Br], default: Br) -> Vec<Br> {
|
||||
let mut data: Vec<_> = list
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(std::iter::once(default))
|
||||
.collect();
|
||||
|
||||
data.sort_by_key(|v| v.target());
|
||||
data.dedup_by_key(|v| v.target());
|
||||
@ -57,7 +61,7 @@ fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> {
|
||||
|
||||
fn write_search_layer(
|
||||
range: Range<usize>,
|
||||
list: &[&Br],
|
||||
list: &[Br],
|
||||
mng: &mut Manager,
|
||||
w: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
|
@ -625,35 +625,38 @@ impl Select {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Temporary {
|
||||
pub(crate) var: usize,
|
||||
}
|
||||
|
||||
impl Temporary {
|
||||
#[must_use]
|
||||
pub const fn var(&self) -> usize {
|
||||
pub const fn var(self) -> usize {
|
||||
self.var
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Local {
|
||||
pub(crate) var: usize,
|
||||
}
|
||||
|
||||
impl Local {
|
||||
#[must_use]
|
||||
pub const fn var(&self) -> usize {
|
||||
pub const fn var(self) -> usize {
|
||||
self.var
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct GetGlobal {
|
||||
pub(crate) var: usize,
|
||||
}
|
||||
|
||||
impl GetGlobal {
|
||||
#[must_use]
|
||||
pub const fn var(&self) -> usize {
|
||||
pub const fn var(self) -> usize {
|
||||
self.var
|
||||
}
|
||||
}
|
||||
@ -687,6 +690,7 @@ impl LoadAt {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MemorySize {
|
||||
pub(crate) memory: usize,
|
||||
}
|
||||
@ -828,6 +832,7 @@ impl ResultList {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Align {
|
||||
pub(crate) new: usize,
|
||||
pub(crate) old: usize,
|
||||
@ -836,21 +841,22 @@ pub struct Align {
|
||||
|
||||
impl Align {
|
||||
#[must_use]
|
||||
pub const fn is_aligned(&self) -> bool {
|
||||
pub const fn is_aligned(self) -> bool {
|
||||
self.length == 0 || self.new == self.old
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn new_range(&self) -> ResultList {
|
||||
pub const fn new_range(self) -> ResultList {
|
||||
ResultList::new(self.new, self.new + self.length)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn old_range(&self) -> ResultList {
|
||||
pub const fn old_range(self) -> ResultList {
|
||||
ResultList::new(self.old, self.old + self.length)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Br {
|
||||
pub(crate) target: usize,
|
||||
pub(crate) align: Align,
|
||||
@ -858,13 +864,13 @@ pub struct Br {
|
||||
|
||||
impl Br {
|
||||
#[must_use]
|
||||
pub const fn target(&self) -> usize {
|
||||
pub const fn target(self) -> usize {
|
||||
self.target
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn align(&self) -> &Align {
|
||||
&self.align
|
||||
pub const fn align(self) -> Align {
|
||||
self.align
|
||||
}
|
||||
}
|
||||
|
||||
@ -886,8 +892,8 @@ impl BrTable {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn default(&self) -> &Br {
|
||||
&self.default
|
||||
pub const fn default(&self) -> Br {
|
||||
self.default
|
||||
}
|
||||
}
|
||||
|
||||
@ -939,8 +945,8 @@ impl BrIf {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn target(&self) -> &Br {
|
||||
&self.target
|
||||
pub const fn target(&self) -> Br {
|
||||
self.target
|
||||
}
|
||||
}
|
||||
|
||||
@ -1026,8 +1032,8 @@ pub struct SetTemporary {
|
||||
|
||||
impl SetTemporary {
|
||||
#[must_use]
|
||||
pub const fn var(&self) -> &Temporary {
|
||||
&self.var
|
||||
pub const fn var(&self) -> Temporary {
|
||||
self.var
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@ -1043,8 +1049,8 @@ pub struct SetLocal {
|
||||
|
||||
impl SetLocal {
|
||||
#[must_use]
|
||||
pub const fn var(&self) -> &Local {
|
||||
&self.var
|
||||
pub const fn var(&self) -> Local {
|
||||
self.var
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@ -1118,8 +1124,8 @@ impl MemoryGrow {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn result(&self) -> &Temporary {
|
||||
&self.result
|
||||
pub const fn result(&self) -> Temporary {
|
||||
self.result
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
@ -7,17 +7,17 @@ use crate::node::{
|
||||
pub trait Visitor {
|
||||
fn visit_select(&mut self, _: &Select) {}
|
||||
|
||||
fn visit_get_temporary(&mut self, _: &Temporary) {}
|
||||
fn visit_get_temporary(&mut self, _: Temporary) {}
|
||||
|
||||
fn visit_get_local(&mut self, _: &Local) {}
|
||||
fn visit_get_local(&mut self, _: Local) {}
|
||||
|
||||
fn visit_get_global(&mut self, _: &GetGlobal) {}
|
||||
fn visit_get_global(&mut self, _: GetGlobal) {}
|
||||
|
||||
fn visit_load_at(&mut self, _: &LoadAt) {}
|
||||
|
||||
fn visit_memory_size(&mut self, _: &MemorySize) {}
|
||||
|
||||
fn visit_value(&mut self, _: &Value) {}
|
||||
fn visit_value(&mut self, _: Value) {}
|
||||
|
||||
fn visit_un_op(&mut self, _: &UnOp) {}
|
||||
|
||||
@ -29,7 +29,7 @@ pub trait Visitor {
|
||||
|
||||
fn visit_unreachable(&mut self) {}
|
||||
|
||||
fn visit_br(&mut self, _: &Br) {}
|
||||
fn visit_br(&mut self, _: Br) {}
|
||||
|
||||
fn visit_br_table(&mut self, _: &BrTable) {}
|
||||
|
||||
@ -78,19 +78,19 @@ impl<T: Visitor> Driver<T> for Select {
|
||||
|
||||
impl<T: Visitor> Driver<T> for Temporary {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_get_temporary(self);
|
||||
visitor.visit_get_temporary(*self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Visitor> Driver<T> for Local {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_get_local(self);
|
||||
visitor.visit_get_local(*self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Visitor> Driver<T> for GetGlobal {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_get_global(self);
|
||||
visitor.visit_get_global(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ impl<T: Visitor> Driver<T> for MemoryFill {
|
||||
|
||||
impl<T: Visitor> Driver<T> for Value {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_value(self);
|
||||
visitor.visit_value(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ impl<T: Visitor> Driver<T> for Expression {
|
||||
|
||||
impl<T: Visitor> Driver<T> for Br {
|
||||
fn accept(&self, visitor: &mut T) {
|
||||
visitor.visit_br(self);
|
||||
visitor.visit_br(*self);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user