Skip to content

Commit b2e2b4b

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 8b0e0e7 + eee0307 commit b2e2b4b

27 files changed

+407
-280
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ under the licensing terms detailed in LICENSE:
1717
* Bowen Wang <[email protected]>
1818
* Emil Laine <[email protected]>
1919
* Stephen Paul Weber <[email protected]>
20+
* Jay Phelps <[email protected]>
2021

2122
Portions of this software are derived from third-party works licensed under
2223
the following terms:

bin/asinit

100644100755
File mode changed.

cli/asc.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,10 @@ exports.main = function main(argv, options, callback) {
218218
if (args.transform) {
219219
let transformArgs = args.transform;
220220
for (let i = 0, k = transformArgs.length; i < k; ++i) {
221-
let filename = transformArgs[i];
222-
filename = path.isAbsolute(filename = filename.trim())
223-
? filename
224-
: path.join(process.cwd(), filename);
221+
let filename = transformArgs[i].trim();
225222
if (/\.ts$/.test(filename)) require("ts-node").register({ transpileOnly: true, skipProject: true });
226223
try {
227-
const classOrModule = require(filename);
224+
const classOrModule = require(require.resolve(filename, { paths: [baseDir, process.cwd()] }));
228225
if (typeof classOrModule === "function") {
229226
Object.assign(classOrModule.prototype, {
230227
baseDir,

src/flow.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export class Flow {
324324
case NativeType.F32: { temps = parentFunction.tempF32s; break; }
325325
case NativeType.F64: { temps = parentFunction.tempF64s; break; }
326326
case NativeType.V128: { temps = parentFunction.tempV128s; break; }
327+
case NativeType.Anyref: { temps = parentFunction.tempAnyrefs; break; }
327328
default: throw new Error("concrete type expected");
328329
}
329330
var local: Local;
@@ -395,6 +396,10 @@ export class Flow {
395396
temps = parentFunction.tempV128s || (parentFunction.tempV128s = []);
396397
break;
397398
}
399+
case NativeType.Anyref: {
400+
temps = parentFunction.tempAnyrefs || (parentFunction.tempAnyrefs = []);
401+
break;
402+
}
398403
default: throw new Error("concrete type expected");
399404
}
400405
assert(local.index >= 0);

src/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,10 @@ export class Module {
14231423
// TODO
14241424
return 0;
14251425
}
1426+
// Not possible to clone an anyref as it is opaque
1427+
case NativeType.Anyref: {
1428+
return 0;
1429+
}
14261430
default: {
14271431
throw new Error("concrete type expected");
14281432
}

src/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,7 @@ export class Function extends TypedElement {
29002900
tempF32s: Local[] | null = null;
29012901
tempF64s: Local[] | null = null;
29022902
tempV128s: Local[] | null = null;
2903+
tempAnyrefs: Local[] | null = null;
29032904

29042905
// used by flows to keep track of break labels
29052906
nextBreakId: i32 = 0;

std/assembly/array.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ export class Array<T> extends ArrayBufferView {
105105
}
106106

107107
@operator("[]=") private __set(index: i32, value: T): void {
108-
ensureSize(changetype<usize>(this), index + 1, alignof<T>());
108+
if (<u32>index >= <u32>this.length_) {
109+
if (index < 0) throw new RangeError(E_INDEXOUTOFRANGE);
110+
ensureSize(changetype<usize>(this), index + 1, alignof<T>());
111+
this.length_ = index + 1;
112+
}
109113
this.__unchecked_set(index, value);
110-
if (index >= this.length_) this.length_ = index + 1;
111114
}
112115

113116
@unsafe @operator("{}=") private __unchecked_set(index: i32, value: T): void {

std/assembly/index.d.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,6 @@ declare abstract class TypedArray<T> implements ArrayBufferView {
12481248
[key: number]: T;
12491249
/** Number of bytes per element. */
12501250
static readonly BYTES_PER_ELEMENT: usize;
1251-
/** Wrap an ArrayBuffer */
1252-
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): ArrayBufferView;
12531251
/** Constructs a new typed array. */
12541252
constructor(length: i32);
12551253
/** The {@link ArrayBuffer} referenced by this view. */
@@ -1301,27 +1299,60 @@ declare abstract class TypedArray<T> implements ArrayBufferView {
13011299
}
13021300

13031301
/** An array of twos-complement 8-bit signed integers. */
1304-
declare class Int8Array extends TypedArray<i8> {}
1302+
declare class Int8Array extends TypedArray<i8> {
1303+
/** Wrap an ArrayBuffer */
1304+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int8Array;
1305+
}
13051306
/** An array of 8-bit unsigned integers. */
1306-
declare class Uint8Array extends TypedArray<u8> {}
1307+
declare class Uint8Array extends TypedArray<u8> {
1308+
/** Wrap an ArrayBuffer */
1309+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8Array;
1310+
}
13071311
/** A clamped array of 8-bit unsigned integers. */
1308-
declare class Uint8ClampedArray extends TypedArray<u8> {}
1312+
declare class Uint8ClampedArray extends TypedArray<u8> {
1313+
/** Wrap an ArrayBuffer */
1314+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8ClampedArray;
1315+
}
13091316
/** An array of twos-complement 16-bit signed integers. */
1310-
declare class Int16Array extends TypedArray<i16> {}
1317+
declare class Int16Array extends TypedArray<i16> {
1318+
/** Wrap an ArrayBuffer */
1319+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int16Array;
1320+
}
13111321
/** An array of 16-bit unsigned integers. */
1312-
declare class Uint16Array extends TypedArray<u16> {}
1322+
declare class Uint16Array extends TypedArray<u16> {
1323+
/** Wrap an ArrayBuffer */
1324+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint16Array;
1325+
}
13131326
/** An array of twos-complement 32-bit signed integers. */
1314-
declare class Int32Array extends TypedArray<i32> {}
1327+
declare class Int32Array extends TypedArray<i32> {
1328+
/** Wrap an ArrayBuffer */
1329+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int32Array;
1330+
}
13151331
/** An array of 32-bit unsigned integers. */
1316-
declare class Uint32Array extends TypedArray<u32> {}
1332+
declare class Uint32Array extends TypedArray<u32> {
1333+
/** Wrap an ArrayBuffer */
1334+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint32Array;
1335+
}
13171336
/** An array of twos-complement 64-bit signed integers. */
1318-
declare class Int64Array extends TypedArray<i64> {}
1337+
declare class Int64Array extends TypedArray<i64> {
1338+
/** Wrap an ArrayBuffer */
1339+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int64Array;
1340+
}
13191341
/** An array of 64-bit unsigned integers. */
1320-
declare class Uint64Array extends TypedArray<u64> {}
1342+
declare class Uint64Array extends TypedArray<u64> {
1343+
/** Wrap an ArrayBuffer */
1344+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint64Array;
1345+
}
13211346
/** An array of 32-bit floating point numbers. */
1322-
declare class Float32Array extends TypedArray<f32> {}
1347+
declare class Float32Array extends TypedArray<f32> {
1348+
/** Wrap an ArrayBuffer */
1349+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float32Array;
1350+
}
13231351
/** An array of 64-bit floating point numbers. */
1324-
declare class Float64Array extends TypedArray<f64> {}
1352+
declare class Float64Array extends TypedArray<f64> {
1353+
/** Wrap an ArrayBuffer */
1354+
static wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float64Array;
1355+
}
13251356

13261357
/** Class representing a sequence of values of type `T`. */
13271358
declare class Array<T> {

tests/compiler/binary.optimized.wat

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@
260260
return
261261
end
262262
local.get $2
263-
i64.const 0
264-
i64.eq
263+
i64.eqz
265264
if (result i64)
266265
local.get $1
267266
i64.const 0

tests/compiler/features/reference-types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
export declare function external(a: anyref): anyref;
44

55
export function internal(a: anyref): anyref {
6-
return a;
6+
const b = external(a);
7+
let c = external(b);
8+
var d = external(c);
9+
return d;
710
}
811

912
// can use reflection to work with anyref values

0 commit comments

Comments
 (0)