Upgrade to walrus 0.4

Also be sure to have an explicit GC pass!
This commit is contained in:
Alex Crichton
2019-02-19 13:07:00 -08:00
parent 5b0cfd7cea
commit 8fb705a1ef
9 changed files with 21 additions and 24 deletions

View File

@ -12,8 +12,9 @@ Micro-interpreter optimized for wasm-bindgen's use case
edition = '2018'
[dependencies]
walrus = "0.2"
failure = "0.1"
log = "0.4"
walrus = "0.4"
[dev-dependencies]
tempfile = "3"

View File

@ -64,7 +64,7 @@ impl Interpreter {
///
/// Note that the `module` passed in to this function must be the same as
/// the `module` passed to `interpret` below.
pub fn new(module: &Module) -> Interpreter {
pub fn new(module: &Module) -> Result<Interpreter, failure::Error> {
let mut ret = Interpreter::default();
// The descriptor functions shouldn't really use all that much memory
@ -102,14 +102,9 @@ impl Interpreter {
ret.name_map.insert(export.name.to_string(), id);
}
for table in module.tables.iter() {
match table.kind {
walrus::TableKind::Function(_) => {}
}
ret.functions = Some(table.id());
}
ret.functions = module.tables.main_function_table()?;
return ret;
return Ok(ret);
}
/// Interprets the execution of the descriptor function `func`.
@ -204,6 +199,7 @@ impl Interpreter {
let functions = self.functions.expect("function table should be present");
let functions = match &module.tables.get(functions).kind {
walrus::TableKind::Function(f) => f,
_ => unreachable!(),
};
let descriptor_id = functions
.elements
@ -348,8 +344,11 @@ impl Frame<'_> {
Expr::WithSideEffects(e) => {
log::debug!("side effects");
for x in e.before.iter() {
self.eval(*x);
}
let ret = self.eval(e.value);
for x in e.side_effects.iter() {
for x in e.after.iter() {
self.eval(*x);
}
return ret;

View File

@ -16,7 +16,7 @@ fn interpret(wat: &str, name: &str, result: Option<&[u32]>) {
println!("status: {}", status);
assert!(status.success());
let module = walrus::Module::from_file(output.path()).unwrap();
let mut i = Interpreter::new(&module);
let mut i = Interpreter::new(&module).unwrap();
assert_eq!(i.interpret_descriptor(name, &module), result);
}