mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Cleanup: Make use of type inference and use 'var' in functions to match actual WebAssembly semantics
This commit is contained in:
parent
7795d48d98
commit
2ed3c22031
485
src/ast.ts
485
src/ast.ts
File diff suppressed because it is too large
Load Diff
@ -83,7 +83,7 @@ export function initialize(program: Program): void {
|
||||
addFunction(program, "assert");
|
||||
|
||||
// conversions and limits
|
||||
let i32Func: FunctionPrototype,
|
||||
var i32Func: FunctionPrototype,
|
||||
u32Func: FunctionPrototype,
|
||||
i64Func: FunctionPrototype,
|
||||
u64Func: FunctionPrototype;
|
||||
@ -144,7 +144,7 @@ export function initialize(program: Program): void {
|
||||
|
||||
/** Adds a built-in constant to the specified program. */
|
||||
function addConstant(program: Program, name: string, type: Type): Global {
|
||||
const global: Global = new Global(program, name, name, null);
|
||||
var global = new Global(program, name, name, null);
|
||||
global.isBuiltIn = true;
|
||||
global.isConstant = true;
|
||||
global.type = type;
|
||||
@ -154,9 +154,10 @@ function addConstant(program: Program, name: string, type: Type): Global {
|
||||
|
||||
/** Adds a built-in function to the specified program. */
|
||||
function addFunction(program: Program, name: string, isGeneric: bool = false): FunctionPrototype {
|
||||
let prototype: FunctionPrototype = new FunctionPrototype(program, name, name, null, null);
|
||||
var prototype = new FunctionPrototype(program, name, name, null, null);
|
||||
prototype.isBuiltIn = true;
|
||||
if (isGeneric) prototype.isGeneric = true;
|
||||
if (isGeneric)
|
||||
prototype.isGeneric = true;
|
||||
program.elements.set(name, prototype);
|
||||
return prototype;
|
||||
}
|
||||
@ -187,18 +188,18 @@ export function compileGetConstant(compiler: Compiler, global: Global): Expressi
|
||||
|
||||
/** Compiles a call to a built-in function. */
|
||||
export function compileCall(compiler: Compiler, prototype: FunctionPrototype, typeArguments: Type[], operands: Expression[], reportNode: Node): ExpressionRef {
|
||||
const module: Module = compiler.module;
|
||||
const usizeType: Type = select<Type>(Type.usize64, Type.usize32, compiler.options.target == Target.WASM64);
|
||||
const nativeUsizeType: NativeType = select<NativeType>(NativeType.I64, NativeType.I32, compiler.options.target == Target.WASM64);
|
||||
var module = compiler.module;
|
||||
var usizeType = select<Type>(Type.usize64, Type.usize32, compiler.options.target == Target.WASM64);
|
||||
var nativeUsizeType = select<NativeType>(NativeType.I64, NativeType.I32, compiler.options.target == Target.WASM64);
|
||||
|
||||
let arg0: ExpressionRef,
|
||||
var arg0: ExpressionRef,
|
||||
arg1: ExpressionRef,
|
||||
arg2: ExpressionRef;
|
||||
|
||||
let tempLocal0: Local;
|
||||
let tempLocal1: Local;
|
||||
var tempLocal0: Local,
|
||||
tempLocal1: Local;
|
||||
|
||||
let ftype: FunctionTypeRef;
|
||||
var ftype: FunctionTypeRef;
|
||||
|
||||
switch (prototype.internalName) {
|
||||
|
||||
|
358
src/compiler.ts
358
src/compiler.ts
@ -195,8 +195,8 @@ export class Compiler extends DiagnosticEmitter {
|
||||
this.module = this.options.noEmit ? Module.createStub() : Module.create();
|
||||
|
||||
// set up start function
|
||||
const startFunctionTemplate: FunctionPrototype = new FunctionPrototype(program, "start", "start", null);
|
||||
const startFunctionInstance: Function = new Function(startFunctionTemplate, startFunctionTemplate.internalName, [], [], Type.void, null);
|
||||
var startFunctionTemplate = new FunctionPrototype(program, "start", "start", null);
|
||||
var startFunctionInstance = new Function(startFunctionTemplate, startFunctionTemplate.internalName, [], [], Type.void, null);
|
||||
this.currentFunction = this.startFunction = startFunctionInstance;
|
||||
}
|
||||
|
||||
@ -207,15 +207,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
this.program.initialize(this.options.target);
|
||||
|
||||
// compile entry file (exactly one, usually)
|
||||
const sources: Source[] = this.program.sources;
|
||||
let i: i32, k = sources.length;
|
||||
for (i = 0; i < k; ++i)
|
||||
var sources = this.program.sources;
|
||||
for (var i = 0, k = sources.length; i < k; ++i)
|
||||
if (sources[i].isEntry)
|
||||
this.compileSource(sources[i]);
|
||||
|
||||
// make start function if not empty
|
||||
if (this.startFunctionBody.length) {
|
||||
let typeRef = this.module.getFunctionTypeBySignature(NativeType.None, []);
|
||||
var typeRef = this.module.getFunctionTypeBySignature(NativeType.None, []);
|
||||
if (!typeRef)
|
||||
typeRef = this.module.addFunctionType("v", NativeType.None, []);
|
||||
this.module.setStart(
|
||||
@ -227,14 +226,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
|
||||
// set up memory
|
||||
if (!this.options.noMemory) {
|
||||
const initial = this.memoryOffset.clone();
|
||||
var initial = this.memoryOffset.clone();
|
||||
if (this.options.target == Target.WASM64)
|
||||
this.module.addGlobal("HEAP_BASE", NativeType.I64, false, this.module.createI64(initial.lo, initial.hi));
|
||||
else
|
||||
this.module.addGlobal("HEAP_BASE", NativeType.I32, false, this.module.createI32(initial.lo));
|
||||
|
||||
// determine initial page size
|
||||
const initialOverlaps = initial.clone();
|
||||
var initialOverlaps = initial.clone();
|
||||
initialOverlaps.and32(0xffff);
|
||||
if (!initialOverlaps.isZero) {
|
||||
initial.or32(0xffff);
|
||||
@ -249,8 +248,8 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// sources
|
||||
|
||||
compileSourceByPath(normalizedPath: string, reportNode: Node): void {
|
||||
for (let i = 0, k = this.program.sources.length; i < k; ++i) {
|
||||
const importedSource = this.program.sources[i];
|
||||
for (var i = 0, k = this.program.sources.length; i < k; ++i) {
|
||||
var importedSource = this.program.sources[i];
|
||||
if (importedSource.normalizedPath == normalizedPath) {
|
||||
this.compileSource(importedSource);
|
||||
return;
|
||||
@ -264,9 +263,9 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return;
|
||||
this.files.add(source.normalizedPath);
|
||||
|
||||
const noTreeShaking = this.options.noTreeShaking;
|
||||
for (let i = 0, k = source.statements.length; i < k; ++i) {
|
||||
const statement: Statement = source.statements[i];
|
||||
var noTreeShaking = this.options.noTreeShaking;
|
||||
for (var i = 0, k = source.statements.length; i < k; ++i) {
|
||||
var statement = source.statements[i];
|
||||
switch (statement.kind) {
|
||||
|
||||
case NodeKind.CLASS:
|
||||
@ -306,15 +305,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
break;
|
||||
|
||||
// otherwise a top-level statement that is part of the start function's body
|
||||
default: {
|
||||
const previousFunction = this.currentFunction;
|
||||
default:
|
||||
var previousFunction = this.currentFunction;
|
||||
this.currentFunction = this.startFunction;
|
||||
const expr = this.compileStatement(statement);
|
||||
var expr = this.compileStatement(statement);
|
||||
if (!this.module.noEmit)
|
||||
this.startFunctionBody.push(expr);
|
||||
this.currentFunction = previousFunction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +320,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// globals
|
||||
|
||||
compileGlobalDeclaration(declaration: VariableDeclaration, isConst: bool): Global | null {
|
||||
const element = this.program.elements.get(declaration.internalName);
|
||||
var element = this.program.elements.get(declaration.internalName);
|
||||
if (!element || element.kind != ElementKind.GLOBAL)
|
||||
throw new Error("global expected");
|
||||
if (!this.compileGlobal(<Global>element)) // reports
|
||||
@ -340,8 +338,8 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (global.isCompiled || (global.isBuiltIn && compileBuiltinGetConstant(this, global)))
|
||||
return true;
|
||||
|
||||
const declaration = global.declaration;
|
||||
let initExpr: ExpressionRef = 0;
|
||||
var declaration = global.declaration;
|
||||
var initExpr: ExpressionRef = 0;
|
||||
|
||||
if (!global.type) { // infer type
|
||||
if (declaration) {
|
||||
@ -362,7 +360,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
throw new Error("declaration expected");
|
||||
}
|
||||
|
||||
const nativeType = global.type.toNativeType();
|
||||
var nativeType = global.type.toNativeType();
|
||||
|
||||
if (global.isDeclared) {
|
||||
if (global.isConstant) {
|
||||
@ -375,7 +373,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return false;
|
||||
}
|
||||
|
||||
let initializeInStart = false;
|
||||
var initializeInStart = false;
|
||||
|
||||
if (global.hasConstantValue) {
|
||||
if (global.type.isLongInteger)
|
||||
@ -386,7 +384,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
initExpr = this.module.createF64(global.constantFloatValue);
|
||||
else if (global.type.isSmallInteger) {
|
||||
if (global.type.isSignedInteger) {
|
||||
const shift = global.type.smallIntegerShift;
|
||||
var shift = global.type.smallIntegerShift;
|
||||
initExpr = this.module.createI32(global.constantIntegerValue ? global.constantIntegerValue.toI32() << shift >> shift : 0);
|
||||
} else
|
||||
initExpr = this.module.createI32(global.constantIntegerValue ? global.constantIntegerValue.toI32() & global.type.smallIntegerMask: 0);
|
||||
@ -411,16 +409,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
} else
|
||||
throw new Error("declaration expected");
|
||||
|
||||
const internalName = global.internalName;
|
||||
var internalName = global.internalName;
|
||||
if (initializeInStart) {
|
||||
this.module.addGlobal(internalName, nativeType, true, global.type.toNativeZero(this.module));
|
||||
const setExpr = this.module.createSetGlobal(internalName, initExpr);
|
||||
var setExpr = this.module.createSetGlobal(internalName, initExpr);
|
||||
if (!this.module.noEmit)
|
||||
this.startFunctionBody.push(setExpr);
|
||||
} else {
|
||||
this.module.addGlobal(internalName, nativeType, global.isMutable, initExpr);
|
||||
if (!global.isMutable && !this.module.noEmit) {
|
||||
const exprType: NativeType = _BinaryenExpressionGetType(initExpr);
|
||||
var exprType = _BinaryenExpressionGetType(initExpr);
|
||||
switch (exprType) {
|
||||
case NativeType.I32:
|
||||
global.constantIntegerValue = new I64(_BinaryenConstGetValueI32(initExpr), 0);
|
||||
@ -447,7 +445,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// enums
|
||||
|
||||
compileEnumDeclaration(declaration: EnumDeclaration): void {
|
||||
const element = this.program.elements.get(declaration.internalName);
|
||||
var element = this.program.elements.get(declaration.internalName);
|
||||
if (!element || element.kind != ElementKind.ENUM)
|
||||
throw new Error("enum expected");
|
||||
this.compileEnum(<Enum>element);
|
||||
@ -457,18 +455,18 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (element.isCompiled)
|
||||
return;
|
||||
|
||||
let previousValue: EnumValue | null = null;
|
||||
var previousValue: EnumValue | null = null;
|
||||
if (element.members)
|
||||
for (let [key, member] of element.members) {
|
||||
for (var member of element.members.values()) {
|
||||
if (member.kind != ElementKind.ENUMVALUE)
|
||||
continue;
|
||||
const val = <EnumValue>member;
|
||||
var val = <EnumValue>member;
|
||||
if (val.hasConstantValue) {
|
||||
this.module.addGlobal(val.internalName, NativeType.I32, false, this.module.createI32(val.constantValue));
|
||||
} else if (val.declaration) {
|
||||
const declaration = val.declaration;
|
||||
let initExpr: ExpressionRef;
|
||||
let initInStart = false;
|
||||
var declaration = val.declaration;
|
||||
var initExpr: ExpressionRef;
|
||||
var initInStart = false;
|
||||
if (declaration.value) {
|
||||
initExpr = this.compileExpression(<Expression>declaration.value, Type.i32);
|
||||
if (!this.module.noEmit && _BinaryenExpressionGetId(initExpr) != ExpressionId.Const) {
|
||||
@ -495,7 +493,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
if (initInStart) {
|
||||
this.module.addGlobal(val.internalName, NativeType.I32, true, this.module.createI32(0));
|
||||
const setExpr = this.module.createSetGlobal(val.internalName, initExpr);
|
||||
var setExpr = this.module.createSetGlobal(val.internalName, initExpr);
|
||||
if (!this.module.noEmit)
|
||||
this.startFunctionBody.push(setExpr);
|
||||
} else {
|
||||
@ -518,11 +516,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// functions
|
||||
|
||||
compileFunctionDeclaration(declaration: FunctionDeclaration, typeArguments: TypeNode[], contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
const element = this.program.elements.get(internalName);
|
||||
var internalName = declaration.internalName;
|
||||
var element = this.program.elements.get(internalName);
|
||||
if (!element || element.kind != ElementKind.FUNCTION_PROTOTYPE)
|
||||
throw new Error("function expected");
|
||||
const instance = this.compileFunctionUsingTypeArguments(<FunctionPrototype>element, typeArguments, contextualTypeArguments, alternativeReportNode); // reports
|
||||
var instance = this.compileFunctionUsingTypeArguments(<FunctionPrototype>element, typeArguments, contextualTypeArguments, alternativeReportNode); // reports
|
||||
if (!instance)
|
||||
return;
|
||||
if (isModuleExport(instance, declaration))
|
||||
@ -530,7 +528,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileFunctionUsingTypeArguments(prototype: FunctionPrototype, typeArguments: TypeNode[], contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): Function | null {
|
||||
const instance = prototype.resolveInclTypeArguments(typeArguments, contextualTypeArguments, alternativeReportNode); // reports
|
||||
var instance = prototype.resolveInclTypeArguments(typeArguments, contextualTypeArguments, alternativeReportNode); // reports
|
||||
if (!instance)
|
||||
return null;
|
||||
return this.compileFunction(instance) ? instance : null;
|
||||
@ -540,7 +538,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (instance.isCompiled)
|
||||
return true;
|
||||
|
||||
const declaration = instance.prototype.declaration;
|
||||
var declaration = instance.prototype.declaration;
|
||||
if (!declaration)
|
||||
throw new Error("declaration expected"); // built-ins are not compiled here
|
||||
|
||||
@ -558,25 +556,25 @@ export class Compiler extends DiagnosticEmitter {
|
||||
instance.isCompiled = true;
|
||||
|
||||
// compile statements
|
||||
let stmts: ExpressionRef[] | null = null;
|
||||
var stmts: ExpressionRef[] | null = null;
|
||||
if (!instance.isDeclared) {
|
||||
const previousFunction = this.currentFunction;
|
||||
var previousFunction = this.currentFunction;
|
||||
this.currentFunction = instance;
|
||||
stmts = this.compileStatements(<Statement[]>declaration.statements);
|
||||
this.currentFunction = previousFunction;
|
||||
}
|
||||
|
||||
// create the function type
|
||||
let k = instance.parameters.length;
|
||||
const nativeResultType = instance.returnType.toNativeType();
|
||||
const nativeParamTypes = new Array<NativeType>(k);
|
||||
const signatureNameParts = new Array<string>(k + 1);
|
||||
for (let i = 0; i < k; ++i) {
|
||||
var k = instance.parameters.length;
|
||||
var nativeResultType = instance.returnType.toNativeType();
|
||||
var nativeParamTypes = new Array<NativeType>(k);
|
||||
var signatureNameParts = new Array<string>(k + 1);
|
||||
for (var i = 0; i < k; ++i) {
|
||||
nativeParamTypes[i] = instance.parameters[i].type.toNativeType();
|
||||
signatureNameParts[i] = instance.parameters[i].type.toSignatureName();
|
||||
}
|
||||
signatureNameParts[k] = instance.returnType.toSignatureName();
|
||||
let typeRef = this.module.getFunctionTypeBySignature(nativeResultType, nativeParamTypes);
|
||||
var typeRef = this.module.getFunctionTypeBySignature(nativeResultType, nativeParamTypes);
|
||||
if (!typeRef)
|
||||
typeRef = this.module.addFunctionType(signatureNameParts.join(""), nativeResultType, nativeParamTypes);
|
||||
|
||||
@ -593,10 +591,10 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// namespaces
|
||||
|
||||
compileNamespaceDeclaration(declaration: NamespaceDeclaration): void {
|
||||
const members = declaration.members;
|
||||
const noTreeShaking = this.options.noTreeShaking;
|
||||
for (let i = 0, k = members.length; i < k; ++i) {
|
||||
const member = members[i];
|
||||
var members = declaration.members;
|
||||
var noTreeShaking = this.options.noTreeShaking;
|
||||
for (var i = 0, k = members.length; i < k; ++i) {
|
||||
var member = members[i];
|
||||
switch (member.kind) {
|
||||
|
||||
case NodeKind.CLASS:
|
||||
@ -639,8 +637,8 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (!ns.members)
|
||||
return;
|
||||
|
||||
const noTreeShaking = this.options.noTreeShaking;
|
||||
for (let [name, element] of ns.members) {
|
||||
var noTreeShaking = this.options.noTreeShaking;
|
||||
for (var element of ns.members.values()) {
|
||||
switch (element.kind) {
|
||||
|
||||
case ElementKind.CLASS_PROTOTYPE:
|
||||
@ -671,11 +669,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// exports
|
||||
|
||||
compileExportStatement(statement: ExportStatement): void {
|
||||
const members = statement.members;
|
||||
for (let i = 0, k = members.length; i < k; ++i) {
|
||||
const member = members[i];
|
||||
const internalExportName = statement.range.source.internalPath + PATH_DELIMITER + member.externalIdentifier.name;
|
||||
const element = this.program.exports.get(internalExportName);
|
||||
var members = statement.members;
|
||||
for (var i = 0, k = members.length; i < k; ++i) {
|
||||
var member = members[i];
|
||||
var internalExportName = statement.range.source.internalPath + PATH_DELIMITER + member.externalIdentifier.name;
|
||||
var element = this.program.exports.get(internalExportName);
|
||||
if (!element) // reported in Program#initialize
|
||||
continue;
|
||||
switch (element.kind) {
|
||||
@ -691,7 +689,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
|
||||
case ElementKind.FUNCTION_PROTOTYPE:
|
||||
if (!(<FunctionPrototype>element).isGeneric) {
|
||||
const functionInstance = this.compileFunctionUsingTypeArguments(<FunctionPrototype>element, []);
|
||||
var functionInstance = this.compileFunctionUsingTypeArguments(<FunctionPrototype>element, []);
|
||||
if (functionInstance && statement.range.source.isEntry)
|
||||
this.module.addFunctionExport(functionInstance.internalName, member.externalIdentifier.name);
|
||||
}
|
||||
@ -716,15 +714,15 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// classes
|
||||
|
||||
compileClassDeclaration(declaration: ClassDeclaration, typeArguments: TypeNode[], contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
const element = this.program.elements.get(internalName);
|
||||
var internalName = declaration.internalName;
|
||||
var element = this.program.elements.get(internalName);
|
||||
if (!element || element.kind != ElementKind.CLASS_PROTOTYPE)
|
||||
throw new Error("class expected");
|
||||
this.compileClassUsingTypeArguments(<ClassPrototype>element, typeArguments, contextualTypeArguments, alternativeReportNode);
|
||||
}
|
||||
|
||||
compileClassUsingTypeArguments(prototype: ClassPrototype, typeArguments: TypeNode[], contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): void {
|
||||
const instance = prototype.resolveInclTypeArguments(typeArguments, contextualTypeArguments, alternativeReportNode);
|
||||
var instance = prototype.resolveInclTypeArguments(typeArguments, contextualTypeArguments, alternativeReportNode);
|
||||
if (!instance)
|
||||
return;
|
||||
this.compileClass(instance);
|
||||
@ -746,7 +744,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
this.memoryOffset.or32(7);
|
||||
this.memoryOffset.add32(1);
|
||||
}
|
||||
const segment = MemorySegment.create(buffer, this.memoryOffset.clone());
|
||||
var segment = MemorySegment.create(buffer, this.memoryOffset.clone());
|
||||
this.memorySegments.push(segment);
|
||||
this.memoryOffset.add32(buffer.length);
|
||||
return segment;
|
||||
@ -810,15 +808,15 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileStatements(statements: Statement[]): ExpressionRef[] {
|
||||
const k = statements.length;
|
||||
const stmts = new Array<ExpressionRef>(k);
|
||||
for (let i = 0; i < k; ++i)
|
||||
var k = statements.length;
|
||||
var stmts = new Array<ExpressionRef>(k);
|
||||
for (var i = 0; i < k; ++i)
|
||||
stmts[i] = this.compileStatement(statements[i]);
|
||||
return stmts; // array of 0-es in noEmit-mode
|
||||
}
|
||||
|
||||
compileBlockStatement(statement: BlockStatement): ExpressionRef {
|
||||
const statements = statement.statements;
|
||||
var statements = statement.statements;
|
||||
if (statements.length == 0)
|
||||
return this.module.createNop();
|
||||
if (statements.length == 1)
|
||||
@ -831,7 +829,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Operation_not_supported, statement.label.range);
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
const context = this.currentFunction.breakContext;
|
||||
var context = this.currentFunction.breakContext;
|
||||
if (context != null)
|
||||
return this.module.createBreak("break|" + (<string>context));
|
||||
|
||||
@ -844,7 +842,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Operation_not_supported, statement.label.range);
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
const context = this.currentFunction.breakContext;
|
||||
var context = this.currentFunction.breakContext;
|
||||
if (context != null && !this.disallowContinue)
|
||||
return this.module.createBreak("continue|" + (<string>context));
|
||||
|
||||
@ -853,12 +851,12 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileDoStatement(statement: DoStatement): ExpressionRef {
|
||||
const label = this.currentFunction.enterBreakContext();
|
||||
const condition = this.compileExpression(statement.condition, Type.i32);
|
||||
const body = this.compileStatement(statement.statement);
|
||||
var label = this.currentFunction.enterBreakContext();
|
||||
var condition = this.compileExpression(statement.condition, Type.i32);
|
||||
var body = this.compileStatement(statement.statement);
|
||||
this.currentFunction.leaveBreakContext();
|
||||
const breakLabel = "break|" + label;
|
||||
const continueLabel = "continue|" + label;
|
||||
var breakLabel = "break|" + label;
|
||||
var continueLabel = "continue|" + label;
|
||||
return this.module.createBlock(breakLabel, [
|
||||
this.module.createLoop(continueLabel,
|
||||
this.module.createBlock(null, [
|
||||
@ -873,7 +871,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileExpressionStatement(statement: ExpressionStatement): ExpressionRef {
|
||||
let expr = this.compileExpression(statement.expression, Type.void, ConversionKind.NONE);
|
||||
var expr = this.compileExpression(statement.expression, Type.void, ConversionKind.NONE);
|
||||
if (this.currentType != Type.void) {
|
||||
expr = this.module.createDrop(expr);
|
||||
this.currentType = Type.void;
|
||||
@ -882,18 +880,18 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileForStatement(statement: ForStatement): ExpressionRef {
|
||||
const context = this.currentFunction.enterBreakContext();
|
||||
const variableWasLocal = this.variableIsLocal;
|
||||
var context = this.currentFunction.enterBreakContext();
|
||||
var variableWasLocal = this.variableIsLocal;
|
||||
if (this.currentFunction == this.startFunction)
|
||||
this.variableIsLocal = true;
|
||||
const initializer = statement.initializer ? this.compileStatement(<Statement>statement.initializer) : this.module.createNop();
|
||||
var initializer = statement.initializer ? this.compileStatement(<Statement>statement.initializer) : this.module.createNop();
|
||||
this.variableIsLocal = variableWasLocal;
|
||||
const condition = statement.condition ? this.compileExpression(<Expression>statement.condition, Type.i32) : this.module.createI32(1);
|
||||
const incrementor = statement.incrementor ? this.compileExpression(<Expression>statement.incrementor, Type.void) : this.module.createNop();
|
||||
const body = this.compileStatement(statement.statement);
|
||||
var condition = statement.condition ? this.compileExpression(<Expression>statement.condition, Type.i32) : this.module.createI32(1);
|
||||
var incrementor = statement.incrementor ? this.compileExpression(<Expression>statement.incrementor, Type.void) : this.module.createNop();
|
||||
var body = this.compileStatement(statement.statement);
|
||||
this.currentFunction.leaveBreakContext();
|
||||
const continueLabel = "continue|" + context;
|
||||
const breakLabel = "break|" + context;
|
||||
var continueLabel = "continue|" + context;
|
||||
var breakLabel = "break|" + context;
|
||||
return this.module.createBlock(breakLabel, [
|
||||
initializer,
|
||||
this.module.createLoop(continueLabel, this.module.createBlock(null, [
|
||||
@ -907,38 +905,38 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileIfStatement(statement: IfStatement): ExpressionRef {
|
||||
const condition = this.compileExpression(statement.condition, Type.i32);
|
||||
const ifTrue = this.compileStatement(statement.ifTrue);
|
||||
const ifFalse = statement.ifFalse ? this.compileStatement(<Statement>statement.ifFalse) : <ExpressionRef>0;
|
||||
var condition = this.compileExpression(statement.condition, Type.i32);
|
||||
var ifTrue = this.compileStatement(statement.ifTrue);
|
||||
var ifFalse = statement.ifFalse ? this.compileStatement(<Statement>statement.ifFalse) : <ExpressionRef>0;
|
||||
return this.module.createIf(condition, ifTrue, ifFalse);
|
||||
}
|
||||
|
||||
compileReturnStatement(statement: ReturnStatement): ExpressionRef {
|
||||
if (this.currentFunction) {
|
||||
const expression = statement.value ? this.compileExpression(<Expression>statement.value, this.currentFunction.returnType) : <ExpressionRef>0;
|
||||
var expression = statement.value ? this.compileExpression(<Expression>statement.value, this.currentFunction.returnType) : <ExpressionRef>0;
|
||||
return this.module.createReturn(expression);
|
||||
}
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
|
||||
compileSwitchStatement(statement: SwitchStatement): ExpressionRef {
|
||||
const context = this.currentFunction.enterBreakContext();
|
||||
const previousDisallowContinue = this.disallowContinue;
|
||||
var context = this.currentFunction.enterBreakContext();
|
||||
var previousDisallowContinue = this.disallowContinue;
|
||||
this.disallowContinue = true;
|
||||
|
||||
// introduce a local for evaluating the condition (exactly once)
|
||||
const tempLocal = this.currentFunction.getTempLocal(Type.i32);
|
||||
let i: i32, k = statement.cases.length;
|
||||
var tempLocal = this.currentFunction.getTempLocal(Type.i32);
|
||||
var i: i32, k = statement.cases.length;
|
||||
|
||||
// prepend initializer to inner block
|
||||
const breaks = new Array<ExpressionRef>(1 + k);
|
||||
var breaks = new Array<ExpressionRef>(1 + k);
|
||||
breaks[0] = this.module.createSetLocal(tempLocal.index, this.compileExpression(statement.condition, Type.i32)); // initializer
|
||||
|
||||
// make one br_if per (possibly dynamic) labeled case (binaryen optimizes to br_table where possible)
|
||||
let breakIndex = 1;
|
||||
let defaultIndex = -1;
|
||||
var breakIndex = 1;
|
||||
var defaultIndex = -1;
|
||||
for (i = 0; i < k; ++i) {
|
||||
const case_ = statement.cases[i];
|
||||
var case_ = statement.cases[i];
|
||||
if (case_.label) {
|
||||
breaks[breakIndex++] = this.module.createBreak("case" + i.toString(10) + "|" + context,
|
||||
this.module.createBinary(BinaryOp.EqI32,
|
||||
@ -959,14 +957,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
) + "|" + context);
|
||||
|
||||
// nest blocks in order
|
||||
let currentBlock = this.module.createBlock("case0|" + context, breaks, NativeType.None);
|
||||
var currentBlock = this.module.createBlock("case0|" + context, breaks, NativeType.None);
|
||||
for (i = 0; i < k; ++i) {
|
||||
const case_ = statement.cases[i];
|
||||
const nextLabel = i == k - 1 ? "break|" + context : "case" + (i + 1).toString(10) + "|" + context;
|
||||
const l = case_.statements.length;
|
||||
const body = new Array<ExpressionRef>(1 + l);
|
||||
case_ = statement.cases[i];
|
||||
var nextLabel = i == k - 1 ? "break|" + context : "case" + (i + 1).toString(10) + "|" + context;
|
||||
var l = case_.statements.length;
|
||||
var body = new Array<ExpressionRef>(1 + l);
|
||||
body[0] = currentBlock;
|
||||
for (let j = 0; j < l; ++j)
|
||||
for (var j = 0; j < l; ++j)
|
||||
body[j + 1] = this.compileStatement(case_.statements[j]);
|
||||
currentBlock = this.module.createBlock(nextLabel, body, NativeType.None);
|
||||
}
|
||||
@ -987,22 +985,22 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileVariableStatement(statement: VariableStatement): ExpressionRef {
|
||||
const declarations = statement.declarations;
|
||||
var declarations = statement.declarations;
|
||||
|
||||
// top-level variables become globals
|
||||
if (this.currentFunction == this.startFunction && !this.variableIsLocal) {
|
||||
const isConst = hasModifier(ModifierKind.CONST, statement.modifiers);
|
||||
for (let i = 0, k = declarations.length; i < k; ++i)
|
||||
var isConst = hasModifier(ModifierKind.CONST, statement.modifiers);
|
||||
for (var i = 0, k = declarations.length; i < k; ++i)
|
||||
this.compileGlobalDeclaration(declarations[i], isConst);
|
||||
return this.module.createNop();
|
||||
}
|
||||
// other variables become locals
|
||||
const initializers = new Array<ExpressionRef>();
|
||||
for (let i = 0, k = declarations.length; i < k; ++i) {
|
||||
const declaration = declarations[i];
|
||||
const name = declaration.name.name;
|
||||
let type: Type | null = null;
|
||||
let init: ExpressionRef = 0;
|
||||
var initializers = new Array<ExpressionRef>();
|
||||
for (i = 0, k = declarations.length; i < k; ++i) {
|
||||
var declaration = declarations[i];
|
||||
var name = declaration.name.name;
|
||||
var type: Type | null = null;
|
||||
var init: ExpressionRef = 0;
|
||||
if (declaration.type) {
|
||||
type = this.program.resolveType(<TypeNode>declaration.type, this.currentFunction.contextualTypeArguments, true); // reports
|
||||
if (!type)
|
||||
@ -1029,11 +1027,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileWhileStatement(statement: WhileStatement): ExpressionRef {
|
||||
const label = this.currentFunction.enterBreakContext();
|
||||
const condition = this.compileExpression(statement.condition, Type.i32);
|
||||
const breakLabel = "break|" + label;
|
||||
const continueLabel = "continue|" + label;
|
||||
const body = this.compileStatement(statement.statement);
|
||||
var label = this.currentFunction.enterBreakContext();
|
||||
var condition = this.compileExpression(statement.condition, Type.i32);
|
||||
var breakLabel = "break|" + label;
|
||||
var continueLabel = "continue|" + label;
|
||||
var body = this.compileStatement(statement.statement);
|
||||
this.currentFunction.leaveBreakContext();
|
||||
return this.module.createBlock(breakLabel, [
|
||||
this.module.createLoop(continueLabel,
|
||||
@ -1050,7 +1048,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
compileExpression(expression: Expression, contextualType: Type, conversionKind: ConversionKind = ConversionKind.IMPLICIT): ExpressionRef {
|
||||
this.currentType = contextualType;
|
||||
|
||||
let expr: ExpressionRef;
|
||||
var expr: ExpressionRef;
|
||||
switch (expression.kind) {
|
||||
|
||||
case NodeKind.ASSERTION:
|
||||
@ -1121,13 +1119,13 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
precomputeExpressionRef(expr: ExpressionRef): ExpressionRef {
|
||||
const nativeType = this.currentType.toNativeType();
|
||||
let typeRef = this.module.getFunctionTypeBySignature(nativeType, []);
|
||||
var nativeType = this.currentType.toNativeType();
|
||||
var typeRef = this.module.getFunctionTypeBySignature(nativeType, []);
|
||||
if (!typeRef)
|
||||
typeRef = this.module.addFunctionType(this.currentType.toSignatureName(), nativeType, []);
|
||||
const funcRef = this.module.addFunction("__precompute", typeRef, [], expr);
|
||||
var funcRef = this.module.addFunction("__precompute", typeRef, [], expr);
|
||||
this.module.runPasses([ "precompute" ], funcRef);
|
||||
const ret = _BinaryenFunctionGetBody(funcRef);
|
||||
var ret = _BinaryenFunctionGetBody(funcRef);
|
||||
this.module.removeFunction("__precompute");
|
||||
// TODO: also remove the function type somehow if no longer used or make the C-API accept
|
||||
// a `null` typeRef, using an implicit type.
|
||||
@ -1148,11 +1146,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (toType.kind == TypeKind.VOID)
|
||||
return this.module.createDrop(expr);
|
||||
|
||||
const fromFloat = fromType.isAnyFloat;
|
||||
const toFloat = toType.isAnyFloat;
|
||||
var fromFloat = fromType.isAnyFloat;
|
||||
var toFloat = toType.isAnyFloat;
|
||||
|
||||
const mod = this.module;
|
||||
let losesInformation = false;
|
||||
var mod = this.module;
|
||||
var losesInformation = false;
|
||||
|
||||
if (fromFloat) {
|
||||
|
||||
@ -1298,20 +1296,20 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileAssertionExpression(expression: AssertionExpression, contextualType: Type): ExpressionRef {
|
||||
const toType = this.program.resolveType(expression.toType, this.currentFunction.contextualTypeArguments); // reports
|
||||
var toType = this.program.resolveType(expression.toType, this.currentFunction.contextualTypeArguments); // reports
|
||||
if (!toType)
|
||||
return this.module.createUnreachable();
|
||||
return this.compileExpression(expression.expression, toType, ConversionKind.EXPLICIT);
|
||||
}
|
||||
|
||||
compileBinaryExpression(expression: BinaryExpression, contextualType: Type): ExpressionRef {
|
||||
let op: BinaryOp;
|
||||
let left: ExpressionRef;
|
||||
let right: ExpressionRef;
|
||||
let compound: Token = 0;
|
||||
var op: BinaryOp;
|
||||
var left: ExpressionRef;
|
||||
var right: ExpressionRef;
|
||||
var compound: Token = 0;
|
||||
|
||||
let condition: ExpressionRef;
|
||||
let tempLocal: Local;
|
||||
var condition: ExpressionRef;
|
||||
var tempLocal: Local;
|
||||
|
||||
switch (expression.operator) {
|
||||
|
||||
@ -1631,7 +1629,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileAssignment(expression: Expression, valueExpression: Expression, contextualType: Type): ExpressionRef {
|
||||
let element: Element | null = null;
|
||||
var element: Element | null = null;
|
||||
switch (expression.kind) {
|
||||
|
||||
case NodeKind.IDENTIFIER:
|
||||
@ -1648,7 +1646,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (!element)
|
||||
return this.module.createUnreachable();
|
||||
|
||||
let type: Type | null = null;
|
||||
var type: Type | null = null;
|
||||
switch (element.kind) {
|
||||
|
||||
case ElementKind.LOCAL:
|
||||
@ -1661,16 +1659,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
break;
|
||||
|
||||
case ElementKind.PROPERTY:
|
||||
const setterPrototype = (<Property>element).setterPrototype;
|
||||
var setterPrototype = (<Property>element).setterPrototype;
|
||||
if (setterPrototype) {
|
||||
const setterInstance = setterPrototype.resolve(); // reports
|
||||
var setterInstance = setterPrototype.resolve(); // reports
|
||||
if (setterInstance) {
|
||||
if (contextualType == Type.void) { // just set if dropped anyway
|
||||
return this.compileCall(setterInstance, [ valueExpression ], expression);
|
||||
} else { // otherwise do a set followed by a get
|
||||
const getterPrototype = (<Property>element).getterPrototype;
|
||||
var getterPrototype = (<Property>element).getterPrototype;
|
||||
if (getterPrototype) {
|
||||
const getterInstance = getterPrototype.resolve(); // reports
|
||||
var getterInstance = getterPrototype.resolve(); // reports
|
||||
if (getterInstance) {
|
||||
return this.module.createBlock(null, [
|
||||
this.compileCall(setterInstance, [ valueExpression ], expression),
|
||||
@ -1696,7 +1694,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileAssignmentWithValue(expression: Expression, valueWithCorrectType: ExpressionRef, tee: bool = false): ExpressionRef {
|
||||
let element: Element | null = null;
|
||||
var element: Element | null = null;
|
||||
switch (expression.kind) {
|
||||
|
||||
case NodeKind.IDENTIFIER:
|
||||
@ -1731,7 +1729,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
if (tee) {
|
||||
const globalNativeType: NativeType = (<Type>(<Global>element).type).toNativeType();
|
||||
var globalNativeType = (<Type>(<Global>element).type).toNativeType();
|
||||
return this.module.createBlock(null, [ // teeGlobal
|
||||
this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType),
|
||||
this.module.createGetGlobal((<Global>element).internalName, globalNativeType)
|
||||
@ -1747,7 +1745,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileCallExpression(expression: CallExpression, contextualType: Type): ExpressionRef {
|
||||
let element: Element | null = null;
|
||||
var element: Element | null = null;
|
||||
switch (expression.expression.kind) {
|
||||
// case NodeKind.SUPER:
|
||||
|
||||
@ -1766,14 +1764,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createUnreachable();
|
||||
|
||||
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
||||
const functionPrototype = <FunctionPrototype>element;
|
||||
let functionInstance: Function | null = null;
|
||||
var functionPrototype = <FunctionPrototype>element;
|
||||
var functionInstance: Function | null = null;
|
||||
if (functionPrototype.isBuiltIn) {
|
||||
const k = expression.typeArguments.length;
|
||||
const resolvedTypeArguments = new Array<Type>(k);
|
||||
var k = expression.typeArguments.length;
|
||||
var resolvedTypeArguments = new Array<Type>(k);
|
||||
sb.length = 0;
|
||||
for (let i = 0; i < k; ++i) {
|
||||
let resolvedType = this.program.resolveType(expression.typeArguments[i], this.currentFunction.contextualTypeArguments, true); // reports
|
||||
for (var i = 0; i < k; ++i) {
|
||||
var resolvedType = this.program.resolveType(expression.typeArguments[i], this.currentFunction.contextualTypeArguments, true); // reports
|
||||
if (!resolvedType)
|
||||
return this.module.createUnreachable();
|
||||
resolvedTypeArguments[i] = resolvedType;
|
||||
@ -1783,7 +1781,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
functionInstance = functionPrototype.instances.get(sb.join(","));
|
||||
if (!functionInstance) {
|
||||
this.currentType = contextualType;
|
||||
let expr = compileBuiltinCall(this, functionPrototype, resolvedTypeArguments, expression.arguments, expression);
|
||||
var expr = compileBuiltinCall(this, functionPrototype, resolvedTypeArguments, expression.arguments, expression);
|
||||
if (!expr) {
|
||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
||||
return this.module.createUnreachable();
|
||||
@ -1806,9 +1804,9 @@ export class Compiler extends DiagnosticEmitter {
|
||||
compileCall(functionInstance: Function, argumentExpressions: Expression[], reportNode: Node): ExpressionRef {
|
||||
|
||||
// validate and compile arguments
|
||||
const parameters = functionInstance.parameters;
|
||||
const parameterCount = parameters.length;
|
||||
const argumentCount = argumentExpressions.length;
|
||||
var parameters = functionInstance.parameters;
|
||||
var parameterCount = parameters.length;
|
||||
var argumentCount = argumentExpressions.length;
|
||||
if (argumentExpressions.length > parameterCount) { // too many arguments
|
||||
this.error(DiagnosticCode.Expected_0_arguments_but_got_1, reportNode.range,
|
||||
(functionInstance.isInstance ? parameterCount - 1 : parameterCount).toString(10),
|
||||
@ -1816,12 +1814,12 @@ export class Compiler extends DiagnosticEmitter {
|
||||
);
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
const operands = new Array<ExpressionRef>(parameterCount);
|
||||
for (let i = 0; i < parameterCount; ++i) {
|
||||
var operands = new Array<ExpressionRef>(parameterCount);
|
||||
for (var i = 0; i < parameterCount; ++i) {
|
||||
if (argumentExpressions.length > i) {
|
||||
operands[i] = this.compileExpression(argumentExpressions[i], parameters[i].type);
|
||||
} else {
|
||||
const initializer = parameters[i].initializer;
|
||||
var initializer = parameters[i].initializer;
|
||||
if (initializer) { // omitted, uses initializer
|
||||
// FIXME: here, the initializer is compiled in the caller's scope.
|
||||
// a solution could be to use a stub for each possible overload, calling the
|
||||
@ -1851,7 +1849,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileElementAccessExpression(expression: ElementAccessExpression, contextualType: Type): ExpressionRef {
|
||||
const element = this.program.resolveElement(expression.expression, this.currentFunction); // reports
|
||||
var element = this.program.resolveElement(expression.expression, this.currentFunction); // reports
|
||||
if (!element)
|
||||
return this.module.createUnreachable();
|
||||
throw new Error("not implemented");
|
||||
@ -1892,7 +1890,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
|
||||
const element = this.program.resolveElement(expression, this.currentFunction); // reports
|
||||
var element = this.program.resolveElement(expression, this.currentFunction); // reports
|
||||
if (!element)
|
||||
return this.module.createUnreachable();
|
||||
|
||||
@ -1907,7 +1905,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (element.isBuiltIn)
|
||||
return compileBuiltinGetConstant(this, <Global>element);
|
||||
|
||||
const global = <Global>element;
|
||||
var global = <Global>element;
|
||||
if (!this.compileGlobal(global)) // reports
|
||||
return this.module.createUnreachable();
|
||||
assert(global.type != null);
|
||||
@ -1936,7 +1934,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// case LiteralKind.ARRAY:
|
||||
|
||||
case LiteralKind.FLOAT: {
|
||||
const floatValue = (<FloatLiteralExpression>expression).value;
|
||||
var floatValue = (<FloatLiteralExpression>expression).value;
|
||||
if (contextualType == Type.f32)
|
||||
return this.module.createF32(<f32>floatValue);
|
||||
this.currentType = Type.f64;
|
||||
@ -1944,7 +1942,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
case LiteralKind.INTEGER: {
|
||||
const intValue = (<IntegerLiteralExpression>expression).value;
|
||||
var intValue = (<IntegerLiteralExpression>expression).value;
|
||||
if (contextualType == Type.bool && (intValue.isZero || intValue.isOne))
|
||||
return this.module.createI32(intValue.isZero ? 0 : 1);
|
||||
if (contextualType == Type.f64)
|
||||
@ -1980,11 +1978,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compilePropertyAccessExpression(propertyAccess: PropertyAccessExpression, contextualType: Type): ExpressionRef {
|
||||
const expression = propertyAccess.expression;
|
||||
const propertyName = propertyAccess.property.name;
|
||||
var expression = propertyAccess.expression;
|
||||
var propertyName = propertyAccess.property.name;
|
||||
|
||||
// the lhs expression is either 'this', 'super', an identifier or another property access
|
||||
let target: Element | null;
|
||||
var target: Element | null;
|
||||
switch (expression.kind) {
|
||||
|
||||
case NodeKind.THIS:
|
||||
@ -2018,7 +2016,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createUnreachable();
|
||||
|
||||
// look up the property within the target to obtain the actual element
|
||||
let element: Element | null;
|
||||
var element: Element | null;
|
||||
switch (target.kind) {
|
||||
|
||||
case ElementKind.LOCAL:
|
||||
@ -2053,7 +2051,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (element.kind == ElementKind.ENUMVALUE) {
|
||||
this.currentType = Type.i32;
|
||||
if ((<EnumValue>element).hasConstantValue)
|
||||
return this.module.createI32((<EnumValue>element).constantValue)
|
||||
return this.module.createI32((<EnumValue>element).constantValue);
|
||||
this.compileEnum((<EnumValue>element).enum);
|
||||
return this.module.createGetGlobal((<EnumValue>element).internalName, NativeType.I32);
|
||||
}
|
||||
@ -2084,9 +2082,9 @@ export class Compiler extends DiagnosticEmitter {
|
||||
return this.module.createGetGlobal((<Global>element).internalName, this.currentType.toNativeType());
|
||||
|
||||
case ElementKind.PROPERTY: // getter
|
||||
const getterPrototype = (<Property>element).getterPrototype;
|
||||
var getterPrototype = (<Property>element).getterPrototype;
|
||||
if (getterPrototype) {
|
||||
const getterInstance = getterPrototype.resolve([], this.currentFunction.contextualTypeArguments);
|
||||
var getterInstance = getterPrototype.resolve([], this.currentFunction.contextualTypeArguments);
|
||||
if (getterInstance) {
|
||||
return this.compileCall(getterInstance, [], propertyAccess);
|
||||
} else {
|
||||
@ -2102,24 +2100,24 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileTernaryExpression(expression: TernaryExpression, contextualType: Type): ExpressionRef {
|
||||
const condition = this.compileExpression(expression.condition, Type.i32);
|
||||
const ifThen = this.compileExpression(expression.ifThen, contextualType);
|
||||
const ifElse = this.compileExpression(expression.ifElse, contextualType);
|
||||
var condition = this.compileExpression(expression.condition, Type.i32);
|
||||
var ifThen = this.compileExpression(expression.ifThen, contextualType);
|
||||
var ifElse = this.compileExpression(expression.ifElse, contextualType);
|
||||
return this.module.createIf(condition, ifThen, ifElse);
|
||||
}
|
||||
|
||||
compileUnaryPostfixExpression(expression: UnaryPostfixExpression, contextualType: Type): ExpressionRef {
|
||||
const operator = expression.operator;
|
||||
var operator = expression.operator;
|
||||
|
||||
// make a getter for the expression (also obtains the type)
|
||||
const getValue = this.compileExpression(expression.operand, contextualType, contextualType == Type.void ? ConversionKind.NONE : ConversionKind.IMPLICIT);
|
||||
var getValue = this.compileExpression(expression.operand, contextualType, contextualType == Type.void ? ConversionKind.NONE : ConversionKind.IMPLICIT);
|
||||
|
||||
// use a temp local for the intermediate value
|
||||
const tempLocal = this.currentFunction.getTempLocal(this.currentType);
|
||||
var tempLocal = this.currentFunction.getTempLocal(this.currentType);
|
||||
|
||||
let op: BinaryOp;
|
||||
let nativeType: NativeType;
|
||||
let nativeOne: ExpressionRef;
|
||||
var op: BinaryOp;
|
||||
var nativeType: NativeType;
|
||||
var nativeOne: ExpressionRef;
|
||||
|
||||
if (tempLocal.type == Type.f32) {
|
||||
op = operator == Token.PLUS_PLUS ? BinaryOp.AddF32 : BinaryOp.SubF32;
|
||||
@ -2143,7 +2141,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// make a setter that sets the new value (temp value +/- 1)
|
||||
const setValue = this.compileAssignmentWithValue(expression.operand,
|
||||
var setValue = this.compileAssignmentWithValue(expression.operand,
|
||||
this.module.createBinary(op,
|
||||
this.module.createGetLocal(tempLocal.index, nativeType),
|
||||
nativeOne
|
||||
@ -2162,10 +2160,10 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
compileUnaryPrefixExpression(expression: UnaryPrefixExpression, contextualType: Type): ExpressionRef {
|
||||
const operandExpression = expression.operand;
|
||||
var operandExpression = expression.operand;
|
||||
|
||||
let operand: ExpressionRef;
|
||||
let op: UnaryOp;
|
||||
var operand: ExpressionRef;
|
||||
var op: UnaryOp;
|
||||
|
||||
switch (expression.operator) {
|
||||
|
||||
@ -2240,7 +2238,7 @@ function isModuleExport(element: Element, declaration: DeclarationStatement): bo
|
||||
return false;
|
||||
if (declaration.range.source.isEntry)
|
||||
return true;
|
||||
let parentNode = declaration.parent;
|
||||
var parentNode = declaration.parent;
|
||||
if (!parentNode)
|
||||
return false;
|
||||
if (parentNode.kind == NodeKind.VARIABLE)
|
||||
@ -2248,7 +2246,7 @@ function isModuleExport(element: Element, declaration: DeclarationStatement): bo
|
||||
return false;
|
||||
if (parentNode.kind != NodeKind.NAMESPACE && parentNode.kind != NodeKind.CLASS)
|
||||
return false;
|
||||
let parent = element.program.elements.get((<DeclarationStatement>parentNode).internalName);
|
||||
var parent = element.program.elements.get((<DeclarationStatement>parentNode).internalName);
|
||||
if (!parent)
|
||||
return false;
|
||||
return isModuleExport(parent, <DeclarationStatement>parentNode);
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
export class Decompiler {
|
||||
|
||||
static decompile(module: Module): string {
|
||||
const decompiler: Decompiler = new Decompiler();
|
||||
var decompiler = new Decompiler();
|
||||
decompiler.decompile(module);
|
||||
return decompiler.finish();
|
||||
}
|
||||
@ -39,13 +39,12 @@ export class Decompiler {
|
||||
}
|
||||
|
||||
decompileFunction(func: FunctionRef): void {
|
||||
const name: string = readString(_BinaryenFunctionGetName(func)) || "$" + this.functionId.toString(10);
|
||||
const body: ExpressionRef = _BinaryenFunctionGetBody(func);
|
||||
var name = readString(_BinaryenFunctionGetName(func)) || "$" + this.functionId.toString(10);
|
||||
var body = _BinaryenFunctionGetBody(func);
|
||||
this.push("function ");
|
||||
this.push(name);
|
||||
this.push("(");
|
||||
let k: Index = _BinaryenFunctionGetNumParams(func);
|
||||
for (let i: Index = 0; i < k; ++i) {
|
||||
for (var i: Index = 0, k: Index = _BinaryenFunctionGetNumParams(func); i < k; ++i) {
|
||||
if (i > 0)
|
||||
this.push(", ");
|
||||
this.push("$");
|
||||
@ -67,12 +66,12 @@ export class Decompiler {
|
||||
}
|
||||
|
||||
decompileExpression(expr: ExpressionRef): void {
|
||||
const id: ExpressionId = _BinaryenExpressionGetId(expr);
|
||||
const type: NativeType = _BinaryenExpressionGetType(expr);
|
||||
var id = _BinaryenExpressionGetId(expr);
|
||||
var type = _BinaryenExpressionGetType(expr);
|
||||
|
||||
let nested: ExpressionRef;
|
||||
let string: string | null;
|
||||
let i: Index, k: Index;
|
||||
var nested: ExpressionRef;
|
||||
var string: string | null;
|
||||
var i: Index, k: Index;
|
||||
|
||||
switch (id) {
|
||||
|
||||
@ -829,7 +828,7 @@ export class Decompiler {
|
||||
}
|
||||
|
||||
finish(): string {
|
||||
const ret: string = this.text.join("");
|
||||
var ret = this.text.join("");
|
||||
this.text = [];
|
||||
return ret;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ export class DiagnosticMessage {
|
||||
}
|
||||
|
||||
static create(code: DiagnosticCode, category: DiagnosticCategory, arg0: string | null = null, arg1: string | null = null): DiagnosticMessage {
|
||||
let message: string = diagnosticCodeToString(code);
|
||||
var message = diagnosticCodeToString(code);
|
||||
if (arg0 != null)
|
||||
message = message.replace("{0}", arg0);
|
||||
if (arg1 != null)
|
||||
@ -98,7 +98,7 @@ export class DiagnosticMessage {
|
||||
|
||||
export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: bool = false, showContext: bool = false): string {
|
||||
// format context first (uses same string builder)
|
||||
let context: string = "";
|
||||
var context = "";
|
||||
if (message.range && showContext)
|
||||
context = formatDiagnosticContext(message.range, useColors);
|
||||
|
||||
@ -114,16 +114,16 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
|
||||
|
||||
// range information if available
|
||||
if (message.range) {
|
||||
const range: Range = message.range;
|
||||
const text: string = range.source.text;
|
||||
var range = message.range;
|
||||
var text = range.source.text;
|
||||
if (showContext) {
|
||||
sb.push("\n");
|
||||
sb.push(context);
|
||||
}
|
||||
sb.push("\n");
|
||||
let pos: i32 = range.start;
|
||||
let line: i32 = 1;
|
||||
let column: i32 = 1;
|
||||
var pos = range.start;
|
||||
var line = 1;
|
||||
var column = 1;
|
||||
while (pos-- > 0)
|
||||
if (text.charCodeAt(pos) == CharCode.LINEFEED)
|
||||
line++;
|
||||
@ -141,10 +141,10 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
|
||||
}
|
||||
|
||||
export function formatDiagnosticContext(range: Range, useColors: bool = false): string {
|
||||
const text: string = range.source.text;
|
||||
const len: i32 = text.length;
|
||||
let start: i32 = range.start;
|
||||
let end: i32 = range.end;
|
||||
var text = range.source.text;
|
||||
var len = text.length;
|
||||
var start = range.start;
|
||||
var end = range.end;
|
||||
while (start > 0 && !isLineBreak(text.charCodeAt(start - 1)))
|
||||
start--;
|
||||
while (end < len && !isLineBreak(text.charCodeAt(end)))
|
||||
@ -176,7 +176,7 @@ export abstract class DiagnosticEmitter {
|
||||
}
|
||||
|
||||
emitDiagnostic(code: DiagnosticCode, category: DiagnosticCategory, range: Range, arg0: string | null = null, arg1: string | null = null) {
|
||||
const message: DiagnosticMessage = DiagnosticMessage.create(code, category, arg0, arg1).withRange(range);
|
||||
var message = DiagnosticMessage.create(code, category, arg0, arg1).withRange(range);
|
||||
this.diagnostics.push(message);
|
||||
if (!this.silentDiagnostics) {
|
||||
console.log(formatDiagnosticMessage(message, true, true) + "\n"); // temporary
|
||||
|
@ -67,7 +67,7 @@ export function nextFile(parser: Parser): string | null {
|
||||
|
||||
/** Obtains the next diagnostic message. Returns `null` once there are no more messages. */
|
||||
export function nextDiagnostic(parser: Parser): DiagnosticMessage | null {
|
||||
const program: Program = parser.program;
|
||||
var program = parser.program;
|
||||
if (program.diagnosticsOffset < program.diagnostics.length)
|
||||
return program.diagnostics[program.diagnosticsOffset++];
|
||||
return null;
|
||||
@ -120,14 +120,14 @@ export function setNoMemory(options: Options, noMemory: bool): void {
|
||||
|
||||
/** Compiles the sources computed by the parser to a module. */
|
||||
export function compile(parser: Parser, options: Options | null = null): Module {
|
||||
const program: Program = parser.finish();
|
||||
const compiler: Compiler = new Compiler(program, options);
|
||||
var program = parser.finish();
|
||||
var compiler = new Compiler(program, options);
|
||||
return compiler.compile();
|
||||
}
|
||||
|
||||
/** Decompiles a module to its (low level) source. */
|
||||
export function decompile(module: Module): string {
|
||||
const decompiler: Decompiler = new Decompiler();
|
||||
var decompiler = new Decompiler();
|
||||
decompiler.decompile(module);
|
||||
return decompiler.finish();
|
||||
}
|
||||
|
177
src/module.ts
177
src/module.ts
@ -246,7 +246,7 @@ export class MemorySegment {
|
||||
offset: U64;
|
||||
|
||||
static create(buffer: Uint8Array, offset: U64) {
|
||||
const segment: MemorySegment = new MemorySegment();
|
||||
var segment = new MemorySegment();
|
||||
segment.buffer = buffer;
|
||||
segment.offset = offset;
|
||||
return segment;
|
||||
@ -262,7 +262,7 @@ export class Module {
|
||||
static MAX_MEMORY_WASM32: Index = 0xffff;
|
||||
|
||||
static create(): Module {
|
||||
const module: Module = new Module();
|
||||
var module = new Module();
|
||||
module.ref = _BinaryenModuleCreate();
|
||||
module.lit = changetype<usize,BinaryenLiteral>(Heap.allocate(16));
|
||||
module.noEmit = false;
|
||||
@ -270,9 +270,9 @@ export class Module {
|
||||
}
|
||||
|
||||
static createFrom(buffer: Uint8Array): Module {
|
||||
const cArr: usize = allocU8Array(buffer);
|
||||
var cArr = allocU8Array(buffer);
|
||||
try {
|
||||
const module: Module = new Module();
|
||||
var module = new Module();
|
||||
module.ref = _BinaryenModuleRead(cArr, buffer.length);
|
||||
module.lit = changetype<usize,BinaryenLiteral>(Heap.allocate(16));
|
||||
module.noEmit = false;
|
||||
@ -283,7 +283,7 @@ export class Module {
|
||||
}
|
||||
|
||||
static createStub(): Module {
|
||||
const module: Module = new Module();
|
||||
var module = new Module();
|
||||
module.ref = 0;
|
||||
module.lit = changetype<usize,BinaryenLiteral>(0);
|
||||
module.noEmit = true;
|
||||
@ -296,8 +296,8 @@ export class Module {
|
||||
|
||||
addFunctionType(name: string, result: NativeType, paramTypes: NativeType[]): FunctionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
const cArr: usize = allocI32Array(paramTypes);
|
||||
var cStr = allocString(name);
|
||||
var cArr = allocI32Array(paramTypes);
|
||||
try {
|
||||
return _BinaryenAddFunctionType(this.ref, cStr, result, cArr, paramTypes.length);
|
||||
} finally {
|
||||
@ -308,7 +308,7 @@ export class Module {
|
||||
|
||||
getFunctionTypeBySignature(result: NativeType, paramTypes: NativeType[]): FunctionTypeRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cArr: usize = allocI32Array(paramTypes);
|
||||
var cArr = allocI32Array(paramTypes);
|
||||
try {
|
||||
return _BinaryenGetFunctionTypeBySignature(this.ref, result, cArr, paramTypes.length);
|
||||
} finally {
|
||||
@ -354,8 +354,8 @@ export class Module {
|
||||
|
||||
createHost(op: HostOp, name: string | null = null, operands: ExpressionRef[] | null = null): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
const cArr: usize = allocI32Array(operands);
|
||||
var cStr = allocString(name);
|
||||
var cArr = allocI32Array(operands);
|
||||
try {
|
||||
return _BinaryenHost(this.ref, op, cStr, cArr, operands ? (<ExpressionRef[]>operands).length : 0);
|
||||
} finally {
|
||||
@ -376,7 +376,7 @@ export class Module {
|
||||
|
||||
createGetGlobal(name: string, type: NativeType): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
var cStr = allocString(name);
|
||||
try {
|
||||
return _BinaryenGetGlobal(this.ref, cStr, type);
|
||||
} finally {
|
||||
@ -433,7 +433,7 @@ export class Module {
|
||||
|
||||
createSetGlobal(name: string, value: ExpressionRef): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
var cStr = allocString(name);
|
||||
try {
|
||||
return _BinaryenSetGlobal(this.ref, cStr, value);
|
||||
} finally {
|
||||
@ -443,8 +443,8 @@ export class Module {
|
||||
|
||||
createBlock(label: string | null, children: ExpressionRef[], type: NativeType = NativeType.Auto): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(label);
|
||||
const cArr: usize = allocI32Array(children);
|
||||
var cStr = allocString(label);
|
||||
var cArr = allocI32Array(children);
|
||||
try {
|
||||
return _BinaryenBlock(this.ref, cStr, cArr, children.length, type);
|
||||
} finally {
|
||||
@ -455,7 +455,7 @@ export class Module {
|
||||
|
||||
createBreak(label: string | null, condition: ExpressionRef = 0, value: ExpressionRef = 0): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(label);
|
||||
var cStr = allocString(label);
|
||||
try {
|
||||
return _BinaryenBreak(this.ref, cStr, condition, value);
|
||||
} finally {
|
||||
@ -470,7 +470,7 @@ export class Module {
|
||||
|
||||
createLoop(label: string | null, body: ExpressionRef): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(label);
|
||||
var cStr = allocString(label);
|
||||
try {
|
||||
return _BinaryenLoop(this.ref, cStr, body);
|
||||
} finally {
|
||||
@ -500,11 +500,11 @@ export class Module {
|
||||
|
||||
createSwitch(names: string[], defaultName: string | null, condition: ExpressionRef, value: ExpressionRef = 0): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const strs: usize[] = new Array(names.length);
|
||||
let i: i32, k: i32 = names.length;
|
||||
for (i = 0; i < k; ++i) strs[i] = allocString(names[i]);
|
||||
const cArr: usize = allocI32Array(strs);
|
||||
const cStr: usize = allocString(defaultName);
|
||||
var strs = new Array<usize>(names.length);
|
||||
for (var i = 0, k: i32 = names.length; i < k; ++i)
|
||||
strs[i] = allocString(names[i]);
|
||||
var cArr = allocI32Array(strs);
|
||||
var cStr = allocString(defaultName);
|
||||
try {
|
||||
return _BinaryenSwitch(this.ref, cArr, k, cStr, condition, value);
|
||||
} finally {
|
||||
@ -516,8 +516,8 @@ export class Module {
|
||||
|
||||
createCall(target: string, operands: ExpressionRef[], returnType: NativeType): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(target);
|
||||
const cArr: usize = allocI32Array(operands);
|
||||
var cStr = allocString(target);
|
||||
var cArr = allocI32Array(operands);
|
||||
try {
|
||||
return _BinaryenCall(this.ref, cStr, cArr, operands.length, returnType);
|
||||
} finally {
|
||||
@ -528,8 +528,8 @@ export class Module {
|
||||
|
||||
createCallImport(target: string, operands: ExpressionRef[], returnType: NativeType): ExpressionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(target);
|
||||
const cArr: usize = allocI32Array(operands);
|
||||
var cStr = allocString(target);
|
||||
var cArr = allocI32Array(operands);
|
||||
try {
|
||||
return _BinaryenCallImport(this.ref, cStr, cArr, operands.length, returnType);
|
||||
} finally {
|
||||
@ -547,7 +547,7 @@ export class Module {
|
||||
|
||||
addGlobal(name: string, type: NativeType, mutable: bool, initializer: ExpressionRef): GlobalRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
var cStr = allocString(name);
|
||||
try {
|
||||
return _BinaryenAddGlobal(this.ref, cStr, type, mutable ? 1 : 0, initializer);
|
||||
} finally {
|
||||
@ -557,8 +557,8 @@ export class Module {
|
||||
|
||||
addFunction(name: string, type: FunctionTypeRef, varTypes: NativeType[], body: ExpressionRef): FunctionRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr: usize = allocString(name);
|
||||
const cArr: usize = allocI32Array(varTypes);
|
||||
var cStr = allocString(name);
|
||||
var cArr = allocI32Array(varTypes);
|
||||
try {
|
||||
return _BinaryenAddFunction(this.ref, cStr, type, cArr, varTypes.length, body);
|
||||
} finally {
|
||||
@ -568,7 +568,7 @@ export class Module {
|
||||
}
|
||||
|
||||
removeFunction(name: string): void {
|
||||
const cStr: usize = allocString(name);
|
||||
var cStr = allocString(name);
|
||||
try {
|
||||
_BinaryenRemoveFunction(this.ref, cStr);
|
||||
} finally {
|
||||
@ -578,8 +578,8 @@ export class Module {
|
||||
|
||||
addFunctionExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddFunctionExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
@ -590,8 +590,8 @@ export class Module {
|
||||
|
||||
addTableExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddTableExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
@ -602,8 +602,8 @@ export class Module {
|
||||
|
||||
addMemoryExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddMemoryExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
@ -614,8 +614,8 @@ export class Module {
|
||||
|
||||
addGlobalExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddGlobalExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
@ -626,7 +626,7 @@ export class Module {
|
||||
|
||||
removeExport(externalName: string): void {
|
||||
if (this.noEmit) return;
|
||||
const cStr = allocString(externalName);
|
||||
var cStr = allocString(externalName);
|
||||
try {
|
||||
_BinaryenRemoveExport(this.ref, cStr);
|
||||
} finally {
|
||||
@ -636,9 +636,9 @@ export class Module {
|
||||
|
||||
addFunctionImport(internalName: string, externalModuleName: string, externalBaseName: string, functionType: FunctionTypeRef): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalModuleName);
|
||||
const cStr3: usize = allocString(externalBaseName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalModuleName);
|
||||
var cStr3 = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddFunctionImport(this.ref, cStr1, cStr2, cStr3, functionType);
|
||||
} finally {
|
||||
@ -650,9 +650,9 @@ export class Module {
|
||||
|
||||
addTableImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalModuleName);
|
||||
const cStr3: usize = allocString(externalBaseName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalModuleName);
|
||||
var cStr3 = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddTableImport(this.ref, cStr1, cStr2, cStr3);
|
||||
} finally {
|
||||
@ -664,9 +664,9 @@ export class Module {
|
||||
|
||||
addMemoryImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalModuleName);
|
||||
const cStr3: usize = allocString(externalBaseName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalModuleName);
|
||||
var cStr3 = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddMemoryImport(this.ref, cStr1, cStr2, cStr3);
|
||||
} finally {
|
||||
@ -678,9 +678,9 @@ export class Module {
|
||||
|
||||
addGlobalImport(internalName: string, externalModuleName: string, externalBaseName: string, globalType: NativeType): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: usize = allocString(internalName);
|
||||
const cStr2: usize = allocString(externalModuleName);
|
||||
const cStr3: usize = allocString(externalBaseName);
|
||||
var cStr1 = allocString(internalName);
|
||||
var cStr2 = allocString(externalModuleName);
|
||||
var cStr3 = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddGlobalImport(this.ref, cStr1, cStr2, cStr3, globalType);
|
||||
} finally {
|
||||
@ -692,7 +692,7 @@ export class Module {
|
||||
|
||||
removeImport(internalName: string): void {
|
||||
if (this.noEmit) return;
|
||||
const cStr: usize = allocString(internalName);
|
||||
var cStr = allocString(internalName);
|
||||
try {
|
||||
_BinaryenRemoveImport(this.ref, cStr);
|
||||
} finally {
|
||||
@ -702,23 +702,23 @@ export class Module {
|
||||
|
||||
setMemory(initial: Index, maximum: Index, segments: MemorySegment[], target: Target, exportName: string | null = null): void {
|
||||
if (this.noEmit) return;
|
||||
const cStr: usize = allocString(exportName);
|
||||
let i: i32, k: i32 = segments.length;
|
||||
const segs: usize[] = new Array(k);
|
||||
const offs: ExpressionRef[] = new Array(k);
|
||||
const sizs: Index[] = new Array(k);
|
||||
for (i = 0; i < k; ++i) {
|
||||
const buffer: Uint8Array = segments[i].buffer;
|
||||
const offset: U64 = segments[i].offset;
|
||||
var cStr = allocString(exportName);
|
||||
var k = segments.length;
|
||||
var segs = new Array<usize>(k);
|
||||
var offs = new Array<ExpressionRef>(k);
|
||||
var sizs = new Array<Index>(k);
|
||||
for (var i = 0; i < k; ++i) {
|
||||
var buffer = segments[i].buffer;
|
||||
var offset = segments[i].offset;
|
||||
segs[i] = allocU8Array(buffer);
|
||||
offs[i] = target == Target.WASM64
|
||||
? this.createI64(offset.lo, offset.hi)
|
||||
: this.createI32(offset.toI32());
|
||||
sizs[i] = buffer.length;
|
||||
}
|
||||
const cArr1: usize = allocI32Array(segs);
|
||||
const cArr2: usize = allocI32Array(offs);
|
||||
const cArr3: usize = allocI32Array(sizs);
|
||||
var cArr1 = allocI32Array(segs);
|
||||
var cArr2 = allocI32Array(offs);
|
||||
var cArr3 = allocI32Array(sizs);
|
||||
try {
|
||||
_BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k);
|
||||
} finally {
|
||||
@ -732,7 +732,7 @@ export class Module {
|
||||
|
||||
setFunctionTable(funcs: FunctionRef[]): void {
|
||||
if (this.noEmit) return;
|
||||
const cArr: usize = allocI32Array(funcs);
|
||||
var cArr = allocI32Array(funcs);
|
||||
try {
|
||||
_BinaryenSetFunctionTable(this.ref, cArr, funcs.length);
|
||||
} finally {
|
||||
@ -756,10 +756,11 @@ export class Module {
|
||||
}
|
||||
|
||||
runPasses(passes: string[], func: FunctionRef = 0): void {
|
||||
let i: i32, k: i32 = passes.length;
|
||||
const names: usize[] = new Array(k);
|
||||
for (i = 0; i < k; ++i) names[i] = allocString(passes[i]);
|
||||
const cArr: usize = allocI32Array(names);
|
||||
var k = passes.length;
|
||||
var names = new Array<usize>(k);
|
||||
for (var i = 0; i < k; ++i)
|
||||
names[i] = allocString(passes[i]);
|
||||
var cArr = allocI32Array(names);
|
||||
try {
|
||||
if (func)
|
||||
_BinaryenFunctionRunPasses(func, this.ref, cArr, k);
|
||||
@ -816,7 +817,7 @@ export class Module {
|
||||
cloneExpression(expr: ExpressionRef, noSideEffects: bool = false, maxDepth: i32 = 0x7fffffff): ExpressionRef {
|
||||
if (this.noEmit || maxDepth < 0) return 0;
|
||||
|
||||
let nested1: ExpressionRef,
|
||||
var nested1: ExpressionRef,
|
||||
nested2: ExpressionRef;
|
||||
|
||||
switch (_BinaryenExpressionGetId(expr)) {
|
||||
@ -862,7 +863,7 @@ export class Relooper {
|
||||
noEmit: bool;
|
||||
|
||||
static create(module: Module): Relooper {
|
||||
const relooper: Relooper = new Relooper();
|
||||
var relooper = new Relooper();
|
||||
relooper.module = module;
|
||||
relooper.ref = _RelooperCreate();
|
||||
relooper.noEmit = false;
|
||||
@ -870,7 +871,7 @@ export class Relooper {
|
||||
}
|
||||
|
||||
static createStub(module: Module): Relooper {
|
||||
const relooper: Relooper = new Relooper();
|
||||
var relooper = new Relooper();
|
||||
relooper.module = module;
|
||||
relooper.ref = 0;
|
||||
relooper.noEmit = true;
|
||||
@ -896,7 +897,7 @@ export class Relooper {
|
||||
|
||||
addBranchForSwitch(from: RelooperBlockRef, to: RelooperBlockRef, indexes: i32[], code: ExpressionRef = 0): void {
|
||||
if (this.noEmit) return;
|
||||
const cArr: usize = allocI32Array(indexes);
|
||||
var cArr = allocI32Array(indexes);
|
||||
try {
|
||||
_RelooperAddBranchForSwitch(from, to, cArr, indexes.length, code);
|
||||
} finally {
|
||||
@ -919,19 +920,19 @@ export function setAPITracing(on: bool): void {
|
||||
|
||||
function allocU8Array(u8s: Uint8Array | null): usize {
|
||||
if (!u8s) return 0;
|
||||
const ptr: usize = Heap.allocate((<Uint8Array>u8s).length);
|
||||
let idx: usize = ptr;
|
||||
for (let i: i32 = 0, k: i32 = (<Uint8Array>u8s).length; i < k; ++i)
|
||||
var ptr = Heap.allocate((<Uint8Array>u8s).length);
|
||||
var idx = ptr;
|
||||
for (var i = 0, k = (<Uint8Array>u8s).length; i < k; ++i)
|
||||
store<u8>(idx++, (<Uint8Array>u8s)[i]);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function allocI32Array(i32s: i32[] | null): usize {
|
||||
if (!i32s) return 0;
|
||||
const ptr: usize = Heap.allocate((<i32[]>i32s).length << 2);
|
||||
let idx: usize = ptr;
|
||||
for (let i: i32 = 0, k: i32 = (<i32[]>i32s).length; i < k; ++i) {
|
||||
let val: i32 = (<i32[]>i32s)[i];
|
||||
var ptr = Heap.allocate((<i32[]>i32s).length << 2);
|
||||
var idx = ptr;
|
||||
for (var i = 0, k = (<i32[]>i32s).length; i < k; ++i) {
|
||||
var val = (<i32[]>i32s)[i];
|
||||
// store<i32>(idx, val) is not portable
|
||||
store<u8>(idx , ( val & 0xff) as u8);
|
||||
store<u8>(idx + 1, ((val >> 8) & 0xff) as u8);
|
||||
@ -943,9 +944,9 @@ function allocI32Array(i32s: i32[] | null): usize {
|
||||
}
|
||||
|
||||
function stringLengthUTF8(str: string): usize {
|
||||
let len: i32 = 0;
|
||||
for (let i: i32 = 0, k: i32 = str.length; i < k; ++i) {
|
||||
let u: i32 = str.charCodeAt(i);
|
||||
var len = 0;
|
||||
for (var i = 0, k = str.length; i < k; ++i) {
|
||||
var u = str.charCodeAt(i);
|
||||
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k)
|
||||
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
|
||||
if (u <= 0x7F)
|
||||
@ -966,10 +967,10 @@ function stringLengthUTF8(str: string): usize {
|
||||
|
||||
function allocString(str: string | null): usize {
|
||||
if (str == null) return 0;
|
||||
const ptr: usize = Heap.allocate(stringLengthUTF8((<string>str)) + 1);
|
||||
let idx: usize = ptr;
|
||||
for (let i: i32 = 0, k: i32 = (<string>str).length; i < k; ++i) {
|
||||
let u: i32 = (<string>str).charCodeAt(i);
|
||||
var ptr = Heap.allocate(stringLengthUTF8((<string>str)) + 1);
|
||||
var idx = ptr;
|
||||
for (var i = 0, k = (<string>str).length; i < k; ++i) {
|
||||
var u = (<string>str).charCodeAt(i);
|
||||
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k)
|
||||
u = 0x10000 + ((u & 0x3FF) << 10) | ((<string>str).charCodeAt(++i) & 0x3FF);
|
||||
if (u <= 0x7F)
|
||||
@ -1007,10 +1008,10 @@ function allocString(str: string | null): usize {
|
||||
|
||||
export function readString(ptr: usize): string | null {
|
||||
if (!ptr) return null;
|
||||
const arr: i32[] = [];
|
||||
var arr = new Array<i32>();
|
||||
// the following is based on Emscripten's UTF8ArrayToString
|
||||
let cp: u32;
|
||||
let u1: u32, u2: u32, u3: u32, u4: u32, u5: u32;
|
||||
var cp: u32;
|
||||
var u1: u32, u2: u32, u3: u32, u4: u32, u5: u32;
|
||||
while (cp = load<u8>(ptr++)) {
|
||||
if (!(cp & 0x80)) {
|
||||
arr.push(cp);
|
||||
|
407
src/parser.ts
407
src/parser.ts
File diff suppressed because it is too large
Load Diff
314
src/program.ts
314
src/program.ts
@ -84,7 +84,7 @@ class QueuedImport {
|
||||
declaration: ImportDeclaration;
|
||||
}
|
||||
|
||||
const noTypesYet: Map<string,Type> = new Map();
|
||||
const noTypesYet = new Map<string,Type>();
|
||||
|
||||
/** Represents an AssemblyScript program. */
|
||||
export class Program extends DiagnosticEmitter {
|
||||
@ -135,15 +135,15 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
initializeBuiltins(this);
|
||||
|
||||
const queuedExports = new Map<string,QueuedExport>();
|
||||
const queuedImports = new Array<QueuedImport>();
|
||||
var queuedExports = new Map<string,QueuedExport>();
|
||||
var queuedImports = new Array<QueuedImport>();
|
||||
|
||||
// build initial lookup maps of internal names to declarations
|
||||
for (let i = 0, k = this.sources.length; i < k; ++i) {
|
||||
const source = this.sources[i];
|
||||
const statements = source.statements;
|
||||
for (let j = 0, l = statements.length; j < l; ++j) {
|
||||
const statement = statements[j];
|
||||
for (var i = 0, k = this.sources.length; i < k; ++i) {
|
||||
var source = this.sources[i];
|
||||
var statements = source.statements;
|
||||
for (var j = 0, l = statements.length; j < l; ++j) {
|
||||
var statement = statements[j];
|
||||
switch (statement.kind) {
|
||||
|
||||
case NodeKind.CLASS:
|
||||
@ -185,24 +185,24 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
let element: Element | null;
|
||||
var element: Element | null;
|
||||
|
||||
// queued imports should be resolvable now through traversing exports and queued exports
|
||||
for (let j = 0; j < queuedImports.length;) {
|
||||
const queuedImport = queuedImports[j];
|
||||
for (i = 0; i < queuedImports.length;) {
|
||||
var queuedImport = queuedImports[i];
|
||||
element = this.tryResolveImport(queuedImport.referencedName, queuedExports);
|
||||
if (element) {
|
||||
this.elements.set(queuedImport.internalName, element);
|
||||
queuedImports.splice(j, 1);
|
||||
queuedImports.splice(i, 1);
|
||||
} else {
|
||||
this.error(DiagnosticCode.Module_0_has_no_exported_member_1, queuedImport.declaration.range, (<ImportStatement>queuedImport.declaration.parent).path.value, queuedImport.declaration.externalIdentifier.name);
|
||||
++j;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// queued exports should be resolvable now that imports are finalized
|
||||
for (let [exportName, queuedExport] of queuedExports) {
|
||||
let currentExport: QueuedExport | null = queuedExport;
|
||||
for (var [exportName, queuedExport] of queuedExports) {
|
||||
var currentExport: QueuedExport | null = queuedExport; // nullable below
|
||||
do {
|
||||
if (currentExport.isReExport) {
|
||||
element = this.exports.get(currentExport.referencedName);
|
||||
@ -227,12 +227,12 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
/** Tries to resolve an import by traversing exports and queued exports. */
|
||||
private tryResolveImport(referencedName: string, queuedExports: Map<string,QueuedExport>): Element | null {
|
||||
let element: Element | null;
|
||||
var element: Element | null;
|
||||
do {
|
||||
element = this.exports.get(referencedName);
|
||||
if (element)
|
||||
return element;
|
||||
const queuedExport = queuedExports.get(referencedName);
|
||||
var queuedExport = queuedExports.get(referencedName);
|
||||
if (!queuedExport)
|
||||
return null;
|
||||
if (queuedExport.isReExport) {
|
||||
@ -244,12 +244,12 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeClass(declaration: ClassDeclaration, namespace: Element | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
return;
|
||||
}
|
||||
const prototype = new ClassPrototype(this, declaration.name.name, internalName, declaration);
|
||||
var prototype = new ClassPrototype(this, declaration.name.name, internalName, declaration);
|
||||
prototype.namespace = namespace;
|
||||
this.elements.set(internalName, prototype);
|
||||
|
||||
@ -282,8 +282,8 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// initialize members
|
||||
const memberDeclarations = declaration.members;
|
||||
for (let i = 0, k = memberDeclarations.length; i < k; ++i) {
|
||||
var memberDeclarations = declaration.members;
|
||||
for (var i = 0, k = memberDeclarations.length; i < k; ++i) {
|
||||
switch (memberDeclarations[i].kind) {
|
||||
|
||||
case NodeKind.FIELD:
|
||||
@ -301,8 +301,8 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeField(declaration: FieldDeclaration, classPrototype: ClassPrototype): void {
|
||||
const name = declaration.name.name;
|
||||
const internalName = declaration.internalName;
|
||||
var name = declaration.name.name;
|
||||
var internalName = declaration.internalName;
|
||||
|
||||
// static fields become global variables
|
||||
if (hasModifier(ModifierKind.STATIC, declaration.modifiers)) {
|
||||
@ -317,7 +317,7 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
classPrototype.members = new Map();
|
||||
const staticField = new Global(this, name, internalName, declaration, null);
|
||||
var staticField = new Global(this, name, internalName, declaration, null);
|
||||
classPrototype.members.set(name, staticField);
|
||||
this.elements.set(internalName, staticField);
|
||||
|
||||
@ -330,19 +330,19 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
classPrototype.instanceMembers = new Map();
|
||||
const instanceField = new FieldPrototype(classPrototype, name, internalName, declaration);
|
||||
var instanceField = new FieldPrototype(classPrototype, name, internalName, declaration);
|
||||
classPrototype.instanceMembers.set(name, instanceField);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeMethod(declaration: MethodDeclaration, classPrototype: ClassPrototype): void {
|
||||
let isGetter = false;
|
||||
var isGetter = false;
|
||||
if ((isGetter = hasModifier(ModifierKind.GET, declaration.modifiers)) || hasModifier(ModifierKind.SET, declaration.modifiers)) {
|
||||
this.initializeAccessor(declaration, classPrototype, isGetter);
|
||||
return;
|
||||
}
|
||||
const name = declaration.name.name;
|
||||
const internalName = declaration.internalName;
|
||||
var name = declaration.name.name;
|
||||
var internalName = declaration.internalName;
|
||||
|
||||
// static methods become global functions
|
||||
if (hasModifier(ModifierKind.STATIC, declaration.modifiers)) {
|
||||
@ -358,7 +358,7 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
classPrototype.members = new Map();
|
||||
const staticPrototype: FunctionPrototype = new FunctionPrototype(this, name, internalName, declaration, null);
|
||||
var staticPrototype = new FunctionPrototype(this, name, internalName, declaration, null);
|
||||
classPrototype.members.set(name, staticPrototype);
|
||||
this.elements.set(internalName, staticPrototype);
|
||||
|
||||
@ -371,16 +371,16 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
classPrototype.instanceMembers = new Map();
|
||||
const instancePrototype: FunctionPrototype = new FunctionPrototype(this, name, internalName, declaration, classPrototype);
|
||||
var instancePrototype = new FunctionPrototype(this, name, internalName, declaration, classPrototype);
|
||||
classPrototype.instanceMembers.set(name, instancePrototype);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeAccessor(declaration: MethodDeclaration, classPrototype: ClassPrototype, isGetter: bool): void {
|
||||
const propertyName = declaration.name.name;
|
||||
const internalPropertyName = declaration.internalName;
|
||||
var propertyName = declaration.name.name;
|
||||
var internalPropertyName = declaration.internalName;
|
||||
|
||||
let propertyElement = this.elements.get(internalPropertyName);
|
||||
var propertyElement = this.elements.get(internalPropertyName);
|
||||
if (propertyElement) {
|
||||
if (propertyElement.kind != ElementKind.PROPERTY || (isGetter ? (<Property>propertyElement).getterPrototype : (<Property>propertyElement).setterPrototype)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalPropertyName);
|
||||
@ -389,16 +389,16 @@ export class Program extends DiagnosticEmitter {
|
||||
} else
|
||||
propertyElement = new Property(this, propertyName, internalPropertyName, classPrototype);
|
||||
|
||||
let name = (isGetter ? GETTER_PREFIX : SETTER_PREFIX) + propertyName;
|
||||
var name = (isGetter ? GETTER_PREFIX : SETTER_PREFIX) + propertyName;
|
||||
|
||||
// static accessors become global functions
|
||||
if (hasModifier(ModifierKind.STATIC, declaration.modifiers)) {
|
||||
const internalStaticName = classPrototype.internalName + STATIC_DELIMITER + name;
|
||||
var internalStaticName = classPrototype.internalName + STATIC_DELIMITER + name;
|
||||
if (this.elements.has(internalStaticName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalStaticName);
|
||||
return;
|
||||
}
|
||||
const staticPrototype = new FunctionPrototype(this, name, internalStaticName, declaration, null);
|
||||
var staticPrototype = new FunctionPrototype(this, name, internalStaticName, declaration, null);
|
||||
if (isGetter)
|
||||
(<Property>propertyElement).getterPrototype = staticPrototype;
|
||||
else
|
||||
@ -410,7 +410,7 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
// instance accessors are remembered until resolved
|
||||
} else {
|
||||
const internalInstanceName = classPrototype.internalName + INSTANCE_DELIMITER + name;
|
||||
var internalInstanceName = classPrototype.internalName + INSTANCE_DELIMITER + name;
|
||||
if (classPrototype.instanceMembers) {
|
||||
if (classPrototype.instanceMembers.has(name)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, declaration.internalName);
|
||||
@ -418,7 +418,7 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
classPrototype.instanceMembers = new Map();
|
||||
const instancePrototype = new FunctionPrototype(this, name, internalInstanceName, declaration, classPrototype);
|
||||
var instancePrototype = new FunctionPrototype(this, name, internalInstanceName, declaration, classPrototype);
|
||||
if (isGetter)
|
||||
(<Property>propertyElement).getterPrototype = instancePrototype;
|
||||
else
|
||||
@ -428,12 +428,12 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeEnum(declaration: EnumDeclaration, namespace: Element | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
return;
|
||||
}
|
||||
const enm = new Enum(this, declaration.name.name, internalName, declaration);
|
||||
var enm = new Enum(this, declaration.name.name, internalName, declaration);
|
||||
enm.namespace = namespace;
|
||||
this.elements.set(internalName, enm);
|
||||
|
||||
@ -454,14 +454,14 @@ export class Program extends DiagnosticEmitter {
|
||||
this.exports.set(internalName, enm);
|
||||
}
|
||||
|
||||
const values = declaration.values;
|
||||
for (let i: i32 = 0, k: i32 = values.length; i < k; ++i)
|
||||
var values = declaration.values;
|
||||
for (var i = 0, k = values.length; i < k; ++i)
|
||||
this.initializeEnumValue(values[i], enm);
|
||||
}
|
||||
|
||||
private initializeEnumValue(declaration: EnumValueDeclaration, enm: Enum): void {
|
||||
const name = declaration.name.name;
|
||||
const internalName = declaration.internalName;
|
||||
var name = declaration.name.name;
|
||||
var internalName = declaration.internalName;
|
||||
if (enm.members) {
|
||||
if (enm.members.has(name)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
@ -469,23 +469,24 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
} else
|
||||
enm.members = new Map();
|
||||
const value = new EnumValue(enm, this, name, internalName, declaration);
|
||||
var value = new EnumValue(enm, this, name, internalName, declaration);
|
||||
enm.members.set(name, value);
|
||||
}
|
||||
|
||||
private initializeExports(statement: ExportStatement, queuedExports: Map<string,QueuedExport>): void {
|
||||
const members = statement.members;
|
||||
for (let i = 0, k = members.length; i < k; ++i)
|
||||
var members = statement.members;
|
||||
for (var i = 0, k = members.length; i < k; ++i)
|
||||
this.initializeExport(members[i], statement.internalPath, queuedExports);
|
||||
}
|
||||
|
||||
private initializeExport(member: ExportMember, internalPath: string | null, queuedExports: Map<string,QueuedExport>): void {
|
||||
const externalName: string = member.range.source.internalPath + PATH_DELIMITER + member.externalIdentifier.name;
|
||||
var externalName = member.range.source.internalPath + PATH_DELIMITER + member.externalIdentifier.name;
|
||||
if (this.exports.has(externalName)) {
|
||||
this.error(DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0, member.externalIdentifier.range, externalName);
|
||||
return;
|
||||
}
|
||||
let referencedName: string;
|
||||
var referencedName: string;
|
||||
var queuedExport: QueuedExport | null;
|
||||
|
||||
// export local element
|
||||
if (internalPath == null) {
|
||||
@ -502,7 +503,7 @@ export class Program extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0, member.externalIdentifier.range, externalName);
|
||||
return;
|
||||
}
|
||||
const queuedExport = new QueuedExport();
|
||||
queuedExport = new QueuedExport();
|
||||
queuedExport.isReExport = false;
|
||||
queuedExport.referencedName = referencedName; // -> internal name
|
||||
queuedExport.member = member;
|
||||
@ -519,8 +520,7 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// walk already known queued exports
|
||||
const seen = new Set<QueuedExport>();
|
||||
let queuedExport: QueuedExport | null;
|
||||
var seen = new Set<QueuedExport>();
|
||||
while (queuedExport = queuedExports.get(referencedName)) {
|
||||
if (queuedExport.isReExport) {
|
||||
if (this.exports.has(queuedExport.referencedName)) {
|
||||
@ -545,21 +545,21 @@ export class Program extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Export_declaration_conflicts_with_exported_declaration_of_0, member.externalIdentifier.range, externalName);
|
||||
return;
|
||||
}
|
||||
const queuedReExport = new QueuedExport();
|
||||
queuedReExport.isReExport = true;
|
||||
queuedReExport.referencedName = referencedName; // -> export name
|
||||
queuedReExport.member = member;
|
||||
queuedExports.set(externalName, queuedReExport);
|
||||
queuedExport = new QueuedExport();
|
||||
queuedExport.isReExport = true;
|
||||
queuedExport.referencedName = referencedName; // -> export name
|
||||
queuedExport.member = member;
|
||||
queuedExports.set(externalName, queuedExport);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeFunction(declaration: FunctionDeclaration, namespace: Element | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
return;
|
||||
}
|
||||
const prototype = new FunctionPrototype(this, declaration.name.name, internalName, declaration, null);
|
||||
var prototype = new FunctionPrototype(this, declaration.name.name, internalName, declaration, null);
|
||||
prototype.namespace = namespace;
|
||||
this.elements.set(internalName, prototype);
|
||||
|
||||
@ -589,12 +589,12 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeImports(statement: ImportStatement, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
||||
const declarations = statement.declarations;
|
||||
var declarations = statement.declarations;
|
||||
if (declarations) {
|
||||
for (let i = 0, k = declarations.length; i < k; ++i)
|
||||
for (var i = 0, k = declarations.length; i < k; ++i)
|
||||
this.initializeImport(declarations[i], statement.internalPath, queuedExports, queuedImports);
|
||||
} else if (statement.namespaceName) {
|
||||
const internalName = statement.range.source.internalPath + "/" + statement.namespaceName.name;
|
||||
var internalName = statement.range.source.internalPath + "/" + statement.namespaceName.name;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, statement.namespaceName.range, internalName);
|
||||
return;
|
||||
@ -605,13 +605,13 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeImport(declaration: ImportDeclaration, internalPath: string, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
return;
|
||||
}
|
||||
|
||||
let referencedName = internalPath + PATH_DELIMITER + declaration.externalIdentifier.name;
|
||||
var referencedName = internalPath + PATH_DELIMITER + declaration.externalIdentifier.name;
|
||||
|
||||
// resolve right away if the export exists
|
||||
if (this.exports.has(referencedName)) {
|
||||
@ -620,8 +620,8 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// walk already known queued exports
|
||||
const seen = new Set<QueuedExport>();
|
||||
let queuedExport: QueuedExport | null;
|
||||
var seen = new Set<QueuedExport>();
|
||||
var queuedExport: QueuedExport | null;
|
||||
while (queuedExport = queuedExports.get(referencedName)) {
|
||||
if (queuedExport.isReExport) {
|
||||
if (this.exports.has(queuedExport.referencedName)) {
|
||||
@ -642,7 +642,7 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// otherwise queue it
|
||||
const queuedImport = new QueuedImport();
|
||||
var queuedImport = new QueuedImport();
|
||||
queuedImport.internalName = internalName;
|
||||
queuedImport.referencedName = referencedName;
|
||||
queuedImport.declaration = declaration;
|
||||
@ -650,12 +650,12 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeInterface(declaration: InterfaceDeclaration, namespace: Element | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
return;
|
||||
}
|
||||
const prototype = new InterfacePrototype(this, declaration.name.name, internalName, declaration);
|
||||
var prototype = new InterfacePrototype(this, declaration.name.name, internalName, declaration);
|
||||
prototype.namespace = namespace;
|
||||
this.elements.set(internalName, prototype);
|
||||
|
||||
@ -676,8 +676,8 @@ export class Program extends DiagnosticEmitter {
|
||||
this.exports.set(internalName, prototype);
|
||||
}
|
||||
|
||||
const memberDeclarations = declaration.members;
|
||||
for (let i = 0, k = memberDeclarations.length; i < k; ++i) {
|
||||
var memberDeclarations = declaration.members;
|
||||
for (var i = 0, k = memberDeclarations.length; i < k; ++i) {
|
||||
switch (memberDeclarations[i].kind) {
|
||||
|
||||
case NodeKind.FIELD:
|
||||
@ -695,9 +695,9 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeNamespace(declaration: NamespaceDeclaration, parentNamespace: Element | null = null): void {
|
||||
const internalName = declaration.internalName;
|
||||
var internalName = declaration.internalName;
|
||||
|
||||
let namespace = this.elements.get(internalName);
|
||||
var namespace = this.elements.get(internalName);
|
||||
if (!namespace) {
|
||||
namespace = new Namespace(this, declaration.name.name, internalName, declaration);
|
||||
namespace.namespace = parentNamespace;
|
||||
@ -721,8 +721,8 @@ export class Program extends DiagnosticEmitter {
|
||||
this.exports.set(internalName, namespace);
|
||||
}
|
||||
|
||||
const members = declaration.members;
|
||||
for (let i = 0, k = members.length; i < k; ++i) {
|
||||
var members = declaration.members;
|
||||
for (var i = 0, k = members.length; i < k; ++i) {
|
||||
switch (members[i].kind) {
|
||||
|
||||
case NodeKind.CLASS:
|
||||
@ -762,7 +762,7 @@ export class Program extends DiagnosticEmitter {
|
||||
private initializeType(declaration: TypeDeclaration, namespace: Element | null = null): void {
|
||||
// type aliases are program globals
|
||||
// TODO: what about namespaced types?
|
||||
const name = declaration.name.name;
|
||||
var name = declaration.name.name;
|
||||
if (this.types.has(name) || this.typeAliases.has(name)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, name);
|
||||
return;
|
||||
@ -771,16 +771,16 @@ export class Program extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private initializeVariables(statement: VariableStatement, namespace: Element | null = null): void {
|
||||
const declarations = statement.declarations;
|
||||
for (let i = 0, k = declarations.length; i < k; ++i) {
|
||||
const declaration = declarations[i];
|
||||
const internalName = declaration.internalName;
|
||||
var declarations = statement.declarations;
|
||||
for (var i = 0, k = declarations.length; i < k; ++i) {
|
||||
var declaration = declarations[i];
|
||||
var internalName = declaration.internalName;
|
||||
if (this.elements.has(internalName)) {
|
||||
this.error(DiagnosticCode.Duplicate_identifier_0, declaration.name.range, internalName);
|
||||
continue;
|
||||
}
|
||||
|
||||
const global = new Global(this, declaration.name.name, internalName, declaration, null);
|
||||
var global = new Global(this, declaration.name.name, internalName, declaration, null);
|
||||
global.namespace = namespace;
|
||||
this.elements.set(internalName, global);
|
||||
|
||||
@ -813,25 +813,25 @@ export class Program extends DiagnosticEmitter {
|
||||
resolveType(node: TypeNode, contextualTypeArguments: Map<string,Type> | null = null, reportNotFound: bool = true): Type | null {
|
||||
|
||||
// resolve parameters
|
||||
const k = node.typeArguments.length;
|
||||
const paramTypes = new Array<Type>(k);
|
||||
for (let i = 0; i < k; ++i) {
|
||||
const paramType = this.resolveType(node.typeArguments[i], contextualTypeArguments, reportNotFound);
|
||||
var k = node.typeArguments.length;
|
||||
var paramTypes = new Array<Type>(k);
|
||||
for (var i = 0; i < k; ++i) {
|
||||
var paramType = this.resolveType(node.typeArguments[i], contextualTypeArguments, reportNotFound);
|
||||
if (!paramType)
|
||||
return null;
|
||||
paramTypes[i] = paramType;
|
||||
}
|
||||
|
||||
let globalName = node.identifier.name;
|
||||
var globalName = node.identifier.name;
|
||||
if (k) // can't be a placeholder if it has parameters
|
||||
globalName += typesToString(paramTypes);
|
||||
else if (contextualTypeArguments) {
|
||||
const placeholderType = contextualTypeArguments.get(globalName);
|
||||
var placeholderType = contextualTypeArguments.get(globalName);
|
||||
if (placeholderType)
|
||||
return placeholderType;
|
||||
}
|
||||
|
||||
let type: Type | null;
|
||||
var type: Type | null;
|
||||
|
||||
// check file-global type
|
||||
if (type = this.types.get(node.range.source.internalPath + PATH_DELIMITER + globalName))
|
||||
@ -842,7 +842,7 @@ export class Program extends DiagnosticEmitter {
|
||||
return type;
|
||||
|
||||
// check type alias
|
||||
let alias = this.typeAliases.get(globalName);
|
||||
var alias = this.typeAliases.get(globalName);
|
||||
if (alias && (type = this.resolveType(alias, null, reportNotFound)))
|
||||
return type;
|
||||
|
||||
@ -854,8 +854,8 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
/** Resolves an array of type parameters to concrete types. */
|
||||
resolveTypeArguments(typeParameters: TypeParameter[], typeArgumentNodes: TypeNode[] | null, contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): Type[] | null {
|
||||
const parameterCount = typeParameters.length;
|
||||
const argumentCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
|
||||
var parameterCount = typeParameters.length;
|
||||
var argumentCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
|
||||
if (parameterCount != argumentCount) {
|
||||
if (argumentCount)
|
||||
this.error(DiagnosticCode.Expected_0_type_arguments_but_got_1, Range.join((<TypeNode[]>typeArgumentNodes)[0].range, (<TypeNode[]>typeArgumentNodes)[argumentCount - 1].range), parameterCount.toString(10), argumentCount.toString(10));
|
||||
@ -863,9 +863,9 @@ export class Program extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Expected_0_type_arguments_but_got_1, alternativeReportNode.range.atEnd, parameterCount.toString(10), "0");
|
||||
return null;
|
||||
}
|
||||
const typeArguments = new Array<Type>(parameterCount);
|
||||
for (let i = 0; i < parameterCount; ++i) {
|
||||
const type = this.resolveType((<TypeNode[]>typeArgumentNodes)[i], contextualTypeArguments, true); // reports
|
||||
var typeArguments = new Array<Type>(parameterCount);
|
||||
for (var i = 0; i < parameterCount; ++i) {
|
||||
var type = this.resolveType((<TypeNode[]>typeArgumentNodes)[i], contextualTypeArguments, true); // reports
|
||||
if (!type)
|
||||
return null;
|
||||
// TODO: check extendsType
|
||||
@ -876,13 +876,13 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
/** Resolves an identifier to the element it refers to. */
|
||||
resolveIdentifier(identifier: IdentifierExpression, contextualFunction: Function): Element | null {
|
||||
const name = identifier.name;
|
||||
const local = contextualFunction.locals.get(name);
|
||||
var name = identifier.name;
|
||||
var local = contextualFunction.locals.get(name);
|
||||
if (local)
|
||||
return local;
|
||||
|
||||
let element: Element | null;
|
||||
let namespace: Element | null;
|
||||
var element: Element | null;
|
||||
var namespace: Element | null;
|
||||
|
||||
// search parent namespaces if applicable
|
||||
if (contextualFunction && (namespace = contextualFunction.prototype.namespace)) {
|
||||
@ -906,8 +906,8 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
/** Resolves a property access the element it refers to. */
|
||||
resolvePropertyAccess(propertyAccess: PropertyAccessExpression, contextualFunction: Function): Element | null {
|
||||
const expression = propertyAccess.expression;
|
||||
let target: Element | null = null;
|
||||
var expression = propertyAccess.expression;
|
||||
var target: Element | null = null;
|
||||
if (expression.kind == NodeKind.IDENTIFIER) {
|
||||
target = this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
|
||||
} else if (expression.kind == NodeKind.PROPERTYACCESS) {
|
||||
@ -916,9 +916,9 @@ export class Program extends DiagnosticEmitter {
|
||||
throw new Error("unexpected target kind");
|
||||
if (!target)
|
||||
return null;
|
||||
const propertyName = propertyAccess.property.name;
|
||||
var propertyName = propertyAccess.property.name;
|
||||
if (target.members) {
|
||||
const member = target.members.get(propertyName);
|
||||
var member = target.members.get(propertyName);
|
||||
if (member)
|
||||
return member;
|
||||
}
|
||||
@ -955,9 +955,9 @@ export class Program extends DiagnosticEmitter {
|
||||
|
||||
function hasDecorator(name: string, decorators: Decorator[] | null): bool {
|
||||
if (decorators)
|
||||
for (let i = 0, k = decorators.length; i < k; ++i) {
|
||||
const decorator = decorators[i];
|
||||
const expression = decorator.name;
|
||||
for (var i = 0, k = decorators.length; i < k; ++i) {
|
||||
var decorator = decorators[i];
|
||||
var expression = decorator.name;
|
||||
if (expression.kind == NodeKind.IDENTIFIER && decorator.arguments.length <= 1 && (<IdentifierExpression>expression).name == name)
|
||||
return true;
|
||||
}
|
||||
@ -1117,7 +1117,7 @@ export class Namespace extends Element {
|
||||
constructor(program: Program, simpleName: string, internalName: string, declaration: NamespaceDeclaration | null = null) {
|
||||
super(program, simpleName, internalName);
|
||||
if ((this.declaration = declaration) && this.declaration.modifiers) {
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.IMPORT: this.isImported = true; break;
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
@ -1141,7 +1141,7 @@ export class Enum extends Element {
|
||||
constructor(program: Program, simpleName: string, internalName: string, declaration: EnumDeclaration | null = null) {
|
||||
super(program, simpleName, internalName);
|
||||
if ((this.declaration = declaration) && this.declaration.modifiers) {
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
case ModifierKind.IMPORT: this.isImported = true; break;
|
||||
@ -1191,7 +1191,7 @@ export class Global extends Element {
|
||||
super(program, simpleName, internalName);
|
||||
if (this.declaration = declaration) {
|
||||
if (this.declaration.modifiers) {
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.IMPORT: this.isImported = true; break;
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
@ -1277,7 +1277,7 @@ export class FunctionPrototype extends Element {
|
||||
super(program, simpleName, internalName);
|
||||
if (this.declaration = declaration) {
|
||||
if (this.declaration.modifiers)
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.IMPORT: this.isImported = true; break;
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
@ -1312,37 +1312,37 @@ export class FunctionPrototype extends Element {
|
||||
get isAccessor(): bool { return (this.flags & (ElementFlags.GETTER | ElementFlags.SETTER)) != 0; }
|
||||
|
||||
resolve(typeArguments: Type[] | null = null, contextualTypeArguments: Map<string,Type> | null = null): Function | null {
|
||||
const instanceKey = typeArguments ? typesToString(typeArguments, "", "") : "";
|
||||
let instance = this.instances.get(instanceKey);
|
||||
var instanceKey = typeArguments ? typesToString(typeArguments, "", "") : "";
|
||||
var instance = this.instances.get(instanceKey);
|
||||
if (instance)
|
||||
return instance;
|
||||
const declaration = this.declaration;
|
||||
var declaration = this.declaration;
|
||||
if (!declaration)
|
||||
throw new Error("declaration expected"); // cannot resolve built-ins
|
||||
|
||||
// override call specific contextual type arguments
|
||||
let i: i32, k: i32;
|
||||
var i: i32, k: i32;
|
||||
if (typeArguments && (k = typeArguments.length)) {
|
||||
const inheritedTypeArguments: Map<string,Type> | null = contextualTypeArguments;
|
||||
var inheritedTypeArguments = contextualTypeArguments;
|
||||
contextualTypeArguments = new Map();
|
||||
if (inheritedTypeArguments)
|
||||
for (let [name, type] of inheritedTypeArguments)
|
||||
contextualTypeArguments.set(name, type);
|
||||
for (var [inheritedName, inheritedType] of inheritedTypeArguments)
|
||||
contextualTypeArguments.set(inheritedName, inheritedType);
|
||||
for (i = 0; i < k; ++i)
|
||||
contextualTypeArguments.set(declaration.typeParameters[i].identifier.name, typeArguments[i]);
|
||||
}
|
||||
|
||||
// resolve parameters
|
||||
k = declaration.parameters.length;
|
||||
const parameters = new Array<Parameter>(k);
|
||||
const parameterTypes = new Array<Type>(k);
|
||||
let typeNode: TypeNode | null;
|
||||
var parameters = new Array<Parameter>(k);
|
||||
var parameterTypes = new Array<Type>(k);
|
||||
var typeNode: TypeNode | null;
|
||||
for (i = 0; i < k; ++i) {
|
||||
if (typeNode = declaration.parameters[i].type) {
|
||||
const type = this.program.resolveType(typeNode, contextualTypeArguments, true); // reports
|
||||
if (type) {
|
||||
parameters[i] = new Parameter(declaration.parameters[i].name.name, type);
|
||||
parameterTypes[i] = type;
|
||||
var parameterType = this.program.resolveType(typeNode, contextualTypeArguments, true); // reports
|
||||
if (parameterType) {
|
||||
parameters[i] = new Parameter(declaration.parameters[i].name.name, parameterType);
|
||||
parameterTypes[i] = parameterType;
|
||||
} else
|
||||
return null;
|
||||
} else
|
||||
@ -1350,12 +1350,12 @@ export class FunctionPrototype extends Element {
|
||||
}
|
||||
|
||||
// resolve return type
|
||||
let returnType: Type;
|
||||
var returnType: Type;
|
||||
if (this.isSetter) {
|
||||
returnType = Type.void; // not annotated
|
||||
} else {
|
||||
if (typeNode = declaration.returnType) {
|
||||
const type = this.program.resolveType(<TypeNode>typeNode, contextualTypeArguments, true); // reports
|
||||
var type = this.program.resolveType(<TypeNode>typeNode, contextualTypeArguments, true); // reports
|
||||
if (type)
|
||||
returnType = type;
|
||||
else
|
||||
@ -1364,7 +1364,7 @@ export class FunctionPrototype extends Element {
|
||||
return null;
|
||||
}
|
||||
|
||||
let internalName = this.internalName;
|
||||
var internalName = this.internalName;
|
||||
if (instanceKey.length)
|
||||
internalName += "<" + instanceKey + ">";
|
||||
instance = new Function(this, internalName, typeArguments, parameters, returnType, null); // TODO: class
|
||||
@ -1373,7 +1373,7 @@ export class FunctionPrototype extends Element {
|
||||
}
|
||||
|
||||
resolveInclTypeArguments(typeArgumentNodes: TypeNode[] | null, contextualTypeArguments: Map<string,Type> | null, alternativeReportNode: Node | null): Function | null {
|
||||
let resolvedTypeArguments: Type[] | null;
|
||||
var resolvedTypeArguments: Type[] | null;
|
||||
if (this.isGeneric) {
|
||||
assert(typeArgumentNodes != null && typeArgumentNodes.length != 0);
|
||||
if (!this.declaration)
|
||||
@ -1427,19 +1427,19 @@ export class Function extends Element {
|
||||
this.returnType = returnType;
|
||||
this.instanceMethodOf = instanceMethodOf;
|
||||
this.flags = prototype.flags;
|
||||
let localIndex = 0;
|
||||
var localIndex = 0;
|
||||
if (instanceMethodOf) {
|
||||
assert(this.isInstance);
|
||||
this.locals.set("this", new Local(prototype.program, "this", localIndex++, instanceMethodOf.type));
|
||||
if (instanceMethodOf.contextualTypeArguments) {
|
||||
if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map();
|
||||
for (let [name, type] of instanceMethodOf.contextualTypeArguments)
|
||||
for (var [name, type] of instanceMethodOf.contextualTypeArguments)
|
||||
this.contextualTypeArguments.set(name, type);
|
||||
}
|
||||
} else
|
||||
assert(!this.isInstance);
|
||||
for (let i = 0, k = parameters.length; i < k; ++i) {
|
||||
const parameter = parameters[i];
|
||||
for (var i = 0, k = parameters.length; i < k; ++i) {
|
||||
var parameter = parameters[i];
|
||||
this.locals.set(parameter.name, new Local(prototype.program, parameter.name, localIndex++, parameter.type));
|
||||
}
|
||||
}
|
||||
@ -1447,9 +1447,9 @@ export class Function extends Element {
|
||||
/** Adds a local of the specified type, with an optional name. */
|
||||
addLocal(type: Type, name: string | null = null): Local {
|
||||
// if it has a name, check previously as this method will throw otherwise
|
||||
let localIndex = this.parameters.length + this.additionalLocals.length;
|
||||
var localIndex = this.parameters.length + this.additionalLocals.length;
|
||||
if (this.isInstance) localIndex++; // plus 'this'
|
||||
const local = new Local(this.prototype.program, name ? name : "anonymous$" + localIndex.toString(10), localIndex, type);
|
||||
var local = new Local(this.prototype.program, name ? name : "anonymous$" + localIndex.toString(10), localIndex, type);
|
||||
if (name) {
|
||||
if (this.locals.has(name))
|
||||
throw new Error("unexpected duplicate local name");
|
||||
@ -1466,7 +1466,7 @@ export class Function extends Element {
|
||||
|
||||
/** Gets a free temporary local of the specified type. */
|
||||
getTempLocal(type: Type): Local {
|
||||
let temps: Local[] | null;
|
||||
var temps: Local[] | null;
|
||||
switch (type.toNativeType()) {
|
||||
case NativeType.I32: temps = this.tempI32s; break;
|
||||
case NativeType.I64: temps = this.tempI64s; break;
|
||||
@ -1481,7 +1481,7 @@ export class Function extends Element {
|
||||
|
||||
/** Frees the temporary local for reuse. */
|
||||
freeTempLocal(local: Local): void {
|
||||
let temps: Local[];
|
||||
var temps: Local[];
|
||||
switch (local.type.toNativeType()) {
|
||||
case NativeType.I32: temps = this.tempI32s || (this.tempI32s = []); break;
|
||||
case NativeType.I64: temps = this.tempI64s || (this.tempI64s = []); break;
|
||||
@ -1494,7 +1494,7 @@ export class Function extends Element {
|
||||
|
||||
/** Gets and immediately frees a temporary local of the specified type. */
|
||||
getAndFreeTempLocal(type: Type): Local {
|
||||
let temps: Local[];
|
||||
var temps: Local[];
|
||||
switch (type.toNativeType()) {
|
||||
case NativeType.I32: temps = this.tempI32s || (this.tempI32s = []); break;
|
||||
case NativeType.I64: temps = this.tempI64s || (this.tempI64s = []); break;
|
||||
@ -1504,14 +1504,14 @@ export class Function extends Element {
|
||||
}
|
||||
if (temps.length > 0)
|
||||
return temps[temps.length - 1];
|
||||
let local: Local = this.addLocal(type);
|
||||
var local: Local = this.addLocal(type);
|
||||
temps.push(local);
|
||||
return local;
|
||||
}
|
||||
|
||||
/** Enters a(nother) break context. */
|
||||
enterBreakContext(): string {
|
||||
const id = this.nextBreakId++;
|
||||
var id = this.nextBreakId++;
|
||||
if (!this.breakStack)
|
||||
this.breakStack = [ id ];
|
||||
else
|
||||
@ -1522,7 +1522,7 @@ export class Function extends Element {
|
||||
/** Leaves the current break context. */
|
||||
leaveBreakContext(): void {
|
||||
assert(this.breakStack != null);
|
||||
const length = (<i32[]>this.breakStack).length;
|
||||
var length = (<i32[]>this.breakStack).length;
|
||||
assert(length > 0);
|
||||
(<i32[]>this.breakStack).pop();
|
||||
if (length > 1) {
|
||||
@ -1563,7 +1563,7 @@ export class FieldPrototype extends Element {
|
||||
super(classPrototype.program, simpleName, internalName);
|
||||
this.classPrototype = classPrototype;
|
||||
if ((this.declaration = declaration) && this.declaration.modifiers) {
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
case ModifierKind.READONLY: this.isReadonly = true; break;
|
||||
@ -1639,7 +1639,7 @@ export class ClassPrototype extends Element {
|
||||
super(program, simpleName, internalName);
|
||||
if (this.declaration = declaration) {
|
||||
if (this.declaration.modifiers) {
|
||||
for (let i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
for (var i = 0, k = this.declaration.modifiers.length; i < k; ++i) {
|
||||
switch (this.declaration.modifiers[i].modifierKind) {
|
||||
case ModifierKind.IMPORT: this.isImported = true; break;
|
||||
case ModifierKind.EXPORT: this.isExported = true; break;
|
||||
@ -1654,29 +1654,29 @@ export class ClassPrototype extends Element {
|
||||
}
|
||||
|
||||
resolve(typeArguments: Type[], contextualTypeArguments: Map<string,Type> | null): Class {
|
||||
const instanceKey = typesToString(typeArguments, "", "");
|
||||
let instance = this.instances.get(instanceKey);
|
||||
var instanceKey = typesToString(typeArguments, "", "");
|
||||
var instance = this.instances.get(instanceKey);
|
||||
if (instance)
|
||||
return instance;
|
||||
const declaration = this.declaration;
|
||||
var declaration = this.declaration;
|
||||
if (!declaration)
|
||||
throw new Error("declaration expected"); // cannot resolve built-ins
|
||||
|
||||
// override call specific contextual type arguments
|
||||
let i: i32, k = typeArguments.length;
|
||||
var i: i32, k = typeArguments.length;
|
||||
if (k) {
|
||||
const inheritedTypeArguments: Map<string,Type> | null = contextualTypeArguments;
|
||||
var inheritedTypeArguments = contextualTypeArguments;
|
||||
contextualTypeArguments = new Map();
|
||||
if (inheritedTypeArguments)
|
||||
for (let [name, type] of inheritedTypeArguments)
|
||||
contextualTypeArguments.set(name, type);
|
||||
for (var [inheritedName, inheritedType] of inheritedTypeArguments)
|
||||
contextualTypeArguments.set(inheritedName, inheritedType);
|
||||
for (i = 0; i < k; ++i)
|
||||
contextualTypeArguments.set(declaration.typeParameters[i].identifier.name, typeArguments[i]);
|
||||
}
|
||||
|
||||
// TODO: set up instance fields and methods
|
||||
if (this.instanceMembers)
|
||||
for (let [key, member] of this.instanceMembers) {
|
||||
for (var member of this.instanceMembers.values()) {
|
||||
switch (member.kind) {
|
||||
case ElementKind.FIELD_PROTOTYPE: break;
|
||||
case ElementKind.FUNCTION_PROTOTYPE: break;
|
||||
@ -1684,7 +1684,7 @@ export class ClassPrototype extends Element {
|
||||
}
|
||||
}
|
||||
|
||||
let internalName = this.internalName;
|
||||
var internalName = this.internalName;
|
||||
if (instanceKey.length)
|
||||
internalName += "<" + instanceKey + ">";
|
||||
instance = new Class(this, internalName, typeArguments, null); // TODO: base class
|
||||
@ -1694,7 +1694,7 @@ export class ClassPrototype extends Element {
|
||||
}
|
||||
|
||||
resolveInclTypeArguments(typeArgumentNodes: TypeNode[] | null, contextualTypeArguments: Map<string,Type> | null, alternativeReportNode: Node | null): Class | null {
|
||||
let resolvedTypeArguments: Type[] | null;
|
||||
var resolvedTypeArguments: Type[] | null;
|
||||
if (this.isGeneric) {
|
||||
assert(typeArgumentNodes != null && typeArgumentNodes.length != 0);
|
||||
if (!this.declaration)
|
||||
@ -1740,21 +1740,21 @@ export class Class extends Element {
|
||||
// inherit contextual type arguments from base class
|
||||
if (base && base.contextualTypeArguments) {
|
||||
if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map();
|
||||
for (let [name, type] of base.contextualTypeArguments)
|
||||
this.contextualTypeArguments.set(name, type);
|
||||
for (var [baseName, baseType] of base.contextualTypeArguments)
|
||||
this.contextualTypeArguments.set(baseName, baseType);
|
||||
}
|
||||
|
||||
// apply instance-specific contextual type arguments
|
||||
const declaration: ClassDeclaration | null = this.prototype.declaration;
|
||||
var declaration = this.prototype.declaration;
|
||||
if (declaration) { // irrelevant for built-ins
|
||||
const typeParameters: TypeParameter[] = declaration.typeParameters;
|
||||
var typeParameters = declaration.typeParameters;
|
||||
if (typeParameters.length != typeArguments.length)
|
||||
throw new Error("unexpected type argument count mismatch");
|
||||
const k = typeArguments.length;
|
||||
var k = typeArguments.length;
|
||||
if (k) {
|
||||
if (!this.contextualTypeArguments)
|
||||
this.contextualTypeArguments = new Map();
|
||||
for (let i = 0; i < k; ++i)
|
||||
for (var i = 0; i < k; ++i)
|
||||
this.contextualTypeArguments.set(typeParameters[i].identifier.name, typeArguments[i]);
|
||||
}
|
||||
}
|
||||
|
129
src/tokenizer.ts
129
src/tokenizer.ts
@ -376,7 +376,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
this.end = source.text.length;
|
||||
this.diagnostics = diagnostics ? diagnostics : new Array();
|
||||
|
||||
const text: string = source.text;
|
||||
var text = source.text;
|
||||
|
||||
// skip bom
|
||||
if (this.pos < this.end && text.charCodeAt(this.pos) == CharCode.BYTEORDERMARK)
|
||||
@ -397,13 +397,13 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private unsafeNext(preferIdentifier: bool = false): Token {
|
||||
const text: string = this.source.text;
|
||||
var text = this.source.text;
|
||||
while (true) {
|
||||
if (this.pos >= this.end)
|
||||
return Token.ENDOFFILE;
|
||||
|
||||
this.tokenPos = this.pos;
|
||||
let c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
switch (c) {
|
||||
|
||||
case CharCode.CARRIAGERETURN:
|
||||
@ -534,7 +534,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
continue;
|
||||
}
|
||||
if (text.charCodeAt(this.pos) == CharCode.ASTERISK) { // multi-line comment
|
||||
let closed: bool = false;
|
||||
var closed = false;
|
||||
while (++this.pos < this.end) {
|
||||
c = text.charCodeAt(this.pos);
|
||||
if (c == CharCode.ASTERISK && this.pos + 1 < this.end && text.charCodeAt(this.pos + 1) == CharCode.SLASH) {
|
||||
@ -687,18 +687,18 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
this.pos++;
|
||||
return Token.AT;
|
||||
|
||||
default: {
|
||||
default:
|
||||
if (isIdentifierStart(c)) {
|
||||
if (isKeywordCharacter(c)) {
|
||||
const posBefore: i32 = this.pos;
|
||||
var posBefore = this.pos;
|
||||
while (++this.pos < this.end && isIdentifierPart(c = text.charCodeAt(this.pos))) {
|
||||
if (!isKeywordCharacter(c)) {
|
||||
this.pos = posBefore;
|
||||
return Token.IDENTIFIER;
|
||||
}
|
||||
}
|
||||
const keywordText: string = text.substring(posBefore, this.pos);
|
||||
const keywordToken: Token = Token.fromKeyword(keywordText);
|
||||
var keywordText = text.substring(posBefore, this.pos);
|
||||
var keywordToken = Token.fromKeyword(keywordText);
|
||||
if (keywordToken != Token.INVALID && !(preferIdentifier && Token.isAlsoIdentifier(keywordToken)))
|
||||
return keywordToken;
|
||||
this.pos = posBefore;
|
||||
@ -711,17 +711,16 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
this.error(DiagnosticCode.Invalid_character, this.range(this.pos, this.pos + 1));
|
||||
this.pos++;
|
||||
return Token.INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
peek(checkOnNewLine: bool = false): Token {
|
||||
const text: string = this.source.text;
|
||||
var text = this.source.text;
|
||||
if (this.nextToken < 0) {
|
||||
const posBefore: i32 = this.pos;
|
||||
const tokenBefore: Token = this.token;
|
||||
const tokenPosBefore: i32 = this.tokenPos;
|
||||
var posBefore = this.pos;
|
||||
var tokenBefore = this.token;
|
||||
var tokenPosBefore = this.tokenPos;
|
||||
this.nextToken = this.unsafeNext();
|
||||
if (checkOnNewLine) {
|
||||
this.nextTokenOnNewLine = false;
|
||||
@ -740,9 +739,9 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
skip(token: Token): bool {
|
||||
const posBefore: i32 = this.pos;
|
||||
const tokenBefore: Token = this.token;
|
||||
const tokenPosBefore: i32 = this.tokenPos;
|
||||
var posBefore = this.pos;
|
||||
var tokenBefore = this.token;
|
||||
var tokenPosBefore = this.tokenPos;
|
||||
if ((this.token = this.unsafeNext(token == Token.IDENTIFIER)) == token) {
|
||||
this.nextToken = -1;
|
||||
return true;
|
||||
@ -755,7 +754,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
// skipUntil(token1: Token, token2: Token = -1): bool {
|
||||
// let next: Token;
|
||||
// var next: Token;
|
||||
// do {
|
||||
// if ((next = this.peek()) == Token.ENDOFFILE)
|
||||
// return false;
|
||||
@ -788,24 +787,24 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readIdentifier(): string {
|
||||
const text: string = this.source.text;
|
||||
const start: i32 = this.pos;
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
while (++this.pos < this.end && isIdentifierPart(text.charCodeAt(this.pos)));
|
||||
return text.substring(start, this.pos);
|
||||
}
|
||||
|
||||
readString(): string {
|
||||
const text: string = this.source.text;
|
||||
const quote: i32 = text.charCodeAt(this.pos++);
|
||||
let start: i32 = this.pos;
|
||||
let result: string = "";
|
||||
var text = this.source.text;
|
||||
var quote = text.charCodeAt(this.pos++);
|
||||
var start = this.pos;
|
||||
var result = "";
|
||||
while (true) {
|
||||
if (this.pos >= this.end) {
|
||||
result += text.substring(start, this.pos);
|
||||
this.error(DiagnosticCode.Unterminated_string_literal, this.range(start - 1, this.end));
|
||||
break;
|
||||
}
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c == quote) {
|
||||
result += text.substring(start, this.pos++);
|
||||
break;
|
||||
@ -832,8 +831,8 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
return "";
|
||||
}
|
||||
|
||||
const text: string = this.source.text;
|
||||
const c: i32 = text.charCodeAt(this.pos++);
|
||||
var text = this.source.text;
|
||||
var c = text.charCodeAt(this.pos++);
|
||||
switch (c) {
|
||||
|
||||
case CharCode._0:
|
||||
@ -891,10 +890,10 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readRegexp(): string {
|
||||
let result: string = "";
|
||||
let start: i32 = this.pos;
|
||||
let escaped: bool = false;
|
||||
const text: string = this.source.text;
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
var result = "";
|
||||
var escaped = false;
|
||||
while (true) {
|
||||
if (this.pos >= this.end) {
|
||||
result += text.substring(start, this.pos);
|
||||
@ -906,7 +905,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c == CharCode.SLASH) {
|
||||
result += text.substring(start, this.pos);
|
||||
this.pos++;
|
||||
@ -923,7 +922,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
testInteger(): bool {
|
||||
const text: string = this.source.text;
|
||||
var text = this.source.text;
|
||||
if (text.charCodeAt(this.pos) == CharCode._0 && this.pos + 1 < this.end) {
|
||||
switch (text.charCodeAt(this.pos + 2)) {
|
||||
case CharCode.X:
|
||||
@ -935,9 +934,9 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let pos: i32 = this.pos;
|
||||
var pos = this.pos;
|
||||
while (pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(pos);
|
||||
var c = text.charCodeAt(pos);
|
||||
if (c == CharCode.DOT || c == CharCode.E || c == CharCode.e)
|
||||
return false;
|
||||
if (c < CharCode._0 || c > CharCode._9)
|
||||
@ -948,7 +947,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readInteger(): I64 {
|
||||
const text: string = this.source.text;
|
||||
var text = this.source.text;
|
||||
if (text.charCodeAt(this.pos) == CharCode._0 && this.pos + 2 < this.end) {
|
||||
switch (text.charCodeAt(this.pos + 1)) {
|
||||
case CharCode.X:
|
||||
@ -965,9 +964,9 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
return this.readOctalInteger();
|
||||
}
|
||||
if (isOctalDigit(text.charCodeAt(this.pos + 1))) {
|
||||
const start: i32 = this.pos;
|
||||
var start = this.pos;
|
||||
this.pos++;
|
||||
const value: I64 = this.readOctalInteger();
|
||||
var value = this.readOctalInteger();
|
||||
this.error(DiagnosticCode.Octal_literals_are_not_allowed_in_strict_mode, this.range(start, this.pos));
|
||||
return value;
|
||||
}
|
||||
@ -976,11 +975,11 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readHexInteger(): I64 {
|
||||
const text: string = this.source.text;
|
||||
const start: i32 = this.pos;
|
||||
let value: I64 = new I64(0, 0);
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
var value = new I64(0, 0);
|
||||
while (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c >= CharCode._0 && c <= CharCode._9) {
|
||||
// value = value * 16 + c - CharCode._0;
|
||||
value.mul32(16);
|
||||
@ -1003,11 +1002,11 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readDecimalInteger(): I64 {
|
||||
const text: string = this.source.text;
|
||||
const start: i32 = this.pos;
|
||||
let value: I64 = new I64(0, 0);
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
var value = new I64(0, 0);
|
||||
while (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c >= CharCode._0 && c <= CharCode._9) {
|
||||
// value = value * 10 + c - CharCode._0;
|
||||
value.mul32(10);
|
||||
@ -1022,11 +1021,11 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readOctalInteger(): I64 {
|
||||
const text: string = this.source.text;
|
||||
const start: i32 = this.pos;
|
||||
let value: I64 = new I64(0, 0);
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
var value = new I64(0, 0);
|
||||
while (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c >= CharCode._0 && c <= CharCode._7) {
|
||||
// value = value * 8 + c - CharCode._0;
|
||||
value.mul32(8);
|
||||
@ -1041,11 +1040,11 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readBinaryInteger(): I64 {
|
||||
const text: string = this.source.text;
|
||||
const start: i32 = this.pos;
|
||||
let value: I64 = new I64();
|
||||
var text = this.source.text;
|
||||
var start = this.pos;
|
||||
var value = new I64();
|
||||
while (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c == CharCode._0) {
|
||||
// value = value * 2;
|
||||
value.mul32(2);
|
||||
@ -1064,8 +1063,8 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readFloat(): f64 {
|
||||
let start: i32 = this.pos;
|
||||
const text: string = this.source.text;
|
||||
var start = this.pos;
|
||||
var text = this.source.text;
|
||||
while (this.pos < this.end && isDecimalDigit(text.charCodeAt(this.pos)))
|
||||
this.pos++;
|
||||
if (this.pos < this.end && text.charCodeAt(this.pos) == CharCode.DOT) {
|
||||
@ -1074,7 +1073,7 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
this.pos++;
|
||||
}
|
||||
if (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos);
|
||||
var c = text.charCodeAt(this.pos);
|
||||
if (c == CharCode.E || c == CharCode.e) {
|
||||
if (++this.pos < this.end && text.charCodeAt(this.pos) == CharCode.MINUS)
|
||||
this.pos++;
|
||||
@ -1086,11 +1085,11 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
readUnicodeEscape(): string {
|
||||
let remain: i32 = 4;
|
||||
let value: i32 = 0;
|
||||
const text: string = this.source.text;
|
||||
var remain = 4;
|
||||
var value = 0;
|
||||
var text = this.source.text;
|
||||
while (this.pos < this.end) {
|
||||
const c: i32 = text.charCodeAt(this.pos++);
|
||||
var c = text.charCodeAt(this.pos++);
|
||||
if (c >= CharCode._0 && c <= CharCode._9)
|
||||
value = value * 16 + c - CharCode._0;
|
||||
else if (c >= CharCode.A && c <= CharCode.F)
|
||||
@ -1112,17 +1111,17 @@ export class Tokenizer extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
private readExtendedUnicodeEscape(): string {
|
||||
const start: i32 = this.pos;
|
||||
const value: I64 = this.readHexInteger();
|
||||
let invalid: bool = false;
|
||||
var start = this.pos;
|
||||
var value = this.readHexInteger();
|
||||
var invalid = false;
|
||||
|
||||
if (value.gt32(0x10FFFF)) {
|
||||
this.error(DiagnosticCode.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive, this.range(start, this.pos));
|
||||
invalid = true;
|
||||
}
|
||||
|
||||
const value32: i32 = value.toI32();
|
||||
const text: string = this.source.text;
|
||||
var value32 = value.toI32();
|
||||
var text = this.source.text;
|
||||
if (this.pos >= this.end) {
|
||||
this.error(DiagnosticCode.Unexpected_end_of_text, this.range(start, this.end));
|
||||
invalid = true;
|
||||
|
14
src/types.ts
14
src/types.ts
@ -91,7 +91,7 @@ export class Type {
|
||||
/** Composes a class type from this type and a class. */
|
||||
asClass(classType: Class): Type {
|
||||
assert(this.kind == TypeKind.USIZE);
|
||||
const ret: Type = new Type(this.kind, this.size);
|
||||
var ret = new Type(this.kind, this.size);
|
||||
ret.classType = classType;
|
||||
return ret;
|
||||
}
|
||||
@ -99,7 +99,7 @@ export class Type {
|
||||
/** Composes a function type from this type and a function. */
|
||||
asFunction(functionType: Function): Type {
|
||||
assert(this.kind == TypeKind.USIZE);
|
||||
const ret: Type = new Type(this.kind, this.size);
|
||||
var ret = new Type(this.kind, this.size);
|
||||
ret.functionType = functionType;
|
||||
return ret;
|
||||
}
|
||||
@ -224,20 +224,20 @@ export class Type {
|
||||
|
||||
/** Converts an array of types to an array of native types. */
|
||||
export function typesToNativeTypes(types: Type[]): NativeType[] {
|
||||
const k: i32 = types.length;
|
||||
const ret: NativeType[] = new Array(k);
|
||||
for (let i: i32 = 0; i < k; ++i)
|
||||
var k = types.length;
|
||||
var ret = new Array<NativeType>(k);
|
||||
for (var i = 0; i < k; ++i)
|
||||
ret[i] = types[i].toNativeType();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Converts an array of types to its combined string representation. Usually type arguments. */
|
||||
export function typesToString(types: Type[], prefix: string = "<", postfix: string = ">"): string {
|
||||
const k: i32 = types.length;
|
||||
var k = types.length;
|
||||
if (!k)
|
||||
return "";
|
||||
sb.length = 0;
|
||||
for (let i: i32 = 0; i < k; ++i)
|
||||
for (var i = 0; i < k; ++i)
|
||||
sb[i] = types[i].toString();
|
||||
return prefix + sb.join(", ") + postfix;
|
||||
}
|
||||
|
@ -208,9 +208,9 @@ function lookupInUnicodeMap(code: u16, map: u16[]): bool {
|
||||
if (code < map[0])
|
||||
return false;
|
||||
|
||||
let lo: i32 = 0;
|
||||
let hi: i32 = map.length;
|
||||
let mid: i32;
|
||||
var lo = 0;
|
||||
var hi = map.length;
|
||||
var mid: i32;
|
||||
|
||||
while (lo + 1 < hi) {
|
||||
mid = lo + (hi - lo) / 2;
|
||||
|
@ -240,8 +240,8 @@ export class I64 {
|
||||
}
|
||||
|
||||
// |other| >= 2, so |this/other| < |MIN_VALUE|
|
||||
let tempLo: i32 = this.lo;
|
||||
let tempHi: i32 = this.hi;
|
||||
var tempLo = this.lo;
|
||||
var tempHi = this.hi;
|
||||
this.shr32(1, 0);
|
||||
this.div32(lo, hi);
|
||||
this.shl32(1, 0);
|
||||
@ -308,12 +308,12 @@ export class I64 {
|
||||
}
|
||||
|
||||
mod32(lo: i32, hi: i32 = 0): void {
|
||||
const thisLo: i32 = this.lo;
|
||||
const thisHi: i32 = this.hi;
|
||||
var thisLo = this.lo;
|
||||
var thisHi = this.hi;
|
||||
this.div32(lo, hi);
|
||||
this.mul32(lo, hi);
|
||||
const resLo: i32 = this.lo;
|
||||
const resHi: i32 = this.hi;
|
||||
var resLo = this.lo;
|
||||
var resHi = this.hi;
|
||||
this.lo = thisLo;
|
||||
this.hi = thisHi;
|
||||
this.sub32(resLo, resHi);
|
||||
@ -407,7 +407,7 @@ export class I64 {
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
let negative: bool = false;
|
||||
var negative = false;
|
||||
if (this.hi < 0) {
|
||||
i64_add_internal(~this.lo, ~this.hi, 1, 0);
|
||||
negative = true;
|
||||
@ -417,7 +417,7 @@ export class I64 {
|
||||
}
|
||||
|
||||
if (i64_hi) {
|
||||
let lo: string = (i64_lo as u32 >>> 0).toString(16);
|
||||
var lo = (i64_lo as u32 >>> 0).toString(16);
|
||||
while (lo.length < 8)
|
||||
lo = "0" + lo;
|
||||
return (negative ? "-0x" : "0x") + (i64_hi as u32 >>> 0).toString(16) + lo;
|
||||
@ -426,21 +426,21 @@ export class I64 {
|
||||
}
|
||||
}
|
||||
|
||||
let i64_lo: i32 = 0;
|
||||
let i64_hi: i32 = 0;
|
||||
var i64_lo = 0;
|
||||
var i64_hi = 0;
|
||||
|
||||
function i64_add_internal(lo: i32, hi: i32, otherLo: i32, otherHi: i32): void {
|
||||
let a48: i32 = hi >>> 16;
|
||||
let a32: i32 = hi & 0xFFFF;
|
||||
let a16: i32 = lo >>> 16;
|
||||
let a00: i32 = lo & 0xFFFF;
|
||||
var a48 = hi >>> 16;
|
||||
var a32 = hi & 0xFFFF;
|
||||
var a16 = lo >>> 16;
|
||||
var a00 = lo & 0xFFFF;
|
||||
|
||||
let b48: i32 = otherHi >>> 16;
|
||||
let b32: i32 = otherHi & 0xFFFF;
|
||||
let b16: i32 = otherLo >>> 16;
|
||||
let b00: i32 = otherLo & 0xFFFF;
|
||||
var b48 = otherHi >>> 16;
|
||||
var b32 = otherHi & 0xFFFF;
|
||||
var b16 = otherLo >>> 16;
|
||||
var b00 = otherLo & 0xFFFF;
|
||||
|
||||
let c48: i32 = 0, c32: i32 = 0, c16: i32 = 0, c00: i32 = 0;
|
||||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||||
c00 += a00 + b00;
|
||||
c16 += c00 >>> 16;
|
||||
c00 &= 0xFFFF;
|
||||
@ -458,15 +458,15 @@ function i64_add_internal(lo: i32, hi: i32, otherLo: i32, otherHi: i32): void {
|
||||
}
|
||||
|
||||
function i64_mul_internal(lo: i32, hi: i32, otherLo: i32, otherHi: i32): void {
|
||||
let a48: i32 = hi >>> 16;
|
||||
let a32: i32 = hi & 0xFFFF;
|
||||
let a16: i32 = lo >>> 16;
|
||||
let a00: i32 = lo & 0xFFFF;
|
||||
var a48 = hi >>> 16;
|
||||
var a32 = hi & 0xFFFF;
|
||||
var a16 = lo >>> 16;
|
||||
var a00 = lo & 0xFFFF;
|
||||
|
||||
let b48: i32 = otherHi >>> 16;
|
||||
let b32: i32 = otherHi & 0xFFFF;
|
||||
let b16: i32 = otherLo >>> 16;
|
||||
let b00: i32 = otherLo & 0xFFFF;
|
||||
var b48 = otherHi >>> 16;
|
||||
var b32 = otherHi & 0xFFFF;
|
||||
var b16 = otherLo >>> 16;
|
||||
var b00 = otherLo & 0xFFFF;
|
||||
|
||||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||||
c00 += a00 * b00;
|
||||
|
@ -6,8 +6,8 @@ import {
|
||||
export function normalize(path: string, trimExtension: bool = false, separator: CharCode = CharCode.SLASH): string {
|
||||
// expects a relative path
|
||||
|
||||
let pos: i32 = 0;
|
||||
let len: i32 = path.length;
|
||||
var pos = 0;
|
||||
var len = path.length;
|
||||
|
||||
// trim leading './'
|
||||
while (pos + 1 < len && path.charCodeAt(pos) == CharCode.DOT && path.charCodeAt(pos + 1) == separator)
|
||||
@ -23,7 +23,7 @@ export function normalize(path: string, trimExtension: bool = false, separator:
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
let atEnd: bool;
|
||||
var atEnd: bool;
|
||||
while (pos + 1 < len) {
|
||||
atEnd = false;
|
||||
|
||||
@ -51,7 +51,7 @@ export function normalize(path: string, trimExtension: bool = false, separator:
|
||||
) {
|
||||
|
||||
// find preceeding '/'
|
||||
let ipos: i32 = pos;
|
||||
var ipos = pos;
|
||||
while (--ipos >= 0) {
|
||||
if (path.charCodeAt(ipos) == separator) {
|
||||
if (pos - ipos != 3 || path.charCodeAt(ipos + 1) != CharCode.DOT || path.charCodeAt(ipos + 2) != CharCode.DOT) { // exclude '..' itself
|
||||
@ -87,7 +87,7 @@ export function resolve(normalizedPath: string, normalizedOrigin: string, separa
|
||||
|
||||
/** Obtains the directory portion of a normalized path. */
|
||||
export function dirname(normalizedPath: string, separator: CharCode = CharCode.SLASH): string {
|
||||
let pos: i32 = normalizedPath.length;
|
||||
var pos = normalizedPath.length;
|
||||
while (--pos > 0)
|
||||
if (normalizedPath.charCodeAt(pos) == separator)
|
||||
return normalizedPath.substring(0, pos);
|
||||
|
@ -1,2 +1,2 @@
|
||||
/** A shared string builder utilized to reduce overall array allocations. */
|
||||
export const sb: string[] = [];
|
||||
export const sb = new Array<string>();
|
||||
|
15
std/portable.d.ts
vendored
15
std/portable.d.ts
vendored
@ -157,6 +157,7 @@ declare class String {
|
||||
private constructor();
|
||||
indexOf(subject: string): i32;
|
||||
lastIndexOf(subject: string): i32;
|
||||
charAt(index: i32): string;
|
||||
charCodeAt(index: i32): i32;
|
||||
substring(from: i32, to?: i32): string;
|
||||
startsWith(subject: string): bool;
|
||||
@ -205,16 +206,18 @@ declare class Map<K,V> {
|
||||
has(key: K): bool;
|
||||
get(key: K): V | null;
|
||||
clear(): void;
|
||||
[Symbol.iterator](): Iterator<[K, V]>;
|
||||
entries(): Iterable<[K, V]>;
|
||||
keys(): Iterable<K>;
|
||||
values(): Iterable<V>;
|
||||
[Symbol.iterator](): Iterator<[K,V]>;
|
||||
}
|
||||
|
||||
interface Iterable<T> {
|
||||
[Symbol.iterator](): Iterator<T>;
|
||||
}
|
||||
|
||||
interface Iterator<T> {}
|
||||
|
||||
declare namespace JSON {
|
||||
/** @deprecated */
|
||||
function stringify(subject: any): string;
|
||||
}
|
||||
|
||||
declare namespace console {
|
||||
/** @deprecated */
|
||||
function log(message: string): void;
|
||||
|
Loading…
x
Reference in New Issue
Block a user