Skip to content

Commit

Permalink
Merge branch 'upstreamMaster' into simplify-decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 13, 2019
2 parents a8c363c + 19d06a3 commit b5a115c
Show file tree
Hide file tree
Showing 14 changed files with 13,835 additions and 6,278 deletions.
2 changes: 1 addition & 1 deletion examples/n-body/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"build": "npm run asbuild && npm run tsbuild",
"server": "http-server . -o -c-1",
"test": "node --noliftoff --nowasm-tier-up --wasm-lazy-compilation --wasm-no-bounds-checks --expose-gc tests"
"test": "node --wasm-lazy-compilation --wasm-no-bounds-checks --expose-gc tests"
},
"devDependencies": {
"http-server": "^0.11.1",
Expand Down
6 changes: 5 additions & 1 deletion lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ function postInstantiate(baseModule, instance) {

/** Reads (copies) the values of an array from the module's memory. */
function __getArray(arr) {
return Array.from(__getArrayView(arr));
const input = __getArrayView(arr);
const len = input.length;
const out = new Array(len);
for (let i = 0; i < len; i++) out[i] = input[i];
return out;
}

baseModule.__getArray = __getArray;
Expand Down
14 changes: 10 additions & 4 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,16 +1137,22 @@ declare abstract class TypedArray<T> implements ArrayBufferView<T> {
indexOf(searchElement: T, fromIndex?: i32): i32;
/** The lastIndexOf() method returns the last index at which a given element can be found in the typed array, or -1 if it is not present. The typed array is searched backwards, starting at fromIndex. */
lastIndexOf(searchElement: T, fromIndex?: i32): i32;
/** Returns copied section of an TypedArray from begin inclusive to end exclusive */
slice(begin?: i32, end?: i32): TypedArray<T>;
/** Returns a new TypedArray of this type on the same ArrayBuffer from begin inclusive to end exclusive. */
subarray(begin?: i32, end?: i32): this;
subarray(begin?: i32, end?: i32): TypedArray<T>;
/** The copyWithin() method copies the sequence of array elements within the array to the position starting at target. The copy is taken from the index positions of the second and third arguments start and end. The end argument is optional and defaults to the length of the array. */
copyWithin(target: i32, start: i32, end?: i32): this;
/** The reduce() method applies a function against an accumulator and each value of the typed array (from left-to-right) has to reduce it to a single value. This method has the same algorithm as Array.prototype.reduce(). */
reduce<W>(callbackfn: (accumulator: W, value: T, index: i32, self: this) => W, initialValue: W): W;
reduce<U>(callbackfn: (accumulator: U, value: T, index: i32, self: this) => U, initialValue: U): U;
/** The reduceRight() method applies a function against an accumulator and each value of the typed array (from left-to-right) has to reduce it to a single value, starting from the end of the array. This method has the same algorithm as Array.prototype.reduceRight(). */
reduceRight<W>(callbackfn: (accumulator: W, value: T, index: i32, self: this) => W, initialValue: W): W;
reduceRight<U>(callbackfn: (accumulator: U, value: T, index: i32, self: this) => U, initialValue: U): U;
/** The some() method tests whether some element in the typed array passes the test implemented by the provided function. This method has the same algorithm as Array.prototype.some().*/
some(callbackfn: (value: T, index: i32, self: this) => bool): bool;
/** The map() method creates a new typed array with the results of calling a provided function on every element in this typed array. This method has the same algorithm as Array.prototype.map().*/
map(callbackfn: (value: T, index: i32, self: this) => T): this;
map(callbackfn: (value: T, index: i32, self: this) => T): TypedArray<T>;
/** The filter() method creates a new typed array with all elements that pass the test implemented by the provided function. This method has the same algorithm as Array.prototype.filter(). */
filter(callbackfn: (value: T, index: i32, self: this) => bool): TypedArray<T>;
/** The sort() method sorts the elements of a typed array numerically in place and returns the typed array. This method has the same algorithm as Array.prototype.sort(), except that sorts the values numerically instead of as strings. TypedArray is one of the typed array types here. */
sort(callback?: (a: T, b: T) => i32): this;
/** The fill() method fills all the elements of a typed array from a start index to an end index with a static value. This method has the same algorithm as Array.prototype.fill(). */
Expand Down
9 changes: 6 additions & 3 deletions std/assembly/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,15 +1033,18 @@ export namespace NativeMath {
}

export function seedRandom(value: i64): void {
assert(value);
random_seeded = true;
random_state0_64 = murmurHash3(value);
random_state1_64 = murmurHash3(~random_state0_64);
random_state0_32 = splitMix32(<u32>value);
random_state1_32 = splitMix32(random_state0_32);
assert(
random_state0_64 != 0 && random_state1_64 != 0 &&
random_state0_32 != 0 && random_state1_32 != 0
);
}

export function random(): f64 { // see: v8/src/base/random-number-generator.cc
export function random(): f64 { // see: v8/src/base/utils/random-number-generator.cc
if (!random_seeded) throw new Error("PRNG must be seeded.");
var s1 = random_state0_64;
var s0 = random_state1_64;
Expand All @@ -1051,7 +1054,7 @@ export namespace NativeMath {
s1 ^= s0;
s1 ^= s0 >> 26;
random_state1_64 = s1;
var r = ((s0 + s1) & 0x000FFFFFFFFFFFFF) | 0x3FF0000000000000;
var r = (s0 >> 12) | 0x3FF0000000000000;
return reinterpret<f64>(r) - 1;
}

Expand Down
Loading

0 comments on commit b5a115c

Please sign in to comment.