diff --git a/src/backend/binaryen/wasm_expr_gen.ts b/src/backend/binaryen/wasm_expr_gen.ts index d16f0e4a..73d1ae2f 100644 --- a/src/backend/binaryen/wasm_expr_gen.ts +++ b/src/backend/binaryen/wasm_expr_gen.ts @@ -77,6 +77,8 @@ import { SpreadValue, TemplateExprValue, EnumerateKeysGetValue, + VTableGetValue, + VTableSetValue, } from '../../semantics/value.js'; import { ArrayType, @@ -187,6 +189,8 @@ export class WASMExpressionGen { return this.wasmObjFieldSet(value); case SemanticsValueKind.OFFSET_SET: return this.wasmObjFieldSet(value); + case SemanticsValueKind.VTABLE_SET: + return this.wasmObjFieldSet(value); case SemanticsValueKind.NEW_LITERAL_OBJECT: return this.wasmNewLiteralObj(value); case SemanticsValueKind.OBJECT_CAST_OBJECT: @@ -200,6 +204,8 @@ export class WASMExpressionGen { case SemanticsValueKind.OFFSET_GETTER: case SemanticsValueKind.OFFSET_GET: return this.wasmObjFieldGet(value); + case SemanticsValueKind.VTABLE_GET: + return this.wasmObjFieldGet(value); case SemanticsValueKind.DYNAMIC_GET: return this.wasmDynamicGet(value); case SemanticsValueKind.DYNAMIC_SET: @@ -1796,7 +1802,7 @@ export class WASMExpressionGen { } private wasmObjFieldSet( - value: ShapeSetValue | OffsetSetValue, + value: ShapeSetValue | OffsetSetValue | VTableSetValue, rightValue?: SemanticsValue, ) { const owner = value.owner as VarValue; @@ -2387,7 +2393,7 @@ export class WASMExpressionGen { } private wasmObjFieldGet( - value: DirectGetValue | ShapeGetValue | OffsetGetValue, + value: DirectGetValue | ShapeGetValue | OffsetGetValue | VTableGetValue, ) { /* Workaround: ShapeGetValue's field index now based on its origin shape, not objectType */ const owner = value.owner; diff --git a/tests/samples/class_vtable_accessor.ts b/tests/samples/class_vtable_accessor.ts new file mode 100644 index 00000000..5b4a4322 --- /dev/null +++ b/tests/samples/class_vtable_accessor.ts @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +class A { + _ref: number; + get ref(): number { + return this._ref; + } + set ref(value: number) { + this._ref = value; + } + + constructor(ref_value: number) { + this._ref = ref_value; + } +} + +class B extends A { + printRef() { + console.log(this.ref); // vtable get + } + setRef() { + this.ref = 888; // vtable set + } + constructor(ref_value: number) { + super(ref_value); + } +} + +class C extends B { + private _C_ref = 100; + set ref(value: number) { + this._ref = value; + } + get ref(): number { + return this._C_ref; + } + + constructor(ref_value: number) { + super(ref_value); + } +} + +export function vtableAccessor() { + const instance = new B(90); + instance.printRef(); + instance.setRef(); + instance.printRef(); +} diff --git a/tools/validate/wamr/validation.json b/tools/validate/wamr/validation.json index 68a50e0d..480a9775 100644 --- a/tools/validate/wamr/validation.json +++ b/tools/validate/wamr/validation.json @@ -1750,6 +1750,16 @@ } ] }, + { + "module": "class_vtable_accessor", + "entries": [ + { + "name": "vtableAccessor", + "args": [], + "result": "90\n888" + } + ] + }, { "module": "class_vtable_call", "entries": [