Make some stuff Copy

This commit is contained in:
Rerumu 2023-06-25 23:27:01 -04:00
parent d33e4a6b3e
commit 0416c30e67
6 changed files with 53 additions and 39 deletions

View File

@ -38,8 +38,12 @@ impl Driver for Br {
} }
} }
fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> { fn to_ordered_table(list: &[Br], default: Br) -> Vec<Br> {
let mut data: Vec<_> = list.iter().chain(std::iter::once(default)).collect(); let mut data: Vec<_> = list
.iter()
.copied()
.chain(std::iter::once(default))
.collect();
data.sort_by_key(|v| v.target()); data.sort_by_key(|v| v.target());
data.dedup_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( fn write_search_layer(
range: Range<usize>, range: Range<usize>,
list: &[&Br], list: &[Br],
mng: &mut Manager, mng: &mut Manager,
w: &mut dyn Write, w: &mut dyn Write,
) -> Result<()> { ) -> Result<()> {

View File

@ -11,7 +11,7 @@ struct Visit {
} }
impl Visit { impl Visit {
fn set_branch(&mut self, br: &Br) { fn set_branch(&mut self, br: Br) {
if br.target() != 0 { if br.target() != 0 {
self.has_branch = true; self.has_branch = true;
} }
@ -19,7 +19,7 @@ impl Visit {
} }
impl Visitor for Visit { impl Visitor for Visit {
fn visit_br(&mut self, stat: &Br) { fn visit_br(&mut self, stat: Br) {
self.set_branch(stat); self.set_branch(stat);
} }
@ -34,7 +34,7 @@ impl Visitor for Visit {
return; return;
} }
for target in table.data() { for &target in table.data() {
self.set_branch(target); self.set_branch(target);
} }

View File

@ -31,7 +31,7 @@ impl Visitor for Visit {
self.local_set.insert(("store", name)); self.local_set.insert(("store", name));
} }
fn visit_value(&mut self, v: &Value) { fn visit_value(&mut self, v: Value) {
let name = match v { let name = match v {
Value::I64(0) => "ZERO", Value::I64(0) => "ZERO",
Value::I64(1) => "ONE", Value::I64(1) => "ONE",

View File

@ -47,8 +47,12 @@ impl Driver for Br {
} }
} }
fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> { fn to_ordered_table(list: &[Br], default: Br) -> Vec<Br> {
let mut data: Vec<_> = list.iter().chain(std::iter::once(default)).collect(); let mut data: Vec<_> = list
.iter()
.copied()
.chain(std::iter::once(default))
.collect();
data.sort_by_key(|v| v.target()); data.sort_by_key(|v| v.target());
data.dedup_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( fn write_search_layer(
range: Range<usize>, range: Range<usize>,
list: &[&Br], list: &[Br],
mng: &mut Manager, mng: &mut Manager,
w: &mut dyn Write, w: &mut dyn Write,
) -> Result<()> { ) -> Result<()> {

View File

@ -625,35 +625,38 @@ impl Select {
} }
} }
#[derive(Clone, Copy)]
pub struct Temporary { pub struct Temporary {
pub(crate) var: usize, pub(crate) var: usize,
} }
impl Temporary { impl Temporary {
#[must_use] #[must_use]
pub const fn var(&self) -> usize { pub const fn var(self) -> usize {
self.var self.var
} }
} }
#[derive(Clone, Copy)]
pub struct Local { pub struct Local {
pub(crate) var: usize, pub(crate) var: usize,
} }
impl Local { impl Local {
#[must_use] #[must_use]
pub const fn var(&self) -> usize { pub const fn var(self) -> usize {
self.var self.var
} }
} }
#[derive(Clone, Copy)]
pub struct GetGlobal { pub struct GetGlobal {
pub(crate) var: usize, pub(crate) var: usize,
} }
impl GetGlobal { impl GetGlobal {
#[must_use] #[must_use]
pub const fn var(&self) -> usize { pub const fn var(self) -> usize {
self.var self.var
} }
} }
@ -687,6 +690,7 @@ impl LoadAt {
} }
} }
#[derive(Clone, Copy)]
pub struct MemorySize { pub struct MemorySize {
pub(crate) memory: usize, pub(crate) memory: usize,
} }
@ -828,6 +832,7 @@ impl ResultList {
} }
} }
#[derive(Clone, Copy)]
pub struct Align { pub struct Align {
pub(crate) new: usize, pub(crate) new: usize,
pub(crate) old: usize, pub(crate) old: usize,
@ -836,21 +841,22 @@ pub struct Align {
impl Align { impl Align {
#[must_use] #[must_use]
pub const fn is_aligned(&self) -> bool { pub const fn is_aligned(self) -> bool {
self.length == 0 || self.new == self.old self.length == 0 || self.new == self.old
} }
#[must_use] #[must_use]
pub const fn new_range(&self) -> ResultList { pub const fn new_range(self) -> ResultList {
ResultList::new(self.new, self.new + self.length) ResultList::new(self.new, self.new + self.length)
} }
#[must_use] #[must_use]
pub const fn old_range(&self) -> ResultList { pub const fn old_range(self) -> ResultList {
ResultList::new(self.old, self.old + self.length) ResultList::new(self.old, self.old + self.length)
} }
} }
#[derive(Clone, Copy)]
pub struct Br { pub struct Br {
pub(crate) target: usize, pub(crate) target: usize,
pub(crate) align: Align, pub(crate) align: Align,
@ -858,13 +864,13 @@ pub struct Br {
impl Br { impl Br {
#[must_use] #[must_use]
pub const fn target(&self) -> usize { pub const fn target(self) -> usize {
self.target self.target
} }
#[must_use] #[must_use]
pub const fn align(&self) -> &Align { pub const fn align(self) -> Align {
&self.align self.align
} }
} }
@ -886,8 +892,8 @@ impl BrTable {
} }
#[must_use] #[must_use]
pub const fn default(&self) -> &Br { pub const fn default(&self) -> Br {
&self.default self.default
} }
} }
@ -939,8 +945,8 @@ impl BrIf {
} }
#[must_use] #[must_use]
pub const fn target(&self) -> &Br { pub const fn target(&self) -> Br {
&self.target self.target
} }
} }
@ -1026,8 +1032,8 @@ pub struct SetTemporary {
impl SetTemporary { impl SetTemporary {
#[must_use] #[must_use]
pub const fn var(&self) -> &Temporary { pub const fn var(&self) -> Temporary {
&self.var self.var
} }
#[must_use] #[must_use]
@ -1043,8 +1049,8 @@ pub struct SetLocal {
impl SetLocal { impl SetLocal {
#[must_use] #[must_use]
pub const fn var(&self) -> &Local { pub const fn var(&self) -> Local {
&self.var self.var
} }
#[must_use] #[must_use]
@ -1118,8 +1124,8 @@ impl MemoryGrow {
} }
#[must_use] #[must_use]
pub const fn result(&self) -> &Temporary { pub const fn result(&self) -> Temporary {
&self.result self.result
} }
#[must_use] #[must_use]

View File

@ -7,17 +7,17 @@ use crate::node::{
pub trait Visitor { pub trait Visitor {
fn visit_select(&mut self, _: &Select) {} 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_load_at(&mut self, _: &LoadAt) {}
fn visit_memory_size(&mut self, _: &MemorySize) {} 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) {} fn visit_un_op(&mut self, _: &UnOp) {}
@ -29,7 +29,7 @@ pub trait Visitor {
fn visit_unreachable(&mut self) {} fn visit_unreachable(&mut self) {}
fn visit_br(&mut self, _: &Br) {} fn visit_br(&mut self, _: Br) {}
fn visit_br_table(&mut self, _: &BrTable) {} 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 { impl<T: Visitor> Driver<T> for Temporary {
fn accept(&self, visitor: &mut T) { fn accept(&self, visitor: &mut T) {
visitor.visit_get_temporary(self); visitor.visit_get_temporary(*self);
} }
} }
impl<T: Visitor> Driver<T> for Local { impl<T: Visitor> Driver<T> for Local {
fn accept(&self, visitor: &mut T) { fn accept(&self, visitor: &mut T) {
visitor.visit_get_local(self); visitor.visit_get_local(*self);
} }
} }
impl<T: Visitor> Driver<T> for GetGlobal { impl<T: Visitor> Driver<T> for GetGlobal {
fn accept(&self, visitor: &mut T) { 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 { impl<T: Visitor> Driver<T> for Value {
fn accept(&self, visitor: &mut T) { 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 { impl<T: Visitor> Driver<T> for Br {
fn accept(&self, visitor: &mut T) { fn accept(&self, visitor: &mut T) {
visitor.visit_br(self); visitor.visit_br(*self);
} }
} }