Rename functions, remove escaped newlines

This commit is contained in:
Anton Danilkin
2018-08-03 18:40:55 +03:00
committed by Alex Crichton
parent 2249032ba8
commit 0ef528165f
4 changed files with 55 additions and 55 deletions

View File

@ -154,7 +154,7 @@ impl Descriptor {
} }
} }
pub fn is_primitive(&self) -> bool { pub fn is_wasm_native(&self) -> bool {
match *self { match *self {
Descriptor::I32 Descriptor::I32
| Descriptor::U32 | Descriptor::U32
@ -164,7 +164,7 @@ impl Descriptor {
} }
} }
pub fn is_as_u32(&self) -> bool { pub fn is_abi_as_u32(&self) -> bool {
match *self { match *self {
Descriptor::I8 Descriptor::I8
| Descriptor::U8 | Descriptor::U8

View File

@ -192,17 +192,17 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if optional { if optional {
if arg.is_primitive() { if arg.is_wasm_native() {
self.cx.expose_is_like_none(); self.cx.expose_is_like_none();
self.js_arguments.push((name.clone(), "number".to_string())); self.js_arguments.push((name.clone(), "number".to_string()));
if self.cx.config.debug { if self.cx.config.debug {
self.cx.expose_assert_num(); self.cx.expose_assert_num();
self.prelude(&format!( self.prelude(&format!(
"\n\ "
if (!isLikeNone({0})) {{\n\ if (!isLikeNone({0})) {{
_assertNum({0});\n\ _assertNum({0});
}}\n\ }}
", ",
name name
)); ));
@ -213,17 +213,17 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
return Ok(self); return Ok(self);
} }
if arg.is_as_u32() { if arg.is_abi_as_u32() {
self.cx.expose_is_like_none(); self.cx.expose_is_like_none();
self.js_arguments.push((name.clone(), "number".to_string())); self.js_arguments.push((name.clone(), "number".to_string()));
if self.cx.config.debug { if self.cx.config.debug {
self.cx.expose_assert_num(); self.cx.expose_assert_num();
self.prelude(&format!( self.prelude(&format!(
"\n\ "
if (!isLikeNone({0})) {{\n\ if (!isLikeNone({0})) {{
_assertNum({0});\n\ _assertNum({0});
}}\n\ }}
", ",
name name
)); ));
@ -243,10 +243,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.cx.expose_global_argument_ptr()?; self.cx.expose_global_argument_ptr()?;
self.js_arguments.push((name.clone(), "BigInt".to_string())); self.js_arguments.push((name.clone(), "BigInt".to_string()));
self.prelude(&format!( self.prelude(&format!(
"\ "
{f}[0] = isLikeNone({name}) ? BigInt(0) : {name};\n\ {f}[0] = isLikeNone({name}) ? BigInt(0) : {name};
const low{i} = isLikeNone({name}) ? 0 : u32CvtShim[0];\n\ const low{i} = isLikeNone({name}) ? 0 : u32CvtShim[0];
const high{i} = isLikeNone({name}) ? 0 : u32CvtShim[1];\n\ const high{i} = isLikeNone({name}) ? 0 : u32CvtShim[1];
", ",
i = i, i = i,
f = f, f = f,
@ -317,10 +317,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.cx.expose_global_argument_ptr()?; self.cx.expose_global_argument_ptr()?;
self.js_arguments.push((name.clone(), "BigInt".to_string())); self.js_arguments.push((name.clone(), "BigInt".to_string()));
self.prelude(&format!( self.prelude(&format!(
"\ "
{f}[0] = {name};\n\ {f}[0] = {name};
const low{i} = u32CvtShim[0];\n\ const low{i} = u32CvtShim[0];
const high{i} = u32CvtShim[1];\n\ const high{i} = u32CvtShim[1];
", ",
i = i, i = i,
f = f, f = f,
@ -415,7 +415,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
} }
if optional { if optional {
if ty.is_primitive() { if ty.is_wasm_native() {
self.ret_ty = "number".to_string(); self.ret_ty = "number".to_string();
self.cx.expose_global_argument_ptr()?; self.cx.expose_global_argument_ptr()?;
self.cx.expose_uint32_memory(); self.cx.expose_uint32_memory();
@ -429,11 +429,11 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.prelude("const retptr = globalArgumentPtr();"); self.prelude("const retptr = globalArgumentPtr();");
self.rust_arguments.insert(0, "retptr".to_string()); self.rust_arguments.insert(0, "retptr".to_string());
self.ret_expr = format!( self.ret_expr = format!(
"\ "
RET;\n\ RET;
const present = getUint32Memory()[retptr / 4];\n\ const present = getUint32Memory()[retptr / 4];
const value = {mem}[retptr / {size} + 1];\n\ const value = {mem}[retptr / {size} + 1];
return present === 0 ? undefined : value;\n\ return present === 0 ? undefined : value;
", ",
size = match ty { size = match ty {
Descriptor::I32 => 4, Descriptor::I32 => 4,
@ -453,7 +453,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
return Ok(self); return Ok(self);
} }
if ty.is_as_u32() { if ty.is_abi_as_u32() {
self.ret_ty = "number".to_string(); self.ret_ty = "number".to_string();
self.ret_expr = " self.ret_expr = "
const ret = RET; const ret = RET;
@ -475,11 +475,11 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.prelude("const retptr = globalArgumentPtr();"); self.prelude("const retptr = globalArgumentPtr();");
self.rust_arguments.insert(0, "retptr".to_string()); self.rust_arguments.insert(0, "retptr".to_string());
self.ret_expr = format!( self.ret_expr = format!(
"\ "
RET;\n\ RET;
const present = getUint32Memory()[retptr / 4];\n\ const present = getUint32Memory()[retptr / 4];
const value = {}()[retptr / 8 + 1];\n\ const value = {}()[retptr / 8 + 1];
return present === 0 ? undefined : value;\n\ return present === 0 ? undefined : value;
", ",
f f
); );

View File

@ -132,7 +132,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
} }
if optional { if optional {
if arg.is_primitive() { if arg.is_wasm_native() {
let value = self.shim_argument(); let value = self.shim_argument();
self.js_arguments.push(format!( self.js_arguments.push(format!(
"{present} === 0 ? undefined : {value}", "{present} === 0 ? undefined : {value}",
@ -142,7 +142,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(()) return Ok(())
} }
if arg.is_as_u32() { if arg.is_abi_as_u32() {
self.js_arguments.push(format!("{0} === 0xFFFFFF ? undefined : {0}", abi)); self.js_arguments.push(format!("{0} === 0xFFFFFF ? undefined : {0}", abi));
return Ok(()) return Ok(())
} }
@ -158,10 +158,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
let high = self.shim_argument(); let high = self.shim_argument();
let name = format!("n{}", abi); let name = format!("n{}", abi);
self.prelude(&format!( self.prelude(&format!(
"\ "
u32CvtShim[0] = {present} === 0 ? 0 : {low};\n\ u32CvtShim[0] = {present} === 0 ? 0 : {low};
u32CvtShim[1] = {present} === 0 ? 0 : {high};\n\ u32CvtShim[1] = {present} === 0 ? 0 : {high};
const {name} = {present} === 0 ? undefined : {f}[0];\n\ const {name} = {present} === 0 ? undefined : {f}[0];
", ",
present = abi, present = abi,
low = low, low = low,
@ -186,9 +186,9 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
let name = format!("n{}", abi); let name = format!("n{}", abi);
self.prelude(&format!( self.prelude(&format!(
"\ "\
u32CvtShim[0] = {low};\n\ u32CvtShim[0] = {low};
u32CvtShim[1] = {high};\n\ u32CvtShim[1] = {high};
const {name} = {f}[0];\n\ const {name} = {f}[0];
", ",
low = abi, low = abi,
high = high, high = high,
@ -358,7 +358,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(()) return Ok(())
} }
if optional { if optional {
if ty.is_primitive() { if ty.is_wasm_native() {
self.cx.expose_is_like_none(); self.cx.expose_is_like_none();
self.cx.expose_uint32_memory(); self.cx.expose_uint32_memory();
match ty { match ty {
@ -370,10 +370,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
}; };
self.shim_arguments.insert(0, "ret".to_string()); self.shim_arguments.insert(0, "ret".to_string());
self.ret_expr = format!( self.ret_expr = format!(
"\ "
const val = JS;\n\ const val = JS;
getUint32Memory()[ret / 4] = !isLikeNone(val);\n\ getUint32Memory()[ret / 4] = !isLikeNone(val);
{mem}[ret / {size} + 1] = isLikeNone(val) ? 0 : val;\n\ {mem}[ret / {size} + 1] = isLikeNone(val) ? 0 : val;
", ",
size = match ty { size = match ty {
Descriptor::I32 => 4, Descriptor::I32 => 4,
@ -393,7 +393,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(()); return Ok(());
} }
if ty.is_as_u32() { if ty.is_abi_as_u32() {
self.cx.expose_is_like_none(); self.cx.expose_is_like_none();
self.ret_expr = " self.ret_expr = "
const val = JS; const val = JS;
@ -414,10 +414,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
}; };
self.shim_arguments.insert(0, "ret".to_string()); self.shim_arguments.insert(0, "ret".to_string());
self.ret_expr = format!( self.ret_expr = format!(
"\ "
const val = JS;\n\ const val = JS;
getUint32Memory()[ret / 4] = !isLikeNone(val);\n\ getUint32Memory()[ret / 4] = !isLikeNone(val);
{}()[ret / 8 + 1] = isLikeNone(val) ? BigInt(0) : val;\n\ {}()[ret / 8 + 1] = isLikeNone(val) ? BigInt(0) : val;
", ",
f f
); );

View File

@ -56,7 +56,7 @@ pub struct WasmOptional64 {
unsafe impl WasmAbi for WasmOptional64 {} unsafe impl WasmAbi for WasmOptional64 {}
macro_rules! type_primitive { macro_rules! type_wasm_native {
($($t:tt as $c:tt => $r:tt)*) => ($( ($($t:tt as $c:tt => $r:tt)*) => ($(
impl IntoWasmAbi for $t { impl IntoWasmAbi for $t {
type Abi = $c; type Abi = $c;
@ -103,7 +103,7 @@ macro_rules! type_primitive {
)*) )*)
} }
type_primitive!( type_wasm_native!(
i32 as i32 => WasmOptionalI32 i32 as i32 => WasmOptionalI32
isize as i32 => WasmOptionalI32 isize as i32 => WasmOptionalI32
u32 as u32 => WasmOptionalU32 u32 as u32 => WasmOptionalU32
@ -112,7 +112,7 @@ type_primitive!(
f64 as f64 => WasmOptionalF64 f64 as f64 => WasmOptionalF64
); );
macro_rules! type_as_u32 { macro_rules! type_abi_as_u32 {
($($t:tt)*) => ($( ($($t:tt)*) => ($(
impl IntoWasmAbi for $t { impl IntoWasmAbi for $t {
type Abi = u32; type Abi = u32;
@ -140,7 +140,7 @@ macro_rules! type_as_u32 {
)*) )*)
} }
type_as_u32!(i8 u8 i16 u16); type_abi_as_u32!(i8 u8 i16 u16);
macro_rules! type_64 { macro_rules! type_64 {
($($t:tt)*) => ($( ($($t:tt)*) => ($(