Skip to content

Commit b8238f8

Browse files
committed
[TS] Enable support for 32-bit int arrays and new method calls
1 parent 0677450 commit b8238f8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ts/js-wasm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef uint32_t JSValue;
3939

4040
DECL_IMPORT(u, u, u, u, u, u)
4141
DECL_IMPORT(b, u, u, u, u, u)
42+
DECL_IMPORT(b, u, u, b, u, u)
43+
DECL_IMPORT(b, u, u, b, u, b)
4244
DECL_IMPORT(b, b, u, u, u, u)
4345
DECL_IMPORT(b, b, b, u, u, u)
4446
DECL_IMPORT(b, b, b, b, u, u)

typescript_strings.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
129129
isWasmInitialized = true;
130130
}
131131
132-
const fn_list = ["uuuuuu", "buuuuu", "bbuuuu", "bbbuuu", "bbbbuu", "bbbbbu",
132+
const fn_list = ["uuuuuu", "buuuuu", "buubuu", "buubub", "bbuuuu", "bbbuuu", "bbbbuu", "bbbbbu",
133133
"bbbbbb", "ubuubu", "ubuuuu", "ubbuuu", "uubuuu", "uubbuu", "uububu", "ububuu", "uuuubu"];
134134
135135
/* @internal */
@@ -290,6 +290,19 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
290290
return actualArray;
291291
}
292292
/* @internal */
293+
export function decodeUint32Array (arrayPointer: number, free = true): Uint32Array {
294+
const arraySize = getArrayLength(arrayPointer);
295+
const actualArrayViewer = new Uint32Array(wasm.memory.buffer, arrayPointer + 8, arraySize);
296+
// Clone the contents, TODO: In the future we should wrap the Viewer in a class that
297+
// will free the underlying memory when it becomes unreachable instead of copying here.
298+
// Note that doing so may have edge-case interactions with memory resizing (invalidating the buffer).
299+
const actualArray = actualArrayViewer.slice(0, arraySize);
300+
if (free) {
301+
wasm.TS_free(arrayPointer);
302+
}
303+
return actualArray;
304+
}
305+
/* @internal */
293306
export function decodeUint64Array (arrayPointer: number, free = true): BigUint64Array {
294307
const arraySize = getArrayLength(arrayPointer);
295308
const actualArrayViewer = new BigUint64Array(
@@ -954,6 +967,8 @@ def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name):
954967
return "const " + conv_name + ": Uint8Array = bindings.decodeUint8Array(" + arr_name + ");"
955968
elif mapped_ty.c_ty == "uint16_t" or mapped_ty.c_ty == "int16_t":
956969
return "const " + conv_name + ": Uint16Array = bindings.decodeUint16Array(" + arr_name + ");"
970+
elif mapped_ty.c_ty == "uint32_t" or mapped_ty.c_ty == "int32_t":
971+
return "const " + conv_name + ": Uint32Array = bindings.decodeUint32Array(" + arr_name + ");"
957972
elif mapped_ty.c_ty == "int64_t":
958973
return "const " + conv_name + ": BigInt64Array = bindings.decodeInt64Array(" + arr_name + ");"
959974
elif mapped_ty.c_ty == "uint64_t":

0 commit comments

Comments
 (0)