Skip to content

Commit 2339d53

Browse files
authored
Change float32/float64 to f32/f64 in the C bindings generator. (bytecodealliance#916)
* Change float32/float64 to f32/f64 in the C bindings generator. Change float32/float64 to f32/f64 in the C bindings generator, in the `Instruction` enum, and in the tests. * Update test names in Go. * Update more tests.
1 parent 730113b commit 2339d53

File tree

27 files changed

+164
-168
lines changed

27 files changed

+164
-168
lines changed

crates/c/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ pub fn push_ty_name(resolve: &Resolve, ty: &Type, src: &mut String) {
731731
Type::S32 => src.push_str("s32"),
732732
Type::U64 => src.push_str("u64"),
733733
Type::S64 => src.push_str("s64"),
734-
Type::F32 => src.push_str("float32"),
735-
Type::F64 => src.push_str("float64"),
734+
Type::F32 => src.push_str("f32"),
735+
Type::F64 => src.push_str("f64"),
736736
Type::String => src.push_str("string"),
737737
Type::Id(id) => {
738738
let ty = &resolve.types[*id];
@@ -2264,10 +2264,10 @@ impl Bindgen for FunctionBindgen<'_, '_> {
22642264

22652265
// f32/f64 have the same representation in the import type and in C,
22662266
// so no conversions necessary.
2267-
Instruction::F32FromFloat32
2268-
| Instruction::F64FromFloat64
2269-
| Instruction::Float32FromF32
2270-
| Instruction::Float64FromF64 => {
2267+
Instruction::CoreF32FromF32
2268+
| Instruction::CoreF64FromF64
2269+
| Instruction::F32FromCoreF32
2270+
| Instruction::F64FromCoreF64 => {
22712271
results.push(operands[0].clone());
22722272
}
22732273

crates/core/src/abi.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ def_instruction! {
174174
/// This may be a noop for some implementations, but it's here in case the
175175
/// native language representation of `f32` is different than the wasm
176176
/// representation of `f32`.
177-
F32FromFloat32 : [1] => [1],
177+
CoreF32FromF32 : [1] => [1],
178178
/// Conversion an interface type `f64` value to a wasm `f64`.
179179
///
180180
/// This may be a noop for some implementations, but it's here in case the
181181
/// native language representation of `f64` is different than the wasm
182182
/// representation of `f64`.
183-
F64FromFloat64 : [1] => [1],
183+
CoreF64FromF64 : [1] => [1],
184184

185185
/// Converts a native wasm `i32` to an interface type `s8`.
186186
///
@@ -211,9 +211,9 @@ def_instruction! {
211211
/// It's safe to assume that the `i32` is indeed a valid unicode code point.
212212
CharFromI32 : [1] => [1],
213213
/// Converts a native wasm `f32` to an interface type `f32`.
214-
Float32FromF32 : [1] => [1],
214+
F32FromCoreF32 : [1] => [1],
215215
/// Converts a native wasm `f64` to an interface type `f64`.
216-
Float64FromF64 : [1] => [1],
216+
F64FromCoreF64 : [1] => [1],
217217

218218
/// Creates a `bool` from an `i32` input, trapping if the `i32` isn't
219219
/// zero or one.
@@ -1067,8 +1067,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
10671067
Type::S64 => self.emit(&I64FromS64),
10681068
Type::U64 => self.emit(&I64FromU64),
10691069
Type::Char => self.emit(&I32FromChar),
1070-
Type::F32 => self.emit(&F32FromFloat32),
1071-
Type::F64 => self.emit(&F64FromFloat64),
1070+
Type::F32 => self.emit(&CoreF32FromF32),
1071+
Type::F64 => self.emit(&CoreF64FromF64),
10721072
Type::String => {
10731073
let realloc = self.list_realloc();
10741074
self.emit(&StringLower { realloc });
@@ -1256,8 +1256,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
12561256
Type::S64 => self.emit(&S64FromI64),
12571257
Type::U64 => self.emit(&U64FromI64),
12581258
Type::Char => self.emit(&CharFromI32),
1259-
Type::F32 => self.emit(&Float32FromF32),
1260-
Type::F64 => self.emit(&Float64FromF64),
1259+
Type::F32 => self.emit(&F32FromCoreF32),
1260+
Type::F64 => self.emit(&F64FromCoreF64),
12611261
Type::String => self.emit(&StringLift),
12621262
Type::Id(id) => match &self.resolve.types[id].kind {
12631263
TypeDefKind::Type(t) => self.lift(t),

crates/csharp/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,10 +1779,10 @@ impl Bindgen for FunctionBindgen<'_, '_> {
17791779
| Instruction::I32FromU8
17801780
| Instruction::I32FromS8
17811781
| Instruction::I32FromS32
1782-
| Instruction::Float32FromF32
1783-
| Instruction::F32FromFloat32
1784-
| Instruction::F64FromFloat64
1785-
| Instruction::Float64FromF64
1782+
| Instruction::F32FromCoreF32
1783+
| Instruction::CoreF32FromF32
1784+
| Instruction::CoreF64FromF64
1785+
| Instruction::F64FromCoreF64
17861786
| Instruction::S32FromI32
17871787
| Instruction::S64FromI64 => results.push(operands[0].clone()),
17881788

crates/rust/src/bindgen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,16 @@ impl Bindgen for FunctionBindgen<'_, '_> {
345345
results.push(format!("{}({s})", self.gen.path_to_as_i32()));
346346
}
347347

348-
Instruction::F32FromFloat32 => {
348+
Instruction::CoreF32FromF32 => {
349349
let s = operands.pop().unwrap();
350350
results.push(format!("{}({s})", self.gen.path_to_as_f32()));
351351
}
352-
Instruction::F64FromFloat64 => {
352+
Instruction::CoreF64FromF64 => {
353353
let s = operands.pop().unwrap();
354354
results.push(format!("{}({s})", self.gen.path_to_as_f64()));
355355
}
356-
Instruction::Float32FromF32
357-
| Instruction::Float64FromF64
356+
Instruction::F32FromCoreF32
357+
| Instruction::F64FromCoreF64
358358
| Instruction::S32FromI32
359359
| Instruction::S64FromI64 => {
360360
results.push(operands.pop().unwrap());

crates/teavm-java/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,10 +1324,10 @@ impl Bindgen for FunctionBindgen<'_, '_> {
13241324
| Instruction::I32FromS32
13251325
| Instruction::I64FromS64
13261326
| Instruction::I64FromU64
1327-
| Instruction::F32FromFloat32
1328-
| Instruction::F64FromFloat64
1329-
| Instruction::Float32FromF32
1330-
| Instruction::Float64FromF64 => results.push(operands[0].clone()),
1327+
| Instruction::CoreF32FromF32
1328+
| Instruction::CoreF64FromF64
1329+
| Instruction::F32FromCoreF32
1330+
| Instruction::F64FromCoreF64 => results.push(operands[0].clone()),
13311331

13321332
Instruction::Bitcasts { casts } => results.extend(
13331333
casts

tests/codegen/floats.wit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package foo:foo;
22

33
interface floats {
4-
float32-param: func(x: float32);
5-
float64-param: func(x: float64);
6-
float32-result: func() -> float32;
7-
float64-result: func() -> float64;
4+
f32-param: func(x: f32);
5+
f64-param: func(x: f64);
6+
f32-result: func() -> f32;
7+
f64-result: func() -> f64;
88
}
99

1010
world the-world {

tests/codegen/issue573.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ world types-example {
108108
}
109109

110110
export f-f1: func(typedef: t10) -> t10;
111-
export f1: func(f: float32, f-list: list<tuple<char, float64>>) -> (val-p1: s64, val2: string);
111+
export f1: func(f: f32, f-list: list<tuple<char, f64>>) -> (val-p1: s64, val2: string);
112112
/// t2 has been renamed with `use self.types-interface.{t2 as t2-renamed}`
113113
export re-named: func(perm: option<permissions>, e: option<empty>) -> t2-renamed;
114114
export re-named2: func(tup: tuple<list<u16>>, e: empty) -> tuple<option<u8>, s8>;

tests/codegen/lists.wit

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface lists {
99
list-s16-param: func(x: list<s16>);
1010
list-s32-param: func(x: list<s32>);
1111
list-s64-param: func(x: list<s64>);
12-
list-float32-param: func(x: list<float32>);
13-
list-float64-param: func(x: list<float64>);
12+
list-f32-param: func(x: list<f32>);
13+
list-f64-param: func(x: list<f64>);
1414

1515
list-u8-ret: func() -> list<u8>;
1616
list-u16-ret: func() -> list<u16>;
@@ -20,8 +20,8 @@ interface lists {
2020
list-s16-ret: func() -> list<s16>;
2121
list-s32-ret: func() -> list<s32>;
2222
list-s64-ret: func() -> list<s64>;
23-
list-float32-ret: func() -> list<float32>;
24-
list-float64-ret: func() -> list<float64>;
23+
list-f32-ret: func() -> list<f32>;
24+
list-f64-ret: func() -> list<f64>;
2525

2626
tuple-list: func(x: list<tuple<u8, s8>>) -> list<tuple<s64, u32>>;
2727
string-list-arg: func(a: list<string>);
@@ -72,8 +72,8 @@ interface lists {
7272
s32,
7373
u64,
7474
s64,
75-
float32,
76-
float64,
75+
f32,
76+
f64,
7777
char,
7878
>>;
7979
load-store-everything: func(a: load-store-all-sizes) -> load-store-all-sizes;

tests/codegen/multi-return.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface multi-return {
55
mrb: func() -> ();
66
mrc: func() -> u32;
77
mrd: func() -> (a: u32);
8-
mre: func() -> (a: u32, b: float32);
8+
mre: func() -> (a: u32, b: f32);
99
}
1010

1111
world the-world {

tests/codegen/resources.wit

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package my:resources;
22

33
interface types {
44
resource z {
5-
constructor(a: float64);
5+
constructor(a: f64);
66
}
77
}
88

@@ -38,19 +38,19 @@ world resources {
3838

3939
export exports: interface {
4040
resource x {
41-
constructor(a: float64);
42-
get-a: func() -> float64;
43-
set-a: func(a: float64);
44-
add: static func(x: x, a: float64) -> x;
41+
constructor(a: f64);
42+
get-a: func() -> f64;
43+
set-a: func(a: f64);
44+
add: static func(x: x, a: f64) -> x;
4545
}
4646
}
4747

4848
import imports: interface {
4949
resource y {
50-
constructor(a: float64);
51-
get-a: func() -> float64;
52-
set-a: func(a: float64);
53-
add: static func(y: y, a: float64) -> y;
50+
constructor(a: f64);
51+
get-a: func() -> f64;
52+
set-a: func(a: f64);
53+
add: static func(y: y, a: f64) -> y;
5454
}
5555
}
5656
}

0 commit comments

Comments
 (0)