FixedArray experimentation

This commit is contained in:
dcode
2019-03-19 15:43:05 +01:00
parent 74789c9c1e
commit 81039c4167
31 changed files with 762 additions and 855 deletions

View File

@ -175,6 +175,7 @@ export namespace LibrarySymbols {
export const V128 = "V128";
export const String = "String";
export const Array = "Array";
export const FixedArray = "FixedArray";
export const ArrayBufferView = "ArrayBufferView";
export const ArrayBuffer = "ArrayBuffer";
export const Math = "Math";

View File

@ -6445,17 +6445,16 @@ export class Compiler extends DiagnosticEmitter {
case LiteralKind.ARRAY: {
assert(!implicitNegate);
let classType = contextualType.classReference;
if (
classType &&
classType.prototype == this.program.arrayPrototype
) {
return this.compileArrayLiteral(
assert(classType.typeArguments)[0],
(<ArrayLiteralExpression>expression).elementExpressions,
false, // TODO: isConst?
expression,
context
);
if (classType) {
if (classType.prototype == this.program.arrayPrototype) {
return this.compileArrayLiteral(
assert(classType.typeArguments)[0],
(<ArrayLiteralExpression>expression).elementExpressions,
false, // TODO: isConst?
expression,
context
);
}
}
this.error(
DiagnosticCode.Operation_not_supported,

View File

@ -348,6 +348,8 @@ export class Program extends DiagnosticEmitter {
arrayBufferInstance: Class | null = null;
/** Array prototype reference. */
arrayPrototype: ClassPrototype | null = null;
/** Fixed array prototype reference. */
fixedArrayPrototype: ClassPrototype | null = null;
/** String instance reference. */
stringInstance: Class | null = null;
/** Abort function reference, if present. */
@ -798,6 +800,10 @@ export class Program extends DiagnosticEmitter {
assert(element.kind == ElementKind.CLASS_PROTOTYPE);
this.arrayPrototype = <ClassPrototype>element;
}
if (element = this.lookupGlobal(LibrarySymbols.FixedArray)) {
assert(element.kind == ElementKind.CLASS_PROTOTYPE);
this.fixedArrayPrototype = <ClassPrototype>element;
}
if (element = this.lookupGlobal(LibrarySymbols.abort)) {
assert(element.kind == ElementKind.FUNCTION_PROTOTYPE);
this.abortInstance = this.resolver.resolveFunction(<FunctionPrototype>element, null);