Skip to content

Commit 6afb0b5

Browse files
committed
Rename functions, remove escaped newlines
1 parent ac2b625 commit 6afb0b5

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

crates/cli-support/src/descriptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Descriptor {
154154
}
155155
}
156156

157-
pub fn is_primitive(&self) -> bool {
157+
pub fn is_wasm_native(&self) -> bool {
158158
match *self {
159159
Descriptor::I32
160160
| Descriptor::U32
@@ -164,7 +164,7 @@ impl Descriptor {
164164
}
165165
}
166166

167-
pub fn is_as_u32(&self) -> bool {
167+
pub fn is_abi_as_u32(&self) -> bool {
168168
match *self {
169169
Descriptor::I8
170170
| Descriptor::U8

crates/cli-support/src/js/js2rust.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,17 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
192192
}
193193

194194
if optional {
195-
if arg.is_primitive() {
195+
if arg.is_wasm_native() {
196196
self.cx.expose_is_like_none();
197197
self.js_arguments.push((name.clone(), "number".to_string()));
198198

199199
if self.cx.config.debug {
200200
self.cx.expose_assert_num();
201201
self.prelude(&format!(
202-
"\n\
203-
if (!isLikeNone({0})) {{\n\
204-
_assertNum({0});\n\
205-
}}\n\
202+
"
203+
if (!isLikeNone({0})) {{
204+
_assertNum({0});
205+
}}
206206
",
207207
name
208208
));
@@ -213,17 +213,17 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
213213
return Ok(self);
214214
}
215215

216-
if arg.is_as_u32() {
216+
if arg.is_abi_as_u32() {
217217
self.cx.expose_is_like_none();
218218
self.js_arguments.push((name.clone(), "number".to_string()));
219219

220220
if self.cx.config.debug {
221221
self.cx.expose_assert_num();
222222
self.prelude(&format!(
223-
"\n\
224-
if (!isLikeNone({0})) {{\n\
225-
_assertNum({0});\n\
226-
}}\n\
223+
"
224+
if (!isLikeNone({0})) {{
225+
_assertNum({0});
226+
}}
227227
",
228228
name
229229
));
@@ -243,10 +243,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
243243
self.cx.expose_global_argument_ptr()?;
244244
self.js_arguments.push((name.clone(), "BigInt".to_string()));
245245
self.prelude(&format!(
246-
"\
247-
{f}[0] = isLikeNone({name}) ? BigInt(0) : {name};\n\
248-
const low{i} = isLikeNone({name}) ? 0 : u32CvtShim[0];\n\
249-
const high{i} = isLikeNone({name}) ? 0 : u32CvtShim[1];\n\
246+
"
247+
{f}[0] = isLikeNone({name}) ? BigInt(0) : {name};
248+
const low{i} = isLikeNone({name}) ? 0 : u32CvtShim[0];
249+
const high{i} = isLikeNone({name}) ? 0 : u32CvtShim[1];
250250
",
251251
i = i,
252252
f = f,
@@ -317,10 +317,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
317317
self.cx.expose_global_argument_ptr()?;
318318
self.js_arguments.push((name.clone(), "BigInt".to_string()));
319319
self.prelude(&format!(
320-
"\
321-
{f}[0] = {name};\n\
322-
const low{i} = u32CvtShim[0];\n\
323-
const high{i} = u32CvtShim[1];\n\
320+
"
321+
{f}[0] = {name};
322+
const low{i} = u32CvtShim[0];
323+
const high{i} = u32CvtShim[1];
324324
",
325325
i = i,
326326
f = f,
@@ -415,7 +415,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
415415
}
416416

417417
if optional {
418-
if ty.is_primitive() {
418+
if ty.is_wasm_native() {
419419
self.ret_ty = "number".to_string();
420420
self.cx.expose_global_argument_ptr()?;
421421
self.cx.expose_uint32_memory();
@@ -429,11 +429,11 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
429429
self.prelude("const retptr = globalArgumentPtr();");
430430
self.rust_arguments.insert(0, "retptr".to_string());
431431
self.ret_expr = format!(
432-
"\
433-
RET;\n\
434-
const present = getUint32Memory()[retptr / 4];\n\
435-
const value = {mem}[retptr / {size} + 1];\n\
436-
return present === 0 ? undefined : value;\n\
432+
"
433+
RET;
434+
const present = getUint32Memory()[retptr / 4];
435+
const value = {mem}[retptr / {size} + 1];
436+
return present === 0 ? undefined : value;
437437
",
438438
size = match ty {
439439
Descriptor::I32 => 4,
@@ -453,7 +453,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
453453
return Ok(self);
454454
}
455455

456-
if ty.is_as_u32() {
456+
if ty.is_abi_as_u32() {
457457
self.ret_ty = "number".to_string();
458458
self.ret_expr = "
459459
const ret = RET;
@@ -475,11 +475,11 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
475475
self.prelude("const retptr = globalArgumentPtr();");
476476
self.rust_arguments.insert(0, "retptr".to_string());
477477
self.ret_expr = format!(
478-
"\
479-
RET;\n\
480-
const present = getUint32Memory()[retptr / 4];\n\
481-
const value = {}()[retptr / 8 + 1];\n\
482-
return present === 0 ? undefined : value;\n\
478+
"
479+
RET;
480+
const present = getUint32Memory()[retptr / 4];
481+
const value = {}()[retptr / 8 + 1];
482+
return present === 0 ? undefined : value;
483483
",
484484
f
485485
);

crates/cli-support/src/js/rust2js.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
132132
}
133133

134134
if optional {
135-
if arg.is_primitive() {
135+
if arg.is_wasm_native() {
136136
let value = self.shim_argument();
137137
self.js_arguments.push(format!(
138138
"{present} === 0 ? undefined : {value}",
@@ -142,7 +142,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
142142
return Ok(())
143143
}
144144

145-
if arg.is_as_u32() {
145+
if arg.is_abi_as_u32() {
146146
self.js_arguments.push(format!("{0} === 0xFFFFFF ? undefined : {0}", abi));
147147
return Ok(())
148148
}
@@ -158,10 +158,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
158158
let high = self.shim_argument();
159159
let name = format!("n{}", abi);
160160
self.prelude(&format!(
161-
"\
162-
u32CvtShim[0] = {present} === 0 ? 0 : {low};\n\
163-
u32CvtShim[1] = {present} === 0 ? 0 : {high};\n\
164-
const {name} = {present} === 0 ? undefined : {f}[0];\n\
161+
"
162+
u32CvtShim[0] = {present} === 0 ? 0 : {low};
163+
u32CvtShim[1] = {present} === 0 ? 0 : {high};
164+
const {name} = {present} === 0 ? undefined : {f}[0];
165165
",
166166
present = abi,
167167
low = low,
@@ -186,9 +186,9 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
186186
let name = format!("n{}", abi);
187187
self.prelude(&format!(
188188
"\
189-
u32CvtShim[0] = {low};\n\
190-
u32CvtShim[1] = {high};\n\
191-
const {name} = {f}[0];\n\
189+
u32CvtShim[0] = {low};
190+
u32CvtShim[1] = {high};
191+
const {name} = {f}[0];
192192
",
193193
low = abi,
194194
high = high,
@@ -358,7 +358,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
358358
return Ok(())
359359
}
360360
if optional {
361-
if ty.is_primitive() {
361+
if ty.is_wasm_native() {
362362
self.cx.expose_is_like_none();
363363
self.cx.expose_uint32_memory();
364364
match ty {
@@ -370,10 +370,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
370370
};
371371
self.shim_arguments.insert(0, "ret".to_string());
372372
self.ret_expr = format!(
373-
"\
374-
const val = JS;\n\
375-
getUint32Memory()[ret / 4] = !isLikeNone(val);\n\
376-
{mem}[ret / {size} + 1] = isLikeNone(val) ? 0 : val;\n\
373+
"
374+
const val = JS;
375+
getUint32Memory()[ret / 4] = !isLikeNone(val);
376+
{mem}[ret / {size} + 1] = isLikeNone(val) ? 0 : val;
377377
",
378378
size = match ty {
379379
Descriptor::I32 => 4,
@@ -393,7 +393,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
393393
return Ok(());
394394
}
395395

396-
if ty.is_as_u32() {
396+
if ty.is_abi_as_u32() {
397397
self.cx.expose_is_like_none();
398398
self.ret_expr = "
399399
const val = JS;
@@ -414,10 +414,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
414414
};
415415
self.shim_arguments.insert(0, "ret".to_string());
416416
self.ret_expr = format!(
417-
"\
418-
const val = JS;\n\
419-
getUint32Memory()[ret / 4] = !isLikeNone(val);\n\
420-
{}()[ret / 8 + 1] = isLikeNone(val) ? BigInt(0) : val;\n\
417+
"
418+
const val = JS;
419+
getUint32Memory()[ret / 4] = !isLikeNone(val);
420+
{}()[ret / 8 + 1] = isLikeNone(val) ? BigInt(0) : val;
421421
",
422422
f
423423
);

src/convert/impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct WasmOptional64 {
5656

5757
unsafe impl WasmAbi for WasmOptional64 {}
5858

59-
macro_rules! type_primitive {
59+
macro_rules! type_wasm_native {
6060
($($t:tt as $c:tt => $r:tt)*) => ($(
6161
impl IntoWasmAbi for $t {
6262
type Abi = $c;
@@ -103,7 +103,7 @@ macro_rules! type_primitive {
103103
)*)
104104
}
105105

106-
type_primitive!(
106+
type_wasm_native!(
107107
i32 as i32 => WasmOptionalI32
108108
isize as i32 => WasmOptionalI32
109109
u32 as u32 => WasmOptionalU32
@@ -112,7 +112,7 @@ type_primitive!(
112112
f64 as f64 => WasmOptionalF64
113113
);
114114

115-
macro_rules! type_as_u32 {
115+
macro_rules! type_abi_as_u32 {
116116
($($t:tt)*) => ($(
117117
impl IntoWasmAbi for $t {
118118
type Abi = u32;
@@ -140,7 +140,7 @@ macro_rules! type_as_u32 {
140140
)*)
141141
}
142142

143-
type_as_u32!(i8 u8 i16 u16);
143+
type_abi_as_u32!(i8 u8 i16 u16);
144144

145145
macro_rules! type_64 {
146146
($($t:tt)*) => ($(

0 commit comments

Comments
 (0)