Fix some map issues; Simplify internal ArrayBuffer API a bit

This commit is contained in:
dcodeIO
2018-06-20 15:51:47 +02:00
parent 48e96cbcf5
commit dd4be7b693
14 changed files with 17159 additions and 1132 deletions

View File

@ -99,6 +99,17 @@ export enum NodeKind {
COMMENT
}
/** Checks if a node represents a constant value. */
export function nodeIsConstantValue(kind: NodeKind): bool {
switch (kind) {
case NodeKind.LITERAL:
case NodeKind.NULL:
case NodeKind.TRUE:
case NodeKind.FALSE: return true;
}
return false;
}
/** Base class of all nodes. */
export abstract class Node {

View File

@ -126,7 +126,9 @@ import {
StringLiteralExpression,
UnaryPostfixExpression,
UnaryPrefixExpression,
FieldDeclaration
FieldDeclaration,
nodeIsConstantValue
} from "./ast";
import {
@ -5503,9 +5505,7 @@ export class Compiler extends DiagnosticEmitter {
let allOptionalsAreConstant = true;
for (let i = numArguments; i < maxArguments; ++i) {
let initializer = parameterNodes[i].initializer;
if (!(initializer && initializer.kind == NodeKind.LITERAL)) {
// TODO: other kinds might be constant as well
// NOTE: if the initializer is missing this is reported in ensureTrampoline below
if (!(initializer !== null && nodeIsConstantValue(initializer.kind))) {
allOptionalsAreConstant = false;
break;
}

View File

@ -3505,34 +3505,33 @@ export class ClassPrototype extends Element {
fieldDeclaration.type,
instance.contextualTypeArguments
);
if (fieldType) {
let fieldInstance = new Field(
<FieldPrototype>member,
internalName + INSTANCE_DELIMITER + (<FieldPrototype>member).simpleName,
fieldType,
fieldDeclaration,
instance
);
switch (fieldType.byteSize) { // align
case 1: break;
case 2: {
if (memoryOffset & 1) ++memoryOffset;
break;
}
case 4: {
if (memoryOffset & 3) memoryOffset = (memoryOffset | 3) + 1;
break;
}
case 8: {
if (memoryOffset & 7) memoryOffset = (memoryOffset | 7) + 1;
break;
}
default: assert(false);
if (!fieldType) break;
let fieldInstance = new Field(
<FieldPrototype>member,
internalName + INSTANCE_DELIMITER + (<FieldPrototype>member).simpleName,
fieldType,
fieldDeclaration,
instance
);
switch (fieldType.byteSize) { // align
case 1: break;
case 2: {
if (memoryOffset & 1) ++memoryOffset;
break;
}
fieldInstance.memoryOffset = memoryOffset;
memoryOffset += fieldType.byteSize;
instance.members.set(member.simpleName, fieldInstance);
case 4: {
if (memoryOffset & 3) memoryOffset = (memoryOffset | 3) + 1;
break;
}
case 8: {
if (memoryOffset & 7) memoryOffset = (memoryOffset | 7) + 1;
break;
}
default: assert(false);
}
fieldInstance.memoryOffset = memoryOffset;
memoryOffset += fieldType.byteSize;
instance.members.set(member.simpleName, fieldInstance);
break;
}