Skip to content

Support anyref variable declartions as Wasm locals #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ under the licensing terms detailed in LICENSE:
* Bowen Wang <[email protected]>
* Emil Laine <[email protected]>
* Stephen Paul Weber <[email protected]>
* Jay Phelps <[email protected]>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
5 changes: 5 additions & 0 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export class Flow {
case NativeType.F32: { temps = parentFunction.tempF32s; break; }
case NativeType.F64: { temps = parentFunction.tempF64s; break; }
case NativeType.V128: { temps = parentFunction.tempV128s; break; }
case NativeType.Anyref: { temps = parentFunction.tempAnyrefs; break; }
default: throw new Error("concrete type expected");
}
var local: Local;
Expand Down Expand Up @@ -395,6 +396,10 @@ export class Flow {
temps = parentFunction.tempV128s || (parentFunction.tempV128s = []);
break;
}
case NativeType.Anyref: {
temps = parentFunction.tempAnyrefs || (parentFunction.tempAnyrefs = []);
break;
}
default: throw new Error("concrete type expected");
}
assert(local.index >= 0);
Expand Down
4 changes: 4 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ export class Module {
// TODO
return 0;
}
// Not possible to clone an anyref as it is opaque
case NativeType.Anyref: {
return 0;
}
default: {
throw new Error("concrete type expected");
}
Expand Down
1 change: 1 addition & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2900,6 +2900,7 @@ export class Function extends TypedElement {
tempF32s: Local[] | null = null;
tempF64s: Local[] | null = null;
tempV128s: Local[] | null = null;
tempAnyrefs: Local[] | null = null;

// used by flows to keep track of break labels
nextBreakId: i32 = 0;
Expand Down
5 changes: 4 additions & 1 deletion tests/compiler/features/reference-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
export declare function external(a: anyref): anyref;

export function internal(a: anyref): anyref {
return a;
const b = external(a);
let c = external(b);
var d = external(c);
return d;
}

// can use reflection to work with anyref values
Expand Down
14 changes: 13 additions & 1 deletion tests/compiler/features/reference-types.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
if
i32.const 0
i32.const 24
i32.const 16
i32.const 19
i32.const 0
call $~lib/builtins/abort
unreachable
Expand All @@ -45,7 +45,19 @@
call $~lib/bindings/console/log
)
(func $features/reference-types/internal (; 6 ;) (type $FUNCSIG$aa) (param $0 anyref) (result anyref)
(local $1 anyref)
(local $2 anyref)
(local $3 anyref)
local.get $0
call $features/reference-types/external
local.set $1
local.get $1
call $features/reference-types/external
local.set $2
local.get $2
call $features/reference-types/external
local.set $3
local.get $3
)
(func $start (; 7 ;) (type $FUNCSIG$v)
call $start:features/reference-types
Expand Down