Skip to content

Commit 3cfe756

Browse files
committed
integrate #2531, prepare types
1 parent bc461ae commit 3cfe756

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

src/glue/binaryen.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export declare function _BinaryenTypeStringref(): TypeRef;
6060
export declare function _BinaryenTypeStringviewWTF8(): TypeRef;
6161
export declare function _BinaryenTypeStringviewWTF16(): TypeRef;
6262
export declare function _BinaryenTypeStringviewIter(): TypeRef;
63+
export declare function _BinaryenTypeNullref(): TypeRef;
64+
export declare function _BinaryenTypeNullExternref(): TypeRef;
65+
export declare function _BinaryenTypeNullFuncref(): TypeRef;
6366

6467
export declare function _BinaryenHeapTypeFunc(): HeapTypeRef;
6568
export declare function _BinaryenHeapTypeExt(): HeapTypeRef;
@@ -594,7 +597,7 @@ export declare function _BinaryenStructSetSetValue(expr: ExpressionRef, valueExp
594597
export declare function _BinaryenArrayNew(module: ModuleRef, type: HeapTypeRef, size: ExpressionRef, init: ExpressionRef): ExpressionRef;
595598
export declare function _BinaryenArrayNewGetInit(expr: ExpressionRef): ExpressionRef;
596599
export declare function _BinaryenArrayNewSetInit(expr: ExpressionRef, initExpr: ExpressionRef): void;
597-
export declare function _BinaryenArrayNewGetSize(expr: ExpressionRef): ExpressionRef;
600+
export declare function _BinaryenArrayNewGetSize(expr: ExpressionRef): ExpressionRef;
598601
export declare function _BinaryenArrayNewSetSize(expr: ExpressionRef, sizeExpr: ExpressionRef): void;
599602

600603
export declare function _BinaryenArrayInit(module: ModuleRef, type: HeapTypeRef, values: ArrayRef<ExpressionRef>, numValues: Index): ExpressionRef;
@@ -605,7 +608,7 @@ export declare function _BinaryenArrayInitAppendValue(expr: ExpressionRef, value
605608
export declare function _BinaryenArrayInitInsertValueAt(expr: ExpressionRef, index: Index, valueExpr: ExpressionRef): void;
606609
export declare function _BinaryenArrayInitRemoveValueAt(expr: ExpressionRef, index: Index): ExpressionRef;
607610

608-
export declare function _BinaryenArrayGet(module: ModuleRef, ref: ExpressionRef, index: ExpressionRef, signed: bool): ExpressionRef;
611+
export declare function _BinaryenArrayGet(module: ModuleRef, ref: ExpressionRef, index: ExpressionRef, type: TypeRef, signed: bool): ExpressionRef;
609612
export declare function _BinaryenArrayGetGetRef(expr: ExpressionRef): ExpressionRef;
610613
export declare function _BinaryenArrayGetSetRef(expr: ExpressionRef, refExpr: ExpressionRef): void;
611614
export declare function _BinaryenArrayGetGetIndex(expr: ExpressionRef): ExpressionRef;

src/glue/binaryen.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export const {
2323
_BinaryenTypeStringviewWTF8,
2424
_BinaryenTypeStringviewWTF16,
2525
_BinaryenTypeStringviewIter,
26+
_BinaryenTypeNullref,
27+
_BinaryenTypeNullExternref,
28+
_BinaryenTypeNullFuncref,
2629

2730
_BinaryenHeapTypeFunc,
2831
_BinaryenHeapTypeExt,

src/module.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,47 @@ export namespace TypeRef {
8181
export const StringviewWTF8 = binaryen._BinaryenTypeStringviewWTF8();
8282
export const StringviewWTF16 = binaryen._BinaryenTypeStringviewWTF16();
8383
export const StringviewIter = binaryen._BinaryenTypeStringviewIter();
84+
// bottom types
85+
export const Noneref = binaryen._BinaryenTypeNullref();
86+
export const Nofuncref = binaryen._BinaryenTypeNullFuncref();
87+
export const Noexternref = binaryen._BinaryenTypeNullExternref();
8488

8589
export const Auto: TypeRef = -1 /* _BinaryenTypeAuto */;
8690
}
8791

8892
/** Reference to a Binaryen heap type. */
8993
export type HeapTypeRef = binaryen.HeapTypeRef;
9094
export namespace HeapTypeRef {
95+
96+
// any extern func
97+
// | | |
98+
// __ eq __ noextern (...)
99+
// / | \ |
100+
// i31 struct array nofunc
101+
// | | |
102+
// none (...) (...)
103+
// | |
104+
// none none
105+
//
106+
// where (...) represents the concrete subtypes
107+
91108
// reference & GC heap types
92-
export const Ext: HeapTypeRef = binaryen._BinaryenHeapTypeExt();
109+
export const Extern: HeapTypeRef = binaryen._BinaryenHeapTypeExt();
93110
export const Func: HeapTypeRef = binaryen._BinaryenHeapTypeFunc();
94111
export const Any: HeapTypeRef = binaryen._BinaryenHeapTypeAny();
95112
export const Eq: HeapTypeRef = binaryen._BinaryenHeapTypeEq();
96113
export const I31: HeapTypeRef = binaryen._BinaryenHeapTypeI31();
97-
export const Data: HeapTypeRef = binaryen._BinaryenHeapTypeData();
114+
export const Data: HeapTypeRef = binaryen._BinaryenHeapTypeData(); // TODO: struct
115+
// export const Array: HeapTypeRef = binaryen._BinaryenHeapTypeArray(); // TODO
98116
// string heap types
99117
export const String: HeapTypeRef = binaryen._BinaryenHeapTypeString();
100118
export const StringviewWTF8: HeapTypeRef = binaryen._BinaryenHeapTypeStringviewWTF8();
101119
export const StringviewWTF16: HeapTypeRef = binaryen._BinaryenHeapTypeStringviewWTF16();
102120
export const StringviewIter: HeapTypeRef = binaryen._BinaryenHeapTypeStringviewIter();
121+
// bottom heap types
122+
export const None: HeapTypeRef = 10; /* TODO_BinaryenHeapTypeNone */
123+
export const Noextern: HeapTypeRef = 11; /* TODO_BinaryenHeapTypeNoext */
124+
export const Nofunc: HeapTypeRef = 12; /* TODO_BinaryenHeapTypeNofunc */
103125
}
104126

105127
/** Packed array element respectively struct field types. */
@@ -3699,7 +3721,7 @@ function tryEnsureBasicType(type: Type): TypeRef {
36993721
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, type.is(TypeFlags.NULLABLE));
37003722
}
37013723
case TypeKind.EXTERNREF: {
3702-
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Ext, type.is(TypeFlags.NULLABLE));
3724+
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Extern, type.is(TypeFlags.NULLABLE));
37033725
}
37043726
case TypeKind.ANYREF: {
37053727
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, type.is(TypeFlags.NULLABLE));

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ export class Type {
607607
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Func, this.is(TypeFlags.NULLABLE));
608608
}
609609
case TypeKind.EXTERNREF: {
610-
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Ext, this.is(TypeFlags.NULLABLE));
610+
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Extern, this.is(TypeFlags.NULLABLE));
611611
}
612612
case TypeKind.ANYREF: {
613613
return binaryen._BinaryenTypeFromHeapType(HeapTypeRef.Any, this.is(TypeFlags.NULLABLE));

0 commit comments

Comments
 (0)