Skip to content

Commit f1d8f48

Browse files
committed
Support anyref variable declarations as Wasm locals
1 parent 6fbc639 commit f1d8f48

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

NOTICE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ under the licensing terms detailed in LICENSE:
1717
* Bowen Wang <[email protected]>
1818
* Emil Laine <[email protected]>
1919
* Stephen Paul Weber <[email protected]>
20+
* Jay Phelps <[email protected]>
2021

2122
Portions of this software are derived from third-party works licensed under
2223
the following terms:
@@ -78,6 +79,7 @@ the following terms:
7879
Hauke Mehrtens
7980
Hiltjo Posthuma
8081
Isaac Dunham
82+
Jay Phelps
8183
Jaydeep Patil
8284
Jens Gustedt
8385
Jeremy Huntwork

src/flow.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export class Flow {
324324
case NativeType.F32: { temps = parentFunction.tempF32s; break; }
325325
case NativeType.F64: { temps = parentFunction.tempF64s; break; }
326326
case NativeType.V128: { temps = parentFunction.tempV128s; break; }
327+
case NativeType.Anyref: { temps = parentFunction.tempAnyrefs; break; }
327328
default: throw new Error("concrete type expected");
328329
}
329330
var local: Local;
@@ -395,6 +396,10 @@ export class Flow {
395396
temps = parentFunction.tempV128s || (parentFunction.tempV128s = []);
396397
break;
397398
}
399+
case NativeType.Anyref: {
400+
temps = parentFunction.tempAnyrefs || (parentFunction.tempAnyrefs = []);
401+
break;
402+
}
398403
default: throw new Error("concrete type expected");
399404
}
400405
assert(local.index >= 0);

src/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,10 @@ export class Module {
14231423
// TODO
14241424
return 0;
14251425
}
1426+
// Not possible to clone an anyref as it is opaque
1427+
case NativeType.Anyref: {
1428+
return 0;
1429+
}
14261430
default: {
14271431
throw new Error("concrete type expected");
14281432
}

src/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,7 @@ export class Function extends TypedElement {
29002900
tempF32s: Local[] | null = null;
29012901
tempF64s: Local[] | null = null;
29022902
tempV128s: Local[] | null = null;
2903+
tempAnyrefs: Local[] | null = null;
29032904

29042905
// used by flows to keep track of break labels
29052906
nextBreakId: i32 = 0;

tests/compiler/features/reference-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
export declare function external(a: anyref): anyref;
44

55
export function internal(a: anyref): anyref {
6-
return a;
6+
const b = external(a);
7+
return b;
78
}
89

910
// can use reflection to work with anyref values

0 commit comments

Comments
 (0)