mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 16:01:30 +00:00
Rename memory instructions; Rework constant handling
This commit is contained in:
@ -36,8 +36,8 @@ export function weakHeapSort<T>(arr: Array<T>, comparator: (a: T, b: T) => i32):
|
||||
|
||||
var length = arr.length;
|
||||
var bitsetSize = (length + 31) >> 5 << shift32;
|
||||
var bitset = allocate_memory(bitsetSize); // indexed in 32-bit chunks below
|
||||
set_memory(bitset, 0, bitsetSize);
|
||||
var bitset = memory.allocate(bitsetSize); // indexed in 32-bit chunks below
|
||||
memory.fill(bitset, 0, bitsetSize);
|
||||
|
||||
// see: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.1863&rep=rep1&type=pdf
|
||||
|
||||
@ -83,7 +83,7 @@ export function weakHeapSort<T>(arr: Array<T>, comparator: (a: T, b: T) => i32):
|
||||
}
|
||||
}
|
||||
|
||||
free_memory(bitset);
|
||||
memory.free(bitset);
|
||||
|
||||
var t = loadUnsafe<T,T>(buffer, 1); // t = arr[1]
|
||||
storeUnsafe<T,T>(buffer, 1, loadUnsafe<T,T>(buffer, 0)); // arr[1] = arr[0]
|
||||
|
@ -20,7 +20,7 @@ export function computeSize(byteLength: i32): usize {
|
||||
/** Allocates a raw ArrayBuffer. Contents remain uninitialized. */
|
||||
export function allocUnsafe(byteLength: i32): ArrayBuffer {
|
||||
assert(<u32>byteLength <= <u32>MAX_BLENGTH);
|
||||
var buffer = allocate_memory(computeSize(byteLength));
|
||||
var buffer = memory.allocate(computeSize(byteLength));
|
||||
store<i32>(buffer, byteLength, offsetof<ArrayBuffer>("byteLength"));
|
||||
return changetype<ArrayBuffer>(buffer);
|
||||
}
|
||||
@ -32,19 +32,19 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf
|
||||
assert(newByteLength <= MAX_BLENGTH);
|
||||
if (newByteLength <= <i32>(computeSize(oldByteLength) - HEADER_SIZE)) { // fast path: zero out additional space
|
||||
store<i32>(changetype<usize>(buffer), newByteLength, offsetof<ArrayBuffer>("byteLength"));
|
||||
set_memory(
|
||||
memory.fill(
|
||||
changetype<usize>(buffer) + HEADER_SIZE + <usize>oldByteLength,
|
||||
0,
|
||||
<usize>(newByteLength - oldByteLength)
|
||||
);
|
||||
} else { // slow path: copy to new buffer
|
||||
let newBuffer = allocUnsafe(newByteLength);
|
||||
move_memory(
|
||||
memory.copy(
|
||||
changetype<usize>(newBuffer) + HEADER_SIZE,
|
||||
changetype<usize>(buffer) + HEADER_SIZE,
|
||||
<usize>oldByteLength
|
||||
);
|
||||
set_memory(
|
||||
memory.fill(
|
||||
changetype<usize>(newBuffer) + HEADER_SIZE + <usize>oldByteLength,
|
||||
0,
|
||||
<usize>(newByteLength - oldByteLength)
|
||||
|
@ -23,7 +23,7 @@ export function clamp<T>(val: T, lo: T, hi: T): T {
|
||||
/** Allocates a raw String with uninitialized contents. */
|
||||
export function allocate(length: i32): String {
|
||||
assert(length > 0 && length <= MAX_LENGTH);
|
||||
var buffer = allocate_memory(HEADER_SIZE + (<usize>length << 1));
|
||||
var buffer = memory.allocate(HEADER_SIZE + (<usize>length << 1));
|
||||
store<i32>(buffer, length);
|
||||
return changetype<String>(buffer);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ export abstract class TypedArray<T,V> {
|
||||
if (<u32>length > MAX_LENGTH) throw new RangeError("Invalid typed array length");
|
||||
var byteLength = length << alignof<T>();
|
||||
var buffer = allocUnsafe(byteLength);
|
||||
set_memory(changetype<usize>(buffer) + HEADER_SIZE_AB, 0, <usize>byteLength);
|
||||
memory.fill(changetype<usize>(buffer) + HEADER_SIZE_AB, 0, <usize>byteLength);
|
||||
this.buffer = buffer;
|
||||
this.byteOffset = 0;
|
||||
this.byteLength = byteLength;
|
||||
@ -64,7 +64,7 @@ export abstract class TypedArray<T,V> {
|
||||
else begin = min(begin, length);
|
||||
if (end < 0) end = max(length + end, begin);
|
||||
else end = max(min(end, length), begin);
|
||||
var slice = allocate_memory(offsetof<this>());
|
||||
var slice = memory.allocate(offsetof<this>());
|
||||
store<usize>(slice, this.buffer, offsetof<this>("buffer"));
|
||||
store<i32>(slice, begin << alignof<T>(), offsetof<this>("byteOffset"));
|
||||
store<i32>(slice, end << alignof<T>(), offsetof<this>("byteLength"));
|
||||
|
Reference in New Issue
Block a user