Skip to content

Commit

Permalink
Merge pull request #18 from lgxbslgx/ADJUST_WASM_RUNTIME
Browse files Browse the repository at this point in the history
  • Loading branch information
lynzrand authored Oct 21, 2024
2 parents adfe44a + bb00a61 commit d624e21
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions wasm_rt/runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,42 @@ let importObject = {
return ptr;
},
minimbt_create_array: (size, initial) => {
if (offset % 4 != 0) {
offset = Math.ceil(offset / 4) * 4
}
if (memory.buffer.byteLength < offset + size * 4) {
memory.grow(1)
}
let view = new Int32Array(memory, offset, size);
let view = new Int32Array(memory.buffer, offset, size);
view.fill(initial)
let ptr = offset
offset += size * 4
return ptr;
},
minimbt_create_float_array: (size, initial) => {
if (offset % 8 != 0) {
offset = Math.ceil(offset / 8) * 8
}
if (memory.buffer.byteLength < offset + size * 8) {
memory.grow(1)
}
let view = new Float64Array(memory, offset, size);
let view = new Float64Array(memory.buffer, offset, size);
view.fill(initial)
let ptr = offset
offset += size * 8
return ptr;
},
minimbt_create_ptr_array: (size, initial) => {
if (offset % 4 != 0) {
offset = Math.ceil(offset / 4) * 4
}
if (memory.buffer.byteLength < offset + size) {
memory.grow(1)
}
let view = new Uint32Array(memory, offset, size);
let view = new Uint32Array(memory.buffer, offset, size);
view.fill(initial >>> 0)
let ptr = offset
offset += size
offset += size * 4
return ptr;
},
minimbt_int_of_float: (f) => Math.trunc(f),
Expand Down

0 comments on commit d624e21

Please sign in to comment.