Skip to content

Commit

Permalink
Fix emscripten compile issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlansneff committed Jan 22, 2019
1 parent 39ddd8f commit 6aca222
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/emscripten/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ pub fn call_malloc(size: i32, instance: &mut Instance) -> u32 {
let ret = instance
.call("_malloc", &[Value::I32(size)])
.expect("_malloc call failed");
if let Some(Value::I32(ptr)) = ret {
ptr as u32
if let [Value::I32(x)] = ret.as_slice() {
*x as u32
} else {
panic!("unexpected value from _malloc: {:?}", ret);
}
Expand All @@ -161,8 +161,8 @@ pub fn call_memalign(alignment: u32, size: u32, instance: &mut Instance) -> u32
&[Value::I32(alignment as i32), Value::I32(size as i32)],
)
.expect("_memalign call failed");
if let Some(Value::I32(res)) = ret {
res as u32
if let [Value::I32(x)] = ret.as_slice() {
*x as u32
} else {
panic!("unexpected value from _memalign {:?}", ret);
}
Expand All @@ -179,8 +179,8 @@ pub fn call_memset(pointer: u32, value: i32, size: u32, instance: &mut Instance)
],
)
.expect("_memset call failed");
if let Some(Value::I32(res)) = ret {
res as u32
if let [Value::I32(x)] = ret.as_slice() {
*x as u32
} else {
panic!("unexpected value from _memset {:?}", ret);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hashbrown::HashMap;
use std::mem;
use wasmer_runtime::{
export::{Context, Export, FuncPointer, GlobalPointer},
import::{ImportObject, NamespaceMap},
import::{ImportObject, Namespace},
memory::LinearMemory,
types::{
FuncSig, GlobalDesc,
Expand All @@ -15,6 +15,8 @@ use wasmer_runtime::{
vm::LocalGlobal,
};

#[macro_use]
mod macros;
//#[cfg(test)]
mod file_descriptor;
pub mod stdio;
Expand Down Expand Up @@ -155,9 +157,9 @@ impl<'a> EmscriptenGlobals<'a> {

pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> ImportObject {
let mut imports = ImportObject::new();
let mut env_namespace = NamespaceMap::new();
let mut asm_namespace = NamespaceMap::new();
let mut global_namespace = NamespaceMap::new();
let mut env_namespace = Namespace::new();
let mut asm_namespace = Namespace::new();
let mut global_namespace = Namespace::new();

// Add globals.
// NOTE: There is really no need for checks, these globals should always be available.
Expand Down
4 changes: 4 additions & 0 deletions lib/emscripten/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
macro_rules! debug {
($fmt:expr) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt), line!()) });
($fmt:expr, $($arg:tt)*) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("wasmer-runtime(:{})::", $fmt, "\n"), line!(), $($arg)*) });
}
5 changes: 4 additions & 1 deletion src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
wasmer_emscripten::generate_emscripten_env(&emscripten_globals),
)
} else {
(InstanceABI::None, wasmer_runtime::import::ImportObject::new())
(
InstanceABI::None,
wasmer_runtime::import::ImportObject::new(),
)
};

let mut instance = module
Expand Down

0 comments on commit 6aca222

Please sign in to comment.