Skip to content

Commit

Permalink
Accept f32/f64 as aliases for float32/float64. (bytecodeallia…
Browse files Browse the repository at this point in the history
…nce#1356)

* Accept `f32`/`f64` as aliases for `float32`/`float64`.

In WebAssembly/component-model#277 there seems to be consensus emerging
to rename `float32`/`float64` to `f32`/`f64`. This PR just adds support
for parsing `f32`/`f64`, and changes nothing else for now, to start
preparing for this change.

* Add a test for `f32`/`f64`.
  • Loading branch information
sunfishcode authored Jan 5, 2024
1 parent a3f8c60 commit 0616ef1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 57 deletions.
4 changes: 2 additions & 2 deletions crates/wit-parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ impl<'a> Tokenizer<'a> {
"s16" => S16,
"s32" => S32,
"s64" => S64,
"float32" => Float32,
"float64" => Float64,
"f32" | "float32" => Float32,
"f64" | "float64" => Float64,
"char" => Char,
"resource" => Resource,
"own" => Own,
Expand Down
6 changes: 4 additions & 2 deletions crates/wit-parser/tests/ui/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ interface types {
type t6 = s16;
type t7 = s32;
type t8 = s64;
type t9 = float32;
type t10 = float64;
type t9a = float32;
type t9b = f32;
type t10a = float64;
type t10b = f64;
type t11 = char;
type t12 = list<char>;
type t13 = string;
Expand Down
126 changes: 73 additions & 53 deletions crates/wit-parser/tests/ui/types.wit.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,52 @@
"t6": 5,
"t7": 6,
"t8": 7,
"t9": 8,
"t10": 9,
"t11": 10,
"t12": 11,
"t13": 12,
"t14": 13,
"t15": 14,
"t16": 15,
"t17": 16,
"t18": 17,
"t20": 18,
"t21": 19,
"t22": 20,
"t23": 21,
"t24": 22,
"t25": 23,
"record": 24,
"t26": 25,
"t27": 26,
"t28": 27,
"t29": 28,
"t30": 29,
"t31": 30,
"t32": 31,
"t33": 32,
"t34": 33,
"t35": 34,
"t36": 35,
"t37": 37,
"t41": 38,
"t42": 39,
"t43": 40,
"t44": 41,
"t45": 44,
"t46": 45,
"t47": 46,
"t48": 47,
"t49": 48,
"t50": 49,
"t51": 50,
"t52": 51,
"t53": 52,
"bar": 53,
"foo": 54
"t9a": 8,
"t9b": 9,
"t10a": 10,
"t10b": 11,
"t11": 12,
"t12": 13,
"t13": 14,
"t14": 15,
"t15": 16,
"t16": 17,
"t17": 18,
"t18": 19,
"t20": 20,
"t21": 21,
"t22": 22,
"t23": 23,
"t24": 24,
"t25": 25,
"record": 26,
"t26": 27,
"t27": 28,
"t28": 29,
"t29": 30,
"t30": 31,
"t31": 32,
"t32": 33,
"t33": 34,
"t34": 35,
"t35": 36,
"t36": 37,
"t37": 39,
"t41": 40,
"t42": 41,
"t43": 42,
"t44": 43,
"t45": 46,
"t46": 47,
"t47": 48,
"t48": 49,
"t49": 50,
"t50": 51,
"t51": 52,
"t52": 53,
"t53": 54,
"bar": 55,
"foo": 56
},
"functions": {},
"package": 0
Expand Down Expand Up @@ -135,7 +137,7 @@
}
},
{
"name": "t9",
"name": "t9a",
"kind": {
"type": "float32"
},
Expand All @@ -144,7 +146,25 @@
}
},
{
"name": "t10",
"name": "t9b",
"kind": {
"type": "float32"
},
"owner": {
"interface": 0
}
},
{
"name": "t10a",
"kind": {
"type": "float64"
},
"owner": {
"interface": 0
}
},
{
"name": "t10b",
"kind": {
"type": "float64"
},
Expand Down Expand Up @@ -544,7 +564,7 @@
},
{
"name": "b",
"type": 36
"type": 38
}
]
}
Expand Down Expand Up @@ -616,21 +636,21 @@
{
"name": null,
"kind": {
"list": 31
"list": 33
},
"owner": null
},
{
"name": null,
"kind": {
"list": 42
"list": 44
},
"owner": null
},
{
"name": "t45",
"kind": {
"list": 43
"list": 45
},
"owner": {
"interface": 0
Expand All @@ -639,7 +659,7 @@
{
"name": "t46",
"kind": {
"type": 41
"type": 43
},
"owner": {
"interface": 0
Expand All @@ -648,7 +668,7 @@
{
"name": "t47",
"kind": {
"type": 41
"type": 43
},
"owner": {
"interface": 0
Expand Down Expand Up @@ -732,7 +752,7 @@
{
"name": "foo",
"kind": {
"type": 53
"type": 55
},
"owner": {
"interface": 0
Expand Down

0 comments on commit 0616ef1

Please sign in to comment.