Skip to content

Commit

Permalink
Rename f32/f64 to float32/float64 (bytecodealliance#198)
Browse files Browse the repository at this point in the history
* Rename f32/f64 to float32/float64

This commit renames the previously-known `f32` and `f64` interface types
to `float32` and `float64` to match the upstream specification.

* Fix a test
  • Loading branch information
alexcrichton authored and willemneal committed May 31, 2022
1 parent 647f72e commit 1247144
Show file tree
Hide file tree
Showing 73 changed files with 306 additions and 306 deletions.
16 changes: 8 additions & 8 deletions crates/gen-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ impl C {
Type::S32 => self.src.h("int32_t"),
Type::U64 => self.src.h("uint64_t"),
Type::S64 => self.src.h("int64_t"),
Type::F32 => self.src.h("float"),
Type::F64 => self.src.h("double"),
Type::Float32 => self.src.h("float"),
Type::Float64 => self.src.h("double"),
Type::Handle(id) => {
self.print_namespace(iface);
self.src.h(&iface.resources[*id].name.to_snake_case());
Expand Down Expand Up @@ -278,8 +278,8 @@ impl C {
Type::S32 => self.src.h("s32"),
Type::U64 => self.src.h("u64"),
Type::S64 => self.src.h("s64"),
Type::F32 => self.src.h("f32"),
Type::F64 => self.src.h("f64"),
Type::Float32 => self.src.h("float32"),
Type::Float64 => self.src.h("float64"),
Type::Handle(id) => self.src.h(&iface.resources[*id].name.to_snake_case()),
Type::Id(id) => {
let ty = &iface.types[*id];
Expand Down Expand Up @@ -1308,10 +1308,10 @@ impl Bindgen for FunctionBindgen<'_> {

// f32/f64 have the same representation in the import type and in C,
// so no conversions necessary.
Instruction::F32FromIf32
| Instruction::F64FromIf64
| Instruction::If32FromF32
| Instruction::If64FromF64 => {
Instruction::F32FromFloat32
| Instruction::F64FromFloat64
| Instruction::Float32FromF32
| Instruction::Float64FromF64 => {
results.push(operands[0].clone());
}

Expand Down
14 changes: 7 additions & 7 deletions crates/gen-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ impl Js {
Type::S32 => Some("Int32Array"),
Type::U64 => Some("BigUint64Array"),
Type::S64 => Some("BigInt64Array"),
Type::F32 => Some("Float32Array"),
Type::F64 => Some("Float64Array"),
Type::Float32 => Some("Float32Array"),
Type::Float64 => Some("Float64Array"),
Type::Char => None,
Type::Handle(_) => None,
Type::Id(id) => match &iface.types[*id].kind {
Expand All @@ -150,8 +150,8 @@ impl Js {
| Type::S16
| Type::U32
| Type::S32
| Type::F32
| Type::F64 => self.src.ts("number"),
| Type::Float32
| Type::Float64 => self.src.ts("number"),
Type::U64 | Type::S64 => self.src.ts("bigint"),
Type::Char => self.src.ts("string"),
Type::Handle(id) => self.src.ts(&iface.resources[*id].name.to_camel_case()),
Expand Down Expand Up @@ -1254,20 +1254,20 @@ impl Bindgen for FunctionBindgen<'_> {
// The native representation in JS of f32 and f64 is just a number,
// so there's nothing to do here. Everything wasm gives us is
// representable in JS.
Instruction::If32FromF32 | Instruction::If64FromF64 => {
Instruction::Float32FromF32 | Instruction::Float64FromF64 => {
results.push(operands.pop().unwrap())
}

// For f32 coming from the host we need to validate that the value
// is indeed a number and that the 32-bit value matches the
// original value.
Instruction::F32FromIf32 => {
Instruction::F32FromFloat32 => {
let validate = self.gen.intrinsic(Intrinsic::ValidateF32);
results.push(format!("{}({})", validate, operands[0]));
}

// Similar to f32, but no range checks, just checks it's a number
Instruction::F64FromIf64 => {
Instruction::F64FromFloat64 => {
let validate = self.gen.intrinsic(Intrinsic::ValidateF64);
results.push(format!("{}({})", validate, operands[0]));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/gen-markdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl Markdown {
Type::S32 => self.src.push_str("`s32`"),
Type::U64 => self.src.push_str("`u64`"),
Type::S64 => self.src.push_str("`s64`"),
Type::F32 => self.src.push_str("`f32`"),
Type::F64 => self.src.push_str("`f64`"),
Type::Float32 => self.src.push_str("`float32`"),
Type::Float64 => self.src.push_str("`float64`"),
Type::Char => self.src.push_str("`char`"),
Type::Handle(id) => {
self.src.push_str("handle<");
Expand Down
8 changes: 4 additions & 4 deletions crates/gen-rust-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,16 +865,16 @@ impl Bindgen for FunctionBindgen<'_> {
results.push(format!("wit_bindgen_rust::rt::as_i32({})", s));
}

Instruction::F32FromIf32 => {
Instruction::F32FromFloat32 => {
let s = operands.pop().unwrap();
results.push(format!("wit_bindgen_rust::rt::as_f32({})", s));
}
Instruction::F64FromIf64 => {
Instruction::F64FromFloat64 => {
let s = operands.pop().unwrap();
results.push(format!("wit_bindgen_rust::rt::as_f64({})", s));
}
Instruction::If32FromF32
| Instruction::If64FromF64
Instruction::Float32FromF32
| Instruction::Float64FromF64
| Instruction::S32FromI32
| Instruction::S64FromI64 => {
results.push(operands.pop().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions crates/gen-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ pub trait RustGenerator {
Type::S16 => self.push_str("i16"),
Type::S32 => self.push_str("i32"),
Type::S64 => self.push_str("i64"),
Type::F32 => self.push_str("f32"),
Type::F64 => self.push_str("f64"),
Type::Float32 => self.push_str("f32"),
Type::Float64 => self.push_str("f64"),
Type::Char => self.push_str("char"),
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/gen-spidermonkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,8 @@ impl abi::Bindgen for Bindgen<'_, '_> {
abi::Instruction::I32FromS16 => todo!(),
abi::Instruction::I32FromU8 => todo!(),
abi::Instruction::I32FromS8 => todo!(),
abi::Instruction::F32FromIf32 => todo!(),
abi::Instruction::F64FromIf64 => todo!(),
abi::Instruction::F32FromFloat32 => todo!(),
abi::Instruction::F64FromFloat64 => todo!(),
abi::Instruction::S8FromI32 => todo!(),
abi::Instruction::U8FromI32 => todo!(),
abi::Instruction::S16FromI32 => todo!(),
Expand All @@ -1501,8 +1501,8 @@ impl abi::Bindgen for Bindgen<'_, '_> {
abi::Instruction::S64FromI64 => todo!(),
abi::Instruction::U64FromI64 => todo!(),
abi::Instruction::CharFromI32 => todo!(),
abi::Instruction::If32FromF32 => todo!(),
abi::Instruction::If64FromF64 => todo!(),
abi::Instruction::Float32FromF32 => todo!(),
abi::Instruction::Float64FromF64 => todo!(),
abi::Instruction::I32FromBorrowedHandle { ty: _ } => todo!(),
abi::Instruction::I32FromOwnedHandle { ty: _ } => todo!(),
abi::Instruction::HandleOwnedFromI32 { ty: _ } => todo!(),
Expand Down
14 changes: 7 additions & 7 deletions crates/gen-wasmtime-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl WasmtimePy {
| Type::S32
| Type::U64
| Type::S64 => self.src.push_str("int"),
Type::F32 | Type::F64 => self.src.push_str("float"),
Type::Float32 | Type::Float64 => self.src.push_str("float"),
Type::Char => self.src.push_str("str"),
Type::Handle(id) => {
// In general we want to use quotes around this to support
Expand Down Expand Up @@ -499,8 +499,8 @@ impl WasmtimePy {
Type::S32 => Some("c_int32"),
Type::U64 => Some("c_uint64"),
Type::S64 => Some("c_int64"),
Type::F32 => Some("c_float"),
Type::F64 => Some("c_double"),
Type::Float32 => Some("c_float"),
Type::Float64 => Some("c_double"),
Type::Char => None,
Type::Handle(_) => None,
Type::Id(id) => match &iface.types[*id].kind {
Expand Down Expand Up @@ -1375,10 +1375,10 @@ impl Bindgen for FunctionBindgen<'_> {

// Python uses `float` for f32/f64, so everything is equivalent
// here.
Instruction::If32FromF32
| Instruction::If64FromF64
| Instruction::F32FromIf32
| Instruction::F64FromIf64 => results.push(operands.pop().unwrap()),
Instruction::Float32FromF32
| Instruction::Float64FromF64
| Instruction::F32FromFloat32
| Instruction::F64FromFloat64 => results.push(operands.pop().unwrap()),

// Validate that i32 values coming from wasm are indeed valid code
// points.
Expand Down
8 changes: 4 additions & 4 deletions crates/gen-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,10 +1441,10 @@ impl Bindgen for FunctionBindgen<'_> {
results.push(format!("wit_bindgen_wasmtime::rt::as_i32({})", s));
}

Instruction::F32FromIf32
| Instruction::F64FromIf64
| Instruction::If32FromF32
| Instruction::If64FromF64
Instruction::F32FromFloat32
| Instruction::F64FromFloat64
| Instruction::Float32FromF32
| Instruction::Float64FromF64
| Instruction::S32FromI32
| Instruction::S64FromI64 => {
results.push(operands.pop().unwrap());
Expand Down
28 changes: 14 additions & 14 deletions crates/parser/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ def_instruction! {
/// This may be a noop for some implementations, but it's here in case the
/// native language representation of `f32` is different than the wasm
/// representation of `f32`.
F32FromIf32 : [1] => [1],
F32FromFloat32 : [1] => [1],
/// Conversion an interface type `f64` value to a wasm `f64`.
///
/// This may be a noop for some implementations, but it's here in case the
/// native language representation of `f64` is different than the wasm
/// representation of `f64`.
F64FromIf64 : [1] => [1],
F64FromFloat64 : [1] => [1],

/// Converts a native wasm `i32` to an interface type `s8`.
///
Expand Down Expand Up @@ -245,9 +245,9 @@ def_instruction! {
/// It's safe to assume that the `i32` is indeed a valid unicode code point.
CharFromI32 : [1] => [1],
/// Converts a native wasm `f32` to an interface type `f32`.
If32FromF32 : [1] => [1],
Float32FromF32 : [1] => [1],
/// Converts a native wasm `f64` to an interface type `f64`.
If64FromF64 : [1] => [1],
Float64FromF64 : [1] => [1],

// Handles

Expand Down Expand Up @@ -847,8 +847,8 @@ impl Interface {
| Type::Handle(_) => result.push(WasmType::I32),

Type::U64 | Type::S64 => result.push(WasmType::I64),
Type::F32 => result.push(WasmType::F32),
Type::F64 => result.push(WasmType::F64),
Type::Float32 => result.push(WasmType::F32),
Type::Float64 => result.push(WasmType::F64),

Type::Id(id) => match &self.types[*id].kind {
TypeDefKind::Type(t) => self.push_wasm(variant, t, result),
Expand Down Expand Up @@ -1298,8 +1298,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
Type::S64 => self.emit(&I64FromS64),
Type::U64 => self.emit(&I64FromU64),
Type::Char => self.emit(&I32FromChar),
Type::F32 => self.emit(&F32FromIf32),
Type::F64 => self.emit(&F64FromIf64),
Type::Float32 => self.emit(&F32FromFloat32),
Type::Float64 => self.emit(&F64FromFloat64),
Type::Handle(ty) => {
let borrowed = match self.lift_lower {
// This means that a return value is being lowered, which is
Expand Down Expand Up @@ -1472,8 +1472,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
Type::S64 => self.emit(&S64FromI64),
Type::U64 => self.emit(&U64FromI64),
Type::Char => self.emit(&CharFromI32),
Type::F32 => self.emit(&If32FromF32),
Type::F64 => self.emit(&If64FromF64),
Type::Float32 => self.emit(&Float32FromF32),
Type::Float64 => self.emit(&Float64FromF64),
Type::Handle(ty) => {
// For more information on these values see the comments in
// `lower` above.
Expand Down Expand Up @@ -1607,8 +1607,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
self.lower_and_emit(ty, addr, &I32Store { offset })
}
Type::U64 | Type::S64 => self.lower_and_emit(ty, addr, &I64Store { offset }),
Type::F32 => self.lower_and_emit(ty, addr, &F32Store { offset }),
Type::F64 => self.lower_and_emit(ty, addr, &F64Store { offset }),
Type::Float32 => self.lower_and_emit(ty, addr, &F32Store { offset }),
Type::Float64 => self.lower_and_emit(ty, addr, &F64Store { offset }),

Type::Id(id) => match &self.iface.types[id].kind {
TypeDefKind::Type(t) => self.write_to_memory(t, addr, offset),
Expand Down Expand Up @@ -1719,8 +1719,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
self.emit_and_lift(ty, addr, &I32Load { offset })
}
Type::U64 | Type::S64 => self.emit_and_lift(ty, addr, &I64Load { offset }),
Type::F32 => self.emit_and_lift(ty, addr, &F32Load { offset }),
Type::F64 => self.emit_and_lift(ty, addr, &F64Load { offset }),
Type::Float32 => self.emit_and_lift(ty, addr, &F32Load { offset }),
Type::Float64 => self.emit_and_lift(ty, addr, &F64Load { offset }),

Type::Id(id) => match &self.iface.types[id].kind {
TypeDefKind::Type(t) => self.read_from_memory(t, addr, offset),
Expand Down
8 changes: 4 additions & 4 deletions crates/parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ enum Type<'a> {
S16,
S32,
S64,
F32,
F64,
Float32,
Float64,
Char,
Handle(Id<'a>),
Name(Id<'a>),
Expand Down Expand Up @@ -492,8 +492,8 @@ impl<'a> Type<'a> {
Some((_span, Token::S16)) => Ok(Type::S16),
Some((_span, Token::S32)) => Ok(Type::S32),
Some((_span, Token::S64)) => Ok(Type::S64),
Some((_span, Token::F32)) => Ok(Type::F32),
Some((_span, Token::F64)) => Ok(Type::F64),
Some((_span, Token::Float32)) => Ok(Type::Float32),
Some((_span, Token::Float64)) => Ok(Type::Float64),
Some((_span, Token::Char)) => Ok(Type::Char),
Some((_span, Token::Handle)) => {
let name = parse_id(tokens)?;
Expand Down
12 changes: 6 additions & 6 deletions crates/parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub enum Token {
S16,
S32,
S64,
F32,
F64,
Float32,
Float64,
Char,
Handle,
Record,
Expand Down Expand Up @@ -245,8 +245,8 @@ impl<'a> Tokenizer<'a> {
"s16" => S16,
"s32" => S32,
"s64" => S64,
"f32" => F32,
"f64" => F64,
"float32" => Float32,
"float64" => Float64,
"char" => Char,
"handle" => Handle,
"record" => Record,
Expand Down Expand Up @@ -506,8 +506,8 @@ impl Token {
S16 => "keyword `s16`",
S32 => "keyword `s32`",
S64 => "keyword `s64`",
F32 => "keyword `f32`",
F64 => "keyword `f64`",
Float32 => "keyword `float32`",
Float64 => "keyword `float64`",
Char => "keyword `char`",
Handle => "keyword `handle`",
Record => "keyword `record`",
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/src/ast/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ impl Resolver {
super::Type::S16 => TypeDefKind::Type(Type::S16),
super::Type::S32 => TypeDefKind::Type(Type::S32),
super::Type::S64 => TypeDefKind::Type(Type::S64),
super::Type::F32 => TypeDefKind::Type(Type::F32),
super::Type::F64 => TypeDefKind::Type(Type::F64),
super::Type::Float32 => TypeDefKind::Type(Type::Float32),
super::Type::Float64 => TypeDefKind::Type(Type::Float64),
super::Type::Char => TypeDefKind::Type(Type::Char),
super::Type::Handle(resource) => {
let id = match self.resource_lookup.get(&*resource.name) {
Expand Down
8 changes: 4 additions & 4 deletions crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub enum Type {
S16,
S32,
S64,
F32,
F64,
Float32,
Float64,
Char,
Handle(ResourceId),
Id(TypeId),
Expand Down Expand Up @@ -430,8 +430,8 @@ impl Interface {
| Type::S32
| Type::U64
| Type::S64
| Type::F32
| Type::F64 => true,
| Type::Float32
| Type::Float64 => true,

Type::Char | Type::Handle(_) => false,

Expand Down
8 changes: 4 additions & 4 deletions crates/parser/src/sizealign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl SizeAlign {
match ty {
Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::F64 => 8,
Type::U32 | Type::S32 | Type::Float32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::Float64 => 8,
Type::Id(id) => self.map[id.index()].0,
}
}
Expand All @@ -70,8 +70,8 @@ impl SizeAlign {
match ty {
Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::F64 => 8,
Type::U32 | Type::S32 | Type::Float32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::Float64 => 8,
Type::Id(id) => self.map[id.index()].1,
}
}
Expand Down
Loading

0 comments on commit 1247144

Please sign in to comment.