Skip to content

Commit

Permalink
Update rust and fix all warnings/clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jblebrun committed Dec 13, 2023
1 parent b5270be commit fb735f2
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "wrausmt"
version = "0.1.0"
authors = ["Jason LeBrun <jblebrun@gmail.com>"]
edition = "2018"
edition = "2021"

[dependencies]
"codegen" = { path = "codegen" }
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait EmitCode: Write + std::fmt::Debug {

impl<W: Write + std::fmt::Debug> EmitCode for W {}

pub static CODE_HEADER: &str = &"use crate::runtime::error::Result;
pub static CODE_HEADER: &str = "use crate::runtime::error::Result;
use crate::runtime::error::TrapKind;
use crate::runtime::exec::ExecutionContext;
use crate::runtime::exec::ExecutionContextActions;
Expand Down
8 changes: 4 additions & 4 deletions codegen/src/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::collections::HashMap;
use std::io::Result;
use std::io::Write;

pub static DATA_TABLE_HEADER: &str = &"use crate::instructions::InstructionData;
pub static DATA_TABLE_HEADER: &str = "use crate::instructions::InstructionData;
use crate::instructions::Operands;
use crate::instructions::BAD_INSTRUCTION;
pub static INSTRUCTION_DATA: &[&InstructionData] = &[
pub static INSTRUCTION_DATA: &[InstructionData] = &[
";

pub trait EmitDataTable: Write {
Expand All @@ -35,13 +35,13 @@ impl<W: Write> EmitDataTable for W {}
fn data_table_item(inst: Option<&Instruction>) -> String {
match inst {
Some(i) => format!(
" &InstructionData {{
" InstructionData {{
opcode: {:#x},
name: \"{}\",
operands: {},
}},\n",
i.opcode, i.name, i.operands
),
_ => " &BAD_INSTRUCTION,\n".into(),
_ => " BAD_INSTRUCTION,\n".into(),
}
}
2 changes: 1 addition & 1 deletion codegen/src/exec_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn exec_table_item(inst: Option<&Instruction>) -> String {
}
}

pub static EXEC_TABLE_HEADER: &str = &"use super::instructions;
pub static EXEC_TABLE_HEADER: &str = "use super::instructions;
use crate::instructions::bad;
use crate::instructions::unimpl;
use crate::instructions::ExecFn;
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ fn emit_module() -> io::Result<()> {
f.write_all(MODULE.as_bytes())
}

pub static MODULE: &str = &"pub mod data_table;
pub static MODULE: &str = "pub mod data_table;
pub mod exec_table;
pub mod instructions;
";

pub static GEN_HEADER: &str = &"/// This file was generated automatically by the codegen crate.
pub static GEN_HEADER: &str = "/// This file was generated automatically by the codegen crate.
/// Do not edit it manually.
///
/// See build.rs for wrausmt or the included codegen crate for more details.
Expand Down
2 changes: 1 addition & 1 deletion src/format/binary/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub trait SectionReader: ReadWasmValues + ReadCode {

section_reader
.ensure_consumed()
.ctx(&format!("Section {}", section_num))?;
.ctx(format!("Section {}", section_num))?;

Ok(section)
}
Expand Down
2 changes: 1 addition & 1 deletion src/format/text/lex/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl CharChecks for u8 {
}

fn is_keyword_start(&self) -> bool {
matches!(self, b'a'..=b'z')
self.is_ascii_lowercase()
}

fn is_whitespace(&self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions src/format/text/lex/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn maybe_number(idchars: &str) -> Option<Token> {
let base = if hex { Base::Hex } else { Base::Dec };

let whole = cursor.consume_while(|c| is_digit(c, hex));
let whole = whole.replace("_", "");
let whole = whole.replace('_', "");

if whole.is_empty() {
return None;
Expand All @@ -108,7 +108,7 @@ pub fn maybe_number(idchars: &str) -> Option<Token> {
}

let frac = cursor.consume_while(|c| is_digit(c, hex));
let frac = frac.replace("_", "");
let frac = frac.replace('_', "");

let expchars = if hex { ['p', 'P'] } else { ['e', 'E'] };

Expand All @@ -119,7 +119,7 @@ pub fn maybe_number(idchars: &str) -> Option<Token> {
}

let exp = cursor.consume_while(|c| is_digit(c, false) || c == '+' || c == '-');
let exp = exp.replace("_", "");
let exp = exp.replace('_', "");

if !cursor.is_empty() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/format/text/module_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct ModuleIdentifiers {
pub dataindices: HashMap<String, u32>,
}

/// A [ModuleBuilder] accepts the various [Field] items coming from the parse, and organizes them
/// A [ModuleBuilder] accepts the various items coming from the parse, and organizes them
/// by sections into a [Module]. This [Module] is still just an abstract representation. ID
/// declarations are collected into maps, but ID usages are not yet resolved. ID resolution and
/// function body compilation happens in a subsequent resolution pass.
Expand Down
2 changes: 1 addition & 1 deletion src/format/text/parse/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ParseErrorContext {

#[derive(Debug)]
pub enum ParseError {
WithContext(ParseErrorContext, Box<ParseError>),
WithContext(Box<ParseErrorContext>, Box<ParseError>),
WithMsg(Vec<String>, Box<ParseError>),
Eof,
Tokenizer(LexError),
Expand Down
2 changes: 1 addition & 1 deletion src/format/text/parse/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<R: Read> Parser<R> {
return Ok(None);
}

let instruction_data = instruction_by_name(&name);
let instruction_data = instruction_by_name(name);

match instruction_data {
Some(data) => {
Expand Down
4 changes: 2 additions & 2 deletions src/format/text/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<R: Read> Parser<R> {
}
pub fn peek_keyword(&self) -> Result<Option<&str>> {
match &self.current.token {
Token::Keyword(id) => Ok(Some(&id)),
Token::Keyword(id) => Ok(Some(id)),
_ => Ok(None),
}
}
Expand All @@ -195,7 +195,7 @@ impl<R: Read> Parser<R> {

pub fn peek_next_keyword(&self) -> Result<Option<&str>> {
match &self.next.token {
Token::Keyword(id) => Ok(Some(&id)),
Token::Keyword(id) => Ok(Some(id)),
_ => Ok(None),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/format/text/parse/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl<R: Read> Parser<R> {

pub fn with_context(&self, err: ParseError) -> ParseError {
ParseError::WithContext(
ParseErrorContext {
Box::new(ParseErrorContext {
context: self.context.clone(),
current: self.current.clone(),
next: self.next.clone(),
},
}),
Box::new(err),
)
}
Expand Down Expand Up @@ -644,7 +644,7 @@ impl<R: Read> Parser<R> {
}

if let Some(val) = self.try_u32()? {
return Ok(Some(Index::unnamed(val as u32)));
return Ok(Some(Index::unnamed(val)));
}

Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions src/format/text/parse/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<R: Read> Parser<R> {
}

fn nanx_f64(sign: Sign, payload: &str) -> Result<f64> {
let payload = payload.replace("_", "");
let payload = payload.replace('_', "");
let payload_num = u64::from_str_radix(&payload, 16)?;
println!("PAYLOAD NUM {:013x}", payload_num);
let base: u64 = match sign {
Expand All @@ -53,7 +53,7 @@ fn nanx_f64(sign: Sign, payload: &str) -> Result<f64> {
}

fn nanx_f32(sign: Sign, payload: &str) -> Result<f32> {
let payload = payload.replace("_", "");
let payload = payload.replace('_', "");
let payload_num = u32::from_str_radix(&payload, 16)?;
println!("PAYLOAD NUM {:06x}", payload_num);
let base: u32 = match sign {
Expand Down
66 changes: 33 additions & 33 deletions src/format/text/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ macro_rules! resolve_all {
( $src:expr, $ic:expr, $types:expr ) => {
$src.into_iter()
.map(|i| i.resolve(&$ic, $types))
.collect::<Result<_>>();
.collect::<Result<_>>()
};
}

/// For an option of an unresolved items, returns an option of the resolved item.
macro_rules! resolve_option {
( $src:expr, $ic:expr, $types:expr ) => {
$src.map(|i| i.resolve(&$ic, $types)).transpose()?;
$src.map(|i| i.resolve(&$ic, $types)).transpose()?
};
}

Expand Down Expand Up @@ -176,7 +176,7 @@ impl Resolve<Instruction<Resolved>> for Instruction<Unresolved> {
Ok(Instruction {
name: self.name,
opcode: self.opcode,
operands: self.operands.resolve(&ic, types)?,
operands: self.operands.resolve(ic, types)?,
})
}
}
Expand All @@ -199,8 +199,8 @@ impl Resolve<Operands<Resolved>> for Operands<Unresolved> {
Operands::BrTable(idxs) => Operands::BrTable(resolve_all!(idxs, ic, types)?),
Operands::Select(r) => Operands::Select(r),
Operands::CallIndirect(idx, tu) => {
let idx = idx.resolve(&ic, types)?;
let tu = tu.resolve(&ic, types)?;
let idx = idx.resolve(ic, types)?;
let tu = tu.resolve(ic, types)?;
Operands::CallIndirect(idx, tu)
}
Operands::Block(id, tu, expr, cnt) => {
Expand All @@ -209,18 +209,18 @@ impl Resolve<Operands<Resolved>> for Operands<Unresolved> {
let expr = expr.resolve(&bic, types)?;
Operands::Block(id, tu, expr, cnt)
}
Operands::FuncIndex(idx) => Operands::FuncIndex(idx.resolve(&ic, types)?),
Operands::TableIndex(idx) => Operands::TableIndex(idx.resolve(&ic, types)?),
Operands::GlobalIndex(idx) => Operands::GlobalIndex(idx.resolve(&ic, types)?),
Operands::ElemIndex(idx) => Operands::ElemIndex(idx.resolve(&ic, types)?),
Operands::DataIndex(idx) => Operands::DataIndex(idx.resolve(&ic, types)?),
Operands::LocalIndex(idx) => Operands::LocalIndex(idx.resolve(&ic, types)?),
Operands::LabelIndex(idx) => Operands::LabelIndex(idx.resolve(&ic, types)?),
Operands::FuncIndex(idx) => Operands::FuncIndex(idx.resolve(ic, types)?),
Operands::TableIndex(idx) => Operands::TableIndex(idx.resolve(ic, types)?),
Operands::GlobalIndex(idx) => Operands::GlobalIndex(idx.resolve(ic, types)?),
Operands::ElemIndex(idx) => Operands::ElemIndex(idx.resolve(ic, types)?),
Operands::DataIndex(idx) => Operands::DataIndex(idx.resolve(ic, types)?),
Operands::LocalIndex(idx) => Operands::LocalIndex(idx.resolve(ic, types)?),
Operands::LabelIndex(idx) => Operands::LabelIndex(idx.resolve(ic, types)?),
Operands::TableInit(tidx, eidx) => {
Operands::TableInit(tidx.resolve(&ic, types)?, eidx.resolve(&ic, types)?)
Operands::TableInit(tidx.resolve(ic, types)?, eidx.resolve(ic, types)?)
}
Operands::TableCopy(tidx, t2idx) => {
Operands::TableCopy(tidx.resolve(&ic, types)?, t2idx.resolve(&ic, types)?)
Operands::TableCopy(tidx.resolve(ic, types)?, t2idx.resolve(ic, types)?)
}
Operands::Memargs(a, o) => Operands::Memargs(a, o),
Operands::HeapType(r) => Operands::HeapType(r),
Expand Down Expand Up @@ -257,7 +257,7 @@ impl Resolve<ImportField<Resolved>> for ImportField<Unresolved> {
name: self.name,
id: self.id,
exports: self.exports,
desc: self.desc.resolve(&ic, types)?,
desc: self.desc.resolve(ic, types)?,
})
}
}
Expand All @@ -269,7 +269,7 @@ impl Resolve<ImportDesc<Resolved>> for ImportDesc<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<ImportDesc<Resolved>> {
Ok(match self {
ImportDesc::Func(tu) => ImportDesc::Func(tu.resolve(&ic, types)?),
ImportDesc::Func(tu) => ImportDesc::Func(tu.resolve(ic, types)?),
ImportDesc::Table(tt) => ImportDesc::Table(tt),
ImportDesc::Mem(mt) => ImportDesc::Mem(mt),
ImportDesc::Global(gt) => ImportDesc::Global(gt),
Expand All @@ -285,7 +285,7 @@ impl Resolve<ExportField<Resolved>> for ExportField<Unresolved> {
) -> Result<ExportField<Resolved>> {
Ok(ExportField {
name: self.name,
exportdesc: self.exportdesc.resolve(&ic, types)?,
exportdesc: self.exportdesc.resolve(ic, types)?,
})
}
}
Expand All @@ -297,10 +297,10 @@ impl Resolve<ExportDesc<Resolved>> for ExportDesc<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<ExportDesc<Resolved>> {
Ok(match self {
ExportDesc::Func(idx) => ExportDesc::Func(idx.resolve(&ic, types)?),
ExportDesc::Table(idx) => ExportDesc::Table(idx.resolve(&ic, types)?),
ExportDesc::Mem(idx) => ExportDesc::Mem(idx.resolve(&ic, types)?),
ExportDesc::Global(idx) => ExportDesc::Global(idx.resolve(&ic, types)?),
ExportDesc::Func(idx) => ExportDesc::Func(idx.resolve(ic, types)?),
ExportDesc::Table(idx) => ExportDesc::Table(idx.resolve(ic, types)?),
ExportDesc::Mem(idx) => ExportDesc::Mem(idx.resolve(ic, types)?),
ExportDesc::Global(idx) => ExportDesc::Global(idx.resolve(ic, types)?),
})
}
}
Expand All @@ -315,7 +315,7 @@ impl Resolve<GlobalField<Resolved>> for GlobalField<Unresolved> {
id: self.id,
exports: self.exports,
globaltype: self.globaltype,
init: self.init.resolve(&ic, types)?,
init: self.init.resolve(ic, types)?,
})
}
}
Expand All @@ -327,7 +327,7 @@ impl Resolve<StartField<Resolved>> for StartField<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<StartField<Resolved>> {
Ok(StartField {
idx: self.idx.resolve(&ic, types)?,
idx: self.idx.resolve(ic, types)?,
})
}
}
Expand All @@ -340,8 +340,8 @@ impl Resolve<ElemField<Resolved>> for ElemField<Unresolved> {
) -> Result<ElemField<Resolved>> {
Ok(ElemField {
id: self.id,
mode: self.mode.resolve(&ic, types)?,
elemlist: self.elemlist.resolve(&ic, types)?,
mode: self.mode.resolve(ic, types)?,
elemlist: self.elemlist.resolve(ic, types)?,
})
}
}
Expand All @@ -354,7 +354,7 @@ impl Resolve<ModeEntry<Resolved>> for ModeEntry<Unresolved> {
) -> Result<ModeEntry<Resolved>> {
Ok(match self {
ModeEntry::Passive => ModeEntry::Passive,
ModeEntry::Active(tp) => ModeEntry::Active(tp.resolve(&ic, types)?),
ModeEntry::Active(tp) => ModeEntry::Active(tp.resolve(ic, types)?),
ModeEntry::Declarative => ModeEntry::Declarative,
})
}
Expand All @@ -367,8 +367,8 @@ impl Resolve<TablePosition<Resolved>> for TablePosition<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<TablePosition<Resolved>> {
Ok(TablePosition {
tableuse: self.tableuse.resolve(&ic, types)?,
offset: self.offset.resolve(&ic, types)?,
tableuse: self.tableuse.resolve(ic, types)?,
offset: self.offset.resolve(ic, types)?,
})
}
}
Expand All @@ -380,7 +380,7 @@ impl Resolve<TableUse<Resolved>> for TableUse<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<TableUse<Resolved>> {
Ok(TableUse {
tableidx: self.tableidx.resolve(&ic, types)?,
tableidx: self.tableidx.resolve(ic, types)?,
})
}
}
Expand All @@ -407,8 +407,8 @@ impl Resolve<DataInit<Resolved>> for DataInit<Unresolved> {
types: &mut Vec<TypeField>,
) -> Result<DataInit<Resolved>> {
Ok(DataInit {
memidx: self.memidx.resolve(&ic, types)?,
offset: self.offset.resolve(&ic, types)?,
memidx: self.memidx.resolve(ic, types)?,
offset: self.offset.resolve(ic, types)?,
})
}
}
Expand Down Expand Up @@ -496,7 +496,7 @@ fn get_func_params(typeuse: &TypeUse<Resolved>, types: &[TypeField]) -> Vec<FPar
let existing = types
.get(typeidx.value() as usize)
.map(|tf| tf.functiontype.clone())
.unwrap_or_else(FunctionType::default);
.unwrap_or_default();
existing.params
}
_ => vec![],
Expand All @@ -509,7 +509,7 @@ impl Resolve<FuncField<Resolved>> for FuncField<Unresolved> {
ic: &ResolutionContext,
types: &mut Vec<TypeField>,
) -> Result<FuncField<Resolved>> {
let typeuse = self.typeuse.resolve(&ic, types)?;
let typeuse = self.typeuse.resolve(ic, types)?;

let params = get_func_params(&typeuse, types);

Expand Down
Loading

0 comments on commit fb735f2

Please sign in to comment.