_Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits");
-//typedef struct int64_tArray { uint32_t *len; /* len + 1 is data */ } int64_tArray;
-//typedef struct uint32_tArray { uint32_t *len; /* len + 1 is data */ } uint32_tArray;
-//typedef struct ptrArray { uint32_t *len; /* len + 1 is data */ } ptrArray;
-//typedef struct int8_tArray { uint32_t *len; /* len + 1 is data */ } int8_tArray;
typedef uint32_t int64_tArray;
typedef uint32_t int8_tArray;
typedef uint32_t uint32_tArray;
typedef bool jboolean;
+uint32_t __attribute__((visibility("default"))) TS_malloc(uint32_t size) {
+ return (uint32_t)MALLOC(size, "JS-Called malloc");
+}
+void __attribute__((visibility("default"))) TS_free(uint32_t ptr) {
+ FREE((void*)ptr);
+}
"""
self.hu_struct_file_prefix = f"""
return Math.ceil(value / 4) * 4;
}
-const encodeArray = (inputArray) => {
- const cArrayPointer = wasm.wasm_malloc((inputArray.length + 1) * 4);
- const arrayMemoryView = new Uint32Array(memory.buffer, cArrayPointer + 4, inputArray.length);
+const encodeUint8Array = (inputArray) => {
+ const cArrayPointer = wasm.TS_malloc(inputArray.length + 4);
+ const arrayLengthView = new Uint32Array(memory.buffer, cArrayPointer, 1);
+ arrayLengthView[0] = inputArray.length;
+ const arrayMemoryView = new Uint8Array(memory.buffer, cArrayPointer + 4, inputArray.length);
+ arrayMemoryView.set(inputArray);
+ return cArrayPointer;
+}
+
+const encodeUint32Array = (inputArray) => {
+ const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 4);
+ const arrayMemoryView = new Uint32Array(memory.buffer, cArrayPointer, inputArray.length);
arrayMemoryView.set(inputArray, 1);
arrayMemoryView[0] = inputArray.length;
return cArrayPointer;
// will free the underlying memory when it becomes unreachable instead of copying here.
const actualArray = actualArrayViewer.slice(0, arraySize);
if (free) {
- wasm.free(arrayPointer);
+ wasm.TS_free(arrayPointer);
}
return actualArray;
}
// will free the underlying memory when it becomes unreachable instead of copying here.
const actualArray = actualArrayViewer.slice(0, arraySize);
if (free) {
- wasm.free(arrayPointer);
+ wasm.TS_free(arrayPointer);
}
return actualArray;
}
const encodeString = (string) => {
// make malloc count divisible by 4
const memoryNeed = nextMultipleOfFour(string.length + 1);
- const stringPointer = wasm.wasm_malloc(memoryNeed);
+ const stringPointer = wasm.TS_malloc(memoryNeed);
const stringMemoryView = new Uint8Array(
memory.buffer, // value
stringPointer, // offset