diff --git a/ts2panda/src/base/builtIn.ts b/ts2panda/src/base/builtIn.ts index 62c716d9fb9f0a05fde1543d64c922d4e9d789c1..3ff3d991203f34209a7bada5b2aa49b5f69b4bf5 100644 --- a/ts2panda/src/base/builtIn.ts +++ b/ts2panda/src/base/builtIn.ts @@ -39,7 +39,7 @@ export function expandHole(pandaGen: PandaGen): IRNode[] { } export function expandNaN(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.NaN); + let vreg = getVregisterCache(pandaGen, CacheList.NAN); return [ new Ldnan(), new Sta(vreg) @@ -47,7 +47,7 @@ export function expandNaN(pandaGen: PandaGen): IRNode[] { } export function expandInfinity(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.Infinity); + let vreg = getVregisterCache(pandaGen, CacheList.INFINITY); return [ new Ldinfinity(), new Sta(vreg) @@ -55,7 +55,7 @@ export function expandInfinity(pandaGen: PandaGen): IRNode[] { } export function expandGlobal(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.Global); + let vreg = getVregisterCache(pandaGen, CacheList.GLOBAL); return [ new Ldglobal(), new Sta(vreg) @@ -63,7 +63,7 @@ export function expandGlobal(pandaGen: PandaGen): IRNode[] { } export function expandUndefined(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.undefined); + let vreg = getVregisterCache(pandaGen, CacheList.UNDEFINED); return [ new Ldundefined(), new Sta(vreg) @@ -71,7 +71,7 @@ export function expandUndefined(pandaGen: PandaGen): IRNode[] { } export function expandSymbol(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.Symbol); + let vreg = getVregisterCache(pandaGen, CacheList.SYMBOL); return [ new Ldsymbol(), new Sta(vreg) @@ -79,7 +79,7 @@ export function expandSymbol(pandaGen: PandaGen): IRNode[] { } export function expandNull(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.Null); + let vreg = getVregisterCache(pandaGen, CacheList.NULL); return [ new Ldnull(), new Sta(vreg) @@ -87,7 +87,7 @@ export function expandNull(pandaGen: PandaGen): IRNode[] { } export function expandTrue(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.True); + let vreg = getVregisterCache(pandaGen, CacheList.TRUE); return [ new Ldtrue(), new Sta(vreg) @@ -95,7 +95,7 @@ export function expandTrue(pandaGen: PandaGen): IRNode[] { } export function expandFalse(pandaGen: PandaGen): IRNode[] { - let vreg = getVregisterCache(pandaGen, CacheList.False); + let vreg = getVregisterCache(pandaGen, CacheList.FALSE); return [ new Ldfalse(), new Sta(vreg) diff --git a/ts2panda/src/base/lexEnv.ts b/ts2panda/src/base/lexEnv.ts index 5393dbd8b148e4487e55d9da6196666bb69005e2..b54da6154dff4071841d928914dfe19ea8eb68d9 100644 --- a/ts2panda/src/base/lexEnv.ts +++ b/ts2panda/src/base/lexEnv.ts @@ -36,7 +36,7 @@ function createLexEnv(pandaGen: PandaGen, scope: VariableScope): IRNode[] { insns.push( newLexicalEnv(lexEnvVars, scopeInfoId), - storeAccumulator(getVregisterCache(pandaGen, CacheList.LexEnv)) + storeAccumulator(getVregisterCache(pandaGen, CacheList.LEXENV)) ); return insns; diff --git a/ts2panda/src/base/lreference.ts b/ts2panda/src/base/lreference.ts index f51dc6f7748ada6c976bfe43a4d542dba3ce8004..4c8f072db2fdc6ff7f038aae703b91604f5b126a 100644 --- a/ts2panda/src/base/lreference.ts +++ b/ts2panda/src/base/lreference.ts @@ -26,7 +26,7 @@ import { Scope } from "../scope"; import { VarDeclarationKind, Variable } from "../variable"; import { isBindingOrAssignmentPattern } from "./util"; -enum ReferenceKind { MemberAccess, LocalOrGlobal, Destructuring }; +enum ReferenceKind { MEMBER_ACCESS, LOCAL_OR_GLOBAL, DESTRUCTURING }; export class LReference { private node: ts.Node; private compiler: Compiler; @@ -49,11 +49,11 @@ export class LReference { this.isDeclaration = isDeclaration; this.refKind = refKind; - if (refKind == ReferenceKind.Destructuring) { + if (refKind == ReferenceKind.DESTRUCTURING) { this.destructuringTarget = node; - } else if (refKind == ReferenceKind.LocalOrGlobal) { + } else if (refKind == ReferenceKind.LOCAL_OR_GLOBAL) { this.variable = variable!; - } else if (refKind == ReferenceKind.MemberAccess) { + } else if (refKind == ReferenceKind.MEMBER_ACCESS) { this.obj = compiler.getPandaGen().getTemp(); this.prop = compiler.getPandaGen().getTemp(); } @@ -62,7 +62,7 @@ export class LReference { getValue() { let pandaGen = this.compiler.getPandaGen(); switch (this.refKind) { - case ReferenceKind.MemberAccess: + case ReferenceKind.MEMBER_ACCESS: let prop: VReg | number | string; if (this.propLiteral === undefined) { prop = this.prop!; @@ -71,10 +71,10 @@ export class LReference { } pandaGen.loadObjProperty(this.node, this.obj, prop); return; - case ReferenceKind.LocalOrGlobal: + case ReferenceKind.LOCAL_OR_GLOBAL: this.compiler.loadTarget(this.node, this.variable!); return; - case ReferenceKind.Destructuring: + case ReferenceKind.DESTRUCTURING: throw new Error("Destructuring target can't be loaded"); default: throw new Error("Invalid LReference kind to GetValue") @@ -84,7 +84,7 @@ export class LReference { setValue() { let pandaGen = this.compiler.getPandaGen(); switch (this.refKind) { - case ReferenceKind.MemberAccess: { + case ReferenceKind.MEMBER_ACCESS: { let prop: VReg | number | string if (this.propLiteral === undefined) { prop = this.prop!; @@ -102,10 +102,10 @@ export class LReference { pandaGen.freeTemps(...[this.obj, this.prop]); return; } - case ReferenceKind.LocalOrGlobal: + case ReferenceKind.LOCAL_OR_GLOBAL: this.compiler.storeTarget(this.node, this.variable!, this.isDeclaration); return; - case ReferenceKind.Destructuring: + case ReferenceKind.DESTRUCTURING: compileDestructuring(this.destructuringTarget, pandaGen, this.compiler); return; default: @@ -149,11 +149,11 @@ export class LReference { } } - return new LReference(realNode, compiler, isDeclaration, ReferenceKind.LocalOrGlobal, variable); + return new LReference(realNode, compiler, isDeclaration, ReferenceKind.LOCAL_OR_GLOBAL, variable); } if (ts.isPropertyAccessExpression(realNode) || ts.isElementAccessExpression(realNode)) { - let lref = new LReference(realNode, compiler, false, ReferenceKind.MemberAccess, undefined); + let lref = new LReference(realNode, compiler, false, ReferenceKind.MEMBER_ACCESS, undefined); let objReg = pandaGen.getTemp(); let propReg = pandaGen.getTemp(); let { obj: object, prop: property } = getObjAndProp(realNode, objReg, propReg, compiler); @@ -171,7 +171,7 @@ export class LReference { } if (isBindingOrAssignmentPattern(realNode)) { - return new LReference(realNode, compiler, isDeclaration, ReferenceKind.Destructuring, undefined); + return new LReference(realNode, compiler, isDeclaration, ReferenceKind.DESTRUCTURING, undefined); } throw new DiagnosticError( diff --git a/ts2panda/src/base/properties.ts b/ts2panda/src/base/properties.ts index cd11acf7e4c1b6f0d0ae040d03163acf15a6df61..58b9695dad612dfbe76edbf4e62ce4bc447e69ea 100644 --- a/ts2panda/src/base/properties.ts +++ b/ts2panda/src/base/properties.ts @@ -18,12 +18,12 @@ import { isValidIndex } from "../expression/memberAccessExpression"; import * as jshelpers from "../jshelpers"; export enum PropertyKind { - Variable, - Constant, - Computed, // Property with computed value (execution time). - Prototype, - Accessor, - Spread + VARIABLE, + CONSTANT, + COMPUTED, // Property with computed value (execution time). + PROTOTYPE, + ACCESSOR, + SPREAD } export class Property { @@ -70,7 +70,7 @@ export class Property { } getValue() { - if (this.propKind == PropertyKind.Accessor) { + if (this.propKind == PropertyKind.ACCESSOR) { throw new Error("Accessor doesn't have valueNode") } return this.valueNode!; @@ -91,19 +91,19 @@ export class Property { } setGetter(getter: ts.GetAccessorDeclaration) { - if (this.propKind != PropertyKind.Accessor) { + if (this.propKind != PropertyKind.ACCESSOR) { this.valueNode = undefined; this.setterNode = undefined; - this.propKind = PropertyKind.Accessor; + this.propKind = PropertyKind.ACCESSOR; } this.getterNode = getter; } setSetter(setter: ts.SetAccessorDeclaration) { - if (this.propKind != PropertyKind.Accessor) { + if (this.propKind != PropertyKind.ACCESSOR) { this.valueNode = undefined; this.getterNode = undefined; - this.propKind = PropertyKind.Accessor; + this.propKind = PropertyKind.ACCESSOR; } this.setterNode = setter; } @@ -123,14 +123,14 @@ export function generatePropertyFromExpr(expr: ts.ObjectLiteralExpression): Prop switch (property.kind) { case ts.SyntaxKind.PropertyAssignment: { if (property.name.kind == ts.SyntaxKind.ComputedPropertyName) { - defineProperty(property.name, property, PropertyKind.Computed, properties, namedPropertyMap); + defineProperty(property.name, property, PropertyKind.COMPUTED, properties, namedPropertyMap); break; } let propName: number | string = getPropName(property.name); if (propName == "__proto__") { if (!hasProto) { - defineProperty(propName, property.initializer, PropertyKind.Prototype, properties, namedPropertyMap); + defineProperty(propName, property.initializer, PropertyKind.PROTOTYPE, properties, namedPropertyMap); hasProto = true; break; } else { @@ -139,28 +139,28 @@ export function generatePropertyFromExpr(expr: ts.ObjectLiteralExpression): Prop } if (isConstantExpr(property.initializer)) { - defineProperty(propName, property.initializer, PropertyKind.Constant, properties, namedPropertyMap); + defineProperty(propName, property.initializer, PropertyKind.CONSTANT, properties, namedPropertyMap); } else { - defineProperty(propName, property.initializer, PropertyKind.Variable, properties, namedPropertyMap); + defineProperty(propName, property.initializer, PropertyKind.VARIABLE, properties, namedPropertyMap); } break; } case ts.SyntaxKind.ShorthandPropertyAssignment: { // ShorthandProperty's name always be Identifier let propName = jshelpers.getTextOfIdentifierOrLiteral(property.name); - defineProperty(propName, property.name, PropertyKind.Variable, properties, namedPropertyMap); + defineProperty(propName, property.name, PropertyKind.VARIABLE, properties, namedPropertyMap); break; } case ts.SyntaxKind.SpreadAssignment: { - defineProperty(undefined, property.expression, PropertyKind.Spread, properties, namedPropertyMap); + defineProperty(undefined, property.expression, PropertyKind.SPREAD, properties, namedPropertyMap); break; } case ts.SyntaxKind.MethodDeclaration: { let propName = getPropName(property.name); if (typeof (propName) == 'string' || typeof (propName) == 'number') { - defineProperty(propName, property, PropertyKind.Variable, properties, namedPropertyMap); + defineProperty(propName, property, PropertyKind.VARIABLE, properties, namedPropertyMap); } else { - defineProperty(propName, property, PropertyKind.Computed, properties, namedPropertyMap); + defineProperty(propName, property, PropertyKind.COMPUTED, properties, namedPropertyMap); } break; } @@ -168,9 +168,9 @@ export function generatePropertyFromExpr(expr: ts.ObjectLiteralExpression): Prop case ts.SyntaxKind.SetAccessor: { let propName = getPropName(property.name); if (typeof (propName) == 'string' || typeof (propName) == 'number') { - defineProperty(propName, property, PropertyKind.Accessor, properties, namedPropertyMap); + defineProperty(propName, property, PropertyKind.ACCESSOR, properties, namedPropertyMap); } else { - defineProperty(propName, property, PropertyKind.Computed, properties, namedPropertyMap); + defineProperty(propName, property, PropertyKind.COMPUTED, properties, namedPropertyMap); } break; } @@ -188,7 +188,7 @@ function defineProperty( propKind: PropertyKind, properties: Property[], namedPropertyMap: Map) { - if (propKind == PropertyKind.Computed || propKind == PropertyKind.Spread) { + if (propKind == PropertyKind.COMPUTED || propKind == PropertyKind.SPREAD) { let prop = new Property(propKind, propName); prop.setValue(propValue); properties.push(prop); @@ -199,9 +199,9 @@ function defineProperty( if (namedPropertyMap.has(name_str)) { let prevProp = properties[namedPropertyMap.get(name_str)!]; - if ((prevProp.getKind() == PropertyKind.Accessor || prevProp.getKind() == PropertyKind.Constant) - && (propKind == PropertyKind.Accessor || propKind == PropertyKind.Constant)) { - if (propKind == PropertyKind.Accessor) { + if ((prevProp.getKind() == PropertyKind.ACCESSOR || prevProp.getKind() == PropertyKind.CONSTANT) + && (propKind == PropertyKind.ACCESSOR || propKind == PropertyKind.CONSTANT)) { + if (propKind == PropertyKind.ACCESSOR) { if (ts.isGetAccessorDeclaration(propValue)) { prevProp!.setGetter(propValue); } else if (ts.isSetAccessorDeclaration(propValue)) { @@ -209,7 +209,7 @@ function defineProperty( } } else { prevProp!.setValue(propValue); - prevProp!.setKind(PropertyKind.Constant); + prevProp!.setKind(PropertyKind.CONSTANT); } return; } @@ -218,7 +218,7 @@ function defineProperty( } namedPropertyMap.set(name_str, properties.length); - if (propKind == PropertyKind.Accessor) { + if (propKind == PropertyKind.ACCESSOR) { if (ts.isGetAccessorDeclaration(propValue)) { prop.setGetter(propValue); } else if (ts.isSetAccessorDeclaration(propValue)) { diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index 18a04e51326805ea38334dfe9ec5af7fe4c5001e..790ee140c3c25fe3448b88842ec82f06aceb7a48 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -649,12 +649,12 @@ export class ExternalType extends BaseType { } transfer2LiteralBuffer(): LiteralBuffer { - let ImpTypeBuf = new LiteralBuffer(); - let ImpTypeLiterals: Array = new Array(); - ImpTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.EXTERNAL)); - ImpTypeLiterals.push(new Literal(LiteralTag.STRING, this.fullRedirectNath)); - ImpTypeBuf.addLiterals(...ImpTypeLiterals); - return ImpTypeBuf; + let impTypeBuf = new LiteralBuffer(); + let impTypeLiterals: Array = new Array(); + impTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.EXTERNAL)); + impTypeLiterals.push(new Literal(LiteralTag.STRING, this.fullRedirectNath)); + impTypeBuf.addLiterals(...impTypeLiterals); + return impTypeBuf; } } @@ -702,15 +702,15 @@ export class UnionType extends BaseType { } transfer2LiteralBuffer(): LiteralBuffer { - let UnionTypeBuf = new LiteralBuffer(); - let UnionTypeLiterals: Array = new Array(); - UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.UNION)); - UnionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.unionedTypeArray.length)); + let unionTypeBuf = new LiteralBuffer(); + let unionTypeLiterals: Array = new Array(); + unionTypeLiterals.push(new Literal(LiteralTag.INTEGER, L2Type.UNION)); + unionTypeLiterals.push(new Literal(LiteralTag.INTEGER, this.unionedTypeArray.length)); for (let type of this.unionedTypeArray) { - this.transferType2Literal(type, UnionTypeLiterals); + this.transferType2Literal(type, unionTypeLiterals); } - UnionTypeBuf.addLiterals(...UnionTypeLiterals); - return UnionTypeBuf; + unionTypeBuf.addLiterals(...unionTypeLiterals); + return unionTypeBuf; } } diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index 24bd25e9a95cce0259a850dfee3faf6802983472..56fa968a4e330df39b93ef15243cf4fec1a7c1c0 100644 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -175,18 +175,18 @@ export function escapeUnicode(data: string) { let char = '\n'; let i = 0; let j = 0; - let new_data = "" + let newData = ""; while ((j = data.indexOf(char, i)) !== -1) { let tmp = data.substring(i, j); if (tmp.indexOf("\\u") != -1) { tmp = addUnicodeEscape(tmp); } - new_data = new_data.concat(tmp, "\n"); + newData = newData.concat(tmp, "\n"); i = j + 1; } - new_data = new_data.concat("}\n"); - return new_data + newData = newData.concat("}\n"); + return newData; } export function initiateTs2abc(args: Array) { diff --git a/ts2panda/src/base/vregisterCache.ts b/ts2panda/src/base/vregisterCache.ts index 4bbb061f742c8ecf6d4253e1b36814e94a14237c..6aa6e8057dd564a7fcb29d553898666e4ea516e2 100644 --- a/ts2panda/src/base/vregisterCache.ts +++ b/ts2panda/src/base/vregisterCache.ts @@ -34,30 +34,30 @@ import { expandLexEnv } from "./lexEnv"; export enum CacheList { MIN, - NaN = MIN, + NAN = MIN, HOLE, FUNC, // load function - Infinity, - undefined, - Symbol, - Null, - Global, - LexEnv, - True, - False, + INFINITY, + UNDEFINED, + SYMBOL, + NULL, + GLOBAL, + LEXENV, + TRUE, + FALSE, MAX } let cacheExpandHandlers = new Map([ [CacheList.HOLE, expandHole], - [CacheList.NaN, expandNaN], - [CacheList.Infinity, expandInfinity], - [CacheList.undefined, expandUndefined], - [CacheList.Symbol, expandSymbol], - [CacheList.Null, expandNull], - [CacheList.Global, expandGlobal], - [CacheList.LexEnv, expandLexEnv], - [CacheList.True, expandTrue], - [CacheList.False, expandFalse], + [CacheList.NAN, expandNaN], + [CacheList.INFINITY, expandInfinity], + [CacheList.UNDEFINED, expandUndefined], + [CacheList.SYMBOL, expandSymbol], + [CacheList.NULL, expandNull], + [CacheList.GLOBAL, expandGlobal], + [CacheList.LEXENV, expandLexEnv], + [CacheList.TRUE, expandTrue], + [CacheList.FALSE, expandFalse], [CacheList.FUNC, expandFunc], ]); diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index ff02ad83b28dcce341b9126eb024f3734da9b7d7..3847fb9b5c4b138a1bd9ba59cf4b6a598cf220cb 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -281,8 +281,8 @@ export class CmdOptions { static getVersion(isBcVersion: boolean = true): void { let js2abc = path.join(path.resolve(__dirname, '../bin'), "js2abc"); - let version_arg = isBcVersion ? "--bc-version" : "--bc-min-version" - execute(`${js2abc}`, [version_arg]); + let versionArg = isBcVersion ? "--bc-version" : "--bc-min-version" + execute(`${js2abc}`, [versionArg]); } static isBcMinVersion(): boolean { diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 4818a0fd771cee14fc0bef2ed1999c23ae0a81d5..8cdd66dc8540b458f25327f02d356d66e42eb1b7 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -154,7 +154,7 @@ export class Compiler { } // spare v3 to save the currrent lexcial env - getVregisterCache(this.pandaGen, CacheList.LexEnv); + getVregisterCache(this.pandaGen, CacheList.LEXENV); this.pandaGen.loadAccFromArgs(this.rootNode); } @@ -192,9 +192,9 @@ export class Compiler { let funcName = jshelpers.getTextOfIdentifierOrLiteral((rootNode).name); let v = functionScope.find(funcName); if (v.scope == functionScope) { - this.pandaGen.loadAccumulator(NodeKind.FirstNodeOfFunction, + this.pandaGen.loadAccumulator(NodeKind.FIRST_NODE_OF_FUNCTION, getVregisterCache(this.pandaGen, CacheList.FUNC)); - this.pandaGen.storeAccToLexEnv(NodeKind.FirstNodeOfFunction, v.scope, v.level, v.v, true); + this.pandaGen.storeAccToLexEnv(NodeKind.FIRST_NODE_OF_FUNCTION, v.scope, v.level, v.v, true); } } } @@ -252,7 +252,7 @@ export class Compiler { return ; } // exit GlobalScopefunction or Function Block return - this.funcBuilder.implicitReturn(NodeKind.Invalid); + this.funcBuilder.implicitReturn(NodeKind.INVALID); } private compileFunctionBody(kind: number, body: ts.ConciseBody): void { @@ -270,12 +270,12 @@ export class Compiler { if (this.funcBuilder instanceof AsyncFunctionBuilder || this.funcBuilder instanceof AsyncGeneratorFunctionBuilder) { this.funcBuilder.resolve(body, retValue); - pandaGen.return(NodeKind.Invalid); + pandaGen.return(NodeKind.INVALID); } else { pandaGen.loadAccumulator(body, retValue); } pandaGen.freeTemps(retValue); - pandaGen.return(NodeKind.Invalid); + pandaGen.return(NodeKind.INVALID); } else { throw new Error("Node " + this.getNodeName(body) + " is unimplemented as a function body"); } @@ -314,7 +314,7 @@ export class Compiler { pandaGen.condition( decl, ts.SyntaxKind.EqualsEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.undefined), + getVregisterCache(pandaGen, CacheList.UNDEFINED), endLabel); this.compileExpression(param.initializer); pandaGen.storeAccumulator(param, paramReg); @@ -492,7 +492,7 @@ export class Compiler { if ((astutils.getVarDeclarationKind(decl) == VarDeclarationKind.LET) && decl.parent.kind != ts.SyntaxKind.CatchClause) { - this.pandaGen.loadAccumulator(decl, getVregisterCache(this.pandaGen, CacheList.undefined)); + this.pandaGen.loadAccumulator(decl, getVregisterCache(this.pandaGen, CacheList.UNDEFINED)); } } lref.setValue(); @@ -817,7 +817,7 @@ export class Compiler { compileCallExpression(expr, this); break; case ts.SyntaxKind.NullKeyword: // line 135 - this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.Null)); + this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.NULL)); break; case ts.SyntaxKind.ThisKeyword: // line 139 this.compileThisKeyword(expr); @@ -921,24 +921,24 @@ export class Compiler { switch (name) { // Those identifier are Built-In value properties case "NaN": - pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.NaN)); + pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.NAN)); return; case "Infinity": - pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.Infinity)); + pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.INFINITY)); return; case "globalThis": - pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.Global)); + pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.GLOBAL)); return; case "undefined": - pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(id, getVregisterCache(this.pandaGen, CacheList.UNDEFINED)); return; default: { // typeof an undeclared variable will return undefined instead of throwing reference error let parent = findOuterNodeOfParenthesis(id); if ((parent.kind == ts.SyntaxKind.TypeOfExpression)) { CmdOptions.isWatchEvaluateExpressionMode() ? - pandaGen.loadByNameViaDebugger(id, name, CacheList.False) : - pandaGen.loadObjProperty(id, getVregisterCache(pandaGen, CacheList.Global), name); + pandaGen.loadByNameViaDebugger(id, name, CacheList.FALSE) : + pandaGen.loadObjProperty(id, getVregisterCache(pandaGen, CacheList.GLOBAL), name); } else { pandaGen.tryLoadGlobalByName(id, name); } @@ -949,9 +949,9 @@ export class Compiler { private compileBooleanLiteral(lit: ts.BooleanLiteral) { if (lit.kind == ts.SyntaxKind.TrueKeyword) { - this.pandaGen.loadAccumulator(lit, getVregisterCache(this.pandaGen, CacheList.True)); + this.pandaGen.loadAccumulator(lit, getVregisterCache(this.pandaGen, CacheList.TRUE)); } else { - this.pandaGen.loadAccumulator(lit, getVregisterCache(this.pandaGen, CacheList.False)); + this.pandaGen.loadAccumulator(lit, getVregisterCache(this.pandaGen, CacheList.FALSE)); } } @@ -968,7 +968,7 @@ export class Compiler { if (arg.text.match(/ *return +this[;]? *$/) == null) { return false; } else { - this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.Global)) + this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.GLOBAL)) return true; } } @@ -990,7 +990,7 @@ export class Compiler { if (v instanceof LocalVariable) { if (CmdOptions.isWatchEvaluateExpressionMode()) { - pandaGen.loadByNameViaDebugger(node, MandatoryThis, CacheList.True); + pandaGen.loadByNameViaDebugger(node, MandatoryThis, CacheList.TRUE); return; } @@ -1020,13 +1020,13 @@ export class Compiler { if (!v || ((scope instanceof GlobalScope) && (v instanceof GlobalVariable))) { // If the variable doesn't exist or if it is global, we must generate // a delete global property instruction. - objReg = getVregisterCache(pandaGen, CacheList.Global); + objReg = getVregisterCache(pandaGen, CacheList.GLOBAL); pandaGen.loadAccumulatorString(unaryExpr, name); pandaGen.deleteObjProperty(expr, objReg); } else { // Otherwise it is a local variable which can't be deleted and we just // return false. - pandaGen.loadAccumulator(unaryExpr, getVregisterCache(pandaGen, CacheList.False)); + pandaGen.loadAccumulator(unaryExpr, getVregisterCache(pandaGen, CacheList.FALSE)); } break; } @@ -1062,7 +1062,7 @@ export class Compiler { // compile the delete operand. this.compileExpression(unaryExpr); // Deleting any value or a result of an expression returns True. - pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.True)); + pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.TRUE)); } } } @@ -1078,7 +1078,7 @@ export class Compiler { // compileExpression() must be called even though its value is not used // because it may have observable sideeffects. this.compileExpression(expr.expression); - pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.UNDEFINED)); } private compileAwaitExpression(expr: ts.AwaitExpression) { @@ -1092,7 +1092,7 @@ export class Compiler { this.compileExpression(expr.expression); this.funcBuilder.await(expr); } else { - pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.UNDEFINED)); this.funcBuilder.await(expr); } } @@ -1200,10 +1200,10 @@ export class Compiler { this.compileExpression(expr.left); pandaGen.storeAccumulator(expr, lhs); // equality comparasion between lhs and null, if true, load right - pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.Null), leftNullishLabel); + pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.NULL), leftNullishLabel); // equality comparasion between lhs and undefined, if true, load right pandaGen.loadAccumulator(expr.left, lhs); - pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), leftNullishLabel); + pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), leftNullishLabel); // lhs is either null or undefined, load left pandaGen.loadAccumulator(expr, lhs); pandaGen.branch(expr, endLabel); @@ -1487,8 +1487,8 @@ export class Compiler { let parent = findOuterNodeOfParenthesis(node); if ((parent.kind == ts.SyntaxKind.TypeOfExpression)) { CmdOptions.isWatchEvaluateExpressionMode() ? - this.pandaGen.loadByNameViaDebugger(node, variable.v.getName(), CacheList.False) : - this.pandaGen.loadObjProperty(node, getVregisterCache(this.pandaGen, CacheList.Global), + this.pandaGen.loadByNameViaDebugger(node, variable.v.getName(), CacheList.FALSE) : + this.pandaGen.loadObjProperty(node, getVregisterCache(this.pandaGen, CacheList.GLOBAL), variable.v.getName()); } else { this.pandaGen.tryLoadGlobalByName(node, variable.v.getName()); diff --git a/ts2panda/src/compilerUtils.ts b/ts2panda/src/compilerUtils.ts index 1d406d114bdd00c1d5406f382975d09e1a2cd9ff..4b8d30e54246f7b6a681ccbb581914a0bbce0854 100644 --- a/ts2panda/src/compilerUtils.ts +++ b/ts2panda/src/compilerUtils.ts @@ -134,7 +134,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand pandaGen.condition( element, ts.SyntaxKind.ExclamationEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.True), + getVregisterCache(pandaGen, CacheList.TRUE), hasInit ? getDefaultLabel : getUndefinedLabel ); @@ -145,7 +145,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand pandaGen.condition( element, ts.SyntaxKind.ExclamationEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.undefined), + getVregisterCache(pandaGen, CacheList.UNDEFINED), getDefaultLabel ) @@ -161,7 +161,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand } pandaGen.label(element, getUndefinedLabel); - pandaGen.loadAccumulator(element, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(element, getVregisterCache(pandaGen, CacheList.UNDEFINED)); pandaGen.label(element, storeLabel); lRef.setValue(); @@ -173,7 +173,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand pandaGen.condition( arr, ts.SyntaxKind.EqualsEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.True), + getVregisterCache(pandaGen, CacheList.TRUE), normalClose ); @@ -223,7 +223,7 @@ function emitRestElement(restElement: ts.BindingName | ts.Expression, iterator: pandaGen.condition( restElement, ts.SyntaxKind.ExclamationEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.True), + getVregisterCache(pandaGen, CacheList.TRUE), doneLabel ); @@ -263,9 +263,9 @@ function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pa let nullLish: Label = new Label(); pandaGen.loadAccumulator(obj, value); - pandaGen.condition(obj, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.Null), nullLish); + pandaGen.condition(obj, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.NULL), nullLish); pandaGen.loadAccumulator(obj, value); - pandaGen.condition(obj, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), nullLish); + pandaGen.condition(obj, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), nullLish); pandaGen.branch(obj, notNullish); // value == null or undefined, throw error @@ -367,7 +367,7 @@ function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pa pandaGen.condition( element, ts.SyntaxKind.ExclamationEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.undefined), + getVregisterCache(pandaGen, CacheList.UNDEFINED), getDefaultLabel ); @@ -396,7 +396,7 @@ function emitRestProperty(restProperty: ts.BindingElement | ts.SpreadAssignment, let lRef = LReference.generateLReference(compiler, target, true); if (excludedProp.length == 0) { - excludedProp = [getVregisterCache(pandaGen, CacheList.undefined)]; + excludedProp = [getVregisterCache(pandaGen, CacheList.UNDEFINED)]; } // Create a Object with the information of excluded properties diff --git a/ts2panda/src/debuginfo.ts b/ts2panda/src/debuginfo.ts index 7e95232598f43762bf4c96f32041774cf20cba93..27c91d6a7ead187c9ea241332f49590b571b309a 100644 --- a/ts2panda/src/debuginfo.ts +++ b/ts2panda/src/debuginfo.ts @@ -36,13 +36,13 @@ export class DebugPosInfo { private br: number | undefined; // bound right private l: number = -1; // line number private c: number = -1; // column number - private nodeKind: NodeKind | undefined = NodeKind.FirstNodeOfFunction; + private nodeKind: NodeKind | undefined = NodeKind.FIRST_NODE_OF_FUNCTION; constructor() { } public setDebugPosInfoNodeState(extendedNode: ts.Node | NodeKind): void { if (DebugInfo.isNode(extendedNode)) { - this.nodeKind = NodeKind.Normal; + this.nodeKind = NodeKind.NORMAL; } else { this.nodeKind = extendedNode; } @@ -84,7 +84,7 @@ export class DebugPosInfo { return this.c; } - public ClearNodeKind(): void { + public clearNodeKind(): void { this.nodeKind = undefined; } } @@ -128,9 +128,9 @@ export class VariableDebugInfo { } export enum NodeKind { - Normal, - Invalid, - FirstNodeOfFunction, + NORMAL, + INVALID, + FIRST_NODE_OF_FUNCTION, } export class DebugInfo { @@ -139,9 +139,9 @@ export class DebugInfo { constructor() { } public static isNode(extendedNode: ts.Node | NodeKind) { - if (extendedNode != NodeKind.Invalid && - extendedNode != NodeKind.FirstNodeOfFunction && - extendedNode != NodeKind.Normal) { + if (extendedNode != NodeKind.INVALID && + extendedNode != NodeKind.FIRST_NODE_OF_FUNCTION && + extendedNode != NodeKind.NORMAL) { return true; } @@ -281,7 +281,7 @@ export class DebugInfo { // count pos offset for (let i = 0; i < insns.length; i++) { - if (insns[i].debugPosInfo.getDebugPosInfoNodeState() == NodeKind.FirstNodeOfFunction) { + if (insns[i].debugPosInfo.getDebugPosInfoNodeState() == NodeKind.FIRST_NODE_OF_FUNCTION) { DebugInfo.setInvalidPosInfoForUninitializeIns(insns[i].debugPosInfo, pandaGen); } diff --git a/ts2panda/src/ecmaModule.ts b/ts2panda/src/ecmaModule.ts index d69254de3850114bc903de52c3c177b9bba4d653..38917963046c77d16fff007fb9fb96dd9948e366 100644 --- a/ts2panda/src/ecmaModule.ts +++ b/ts2panda/src/ecmaModule.ts @@ -231,9 +231,9 @@ export function setModuleNamespaceImports(compiler: Compiler, moduleScope: Scope } moduleScope.module().getNamespaceImportEntries().forEach(entry => { - let namespace_lref = LReference.generateLReference(compiler, (entry.node).name, true); + let namespaceLref = LReference.generateLReference(compiler, (entry.node).name, true); pandagen.getModuleNamespace(entry.node, entry.moduleRequest); - namespace_lref.setValue(); + namespaceLref.setValue(); }); } diff --git a/ts2panda/src/expression/callExpression.ts b/ts2panda/src/expression/callExpression.ts index a42cb042966a940f5cd3ee0ea3c31830da101a39..3ddf06139dcd342e9dcf1262a6a7fa2951428c6d 100644 --- a/ts2panda/src/expression/callExpression.ts +++ b/ts2panda/src/expression/callExpression.ts @@ -139,7 +139,7 @@ export function emitCall(expr: ts.CallExpression, args: VReg[], passThis: boolea // spread argument exist let calleeReg = args[0]; - let thisReg = passThis ? args[1] : getVregisterCache(pandaGen, CacheList.undefined); + let thisReg = passThis ? args[1] : getVregisterCache(pandaGen, CacheList.UNDEFINED); let argArray = pandaGen.getTemp(); createArrayFromElements(expr, compiler, >expr.arguments, argArray); pandaGen.callSpread(debugNode, calleeReg, thisReg, argArray); diff --git a/ts2panda/src/expression/numericLiteral.ts b/ts2panda/src/expression/numericLiteral.ts index b20056c5d2e81b7937dfc182b084dc385f9719be..e0aa46643e141305ed194e796c93d060ce4fb171 100644 --- a/ts2panda/src/expression/numericLiteral.ts +++ b/ts2panda/src/expression/numericLiteral.ts @@ -40,10 +40,10 @@ export function compileNumericLiteral(pandaGen: PandaGen, lit: ts.NumericLiteral let value = Number.parseFloat(text); // check whether value is a NaN if (Number.isNaN(value)) { - pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.NaN)); + pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.NAN)); } else if (!Number.isFinite(value)) { // check whether value is a Infinity - pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.Infinity)); + pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.INFINITY)); } else if (isInteger(value)) { // check whether value is a SafeInteger pandaGen.loadAccumulatorInt(lit, value); diff --git a/ts2panda/src/expression/objectLiteralExpression.ts b/ts2panda/src/expression/objectLiteralExpression.ts index 1d6af9384c4f132e56561f2e59e14493848057c9..b02d531748b456d63d5cd78d670ea22a36b80634 100644 --- a/ts2panda/src/expression/objectLiteralExpression.ts +++ b/ts2panda/src/expression/objectLiteralExpression.ts @@ -59,24 +59,24 @@ function compileProperties(compiler: Compiler, properties: Property[], literalBu let hasMethod: boolean = false; for (let prop of properties) { - if (prop.getKind() == PropertyKind.Spread || prop.getKind() == PropertyKind.Computed) { + if (prop.getKind() == PropertyKind.SPREAD || prop.getKind() == PropertyKind.COMPUTED) { break; } - if (prop.getKind() == PropertyKind.Prototype || prop.isRedeclared()) { + if (prop.getKind() == PropertyKind.PROTOTYPE || prop.isRedeclared()) { continue; } let nameLiteral = new Literal(LiteralTag.STRING, String(prop.getName())); - if (prop.getKind() == PropertyKind.Constant) { + if (prop.getKind() == PropertyKind.CONSTANT) { let valLiteral: Literal = createConstantLiteral(prop); literalBuffer.addLiterals(nameLiteral, valLiteral!); prop.setCompiled(); // need to be careful } - if (prop.getKind() == PropertyKind.Variable) { + if (prop.getKind() == PropertyKind.VARIABLE) { let compilerDriver = compiler.getCompilerDriver(); let valueNode = prop.getValue(); let valLiteral: Literal; @@ -98,7 +98,7 @@ function compileProperties(compiler: Compiler, properties: Property[], literalBu } } - if (prop.getKind() == PropertyKind.Accessor) { + if (prop.getKind() == PropertyKind.ACCESSOR) { let valLiteral = new Literal(LiteralTag.ACCESSOR, null); literalBuffer.addLiterals(nameLiteral, valLiteral); } @@ -170,9 +170,9 @@ function compileAccessorProperty(pandaGen: PandaGen, compiler: Compiler, objReg: if (prop.getGetter() !== undefined && prop.getSetter() !== undefined) { pandaGen.defineGetterSetterByValue(accessor!, objReg, propReg, getterReg, setterReg, false); } else if (ts.isGetAccessorDeclaration(accessor!)) { - pandaGen.defineGetterSetterByValue(accessor, objReg, propReg, getterReg, getVregisterCache(pandaGen, CacheList.undefined), false); + pandaGen.defineGetterSetterByValue(accessor, objReg, propReg, getterReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), false); } else { - pandaGen.defineGetterSetterByValue(accessor!, objReg, propReg, getVregisterCache(pandaGen, CacheList.undefined), setterReg, false); + pandaGen.defineGetterSetterByValue(accessor!, objReg, propReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), setterReg, false); } pandaGen.freeTemps(getterReg, setterReg, propReg); @@ -211,7 +211,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VRe let getter = prop.getValue(); createMethodOrAccessor(pandaGen, compiler, objReg, getter); pandaGen.storeAccumulator(getter, accessorReg); - pandaGen.defineGetterSetterByValue(getter, objReg, keyReg, accessorReg, getVregisterCache(pandaGen, CacheList.undefined), true); + pandaGen.defineGetterSetterByValue(getter, objReg, keyReg, accessorReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), true); pandaGen.freeTemps(accessorReg); break; } @@ -220,7 +220,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VRe let setter = prop.getValue(); createMethodOrAccessor(pandaGen, compiler, objReg, setter); pandaGen.storeAccumulator(setter, accessorReg); - pandaGen.defineGetterSetterByValue(setter, objReg, keyReg, getVregisterCache(pandaGen, CacheList.undefined), accessorReg, true); + pandaGen.defineGetterSetterByValue(setter, objReg, keyReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), accessorReg, true); pandaGen.freeTemps(accessorReg); break; } @@ -244,20 +244,20 @@ function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, propert for (let prop of properties) { if (!prop.isCompiled()) { switch (prop.getKind()) { - case PropertyKind.Accessor: { + case PropertyKind.ACCESSOR: { compileAccessorProperty(pandaGen, compiler, objReg, prop); break; } - case PropertyKind.Spread: { + case PropertyKind.SPREAD: { compileSpreadProperty(compiler, prop, objReg); break; } - case PropertyKind.Computed: { + case PropertyKind.COMPUTED: { compileComputedProperty(compiler, prop, objReg); break; } - case PropertyKind.Constant: - case PropertyKind.Variable: { + case PropertyKind.CONSTANT: + case PropertyKind.VARIABLE: { let nameSetting: boolean = false; if (ts.isMethodDeclaration(prop.getValue())) { createMethodOrAccessor(pandaGen, compiler, objReg, prop.getValue()); @@ -269,7 +269,7 @@ function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, propert pandaGen.storeOwnProperty(prop.getValue().parent, objReg, (prop.getName()), nameSetting); break; } - case PropertyKind.Prototype: { + case PropertyKind.PROTOTYPE: { compileProtoProperty(compiler, prop, objReg); break; } diff --git a/ts2panda/src/expression/yieldExpression.ts b/ts2panda/src/expression/yieldExpression.ts index 4280d68c28539865acdcd3e2ba0e8a881de54127..2c411852689565fb4d47b9ed70e8407e8589066e 100644 --- a/ts2panda/src/expression/yieldExpression.ts +++ b/ts2panda/src/expression/yieldExpression.ts @@ -35,7 +35,7 @@ function genYieldExpr(compiler: Compiler, expr: ts.YieldExpression) { compiler.compileExpression(expr.expression); funcBuilder.yield(expr); } else { - pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.UNDEFINED)); funcBuilder.yield(expr); } } diff --git a/ts2panda/src/function/asyncFunctionBuilder.ts b/ts2panda/src/function/asyncFunctionBuilder.ts index 3dc968aff000078695cf897406feacd0409de805..80f3ed865dab35c712417e60dff4cbf036b5d1a7 100644 --- a/ts2panda/src/function/asyncFunctionBuilder.ts +++ b/ts2panda/src/function/asyncFunctionBuilder.ts @@ -25,9 +25,9 @@ import { CatchTable, LabelPair } from "../statement/tryStatement"; import { FunctionBuilder, FunctionBuilderType } from "./functionBuilder"; enum ResumeMode { - Return, - Throw, - Next + RETURN, + THROW, + NEXT }; /** @@ -47,8 +47,8 @@ export class AsyncFunctionBuilder extends FunctionBuilder { prepare(node: ts.Node): void { let pandaGen = this.pg; - pandaGen.asyncFunctionEnter(NodeKind.Invalid); - pandaGen.storeAccumulator(NodeKind.Invalid, this.funcObj); + pandaGen.asyncFunctionEnter(NodeKind.INVALID); + pandaGen.storeAccumulator(NodeKind.INVALID, this.funcObj); pandaGen.label(node, this.beginLabel); } @@ -66,7 +66,7 @@ export class AsyncFunctionBuilder extends FunctionBuilder { } implicitReturn(node: ts.Node | NodeKind): void { - this.pg.loadAccumulator(node, getVregisterCache(this.pg, CacheList.undefined)); + this.pg.loadAccumulator(node, getVregisterCache(this.pg, CacheList.UNDEFINED)); this.pg.asyncFunctionResolve(node, this.funcObj); this.pg.return(node); } @@ -79,7 +79,7 @@ export class AsyncFunctionBuilder extends FunctionBuilder { pandaGen.storeAccumulator(node, modeType); // .reject - pandaGen.loadAccumulatorInt(node, ResumeMode.Throw); + pandaGen.loadAccumulatorInt(node, ResumeMode.THROW); let notThrowLabel = new Label(); @@ -107,8 +107,8 @@ export class AsyncFunctionBuilder extends FunctionBuilder { pandaGen.label(node, this.endLabel); // exception is in acc - pandaGen.asyncFunctionReject(NodeKind.Invalid, this.funcObj); - pandaGen.return(NodeKind.Invalid); + pandaGen.asyncFunctionReject(NodeKind.INVALID, this.funcObj); + pandaGen.return(NodeKind.INVALID); pandaGen.freeTemps(this.funcObj, this.resumeVal); diff --git a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts index 4484fb628c5be8fc5fa4a0886179de4aba1518f0..5e92852dfa39c4ea5a6d33c6f116a12e800f165b 100644 --- a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts +++ b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts @@ -63,7 +63,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { pg.storeAccumulator(node, this.funcObj); pg.label(node, this.beginLabel); - pg.loadAccumulator(node, getVregisterCache(pg, CacheList.undefined)); + pg.loadAccumulator(node, getVregisterCache(pg, CacheList.UNDEFINED)); pg.suspendGenerator(node, this.funcObj); pg.resumeGenerator(node, this.funcObj); pg.storeAccumulator(node, this.resumeVal); @@ -79,7 +79,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { let pg = this.pg; pg.storeAccumulator(node, this.resumeVal); pg.generatorComplete(node, this.funcObj); - pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.True)); + pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.TRUE)); pg.return(node); } @@ -91,12 +91,12 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.resumeGenerator(node); } pg.generatorComplete(node, this.funcObj); - pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.True)); + pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.TRUE)); pg.return(node); } implicitReturn(node: ts.Node | NodeKind): void { - this.pg.loadAccumulator(node, getVregisterCache(this.pg, CacheList.undefined)); + this.pg.loadAccumulator(node, getVregisterCache(this.pg, CacheList.UNDEFINED)); this.directReturn(node); } @@ -114,7 +114,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { * is at the top of the execution context stack as the running execution context. * 27.6.3.8.9 Return ! AsyncGeneratorResolve(generator, value, false). */ - pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.False)); + pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, getVregisterCache(pg, CacheList.FALSE)); this.resumeGenerator(node); this.handleAsyncYieldResume(node); @@ -139,7 +139,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.resumeVal = nextResult; // 6. Let received be NormalCompletion(undefined) - pg.storeConst(node, this.resumeVal, CacheList.undefined); + pg.storeConst(node, this.resumeVal, CacheList.UNDEFINED); pg.loadAccumulatorInt(node, ResumeMode.NEXT); pg.storeAccumulator(node, this.resumeType); pg.moveVreg(node, nextMethod, iter.method()); @@ -152,7 +152,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { let iterCompletion = new Label(); // 7. Repeat pg.label(node, loopStart); - pg.storeConst(node, exitReturn, CacheList.False); + pg.storeConst(node, exitReturn, CacheList.FALSE); // a. If received.[[Type]] is normal, then pg.loadAccumulatorInt(node, ResumeMode.NEXT); @@ -186,7 +186,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { // c. Else, // i. Assert: received.[[Type]] is return pg.label(node, returnCompletion); - pg.storeConst(node, exitReturn, CacheList.True); + pg.storeConst(node, exitReturn, CacheList.TRUE); // ii. Let return be ? GetMethod(iterator, "return"). iter.getMethod("return"); @@ -222,7 +222,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.await(node); pg.generatorYield(node, this.funcObj); - pg.storeConst(node, done, CacheList.False); + pg.storeConst(node, done, CacheList.FALSE); pg.asyncgeneratorresolve(node, this.funcObj, this.resumeVal, done); this.resumeGenerator(node); @@ -332,7 +332,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { resolve(node: ts.Node | NodeKind, value: VReg) { let pandaGen = this.pg; - pandaGen.asyncgeneratorresolve(node, this.funcObj, value, getVregisterCache(pandaGen, CacheList.True)); + pandaGen.asyncgeneratorresolve(node, this.funcObj, value, getVregisterCache(pandaGen, CacheList.TRUE)); } cleanUp(node: ts.Node) { @@ -343,7 +343,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { pandaGen.generatorComplete(node, this.funcObj); pandaGen.loadAccumulator(node, this.resumeVal); pandaGen.asyncgeneratorreject(node, this.funcObj); // exception is in acc - pandaGen.return(NodeKind.Invalid); + pandaGen.return(NodeKind.INVALID); this.pg.freeTemps(this.funcObj, this.resumeVal, this.resumeType); new CatchTable(pandaGen, this.endLabel, new LabelPair(this.beginLabel, this.endLabel)); } diff --git a/ts2panda/src/function/functionBuilder.ts b/ts2panda/src/function/functionBuilder.ts index 23a32bcc1ac35227e48ccd4221dace4be4293913..a9fe308ee2969f464a49db0bc77e7ef809e86163 100644 --- a/ts2panda/src/function/functionBuilder.ts +++ b/ts2panda/src/function/functionBuilder.ts @@ -74,7 +74,7 @@ export class FunctionBuilder { } implicitReturn(node: ts.Node | NodeKind) { - CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.Invalid) : this.pg.returnUndefined(node); + CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.INVALID) : this.pg.returnUndefined(node); } builderType(): FunctionBuilderType { diff --git a/ts2panda/src/function/generatorFunctionBuilder.ts b/ts2panda/src/function/generatorFunctionBuilder.ts index bbbd621c70831dab558bd35efa3bd321b6be36a8..cd02b3460827c4cee8e89544d650fae8c0c2284d 100644 --- a/ts2panda/src/function/generatorFunctionBuilder.ts +++ b/ts2panda/src/function/generatorFunctionBuilder.ts @@ -26,7 +26,7 @@ import { PandaGen } from "../pandagen"; import { IteratorRecord, IteratorType, getIteratorRecord } from "../statement/forOfStatement"; import { FunctionBuilder } from "./functionBuilder"; -enum ResumeMode { Return = 0, Throw, Next }; +enum ResumeMode { RETURN = 0, THROW, NEXT }; /** * function *foo() { @@ -49,7 +49,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { // backend handle funcobj, frontend set undefined pandaGen.createGeneratorObj(node, getVregisterCache(pandaGen, CacheList.FUNC)); pandaGen.storeAccumulator(node, this.funcObj); - pandaGen.loadAccumulator(node, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(node, getVregisterCache(pandaGen, CacheList.UNDEFINED)); pandaGen.suspendGenerator(node, this.funcObj); pandaGen.resumeGenerator(node, this.funcObj); pandaGen.storeAccumulator(node, this.resumeVal); @@ -62,7 +62,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { } implicitReturn(node: ts.Node | NodeKind) { - CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.Invalid) : this.pg.returnUndefined(node); + CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.INVALID) : this.pg.returnUndefined(node); } yield(node: ts.Node) { @@ -71,7 +71,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { let value = pandaGen.getTemp(); pandaGen.storeAccumulator(node, value); - pandaGen.Createiterresultobj(node, value, getVregisterCache(pandaGen, CacheList.False)); + pandaGen.Createiterresultobj(node, value, getVregisterCache(pandaGen, CacheList.FALSE)); pandaGen.suspendGenerator(node, this.funcObj); pandaGen.freeTemps(iterRslt, value); @@ -93,25 +93,25 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { let callreturnLabel = new Label(); let callthrowLabel = new Label(); let iteratorCompletionLabel = new Label(); - let exitLabel_return = new Label(); - let exitLabel_throw = new Label(); - let exitLabel_value = new Label(); - let exitLabel_TypeError = new Label(); + let exitLabelReturn = new Label(); + let exitLabelThrow = new Label(); + let exitLabelValue = new Label(); + let exitLabelTypeError = new Label(); // get innerIterator & iterator.[[Nextmethod]] (spec 4 & 5), support async in the future let type: IteratorType = IteratorType.Normal; let iterator: IteratorRecord = getIteratorRecord(pandaGen, expr, method, object, type); // init receivedValue with Undefined (spec 6) - pandaGen.moveVreg(expr, receivedValue, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.moveVreg(expr, receivedValue, getVregisterCache(pandaGen, CacheList.UNDEFINED)); // init modeType with Next (spec 6) - pandaGen.loadAccumulatorInt(expr, ResumeMode.Next); + pandaGen.loadAccumulatorInt(expr, ResumeMode.NEXT); pandaGen.storeAccumulator(expr, modeType); // starts executeing iterator.[[method]] (spec 7) pandaGen.label(expr, loopStartLabel); - pandaGen.loadAccumulatorInt(expr, ResumeMode.Next); + pandaGen.loadAccumulatorInt(expr, ResumeMode.NEXT); pandaGen.condition(expr, ts.SyntaxKind.EqualsEqualsToken, modeType, callreturnLabel); // call next @@ -120,19 +120,19 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { // call return pandaGen.label(expr, callreturnLabel); - pandaGen.loadAccumulatorInt(expr, ResumeMode.Return); + pandaGen.loadAccumulatorInt(expr, ResumeMode.RETURN); pandaGen.condition(expr, ts.SyntaxKind.EqualsEqualsToken, modeType, callthrowLabel); pandaGen.loadObjProperty(expr, iterator.getObject(), "return"); pandaGen.storeAccumulator(expr, method); // whether iterator.[[return]] exists - pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), exitLabel_return); + pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), exitLabelReturn); pandaGen.call(expr, [method, iterator.getObject(), receivedValue], true); pandaGen.branch(expr, iteratorCompletionLabel); // no return method - pandaGen.label(expr, exitLabel_return); + pandaGen.label(expr, exitLabelReturn); // if there are finally blocks, should implement these at first. this.compiler.compileFinallyBeforeCFC( @@ -151,19 +151,19 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.storeAccumulator(expr, method); // whether iterator.[[throw]] exists - pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), exitLabel_throw); + pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), exitLabelThrow); pandaGen.call(expr, [method, iterator.getObject(), receivedValue], true); pandaGen.branch(expr, iteratorCompletionLabel); // NOTE: If iterator does not have a throw method, this throw is // going to terminate the yield* loop. But first we need to give // iterator a chance to clean up. - pandaGen.label(expr, exitLabel_throw); + pandaGen.label(expr, exitLabelThrow); pandaGen.loadObjProperty(expr, iterator.getObject(), "return"); pandaGen.storeAccumulator(expr, method); // whether iterator.[[return]] exists - pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), exitLabel_TypeError); + pandaGen.condition(expr, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), exitLabelTypeError); // [[return]] exists pandaGen.call(expr, [method, iterator.getObject()], true); @@ -172,7 +172,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.throwIfNotObject(expr, innerResult); pandaGen.freeTemps(innerResult); - pandaGen.label(expr, exitLabel_TypeError); + pandaGen.label(expr, exitLabelTypeError); pandaGen.throwThrowNotExist(expr); // iteratorCompletion @@ -181,7 +181,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.throwIfNotObject(expr, this.resumeVal); pandaGen.loadObjProperty(expr, this.resumeVal, "done"); - pandaGen.jumpIfTrue(expr, exitLabel_value); + pandaGen.jumpIfTrue(expr, exitLabelValue); pandaGen.loadAccumulator(expr, this.resumeVal); pandaGen.suspendGenerator(expr, this.funcObj); @@ -196,11 +196,11 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { // produce a value. let outputLabel = new Label(); - pandaGen.label(expr, exitLabel_value); + pandaGen.label(expr, exitLabelValue); pandaGen.loadObjProperty(expr, this.resumeVal, "value"); let outputResult = pandaGen.getTemp(); pandaGen.storeAccumulator(expr, outputResult); - pandaGen.loadAccumulatorInt(expr, ResumeMode.Return); + pandaGen.loadAccumulatorInt(expr, ResumeMode.RETURN); pandaGen.condition(expr, ts.SyntaxKind.EqualsEqualsToken, modeType, outputLabel); this.compiler.compileFinallyBeforeCFC( @@ -226,7 +226,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.storeAccumulator(node, modeType); // .return(value) - pandaGen.loadAccumulatorInt(node, ResumeMode.Return); + pandaGen.loadAccumulatorInt(node, ResumeMode.RETURN); let notRetLabel = new Label(); @@ -245,7 +245,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { // .throw(value) pandaGen.label(node, notRetLabel); - pandaGen.loadAccumulatorInt(node, ResumeMode.Throw); + pandaGen.loadAccumulatorInt(node, ResumeMode.THROW); let notThrowLabel = new Label(); diff --git a/ts2panda/src/hoisting.ts b/ts2panda/src/hoisting.ts index e544b95c25568d21b38e409e2c2fcc74426d9850..586f60dd4854113278aa440bc92a68f0e3b65122 100644 --- a/ts2panda/src/hoisting.ts +++ b/ts2panda/src/hoisting.ts @@ -54,15 +54,15 @@ export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen) { let name = decl.name; if (scope instanceof GlobalScope) { - pandaGen.loadAccumulator(decl.node, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(decl.node, getVregisterCache(pandaGen, CacheList.UNDEFINED)); pandaGen.storeGlobalVar(decl.node, name); } else if (scope instanceof FunctionScope || scope instanceof ModuleScope) { let v: ModuleVariable = (scope.findLocal(name)!); - pandaGen.loadAccumulator(NodeKind.FirstNodeOfFunction, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(NodeKind.FIRST_NODE_OF_FUNCTION, getVregisterCache(pandaGen, CacheList.UNDEFINED)); if (decl.isModule !== ModuleVarKind.NOT) { - pandaGen.storeModuleVariable(NodeKind.FirstNodeOfFunction, v); + pandaGen.storeModuleVariable(NodeKind.FIRST_NODE_OF_FUNCTION, v); } else { - pandaGen.storeAccToLexEnv(NodeKind.FirstNodeOfFunction, scope, 0, v, true); + pandaGen.storeAccToLexEnv(NodeKind.FIRST_NODE_OF_FUNCTION, scope, 0, v, true); } } else { throw new Error("Wrong scope to hoist"); @@ -75,15 +75,15 @@ export function hoistFunction(decl: FuncDecl, scope: Scope, pandaGen: PandaGen, let env = compiler.getCurrentEnv(); if (scope instanceof GlobalScope) { - pandaGen.defineFunction(NodeKind.FirstNodeOfFunction, decl.node, internalName); - pandaGen.storeGlobalVar(NodeKind.FirstNodeOfFunction, funcName); + pandaGen.defineFunction(NodeKind.FIRST_NODE_OF_FUNCTION, decl.node, internalName); + pandaGen.storeGlobalVar(NodeKind.FIRST_NODE_OF_FUNCTION, funcName); } else if ((scope instanceof FunctionScope) || (scope instanceof LocalScope) || (scope instanceof ModuleScope)) { let v: ModuleVariable = (scope.findLocal(funcName)!); - pandaGen.defineFunction(NodeKind.FirstNodeOfFunction, decl.node, internalName); + pandaGen.defineFunction(NodeKind.FIRST_NODE_OF_FUNCTION, decl.node, internalName); if (decl.isModule !== ModuleVarKind.NOT) { - pandaGen.storeModuleVariable(NodeKind.FirstNodeOfFunction, v); + pandaGen.storeModuleVariable(NodeKind.FIRST_NODE_OF_FUNCTION, v); } else { - pandaGen.storeAccToLexEnv(NodeKind.FirstNodeOfFunction, scope, 0, v, true); + pandaGen.storeAccToLexEnv(NodeKind.FIRST_NODE_OF_FUNCTION, scope, 0, v, true); } } else { throw new Error("Wrong scope to hoist"); diff --git a/ts2panda/src/lexenv.ts b/ts2panda/src/lexenv.ts index 0b9ab61236053577fe8527f70cf3098e0ba4d5fe..6bb1670cd4643853c48ea5aabca33ac795d9f891 100644 --- a/ts2panda/src/lexenv.ts +++ b/ts2panda/src/lexenv.ts @@ -195,8 +195,8 @@ function checkConstAssignment(pg: PandaGen, v: Variable, expansion: IRNode[], no expansion.push(throwConstAssignment(nameReg)); } - if (v.isClass() && node != NodeKind.FirstNodeOfFunction && - node != NodeKind.Invalid && node != NodeKind.Normal) { + if (v.isClass() && node != NodeKind.FIRST_NODE_OF_FUNCTION && + node != NodeKind.INVALID && node != NodeKind.NORMAL) { let className = v.getName(); while (node) { if (ts.isClassLike(node) && node.name && diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index dd46cd8f7a4f3b3b5c72ae8854053b2c36d9a271..427739d7f08d6489e84a6f16f0d60d5fc67bb9f7 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -739,7 +739,7 @@ export class PandaGen { } loadByNameViaDebugger(node: ts.Node, string_id: string, boolVal: CacheList) { - this.loadObjProperty(node, getVregisterCache(this, CacheList.Global), "debuggerGetValue"); + this.loadObjProperty(node, getVregisterCache(this, CacheList.GLOBAL), "debuggerGetValue"); let getValueReg = this.getTemp(); this.storeAccumulator(node, getValueReg); let variableReg = this.getTemp(); @@ -753,14 +753,14 @@ export class PandaGen { // eg. print tryLoadGlobalByName(node: ts.Node, string_id: string) { - CmdOptions.isWatchEvaluateExpressionMode() ? this.loadByNameViaDebugger(node, string_id, CacheList.True) + CmdOptions.isWatchEvaluateExpressionMode() ? this.loadByNameViaDebugger(node, string_id, CacheList.TRUE) : this.add(node, tryLoadGlobalByName(string_id)); } storeByNameViaDebugger(node: ts.Node, string_id: string) { let valueReg = this.getTemp(); this.storeAccumulator(node, valueReg); - this.loadObjProperty(node, getVregisterCache(this, CacheList.Global), "debuggerSetValue"); + this.loadObjProperty(node, getVregisterCache(this, CacheList.GLOBAL), "debuggerSetValue"); let setValueReg = this.getTemp(); this.storeAccumulator(node, setValueReg); let variableReg = this.getTemp(); @@ -808,7 +808,7 @@ export class PandaGen { // @ts-ignore label(node: ts.Node, label: Label) { - this.add(NodeKind.Invalid, label); + this.add(NodeKind.INVALID, label); } branch(node: ts.Node | NodeKind, target: Label) { @@ -817,12 +817,12 @@ export class PandaGen { branchIfNotUndefined(node: ts.Node, target: Label) { // the compared value is in acc - this.condition(node, ts.SyntaxKind.EqualsEqualsToken, getVregisterCache(this, CacheList.undefined), target); + this.condition(node, ts.SyntaxKind.EqualsEqualsToken, getVregisterCache(this, CacheList.UNDEFINED), target); } branchIfUndefined(node: ts.Node, target: Label) { // the compared value is in acc - this.condition(node, ts.SyntaxKind.ExclamationEqualsToken, getVregisterCache(this, CacheList.undefined), target) + this.condition(node, ts.SyntaxKind.ExclamationEqualsToken, getVregisterCache(this, CacheList.UNDEFINED), target) } isTrue(node: ts.Node) { @@ -971,11 +971,11 @@ export class PandaGen { let endLabel = new Label(); this.jumpIfFalse(node, falseLabel); // operand is true - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.False))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.FALSE))); this.branch(node, endLabel); // operand is false this.label(node, falseLabel); - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.True))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.TRUE))); this.label(node, endLabel); break; case SyntaxKind.TildeToken: @@ -1248,9 +1248,9 @@ export class PandaGen { defineGetterSetterByValue(node: ts.Node, obj: VReg, name: VReg, getter: VReg, setter: VReg, isComputedPropertyName: boolean) { if (isComputedPropertyName) { - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.True))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.TRUE))); } else { - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.False))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.FALSE))); } this.add(node, defineGetterSetterByValue(obj, name, getter, setter)); } @@ -1509,10 +1509,10 @@ export class PandaGen { break; } this.add(node, new Jeqz(falseLabel)); - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.True))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.TRUE))); this.branch(node, endLabel); this.label(node, falseLabel); - this.add(node, loadAccumulator(getVregisterCache(this, CacheList.False))); + this.add(node, loadAccumulator(getVregisterCache(this, CacheList.FALSE))); this.label(node, endLabel); } diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts index 616d899360330fc4ab5c764d190131241c2eb79a..3ffdbbb6f8cff9a24683d396299685ef2ca6df70 100644 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -77,14 +77,14 @@ export class ClassDecl extends Decl { } export class CatchParameter extends Decl { - constructor(CpName: string, node: ts.Node, isModule: ModuleVarKind = ModuleVarKind.NOT) { - super(CpName, node, isModule); + constructor(cpName: string, node: ts.Node, isModule: ModuleVarKind = ModuleVarKind.NOT) { + super(cpName, node, isModule); } } export class FunctionParameter extends Decl { - constructor(FpName: string, node: ts.Node, isModule: ModuleVarKind = ModuleVarKind.NOT) { - super(FpName, node, isModule); + constructor(fpName: string, node: ts.Node, isModule: ModuleVarKind = ModuleVarKind.NOT) { + super(fpName, node, isModule); } } diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index e455b1a3aec5fefd714f375439a291a7115a1ca5..83781acb519401fe7fff8a34d97fe6e2a083175b 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -76,7 +76,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe for (; propertyIndex < properties.length; propertyIndex++) { let prop = properties[propertyIndex]; let tmpVreg = pandaGen.getTemp(); - if (prop.getKind() == PropertyKind.Constant) { + if (prop.getKind() == PropertyKind.CONSTANT) { staticItemsNum++; let nameLiteral = new Literal(LiteralTag.STRING, String(prop.getName())); classBuffer.addLiterals(nameLiteral); @@ -85,7 +85,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe prop.setCompiled(); } - if (prop.getKind() == PropertyKind.Variable) { + if (prop.getKind() == PropertyKind.VARIABLE) { if (prop.getValue().kind != ts.SyntaxKind.Constructor) { if (jshelpers.hasStaticModifier(prop.getValue())) { staticItemsNum++; @@ -110,7 +110,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe } pandaGen.freeTemps(tmpVreg); - if (prop.getKind() == PropertyKind.Computed || prop.getKind() == PropertyKind.Accessor) { + if (prop.getKind() == PropertyKind.COMPUTED || prop.getKind() == PropertyKind.ACCESSOR) { break; } } @@ -217,20 +217,20 @@ function compileUnCompiledProperty(compiler: Compiler, properties: Property[], c } switch (prop.getKind()) { - case PropertyKind.Constant: + case PropertyKind.CONSTANT: compiler.compileExpression(prop.getValue()); pandaGen.storeOwnProperty(prop.getValue().parent, classReg, prop.getName()); break; - case PropertyKind.Variable: + case PropertyKind.VARIABLE: compileUnCompiledVariable(compiler, prop, classReg); break; - case PropertyKind.Computed: + case PropertyKind.COMPUTED: let keyReg = pandaGen.getTemp(); compiler.compileExpression((prop.getName()).expression); pandaGen.storeAccumulator(prop.getValue(), keyReg); compileComputedProperty(compiler, prop, classReg, keyReg); break; - case PropertyKind.Accessor: + case PropertyKind.ACCESSOR: setClassAccessor(pandaGen, compiler, classReg, prop); break; default: @@ -377,7 +377,7 @@ export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, ar } else { let num = args.length; loadCtorObj(node, compiler); - pandaGen.superCall(node, num, num ? args : [getVregisterCache(pandaGen, CacheList.undefined)]); + pandaGen.superCall(node, num, num ? args : [getVregisterCache(pandaGen, CacheList.UNDEFINED)]); } let tmpReg = pandaGen.getTemp(); @@ -442,7 +442,7 @@ export function defineClassMember( properties: Property[], namedPropertyMap: Map) { let staticFlag = false; - if (propKind == PropertyKind.Computed || propKind == PropertyKind.Spread) { + if (propKind == PropertyKind.COMPUTED || propKind == PropertyKind.SPREAD) { let prop = new Property(propKind, propName); prop.setValue(propValue); if (jshelpers.hasStaticModifier(propValue)) { @@ -455,7 +455,7 @@ export function defineClassMember( let name_str = propertyKeyAsString(propName); if (!checkAndUpdateProperty(namedPropertyMap, name_str, propKind, propValue)) { let prop = new Property(propKind, propName); - if (propKind == PropertyKind.Accessor) { + if (propKind == PropertyKind.ACCESSOR) { if (ts.isGetAccessorDeclaration(propValue)) { prop.setGetter(propValue); } else if (ts.isSetAccessorDeclaration(propValue)) { @@ -549,7 +549,7 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar } if (ts.isComputedPropertyName(member.name!)) { - if (defineClassMember(member.name, member, PropertyKind.Computed, properties, namedPropertyMap)) { + if (defineClassMember(member.name, member, PropertyKind.COMPUTED, properties, namedPropertyMap)) { staticNum++; } } else { @@ -557,17 +557,17 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar let initializer = (member).initializer; if (initializer) { if (isConstantExpr(initializer)) { - if (defineClassMember(memberName, initializer, PropertyKind.Constant, properties, namedPropertyMap)) { + if (defineClassMember(memberName, initializer, PropertyKind.CONSTANT, properties, namedPropertyMap)) { staticNum++; } } else { - if (defineClassMember(memberName, initializer, PropertyKind.Variable, properties, namedPropertyMap)) { + if (defineClassMember(memberName, initializer, PropertyKind.VARIABLE, properties, namedPropertyMap)) { staticNum++; } } } else { initializer = ts.createIdentifier("undefined"); - if (defineClassMember(memberName, initializer, PropertyKind.Constant, properties, namedPropertyMap)) { + if (defineClassMember(memberName, initializer, PropertyKind.CONSTANT, properties, namedPropertyMap)) { staticNum++; } } @@ -577,11 +577,11 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar case ts.SyntaxKind.MethodDeclaration: { let memberName = getPropName(member.name!); if (typeof (memberName) == 'string' || typeof (memberName) == 'number') { - if (defineClassMember(memberName, member, PropertyKind.Variable, properties, namedPropertyMap)) { + if (defineClassMember(memberName, member, PropertyKind.VARIABLE, properties, namedPropertyMap)) { staticNum++; } } else { - if (defineClassMember(memberName, member, PropertyKind.Computed, properties, namedPropertyMap)) { + if (defineClassMember(memberName, member, PropertyKind.COMPUTED, properties, namedPropertyMap)) { staticNum++; } } @@ -591,11 +591,11 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar case ts.SyntaxKind.SetAccessor: { let accessorName = getPropName(member.name!); if (typeof (accessorName) == 'string' || typeof (accessorName) == 'number') { - if (defineClassMember(accessorName, member, PropertyKind.Accessor, properties, namedPropertyMap)) { + if (defineClassMember(accessorName, member, PropertyKind.ACCESSOR, properties, namedPropertyMap)) { staticNum++; } } else { - if (defineClassMember(accessorName, member, PropertyKind.Computed, properties, namedPropertyMap)) { + if (defineClassMember(accessorName, member, PropertyKind.COMPUTED, properties, namedPropertyMap)) { staticNum++; } } @@ -620,7 +620,7 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar properties.push(...staticItems); if (constructNode) { - defineClassMember("constructor", constructNode, PropertyKind.Variable, properties, namedPropertyMap); + defineClassMember("constructor", constructNode, PropertyKind.VARIABLE, properties, namedPropertyMap); } return properties; @@ -650,7 +650,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V let getProtoReg = pandaGen.getTemp(); let getter = prop.getValue(); let getFlag = createClassMethodOrAccessor(compiler, classReg, getProtoReg, accessorReg, getter); - pandaGen.defineGetterSetterByValue(getter, getFlag ? getProtoReg : classReg, keyReg, accessorReg, getVregisterCache(pandaGen, CacheList.undefined), true); + pandaGen.defineGetterSetterByValue(getter, getFlag ? getProtoReg : classReg, keyReg, accessorReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), true); pandaGen.freeTemps(accessorReg, getProtoReg); break; } @@ -659,7 +659,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V let setter = prop.getValue(); let setProtoReg = pandaGen.getTemp(); let setFlag = createClassMethodOrAccessor(compiler, classReg, setProtoReg, accesReg, setter); - pandaGen.defineGetterSetterByValue(setter, setFlag ? setProtoReg : classReg, keyReg, getVregisterCache(pandaGen, CacheList.undefined), accesReg, true); + pandaGen.defineGetterSetterByValue(setter, setFlag ? setProtoReg : classReg, keyReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), accesReg, true); pandaGen.freeTemps(accesReg, setProtoReg); break; } @@ -696,9 +696,9 @@ function setClassAccessor(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, if (prop.getGetter() !== undefined && prop.getSetter() !== undefined) { pandaGen.defineGetterSetterByValue(accessor!, flag ? tmpVreg : objReg, propReg, getterReg, setterReg, false); } else if (ts.isGetAccessorDeclaration(accessor!)) { - pandaGen.defineGetterSetterByValue(accessor, flag ? tmpVreg : objReg, propReg, getterReg, getVregisterCache(pandaGen, CacheList.undefined), false); + pandaGen.defineGetterSetterByValue(accessor, flag ? tmpVreg : objReg, propReg, getterReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), false); } else { - pandaGen.defineGetterSetterByValue(accessor!, flag ? tmpVreg : objReg, propReg, getVregisterCache(pandaGen, CacheList.undefined), setterReg, false); + pandaGen.defineGetterSetterByValue(accessor!, flag ? tmpVreg : objReg, propReg, getVregisterCache(pandaGen, CacheList.UNDEFINED), setterReg, false); } pandaGen.freeTemps(getterReg, setterReg, propReg, tmpVreg); @@ -754,7 +754,7 @@ export function setPrototypeAttributes(compiler: Compiler, node: ts.Node, classR function checkAndUpdateProperty(namedPropertyMap: Map, name: string, propKind: PropertyKind, valueNode: ts.Node): boolean { if (namedPropertyMap.has(name)) { let prop = namedPropertyMap.get(name); - if (propKind == PropertyKind.Accessor) { + if (propKind == PropertyKind.ACCESSOR) { if (ts.isGetAccessorDeclaration(valueNode)) { if (!scalarArrayEquals(prop!.getGetter(), valueNode)) { return false; diff --git a/ts2panda/src/statement/forOfStatement.ts b/ts2panda/src/statement/forOfStatement.ts index d4f1dede5a7244a7aa076b3309a530e3f9052868..002afd2a0ed5d92a2473d9c9e7719415820f4fbf 100644 --- a/ts2panda/src/statement/forOfStatement.ts +++ b/ts2panda/src/statement/forOfStatement.ts @@ -83,7 +83,7 @@ export function compileForOfStatement(stmt: ts.ForOfStatement, compiler: Compile compiler.popEnv(); } - pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.False)); + pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.FALSE)); pandaGen.storeAccumulator(stmt, doneReg); let labelTarget = new LabelTarget(stmt, endLabel, nextLabel, needCreateLoopEnv); diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index e1c02b44e8854479632dea16ade67113b185e87f..60bb6f4c874f254d0b8398f53f4b24348de3cae3 100644 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -287,7 +287,7 @@ export function compileForInStatement(stmt: ts.ForInStatement, compiler: Compile // get next prop of enumerator pandaGen.getNextPropName(stmt, iterReg); pandaGen.storeAccumulator(stmt, propName); - pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), loopEndLabel); + pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), loopEndLabel); let lref = LReference.generateLReference(compiler, stmt.initializer, false); pandaGen.loadAccumulator(stmt, propName); diff --git a/ts2panda/src/statement/returnStatement.ts b/ts2panda/src/statement/returnStatement.ts index 6b4365aa7a508965b4d5a4eee5210e68af1f4407..b334535e9643d4cfcfcdca54b09c57d760fde90f 100644 --- a/ts2panda/src/statement/returnStatement.ts +++ b/ts2panda/src/statement/returnStatement.ts @@ -41,7 +41,7 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, let need2CheckSuper = pandaGen.getTemp(); if (!expr) { - pandaGen.moveVreg(stmt, need2CheckSuper, getVregisterCache(pandaGen, CacheList.True)); + pandaGen.moveVreg(stmt, need2CheckSuper, getVregisterCache(pandaGen, CacheList.TRUE)); } else { if (ts.isCallExpression(expr) && expr.expression.kind == ts.SyntaxKind.SuperKeyword) { compileNormalReturn(stmt, returnValue, compiler); @@ -50,10 +50,10 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, } if (expr.kind == ts.SyntaxKind.ThisKeyword) { - pandaGen.moveVreg(stmt, need2CheckSuper, getVregisterCache(pandaGen, CacheList.True)); + pandaGen.moveVreg(stmt, need2CheckSuper, getVregisterCache(pandaGen, CacheList.TRUE)); } else { compiler.compileExpression(expr); - pandaGen.binary(stmt, ts.SyntaxKind.EqualsEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.binary(stmt, ts.SyntaxKind.EqualsEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED)); pandaGen.storeAccumulator(stmt, need2CheckSuper); } } @@ -61,7 +61,7 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, let compile = new Label(); let notCompile = new Label(); pandaGen.loadAccumulator(stmt, need2CheckSuper); - pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.False), compile); + pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.FALSE), compile); // load this let thisReg = pandaGen.getTemp(); @@ -74,7 +74,7 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, if (expr) { compiler.compileExpression(expr); } else { - pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.UNDEFINED)); } pandaGen.label(stmt, notCompile); @@ -89,7 +89,7 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, let returnLabel = new Label(); let normalLabel = new Label(); pandaGen.loadAccumulator(stmt, need2CheckSuper); - pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.False), normalLabel); + pandaGen.condition(stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.FALSE), normalLabel); // check if super has been called checkValidUseSuperBeforeSuper(compiler, stmt); pandaGen.branch(stmt, returnLabel); @@ -113,7 +113,7 @@ function compileNormalReturn(stmt: ts.ReturnStatement, returnValue: VReg, compil compiler.compileExpression(expr); } else { empty = true; - pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.undefined)); + pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.UNDEFINED)); } pandaGen.storeAccumulator(stmt, returnValue); diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts index f20de8ef20cc03a08432970f331e0edd12647949..37e5a3dd4ba27e1895aba9506b4fc3a54cd92434 100644 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -281,7 +281,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { let loopScope = compiler.getRecorder().getScopeOfNode(stmt); - pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.True)); + pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.TRUE)); pandaGen.storeAccumulator(stmt, this.doneReg); pandaGen.label(stmt, this.labelTarget.getContinueTargetLabel()!); @@ -297,7 +297,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { pandaGen.loadObjProperty(stmt, resultReg, "value"); pandaGen.storeAccumulator(stmt, resultReg); - pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.False)); + pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.FALSE)); pandaGen.storeAccumulator(stmt, this.doneReg); let lref = LReference.generateLReference(this.compiler, stmt.initializer, isDeclaration); @@ -321,12 +321,12 @@ export class TryBuilderWithForOf extends TryBuilderBase { pandaGen.condition( (this.stmt).expression, ts.SyntaxKind.ExclamationEqualsEqualsToken, - getVregisterCache(pandaGen, CacheList.True), + getVregisterCache(pandaGen, CacheList.TRUE), noReturn); // Iterator Close pandaGen.loadObjProperty(this.stmt, this.iterator.getObject(), "return"); pandaGen.storeAccumulator(this.stmt, this.iterator.getNextMethod()); - pandaGen.condition(this.stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.undefined), noReturn); + pandaGen.condition(this.stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(pandaGen, CacheList.UNDEFINED), noReturn); pandaGen.call(this.stmt, [this.iterator.getNextMethod(), this.iterator.getObject()], true); if (this.iterator.getType() == IteratorType.Async) { ((this.compiler.getFuncBuilder())).await(this.stmt); @@ -345,7 +345,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { let innerResult = this.pandaGen.getTemp(); this.pandaGen.loadObjProperty(this.stmt, this.iterator.getObject(), "return"); this.pandaGen.storeAccumulator(this.stmt, this.iterator.getNextMethod()); - this.pandaGen.condition(this.stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(this.pandaGen, CacheList.undefined), noReturn); + this.pandaGen.condition(this.stmt, ts.SyntaxKind.ExclamationEqualsEqualsToken, getVregisterCache(this.pandaGen, CacheList.UNDEFINED), noReturn); this.pandaGen.call(this.stmt, [this.iterator.getNextMethod(), this.iterator.getObject()], true); this.pandaGen.storeAccumulator(this.stmt, innerResult); diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts index 69750aa96d705382192db70eb4b59774d1edd5f5..90d4cd760364015edfc898ed7972e0e5627d6b44 100644 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -764,16 +764,16 @@ function checkForInStatement(node: ts.ForInStatement) { } const enum OuterExpressionKinds { - Parentheses = 1 << 0, - TypeAssertions = 1 << 1, - NonNullAssertions = 1 << 2, - PartiallyEmittedExpressions = 1 << 3, - Assertions = TypeAssertions | NonNullAssertions, - All = Parentheses | Assertions | PartiallyEmittedExpressions + PARENTHESES = 1 << 0, + TYPEASSERTIONS = 1 << 1, + NON_NULL_ASSERTIONS= 1 << 2, + PARTIALLY_EMITTED_EXPRESSIONS = 1 << 3, + ASSERTIONS= TYPEASSERTIONS | NON_NULL_ASSERTIONS, + ALL = PARENTHESES | ASSERTIONS | PARTIALLY_EMITTED_EXPRESSIONS } function checkReferenceExpression(expr: ts.Expression, invalidReferenceCode: DiagnosticCode, invalidOptionalChainCode: DiagnosticCode) { - let node = jshelpers.skipOuterExpressions(expr, OuterExpressionKinds.Assertions | OuterExpressionKinds.Parentheses); + let node = jshelpers.skipOuterExpressions(expr, OuterExpressionKinds.ASSERTIONS | OuterExpressionKinds.PARENTHESES); if (node.kind !== ts.SyntaxKind.Identifier && node.kind !== ts.SyntaxKind.PropertyAccessExpression && node.kind !== ts.SyntaxKind.ElementAccessExpression) { throw new DiagnosticError(expr, invalidReferenceCode); } @@ -952,12 +952,12 @@ function checkComputedPropertyName(node: ts.Node) { } const enum DeclarationMeaning { - GetAccessor = 1, - SetAccessor = 2, - PropertyAssignment = 4, - Method = 8, - GetOrSetAccessor = GetAccessor | SetAccessor, - PropertyAssignmentOrMethod = PropertyAssignment | Method, + GET_ACCESSOR = 1, + SET_ACCESSOR = 2, + PROPERTY_ASSIGNMENT = 4, + METHOD= 8, + GET_OR_SET_ACCESSOR = GET_ACCESSOR | SET_ACCESSOR, + PROPERTY_ASSIGNMENT_OR_METHOD = PROPERTY_ASSIGNMENT | METHOD, } function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { @@ -1010,7 +1010,7 @@ function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { if (!existKind) { seen.set(effectName, curKind); } else { - if ((curKind & DeclarationMeaning.PropertyAssignmentOrMethod) && (existKind & DeclarationMeaning.PropertyAssignmentOrMethod)) { + if ((curKind & DeclarationMeaning.PROPERTY_ASSIGNMENT_OR_METHOD) && (existKind & DeclarationMeaning.PROPERTY_ASSIGNMENT_OR_METHOD)) { if (effectName === "___proto__") { throw new DiagnosticError(name, DiagnosticCode.Duplicate_identifier_0, file, [jshelpers.getTextOfNode(name)]); } @@ -1041,14 +1041,14 @@ function getPropertieDeclaration(node: ts.Node, name: ts.Node) { checkInvalidExclamationToken(node.exclamationToken); } else if (ts.isPropertyAssignment(node)) { checkInvalidQuestionMark(node.questionToken); - decl = DeclarationMeaning.PropertyAssignment; + decl = DeclarationMeaning.PROPERTY_ASSIGNMENT; } else if (ts.isMethodDeclaration(node)) { - decl = DeclarationMeaning.Method; + decl = DeclarationMeaning.METHOD; } else if (ts.isGetAccessor(node)) { checkGetAccessor(node); - decl = DeclarationMeaning.GetAccessor; + decl = DeclarationMeaning.GET_ACCESSOR; } else if (ts.isSetAccessor(node)) { - decl = DeclarationMeaning.SetAccessor; + decl = DeclarationMeaning.SET_ACCESSOR; } else { LOGE("Unexpected syntax kind:" + node.kind); } diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index f6d17a09f2e198a277d59755a337f5bf718caf38..fde4f3a091a6d204c93406d5aded74508bee81e0 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -60,7 +60,7 @@ import { getLiteralKey } from "./base/util"; const dollarSign: RegExp = /\$/g; const starSign: RegExp = /\*/g; -const JsonType = { +const jsonType = { "function": 0, "record": 1, "string": 2, @@ -143,7 +143,7 @@ export class Ts2Panda { }); } - insn.debugPosInfo.ClearNodeKind(); + insn.debugPosInfo.clearNodeKind(); insns.push(new Ins( insOpcode, @@ -166,7 +166,7 @@ export class Ts2Panda { let strings_arr = Array.from(Ts2Panda.strings); let strObject = { - "t": JsonType.string, + "t": jsonType.string, "s": strings_arr } @@ -204,7 +204,7 @@ export class Ts2Panda { literalArrays.forEach(function(literalArray) { let literalArrayObject = { - "t": JsonType.literal_arr, + "t": jsonType.literal_arr, "lit_arr": literalArray } let jsonLiteralArrUnicode = escapeUnicode(JSON.stringify(literalArrayObject, null, 2)); @@ -220,7 +220,7 @@ export class Ts2Panda { static dumpCmdOptions(ts2abc: any): void { let enableRecordType: boolean = CmdOptions.needRecordType() && CompilerDriver.isTsFile; let options = { - "t": JsonType.options, + "t": jsonType.options, "merge_abc": CmdOptions.isMergeAbc(), "module_mode": CmdOptions.isModules(), "commonjs_module": CmdOptions.isCommonJs(), @@ -245,7 +245,7 @@ export class Ts2Panda { static dumpRecord(ts2abc: any, recordName: string): void { let record = { - "t": JsonType.record, + "t": jsonType.record, "rb": new Record(recordName), "pn": CmdOptions.getPackageName() } @@ -443,7 +443,7 @@ export class Ts2Panda { LOGD(func); let funcObject = { - "t": JsonType.function, + "t": jsonType.function, "fb": func } let jsonFuncUnicode = escapeUnicode(JSON.stringify(funcObject, null, 2)); @@ -458,7 +458,7 @@ export class Ts2Panda { static dumpModuleRecords(ts2abc: any): void { Ts2Panda.moduleRecordlist.forEach(function(module){ let moduleObject = { - "t": JsonType.module, + "t": jsonType.module, "mod": module }; let jsonModuleUnicode = escapeUnicode(JSON.stringify(moduleObject, null, 2)); @@ -482,7 +482,7 @@ export class Ts2Panda { 'tsi': typeSummaryIndex } let typeInfoObject = { - 't': JsonType.type_info, + 't': jsonType.type_info, 'ti': typeInfo }; let jsonTypeInfoUnicode = escapeUnicode(JSON.stringify(typeInfoObject, null, 2)); @@ -496,7 +496,7 @@ export class Ts2Panda { static dumpInputJsonFileContent(ts2abc: any, inputJsonFileContent: string): void { let inputJsonFileContentObject = { - "t": JsonType.input_json_file_content, + "t": jsonType.input_json_file_content, "ijfc": inputJsonFileContent } @@ -511,7 +511,7 @@ export class Ts2Panda { static dumpOutputFileName(ts2abc: any, outputFileName: string): void { let outputFileNameObject = { - "t": JsonType.output_filename, + "t": jsonType.output_filename, "ofn": outputFileName } diff --git a/ts2panda/src/typeChecker.ts b/ts2panda/src/typeChecker.ts index 85764ad230978c4d07f81b6e5dc1a15d5c549cb1..308c991e406f3328e07de9220b86048926bb246a 100644 --- a/ts2panda/src/typeChecker.ts +++ b/ts2panda/src/typeChecker.ts @@ -154,8 +154,8 @@ export class TypeChecker { if (TypeRecorder.getInstance().inNampespaceMap(localName)) { let redirectPath = TypeRecorder.getInstance().getPathForNamespace(localName)!; let externalType = new ExternalType(externalName, redirectPath); - let ImportTypeIndex = externalType.shiftedTypeIndex; - return ImportTypeIndex; + let importTypeIndex = externalType.shiftedTypeIndex; + return importTypeIndex; } return PrimitiveType.ANY; } @@ -183,9 +183,9 @@ export class TypeChecker { return this.getTypeForClassDeclOrExp(typeDeclNode, getTypeForInstace); case ts.SyntaxKind.ImportSpecifier: case ts.SyntaxKind.ImportClause: - let ImportTypeIndex = TypeRecorder.getInstance().tryGetTypeIndex(typeDeclNode); - if (ImportTypeIndex != PrimitiveType.ANY) { - return ImportTypeIndex; + let importTypeIndex = TypeRecorder.getInstance().tryGetTypeIndex(typeDeclNode); + if (importTypeIndex != PrimitiveType.ANY) { + return importTypeIndex; } return PrimitiveType.ANY; case ts.SyntaxKind.PropertyAccessExpression: diff --git a/ts2panda/src/typeRecorder.ts b/ts2panda/src/typeRecorder.ts index a760ffc08c2b5bb409c42a1a88ee9cc4a14c70d5..851728c1f69156e8411f8712a050de8f9ba1882d 100644 --- a/ts2panda/src/typeRecorder.ts +++ b/ts2panda/src/typeRecorder.ts @@ -159,8 +159,8 @@ export class TypeRecorder { if (moduleStmt.getNameSpace() != "") { this.setNamespaceMap(moduleStmt.getNameSpace(), moduleStmt.getModuleRequest()); let externalType = new ExternalType("*", moduleStmt.getNameSpace()); - let ImportTypeIndex = externalType.shiftedTypeIndex; - this.addUserDefinedTypeSet(ImportTypeIndex); + let importTypeIndex = externalType.shiftedTypeIndex; + this.addUserDefinedTypeSet(importTypeIndex); } } diff --git a/ts2panda/templates/irnodes.ts.erb b/ts2panda/templates/irnodes.ts.erb index acb70721c29bcbd4acc07ef3ae09fd6cce40d2b4..a0c5845a8d0a3d75a23813d30783704c0de55007 100755 --- a/ts2panda/templates/irnodes.ts.erb +++ b/ts2panda/templates/irnodes.ts.erb @@ -288,7 +288,7 @@ export function getInsnFormats(opcode: IRNodeKind) { } export abstract class IRNode { - private node: ts.Node | NodeKind = NodeKind.Normal; + private node: ts.Node | NodeKind = NodeKind.NORMAL; public static pg: PandaGen | undefined = undefined; constructor( readonly kind: IRNodeKind, @@ -316,9 +316,9 @@ export abstract class IRNode { } getNodeName() { - if (this.node != NodeKind.Invalid && - this.node != NodeKind.FirstNodeOfFunction && - this.node != NodeKind.Normal) { + if (this.node != NodeKind.INVALID && + this.node != NodeKind.FIRST_NODE_OF_FUNCTION && + this.node != NodeKind.NORMAL) { return ts.SyntaxKind[(this.node).kind]; } diff --git a/ts2panda/tests/expression/functionExpression.test.ts b/ts2panda/tests/expression/functionExpression.test.ts index da9270f1ca47384322192e1802fddb4843077426..bfc8c512d7b6d467d1003da3ab676538359237e0 100644 --- a/ts2panda/tests/expression/functionExpression.test.ts +++ b/ts2panda/tests/expression/functionExpression.test.ts @@ -57,7 +57,7 @@ describe("compileFunctionExpression", function () { let pandaGens = compileAllSnippet(source, passes); IRNode.pg = new PandaGen("", creatAstFromSnippet(``), 0, undefined); - let expected_func = [ + let expectedFunc = [ new Ldfunction(), new Sta(new VReg()), new Lda(new VReg()), @@ -72,7 +72,7 @@ describe("compileFunctionExpression", function () { let checkCount = 0; pandaGens.forEach((pg) => { if (pg.internalName == "UnitTest.test") { - expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc), "check func insns").to.be.true; checkCount++; } }); @@ -172,7 +172,7 @@ describe("compileFunctionExpression", function () { let checkCount = 0; IRNode.pg = new PandaGen("", creatAstFromSnippet(``), 0, undefined); - let expected_func = [ + let expectedFunc = [ new Lda(new VReg()), new Sta(new VReg()), new Lda(new VReg()), @@ -184,7 +184,7 @@ describe("compileFunctionExpression", function () { pandaGens.forEach((pg) => { if (pg.internalName == "UnitTest.p") { - expect(checkInstructions(pg.getInsns(), expected_func), "check arrow func insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc), "check arrow func insns").to.be.true; checkCount++; } @@ -229,7 +229,7 @@ describe("compileFunctionExpression", function () { let notRetLabel1 = new Label(); let notThrowLabel1 = new Label(); - let expected_func = [ + let expectedFunc = [ new Creategeneratorobj(new VReg()), new Sta(new VReg()), new Lda(new VReg()), @@ -290,7 +290,7 @@ describe("compileFunctionExpression", function () { pandaGens.forEach((pg) => { if (pg.internalName == "UnitTest.a") { - expect(checkInstructions(pg.getInsns(), expected_func), "check generator func insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc), "check generator func insns").to.be.true; checkCount++; } @@ -318,7 +318,7 @@ describe("compileFunctionExpression", function () { let endLabel = new Label(); let nextLabel = new Label(); - let expected_func = [ + let expectedFunc = [ new Asyncfunctionenter(), new Sta(new VReg()), beginLabel, @@ -354,7 +354,7 @@ describe("compileFunctionExpression", function () { pg.getInsns().forEach(ins => { console.log(ins.toString()); }) - expect(checkInstructions(pg.getInsns(), expected_func), "check async func insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc), "check async func insns").to.be.true; checkCount++; } diff --git a/ts2panda/tests/expression/prefixOperations.test.ts b/ts2panda/tests/expression/prefixOperations.test.ts index f81500f70661b190e7ed8efbbe9d95d6d26b09e6..98de90cfc49ebe8ad6dbcda0e7a69cb60f4583a8 100644 --- a/ts2panda/tests/expression/prefixOperations.test.ts +++ b/ts2panda/tests/expression/prefixOperations.test.ts @@ -153,14 +153,14 @@ describe("PrefixOperationsTest", function () { let insns = compileMainSnippet("let i = 5; let j = ~i"); IRNode.pg = new PandaGen("foo", creatAstFromSnippet("let i = 5; let j = ~i"), 0, undefined); - let temp_i = new VReg(); + let tempI = new VReg(); let expected = [ new Ldai(new Imm(5)), new Sttoglobalrecord(new Imm(0), 'i'), new Tryldglobalbyname(new Imm(1), 'i'), - new Sta(temp_i), - new Lda(temp_i), + new Sta(tempI), + new Lda(tempI), new Not(new Imm(2)), new Sttoglobalrecord(new Imm(3), 'j'), new Returnundefined() diff --git a/ts2panda/tests/lexenv.test.ts b/ts2panda/tests/lexenv.test.ts index ac103f52d52659c5e2270eaf7fbab2b5a395f2df..18961ab5ce4994263f6158c49465f606bff3f1fb 100644 --- a/ts2panda/tests/lexenv.test.ts +++ b/ts2panda/tests/lexenv.test.ts @@ -355,7 +355,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let pandaGens = compileAllSnippet(source); IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expected_main = [ + let expectedMain = [ new Lda(new VReg()), new Stglobalvar(new Imm(0), "outer"), new Definefunc(new Imm(1), "UnitTest.func", new Imm(0)), @@ -365,7 +365,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { new Returnundefined() ]; IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expected_func = [ + let expectedFunc = [ new Ldai(new Imm(2)), new Stglobalvar(new Imm(0), "outer"), new Returnundefined() @@ -373,9 +373,9 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { pandaGens.forEach((pg) => { if (pg.internalName == "UnitTest.func_main_0") { - expect(checkInstructions(pg.getInsns(), expected_main)).to.be.true; + expect(checkInstructions(pg.getInsns(), expectedMain)).to.be.true; } else if (pg.internalName == "UnitTest.func") { - expect(checkInstructions(pg.getInsns(), expected_func)).to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc)).to.be.true; } }) }); @@ -392,7 +392,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let passes = [new CacheExpander()]; let pandaGens = compileAllSnippet(source, passes); IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expected_main = [ + let expectedMain = [ new Definefunc(new Imm(0), "UnitTest.func", new Imm(0)), new Stglobalvar(new Imm(1), "func"), // global.func = func_func_1 new Ldai(new Imm(1)), // value = 1 @@ -401,7 +401,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { ]; IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expected_func = [ + let expectedFunc = [ new Ldai(new Imm(2)), // ...insnsStoreLexVar_func, new Trystglobalbyname(new Imm(0), "outer"), @@ -411,12 +411,12 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { pandaGens.forEach((pg) => { let scope = pg.getScope(); if (pg.internalName == "UnitTest.func_main_0") { - expect(checkInstructions(pg.getInsns(), expected_main), "check main insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedMain), "check main insns").to.be.true; expect(scope.getNumLexEnv(), "main scope has 0 lexvar").to.be.equal(0); // expect(scope.hasLexEnv(), "main scope has lexenv").to.be.true; } else if (pg.internalName == "UnitTest.func") { - expect(checkInstructions(pg.getInsns(), expected_func), "check func insns").to.be.true; + expect(checkInstructions(pg.getInsns(), expectedFunc), "check func insns").to.be.true; expect(scope.getNumLexEnv(), "func scope has 1 lexvar").to.be.equal(0); // expect(scope.hasLexEnv(), "func scope has lexenv").to.be.true; } @@ -439,7 +439,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { `; IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expect_outer: IRNode[] = [ + let expectOuter: IRNode[] = [ new Newlexenv(new Imm(2)), new Sta(new VReg()), new Lda(new VReg()), @@ -460,7 +460,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { ]; IRNode.pg = new PandaGen("foo", creatAstFromSnippet(`class C {}; export {C}`), 0, undefined); - let expect_anonymous = [ + let expectAnonymous = [ new Ldlexvar(new Imm(0), new Imm(0)), new Sta(new VReg()), new Lda(new VReg()), @@ -505,7 +505,7 @@ describe("lexenv-compile-testcase in lexenv.test.ts", function () { let globalA = globalScope!.findLocal("a"); expect(globalA instanceof GlobalVariable, "globalA is GlobalVariable").to.be.true; - expect(checkInstructions(anonymousPg!.getInsns(), expect_anonymous), "check anonymous func ins").to.be.true; - expect(checkInstructions(outerPg!.getInsns(), expect_outer), "check outer func ins").to.be.true; + expect(checkInstructions(anonymousPg!.getInsns(), expectAnonymous), "check anonymous func ins").to.be.true; + expect(checkInstructions(outerPg!.getInsns(), expectOuter), "check outer func ins").to.be.true; }); }); diff --git a/ts2panda/tests/statements/functionDeclaration.test.ts b/ts2panda/tests/statements/functionDeclaration.test.ts index 6405c9cd96eb502d1f63fcaafccd9f81b29c368b..a6001cbc6a78fe471788fd6f1d1cb96a9a0c0735 100644 --- a/ts2panda/tests/statements/functionDeclaration.test.ts +++ b/ts2panda/tests/statements/functionDeclaration.test.ts @@ -124,14 +124,14 @@ describe("FunctionDeclarationTest", function () { let endLabel = new Label(); IRNode.pg = new PandaGen("", creatAstFromSnippet(``), 0, undefined); - let expected_main = [ + let expectedMain = [ new Definefunc(new Imm(0), "UnitTest.test", new Imm(1)), new Stglobalvar(new Imm(1), "test"), new Returnundefined() ]; IRNode.pg = new PandaGen("", creatAstFromSnippet(``), 0, undefined); - let expected_func = [ + let expectedFunc = [ // func_test_0 new Lda(new VReg()), new Stricteq(new Imm(0), undefinedVReg), @@ -145,10 +145,10 @@ describe("FunctionDeclarationTest", function () { compilerunit.forEach(element => { if (element.internalName == "UnitTest.func_main_0") { let insns = element.getInsns(); - expect(checkInstructions(insns, expected_main)).to.be.true; + expect(checkInstructions(insns, expectedMain)).to.be.true; } else if (element.internalName == "UnitTest.test") { let insns = element.getInsns(); - expect(checkInstructions(insns, expected_func)).to.be.true; + expect(checkInstructions(insns, expectedFunc)).to.be.true; let parameterLength = element.getParameterLength(); expect(parameterLength == 1).to.be.true; } @@ -162,7 +162,7 @@ describe("FunctionDeclarationTest", function () { IRNode.pg = new PandaGen("", creatAstFromSnippet(``), 0, undefined); let idx = new Imm(1); let lastParam = new VReg(); - let expected_func = [ + let expectedFunc = [ // func_test_0 new Copyrestargs(idx), new Sta(lastParam), @@ -172,6 +172,6 @@ describe("FunctionDeclarationTest", function () { let functionPg = snippetCompiler.getPandaGenByName("UnitTest.test"); let insns = functionPg!.getInsns(); - expect(checkInstructions(insns, expected_func)).to.be.true; + expect(checkInstructions(insns, expectedFunc)).to.be.true; }); });