Skip to content
Open
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
10 changes: 5 additions & 5 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,11 +1663,10 @@ BinaryenExpressionRef BinaryenPop(BinaryenModuleRef module, BinaryenType type) {
}

BinaryenExpressionRef BinaryenRefNull(BinaryenModuleRef module,
BinaryenType type) {
Type type_(type);
assert(type_.isNullable());
BinaryenHeapType heaptype) {
HeapType heaptype_(heaptype);
return static_cast<Expression*>(
Builder(*(Module*)module).makeRefNull(type_.getHeapType()));
Builder(*(Module*)module).makeRefNull(heaptype_));
}

BinaryenExpressionRef BinaryenRefIsNull(BinaryenModuleRef module,
Expand Down Expand Up @@ -1741,7 +1740,8 @@ BinaryenExpressionRef BinaryenTableGrow(BinaryenModuleRef module,
BinaryenExpressionRef delta) {
if (value == nullptr) {
auto tableType = (*(Module*)module).getTableOrNull(name)->type;
value = BinaryenRefNull(module, (BinaryenType)tableType.getID());
value = BinaryenRefNull(module,
(BinaryenHeapType)tableType.getHeapType().getID());
}
return static_cast<Expression*>(
Builder(*(Module*)module)
Expand Down
24 changes: 22 additions & 2 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ function initializeConstants() {
Module[entry[0]] = Module['_BinaryenType' + entry[1]]();
});

[
['func', 'Func'],
['extern', 'Ext'],
['any', 'Any'],
['eq', 'Eq'],
['i31', 'I31'],
['struct', 'Struct'],
['array', 'Array'],
['string', 'String'],
/*
TODO: Reconcile with `none` above (line 32).
Maybe keep this as 'none' and change the above to 'void'?
['none', 'None'],
*/
Comment on lines +64 to +68

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine to uncomment because it will create _BinaryenHeapTypeNone, which will not conflict with _BinaryenTypeNone. I agree it's confusing, but Binaryen's none type predates the standard none heap type by many years, and it's not clear that renaming it would be worth the churn.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment it then wouldn’t it override the existing 'none' property on Module?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Yeah, that's unfortunate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah so I think for this PR I can leave the comment as is, but maybe we want to open a separate issue/discussion on the 'none'. What do maintainers think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds fine to me.

['noextern', 'Noext'],
['nofunc', 'Nofunc'],
].forEach(entry => {
Module[entry[0]] = Module['_BinaryenHeapType' + entry[1]]();
});

[ ['notPacked', 'NotPacked'],
['i8', 'Int8'],
['i16', 'Int16']
Expand Down Expand Up @@ -2438,8 +2458,8 @@ function wrapModule(module, self = {}) {
};

self['ref'] = {
'null'(type) {
return Module['_BinaryenRefNull'](module, type);
'null'(heaptype) {
return Module['_BinaryenRefNull'](module, heaptype);
},
'is_null'(value) {
return Module['_BinaryenRefIsNull'](module, value);
Expand Down
8 changes: 4 additions & 4 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,13 @@ function test_core() {
module.return_call_indirect("t0", makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32),

// Reference types
module.ref.is_null(module.ref.null(binaryen.externref)),
module.ref.is_null(module.ref.null(binaryen.funcref)),
module.ref.is_null(module.ref.null(binaryen.extern)),
module.ref.is_null(module.ref.null(binaryen.func)),
module.ref.is_null(module.ref.func("foobar", foobarType)),
module.select(temp10, module.ref.null(binaryen.funcref), module.ref.func("foobar", foobarType)),
module.select(temp10, module.ref.null(binaryen.func), module.ref.func("foobar", foobarType)),

// GC
module.ref.eq(module.ref.null(binaryen.eqref), module.ref.null(binaryen.eqref)),
module.ref.eq(module.ref.null(binaryen.eq), module.ref.null(binaryen.eq)),

// Exception handling
module.try(
Expand Down
20 changes: 10 additions & 10 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ void test_core() {
temp15 = makeInt32(module, 110),
temp16 = makeInt64(module, 111);
BinaryenExpressionRef externrefExpr =
BinaryenRefNull(module, BinaryenTypeNullExternref());
BinaryenRefNull(module, BinaryenHeapTypeNoext());
BinaryenExpressionRef funcrefExpr =
BinaryenRefNull(module, BinaryenTypeNullFuncref());
BinaryenRefNull(module, BinaryenHeapTypeNofunc());
funcrefExpr =
BinaryenRefFunc(module, "kitchen()sinker", kitchenSinkerRefType);
BinaryenExpressionRef i31refExpr =
Expand Down Expand Up @@ -1065,21 +1065,21 @@ void test_core() {
BinaryenSelect(
module,
temp10,
BinaryenRefNull(module, BinaryenTypeNullFuncref()),
BinaryenRefNull(module, BinaryenHeapTypeNofunc()),
BinaryenRefFunc(module, "kitchen()sinker", kitchenSinkerRefType)),
// GC
BinaryenRefEq(module,
BinaryenRefNull(module, BinaryenTypeNullref()),
BinaryenRefNull(module, BinaryenTypeNullref())),
BinaryenRefNull(module, BinaryenHeapTypeNone()),
BinaryenRefNull(module, BinaryenHeapTypeNone())),
BinaryenRefAs(module,
BinaryenRefAsNonNull(),
BinaryenRefNull(module, BinaryenTypeNullref())),
BinaryenRefNull(module, BinaryenHeapTypeNone())),
BinaryenRefAs(module,
BinaryenRefAsAnyConvertExtern(),
BinaryenRefNull(module, BinaryenTypeNullExternref())),
BinaryenRefNull(module, BinaryenHeapTypeNoext())),
BinaryenRefAs(module,
BinaryenRefAsExternConvertAny(),
BinaryenRefNull(module, BinaryenTypeNullref())),
BinaryenRefNull(module, BinaryenHeapTypeNone())),
// Exception handling
BinaryenTry(module, NULL, tryBody, catchTags, 1, catchBodies, 2, NULL),
// (try $try_outer
Expand Down Expand Up @@ -1360,7 +1360,7 @@ void test_core() {
BinaryenArrayNew(module,
BinaryenTypeGetHeapType(funcArray),
makeInt32(module, 0),
BinaryenRefNull(module, BinaryenTypeNullFuncref())));
BinaryenRefNull(module, BinaryenHeapTypeNofunc())));
BinaryenAddGlobal(
module,
"i32Struct-global",
Expand Down Expand Up @@ -1429,7 +1429,7 @@ void test_core() {
BinaryenTableSizeSetTable(tablesize, table);

BinaryenExpressionRef valueExpr =
BinaryenRefNull(module, BinaryenTypeNullFuncref());
BinaryenRefNull(module, BinaryenHeapTypeNofunc());
BinaryenExpressionRef sizeExpr = makeInt32(module, 0);
BinaryenExpressionRef growExpr =
BinaryenTableGrow(module, "0", valueExpr, sizeExpr);
Expand Down
Loading