Last active
January 3, 2018 14:52
-
-
Save pepyakin/45e2887cfedfd23209717bd9d6b2e7a5 to your computer and use it in GitHub Desktop.
cargo expand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Resolver; | |
impl<'a> Data<'a> { | |
fn resolver() -> Resolver { | |
Resolver | |
} | |
} | |
impl ImportResolver for Resolver { | |
fn resolve_func(&self, name: &str, _signature: &FunctionType) -> FuncRef { | |
if name == "add" { | |
return FuncRef::Host(0); | |
} | |
if name == "inc" { | |
return FuncRef::Host(0 + 1); | |
} | |
if name == "dummy" { | |
return FuncRef::Host(0 + 1 + 1); | |
} | |
if name == "is_negative" { | |
return FuncRef::Host(0 + 1 + 1 + 1); | |
} | |
if name == "print_div" { | |
return FuncRef::Host(0 + 1 + 1 + 1 + 1); | |
}; | |
{ | |
{ | |
::rt::begin_panic("explicit panic", &("src/lib.rs", 354u32, 0u32)) | |
} | |
}; | |
} | |
fn resolve_memory(&self, name: &str) -> MemRef { | |
{ | |
::rt::begin_panic("not yet implemented", &("src/lib.rs", 354u32, 0u32)) | |
} | |
} | |
} | |
impl<'a> ::Externals for Data<'a> { | |
fn invoke_index( | |
&mut self, | |
index: u32, | |
args: &[::RuntimeValue], | |
) -> Result<Option<::RuntimeValue>, ::Error> { | |
let mut state = self; | |
let mut args = args.iter().cloned(); | |
if index == 0 { | |
{ | |
{ | |
let mut body = || { | |
let a: <u32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
let b: <u32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
{ | |
a + b | |
} | |
}; | |
let r: <u32 as ::ConvertibleToWasm>::NativeType = body(); | |
return Ok(Some({ | |
use ConvertibleToWasm; | |
r.to_runtime_value() | |
})); | |
} | |
} | |
} | |
if index == 0 + 1 { | |
{ | |
{ | |
let mut body = || { | |
let n: <u32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
{ | |
*state.acc += n; | |
*state.acc as u64 | |
} | |
}; | |
let r: <u64 as ::ConvertibleToWasm>::NativeType = body(); | |
return Ok(Some({ | |
use ConvertibleToWasm; | |
r.to_runtime_value() | |
})); | |
} | |
} | |
} | |
if index == 0 + 1 + 1 { | |
{ | |
{ | |
let mut body = || { | |
{ | |
::io::_print(::std::fmt::Arguments::new_v1( | |
&["3\n"], | |
&match () { | |
() | |
=> | |
[], | |
}, | |
)) | |
} | |
}; | |
body(); | |
return Ok(None); | |
} | |
} | |
} | |
if index == 0 + 1 + 1 + 1 { | |
{ | |
{ | |
let mut body = || { | |
let n: <i32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
{ | |
if n < 0 { | |
return 1; | |
} | |
0 | |
} | |
}; | |
let r: <u32 as ::ConvertibleToWasm>::NativeType = body(); | |
return Ok(Some({ | |
use ConvertibleToWasm; | |
r.to_runtime_value() | |
})); | |
} | |
} | |
} | |
if index == 0 + 1 + 1 + 1 + 1 { | |
{ | |
{ | |
let mut body = || { | |
let a: <u32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
let b: <u32 as ::ConvertibleToWasm>::NativeType = | |
args.next().unwrap().into(); | |
{ | |
if b == 0 { | |
return; | |
} | |
::io::_print(::std::fmt::Arguments::new_v1_formatted( | |
&["", "\n"], | |
&match (&(a / b),) { | |
(__arg0,) => { | |
[ | |
::std::fmt::ArgumentV1::new( | |
__arg0, | |
::std::fmt::Display::fmt, | |
), | |
] | |
} | |
}, | |
&[ | |
::std::fmt::rt::v1::Argument { | |
position: ::std::fmt::rt::v1::Position::At(0usize), | |
format: ::std::fmt::rt::v1::FormatSpec { | |
fill: ' ', | |
align: ::std::fmt::rt::v1::Alignment::Unknown, | |
flags: 0u32, | |
precision: ::std::fmt::rt::v1::Count::Implied, | |
width: ::std::fmt::rt::v1::Count::Implied, | |
}, | |
}, | |
], | |
)); | |
} | |
}; | |
body(); | |
return Ok(None); | |
} | |
} | |
} | |
{ | |
::rt::begin_panic_fmt( | |
&::std::fmt::Arguments::new_v1_formatted( | |
&["fn with index ", " is undefined"], | |
&match (&(0 + 1 + 1 + 1 + 1 + 1),) { | |
(__arg0,) => { | |
[ | |
::std::fmt::ArgumentV1::new(__arg0, ::std::fmt::Display::fmt), | |
] | |
} | |
}, | |
&[ | |
::std::fmt::rt::v1::Argument { | |
position: ::std::fmt::rt::v1::Position::At(0usize), | |
format: ::std::fmt::rt::v1::FormatSpec { | |
fill: ' ', | |
align: ::std::fmt::rt::v1::Alignment::Unknown, | |
flags: 0u32, | |
precision: ::std::fmt::rt::v1::Count::Implied, | |
width: ::std::fmt::rt::v1::Count::Implied, | |
}, | |
}, | |
], | |
), | |
&("src/lib.rs", 354u32, 0u32), | |
) | |
}; | |
} | |
fn check_signature(&self, index: usize, signature: &FunctionType) -> bool { | |
if index == 0 { | |
return { | |
signature.params() == | |
&[ | |
{ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}, | |
{ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}, | |
] && | |
signature.return_type() == | |
Some({ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}) | |
}; | |
} | |
if index == 0 + 1 { | |
return { | |
signature.params() == | |
&[ | |
{ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}, | |
] && | |
signature.return_type() == | |
Some({ | |
use ConvertibleToWasm; | |
<u64>::VALUE_TYPE | |
}) | |
}; | |
} | |
if index == 0 + 1 + 1 { | |
return { | |
signature.params() == &[] && signature.return_type() == None | |
}; | |
} | |
if index == 0 + 1 + 1 + 1 { | |
return { | |
signature.params() == | |
&[ | |
{ | |
use ConvertibleToWasm; | |
<i32>::VALUE_TYPE | |
}, | |
] && | |
signature.return_type() == | |
Some({ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}) | |
}; | |
} | |
if index == 0 + 1 + 1 + 1 + 1 { | |
return { | |
signature.params() == | |
&[ | |
{ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}, | |
{ | |
use ConvertibleToWasm; | |
<u32>::VALUE_TYPE | |
}, | |
] && signature.return_type() == None | |
}; | |
} | |
{ | |
{ | |
::rt::begin_panic_fmt( | |
&::std::fmt::Arguments::new_v1_formatted( | |
&["fn with index ", " is undefined"], | |
&match (&(0 + 1 + 1 + 1 + 1 + 1),) { | |
(__arg0,) => { | |
[ | |
::std::fmt::ArgumentV1::new(__arg0, ::std::fmt::Display::fmt), | |
] | |
} | |
}, | |
&[ | |
::std::fmt::rt::v1::Argument { | |
position: ::std::fmt::rt::v1::Position::At(0usize), | |
format: ::std::fmt::rt::v1::FormatSpec { | |
fill: ' ', | |
align: ::std::fmt::rt::v1::Alignment::Unknown, | |
flags: 0u32, | |
precision: ::std::fmt::rt::v1::Count::Implied, | |
width: ::std::fmt::rt::v1::Count::Implied, | |
}, | |
}, | |
], | |
), | |
&("src/lib.rs", 354u32, 0u32), | |
) | |
}; | |
}; | |
} | |
fn memory_by_index(&self, index: usize) -> &MemoryInstance { | |
{ | |
::rt::begin_panic("not yet implemented", &("src/lib.rs", 354u32, 0u32)) | |
} | |
} | |
fn table_by_index(&self, index: usize) -> &TableInstance { | |
{ | |
::rt::begin_panic("not yet implemented", &("src/lib.rs", 354u32, 0u32)) | |
} | |
} | |
fn global_by_index(&self, index: usize) -> &GlobalInstance { | |
{ | |
::rt::begin_panic("not yet implemented", &("src/lib.rs", 354u32, 0u32)) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl_function_executor!( | |
state: Data<'a>, | |
add(a: u32, b: u32) -> u32 => { a + b }, | |
inc(n: u32) -> u64 => { *state.acc += n; *state.acc as u64 }, | |
dummy() => { println!("3") }, | |
is_negative(n: i32) -> u32 => { | |
// Test for an early return in function with return value. | |
if n < 0 { | |
return 1; | |
} | |
0 | |
}, | |
print_div(a: u32, b: u32) => { | |
// Test for an early return in function without return value. | |
if b == 0 { | |
return; | |
} | |
println!("{}", a / b); | |
} | |
=> <'a> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment