diff --git a/test262/README.md b/test262/README.md index c7ce6a86eb76cd18aca07c390751fb73e2c9c688..d52468b8ba7cd7079206fc79c9a9d522945e9b50 100644 --- a/test262/README.md +++ b/test262/README.md @@ -24,7 +24,7 @@ usage: run_test262.py [-h] [--dir DIR] [--file FILE] [--mode [{1,2,3}]] [--ark-frontend [{ts2panda,es2panda}]] optional arguments: - -h, --help show this help message and exit + -h, --help Show this help message and exit --dir DIR Directory to test --file FILE File to test --mode [{1,2,3}] selection information as: 1: only default 2: @@ -45,19 +45,18 @@ optional arguments: --ark-tool ARK_TOOL ark's binary tool --ark-frontend-tool ARK_FRONTEND_TOOL ark frontend conversion tool - --libs-dir LIBS_DIR The path collection of dependent so has been divided - by':' + --libs-dir LIBS_DIR The path collection of dependent so, divided by':' --ark-frontend [{ts2panda,es2panda}] Choose one of them ``` -### 2.2 run all the test cases +### 2.2 Run all the test cases ``` python3 test262/run_test262.py ``` -### 2.3 run `es51` related test cases +### 2.3 Run `es51` related test cases ```python python3 test262/run_test262.py --es51 @@ -65,34 +64,34 @@ python3 test262/run_test262.py --es51 After the execution finished, a directory named `test_es51` is created under directory `test262/data` , which is used to store all `es51` cases. -### 2.4 run `es2015` related test cases +### 2.4 Run `es2015` related test cases #### 2.4.1 only include use cases for ES2015 ```python python3 test262/run_test262.py --es2015 only ``` -#### 2.4.2 contains all use cases for ES5 and ES2015 +#### 2.4.2 Contains all use cases for ES5 and ES2015 ```python python3 test262/run_test262.py --es2015 all ``` -### 2.5 run single test case +### 2.5 Run single test case ```python python3 test262/run_test262.py --file test262/data/test_es5/language/statements/break/12.8-1.js ``` -### 2.6 run all the test cases under specified directory +### 2.6 Run all the test cases under specified directory ```python python3 test262/run_test262.py --dir test262/data/test_es5/language/statements ``` -### 2.7 run single test case with other engines. Take d8 as an example +### 2.7 Run single test case with other engines. Take d8 as an example ```python python3 test262/run_test262.py --engine="/home/share/v8-code/v8/out.gn/x64.release/d8" --file test262/data/test_es5/language/statements/break/12.8-1.js ``` -### 2.8 run single test case with `babel` conversion +### 2.8 Run single test case with `babel` conversion ``` python3 test262/run_test262.py --babel --file test262/data/test_es5/language/statements/break/12.8-1.js ``` @@ -155,7 +154,7 @@ Ran 1 tests used time is: 0:00:13.303865 ``` -* `default` indicates `non-strict` mode, `strict mode` indicates the strict mode. +* `default` indicates `non-strict` mode; `strict mode` indicates the strict mode. * After the execution finished, the following files are generated under directory `out/test262/` (you can specified it in `test262/config.py`): @@ -170,7 +169,7 @@ used time is: 0:00:13.303865 `.abc` indicates the generated binary `abc` file. -`.err` indicates error occurs during the test. +`.err` indicates that an error occurred during the test. `.fail/.pass` is the file saved after `js` file has been preprocessed. diff --git a/test262/config.py b/test262/config.py index 2c3f28ba79f788ad47cab2d3ab27cc68465f1937..c521b973dd530584ae87c384f91dde836def4731 100755 --- a/test262/config.py +++ b/test262/config.py @@ -1,5 +1,5 @@ -# coding: utf-8 #!/usr/bin/python3 +# coding: utf-8 """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index 73a64ff631f98c290deef0bd9fa15aaf9922825d..97752ef074164566fb3186cad224d9c84d6cc53e 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -1,5 +1,5 @@ -# coding: utf-8 #!/usr/bin/python3 +# coding: utf-8 """ Copyright (c) 2021 Huawei Device Co., Ltd. diff --git a/test262/run_test262.py b/test262/run_test262.py index 256a044b24803d153d468fa302af4c9486750258..663fca577e97703d42246a226f6e9cc3da241226 100755 --- a/test262/run_test262.py +++ b/test262/run_test262.py @@ -1,5 +1,5 @@ -# coding: utf-8 #!/usr/bin/python3 +# coding: utf-8 """ Copyright (c) 2021 Huawei Device Co., Ltd. @@ -72,8 +72,7 @@ def parse_args(): parser.add_argument('--ark-frontend', nargs='?', choices=ARK_FRONTEND_LIST, type=str, help="Choose one of them") - args = parser.parse_args() - return args + return parser.parse_args() def run_check(runnable, env=None): diff --git a/test262/utils.py b/test262/utils.py index 91ed1da527be3474dc06d7bfa73d99710261acc3..2d62db1db5eba6aeb004078f830fab1a70dc3d12 100755 --- a/test262/utils.py +++ b/test262/utils.py @@ -33,8 +33,7 @@ TERM_FUCHSIA = '\033[1;35m' def current_time(): - dt_ms = datetime.datetime.now().strftime('%m-%d %H:%M:%S.%f') - return dt_ms + return datetime.datetime.now().strftime('%m-%d %H:%M:%S.%f') class Logging(): @@ -82,8 +81,7 @@ class CommandCwd(): cmd = " ".join(self.cmds) LOGGING.debug("command: " + cmd + " | " + "dir: " + self.cwd) proc = subprocess.Popen(self.cmds, cwd=self.cwd) - ret = proc.wait() - return ret + return proc.wait() def run_cmd_cwd(commands, cwd=os.getcwd()): diff --git a/ts2panda/scripts/generate_plugin.py b/ts2panda/scripts/generate_plugin.py index 996cabd9e3724a7c8e7864b0d27513645013d518..306e9696d26223c0d8a8410728e56b1b30b586d7 100755 --- a/ts2panda/scripts/generate_plugin.py +++ b/ts2panda/scripts/generate_plugin.py @@ -83,7 +83,6 @@ def gen_bin_info(input_arguments): def gen_java_method(input_arguments): - file_name = input_arguments.plugin_name file_path = input_arguments.plugin_path out_file = input_arguments.generated_file diff --git a/ts2panda/scripts/run.py b/ts2panda/scripts/run.py index 9a2534954721c24643d91d34abc0efe06b17e9c4..fd8c697470c4c1a5adf70c2a2caaf00ec065bedf 100755 --- a/ts2panda/scripts/run.py +++ b/ts2panda/scripts/run.py @@ -25,7 +25,6 @@ import platform def parse_args(): - parser = argparse.ArgumentParser() parser.add_argument('--src-dir', @@ -39,14 +38,14 @@ def parse_args(): parser.add_argument("--node-modules", help='path to node-modules exetuable') - arguments = parser.parse_args() - return arguments + return parser.parse_args() def set_env(node_dir): - jsoner_format = ":" if platform.system() == "Windows": jsoner_format = ";" + else: + jsoner_format = ":" os.environ["PATH"] = f'{node_dir}{jsoner_format}{os.environ["PATH"]}' diff --git a/ts2panda/src/addVariable2Scope.ts b/ts2panda/src/addVariable2Scope.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/assemblyDumper.ts b/ts2panda/src/assemblyDumper.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/astutils.ts b/ts2panda/src/astutils.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/base/iterator.ts b/ts2panda/src/base/iterator.ts old mode 100755 new mode 100644 index 748113e81e03af58dac38f88035cfbaa6b37dc0d..b1d5efcee726673855de2de2e6b8c0ba11178658 --- a/ts2panda/src/base/iterator.ts +++ b/ts2panda/src/base/iterator.ts @@ -42,7 +42,7 @@ export class Iterator { pandaGen.getIterator(this.node); pandaGen.storeAccumulator(this.node, iterator); - // get next method + // get the next method pandaGen.loadObjProperty(this.node, iterator, "next"); pandaGen.storeAccumulator(this.node, this.iterRecord.nextMethod); } @@ -52,7 +52,7 @@ export class Iterator { * if (!isObject(iterResult)) { * throw TypeError * } - * */ + */ callNext(iterResult: VReg) { this.pandaGen.getIteratorNext(this.node, this.iterRecord.iterator, this.iterRecord.nextMethod); this.pandaGen.storeAccumulator(this.node, iterResult); diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts old mode 100755 new mode 100644 index 7e6b56152f9d102b197bf380b76087fb9827f64b..4a3079a971bde8cff9269b8734ed8423dc3da626 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -19,7 +19,7 @@ * and asks Pandagen to generate bytecode. * * This file shold not contain import from irnodes.ts. - * The interface of PandaGen shold be enoght. + * The interface of PandaGen shold be enough. */ import * as ts from "typescript"; @@ -481,7 +481,7 @@ export class Compiler { if (stmt.elseStatement) { let flowNode = jshelpers.getFlowNode(stmt); if (flowNode !== undefined) { - if (!(flowNode.flags & ts.FlowFlags.Unreachable)) { //if not unreachable + if (!(flowNode.flags & ts.FlowFlags.Unreachable)) { // if not unreachable this.pandaGen.branch(DebugInfo.getLastNode(), ifEndLabel); } } @@ -521,7 +521,7 @@ export class Compiler { let labelName: string = jshelpers.getTextOfIdentifierOrLiteral(stmt.label); let blockEndLabel = undefined; - // because there is no labled in the block statement, we need add the end lable. + // because there is no label in the block statement, we need to add the end label. if (stmt.statement.kind == ts.SyntaxKind.Block) { blockEndLabel = new Label(); @@ -536,7 +536,7 @@ export class Compiler { this.pandaGen.label(stmt, blockEndLabel); } - // because the scope of the label just in labeld statment, we need delete it. + // because the scope of the label is just in labeled statment, we need to delete it. LabelTarget.deleteName2LabelTarget(labelName); this.popScope(); } @@ -923,7 +923,6 @@ export class Compiler { let objReg: VReg; let propReg: VReg; let unaryExpr = expr.expression; - switch (unaryExpr.kind) { case ts.SyntaxKind.Identifier: { // Check if this is a known variable. @@ -958,7 +957,6 @@ export class Compiler { } let { prop: prop } = getObjAndProp(unaryExpr, objReg, propReg, this); - switch (typeof prop) { case "string": pandaGen.loadAccumulatorString(expr, prop); diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts old mode 100755 new mode 100644 index ccdcafeb2d0c70927508870f322eaa65b6893646..0eeb3cd8814e91e19b4519c449937b7306f35dd1 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -149,7 +149,9 @@ export class CompilerDriver { this.getASTStatistics(node, statics); statics.forEach((element, idx) => { - if (element > 0) LOGD(this.kind2String(idx) + " = " + element); + if (element > 0) { + LOGD(this.kind2String(idx) + " = " + element); + } }); } diff --git a/ts2panda/src/compilerStatistics.ts b/ts2panda/src/compilerStatistics.ts old mode 100755 new mode 100644 index 3a868a94ceebf426a1c2d3350b7bd13886e94226..71f1ef1c7ee0761ec76ebc48dbb262ab3563595f --- a/ts2panda/src/compilerStatistics.ts +++ b/ts2panda/src/compilerStatistics.ts @@ -190,10 +190,10 @@ class HistogramStatistics { LOGD("Histogram:", "====== (" + this.funcName + ") ======"); LOGD("op code\t\t\tinsns number\tins size\ttotal size\tsize percentage"); this.insHistogram.forEach((value, key) => { - if (key.length < 8) { + if (key.length < 8) { // 8 indicates insn name length LOGD(key + "\t\t\t" + value.getCount() + "\t\t"+ value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" - + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); - } else if (key.length < 16) { + + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); // multiplying 100 is to calculate percentage data + } else if (key.length < 16) { // 16 indicates insn name length LOGD(key + "\t\t" + value.getCount() + "\t\t" + value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); } else { diff --git a/ts2panda/src/compilerUtils.ts b/ts2panda/src/compilerUtils.ts old mode 100755 new mode 100644 index 689fd2615e2aea8a047983a5ba30580867b12ed9..4e667e175810d6493c47126d780ca5664c28a6e5 --- a/ts2panda/src/compilerUtils.ts +++ b/ts2panda/src/compilerUtils.ts @@ -189,7 +189,8 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand pandaGen.freeTemps(iter, nextMethod, iterDone, iterValue, nextResult, exception); } -function emitRestElement(restElement: ts.BindingName | ts.Expression, iterator: Iterator, iterResult: VReg, pandaGen: PandaGen, compiler: Compiler, isDeclaration: boolean) { +function emitRestElement(restElement: ts.BindingName | ts.Expression, iterator: Iterator, iterResult: VReg, + pandaGen: PandaGen, compiler: Compiler, isDeclaration: boolean) { let arrayObj = pandaGen.getTemp(); let index = pandaGen.getTemp(); @@ -384,7 +385,8 @@ function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pa pandaGen.freeTemps(value, ...properties); } -function emitRestProperty(restProperty: ts.BindingElement | ts.SpreadAssignment, excludedProp: Array, obj: VReg, pandaGen: PandaGen, compiler: Compiler) { +function emitRestProperty(restProperty: ts.BindingElement | ts.SpreadAssignment, excludedProp: Array, + obj: VReg, pandaGen: PandaGen, compiler: Compiler) { let isDeclaration = ts.isBindingElement(restProperty) ? true : false; let target = isDeclaration ? (restProperty).name : (restProperty).expression; let lRef = LReference.generateLReference(compiler, target, true); diff --git a/ts2panda/src/debuginfo.ts b/ts2panda/src/debuginfo.ts old mode 100755 new mode 100644 index 704e34fe58363e662b840653e86e6c12aa16b172..527b8f0d50b933fcff00b9dff70631f05455dbf1 --- a/ts2panda/src/debuginfo.ts +++ b/ts2panda/src/debuginfo.ts @@ -115,7 +115,6 @@ export class VariableDebugInfo { constructor(name: string, signature: string, signatureType: string, reg: number, start: number = 0, length: number = 0) { - this.name = name; this.signature = signature; this.signatureType = signatureType; diff --git a/ts2panda/src/expression/arrayLiteralExpression.ts b/ts2panda/src/expression/arrayLiteralExpression.ts old mode 100755 new mode 100644 index 47921fe18fd79516bd3755edb808075ba7513606..1d16860880ccd9101984bc037477ab55d1e0d2f8 --- a/ts2panda/src/expression/arrayLiteralExpression.ts +++ b/ts2panda/src/expression/arrayLiteralExpression.ts @@ -94,7 +94,7 @@ export function createArrayFromElements(node: ts.Node, compiler: Compiler, eleme } if (i == elements.length - 1) { - // omittedExpression is last element, we need set the array's length + // omittedExpression is the last element, we need to set the length of the array if (hasSpread) { pandaGen.loadAccumulator(element, indexReg); pandaGen.storeObjProperty(element, arrayObj, "length"); diff --git a/ts2panda/src/expression/callExpression.ts b/ts2panda/src/expression/callExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/memberAccessExpression.ts b/ts2panda/src/expression/memberAccessExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/metaProperty.ts b/ts2panda/src/expression/metaProperty.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/newExpression.ts b/ts2panda/src/expression/newExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/numericLiteral.ts b/ts2panda/src/expression/numericLiteral.ts old mode 100755 new mode 100644 index 14991ea0068d2aeeb9a07ed8421e54218fdec81b..b20056c5d2e81b7937dfc182b084dc385f9719be --- a/ts2panda/src/expression/numericLiteral.ts +++ b/ts2panda/src/expression/numericLiteral.ts @@ -36,17 +36,16 @@ export function isInteger(value: number): Boolean { } export function compileNumericLiteral(pandaGen: PandaGen, lit: ts.NumericLiteral) { - let text = jshelpers.getTextOfIdentifierOrLiteral(lit); let value = Number.parseFloat(text); - // check value whether is a NaN + // check whether value is a NaN if (Number.isNaN(value)) { pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.NaN)); } else if (!Number.isFinite(value)) { - // check value whether is a Infinity + // check whether value is a Infinity pandaGen.loadAccumulator(lit, getVregisterCache(pandaGen, CacheList.Infinity)); } else if (isInteger(value)) { - // check value whether is a SafeInteger + // check whether value is a SafeInteger pandaGen.loadAccumulatorInt(lit, value); } else { pandaGen.loadAccumulatorFloat(lit, value); diff --git a/ts2panda/src/expression/objectLiteralExpression.ts b/ts2panda/src/expression/objectLiteralExpression.ts old mode 100755 new mode 100644 index ae87861761bd81545687923b3a41bb79bf2b72fb..574b8d9a6dcb313d84067c539a04abd780fbde0c --- a/ts2panda/src/expression/objectLiteralExpression.ts +++ b/ts2panda/src/expression/objectLiteralExpression.ts @@ -33,7 +33,7 @@ export function compileObjectLiteralExpression(compiler: Compiler, expr: ts.Obje let objReg = pandaGen.getTemp(); let hasMethod: boolean = false; - // emptyObjectLiteral + // empty ObjectLiteral expression if (properties.length == 0) { pandaGen.createEmptyObject(expr); pandaGen.storeAccumulator(expr, objReg); diff --git a/ts2panda/src/expression/parenthesizedExpression.ts b/ts2panda/src/expression/parenthesizedExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/regularExpression.ts b/ts2panda/src/expression/regularExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/stringLiteral.ts b/ts2panda/src/expression/stringLiteral.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/templateExpression.ts b/ts2panda/src/expression/templateExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/expression/yieldExpression.ts b/ts2panda/src/expression/yieldExpression.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/function/asyncFunctionBuilder.ts b/ts2panda/src/function/asyncFunctionBuilder.ts old mode 100755 new mode 100644 index 3d053e8557ceb40363d57e04d5e12c999932ed3b..63b68879fc771ab0bdbc199928cda416dd88c561 --- a/ts2panda/src/function/asyncFunctionBuilder.ts +++ b/ts2panda/src/function/asyncFunctionBuilder.ts @@ -83,7 +83,7 @@ export class AsyncFunctionBuilder { let notThrowLabel = new Label(); - // Jump to normal code + // jump to normal code pandaGen.condition(node, ts.SyntaxKind.EqualsEqualsToken, modeType, notThrowLabel); pandaGen.loadAccumulator(node, this.retVal); pandaGen.throw(node); diff --git a/ts2panda/src/hoisting.ts b/ts2panda/src/hoisting.ts old mode 100755 new mode 100644 index e2ffcc12a1f5e3bb88ccc1d78101aa3d024b01f6..c18cab39dc057896cf695d6ed7f4b1d3f92c6c6d --- a/ts2panda/src/hoisting.ts +++ b/ts2panda/src/hoisting.ts @@ -33,13 +33,14 @@ import { } from "./scope"; import { LocalVariable } from "./variable"; -export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, pandaGen: PandaGen, recorder: Recorder, compiler: Compiler) { +export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, pandaGen: PandaGen, + recorder: Recorder, compiler: Compiler) { let variableScope = recorder.getScopeOfNode(rootNode); let hoistDecls = recorder.getHoistDeclsOfScope(variableScope); hoistDecls ?.forEach((decl) => { if (decl instanceof VarDecl) { - hoistVar(decl, variableScope, pandaGen, compiler); + hoistVar(decl, variableScope, pandaGen); } else if (decl instanceof FuncDecl) { let compilerDriver = compiler.getCompilerDriver(); hoistFunction(decl, variableScope, pandaGen, compiler, compilerDriver); @@ -49,7 +50,7 @@ export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, p }); } -export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen, compiler: Compiler) { +export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen) { let name = decl.name; if (scope instanceof GlobalScope) { @@ -91,7 +92,7 @@ export function hoistFunction(decl: FuncDecl, scope: Scope, pandaGen: PandaGen, } } -// this function is called when hoisting function inside block +// this function is called when hoisting function inside blocks export function hoistFunctionInBlock(scope: Scope, pandaGen: PandaGen, strictMode: boolean, compiler: Compiler) { let decls = scope.getDecls(); let funcToHoist = new Array(); diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/intrinsicExpander.ts b/ts2panda/src/intrinsicExpander.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/jshelpers.d.ts b/ts2panda/src/jshelpers.d.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/lexenv.ts b/ts2panda/src/lexenv.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/log.ts b/ts2panda/src/log.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/modules.ts b/ts2panda/src/modules.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/pandasm.ts b/ts2panda/src/pandasm.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/pass.ts b/ts2panda/src/pass.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/pass/ICPass.ts b/ts2panda/src/pass/ICPass.ts old mode 100755 new mode 100644 index b3deb8eae468c785df6ce3cf7cd3a6222a403e7c..e05499f05c8cfa76ebf5ca86174f9e49b6b4f0cd --- a/ts2panda/src/pass/ICPass.ts +++ b/ts2panda/src/pass/ICPass.ts @@ -46,6 +46,7 @@ class ICPassImpl { pg.setICSize(icSize); } } + export class ICPass implements Pass { run(pg: PandaGen): void { let icPass = new ICPassImpl(); diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/regAllocator.ts b/ts2panda/src/regAllocator.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts old mode 100755 new mode 100644 index d327a0a44d4068dd31443fe81054e8f4b6acc909..e2aa29a06262b379970d0abd4e2ca518590cdc75 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -439,14 +439,14 @@ export class FunctionScope extends VariableScope { LOGD(this.debugTag, "functionscope.add (" + name + "), kind:" + declKind); if (declKind == VarDeclarationKind.NONE) { - // the variable declared without anything should be gloabal + // the variable declared without anything should be global // See EcmaStandard: 13.3.2 Variable Statement let globalScope = this.getRootScope(); if (globalScope instanceof GlobalScope || globalScope instanceof ModuleScope) { v = globalScope.add(name, declKind); } else { v = undefined; - throw new Error("Error: global variable must define in globalscope"); + throw new Error("Error: global variable must be defined in global scope"); } } else if (declKind == VarDeclarationKind.VAR || declKind == VarDeclarationKind.FUNCTION) { v = new LocalVariable(declKind, name); @@ -483,13 +483,15 @@ export class LocalScope extends Scope { if (root instanceof GlobalScope || root instanceof ModuleScope) { return root.add(name, declKind, status); } else { - LOGE(undefined, "Error: this scope'root is not globalscope, it is wrong"); + LOGE(undefined, "Error: the root of this scope is not global scope, it is wrong"); return undefined; } } else if (declKind == VarDeclarationKind.VAR) { - // the variable declared without anything should be accessible - // in all parent scopes so delegate creation to the parent - // See EcmaStandard: 13.3.2 Variable Statement + /** + * the variable declared without anything should be accessible + * in all parent scopes so delegate creation to the parent + * See EcmaStandard: 13.3.2 Variable Statement + */ let functionScope = this.getNearestVariableScope(); v = functionScope!.add(name, declKind); } else { diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/statement/forOfStatement.ts b/ts2panda/src/statement/forOfStatement.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/statement/labelTarget.ts b/ts2panda/src/statement/labelTarget.ts old mode 100755 new mode 100644 index d7400e06602b4ec12da866559e2b1ef7ac90c650..0ee16c2c1c5cc40deefacd12950605cd67bffeb7 --- a/ts2panda/src/statement/labelTarget.ts +++ b/ts2panda/src/statement/labelTarget.ts @@ -79,12 +79,12 @@ export class LabelTarget { while (node.kind == ts.SyntaxKind.LabeledStatement) { let labeledStmt = node; let labelName = jshelpers.getTextOfIdentifierOrLiteral(labeledStmt.label); - - // make sure saved label is different. + + // make sure saved label is different if (LabelTarget.name2LabelTarget.has(labelName)) { throw new DiagnosticError(node, DiagnosticCode.Duplicate_label_0); } - + LabelTarget.name2LabelTarget.set(labelName, labelTarget); node = node.parent; } diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts old mode 100755 new mode 100644 index 4302319c003325f57d335c001adc261d86ac5878..fc6b1247ae11b3acfc6137728e5dc897c5c83c58 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -15,8 +15,8 @@ /** * The loopStatement implementation. - * This file implement compilation process of loop statement - * and asks Pandagen to generate bytecode. + * This file implements Compilation process of loop statement + * and uses Pandagen to generate bytecode. * */ @@ -163,7 +163,7 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { // loopIncrementor pandaGen.label(stmt, incLabel); - // load init from current env for the use of next iteration + // load init from current env for the use of the next iteration type variableInfo = { scope: Scope | undefined, level: number, v: Variable | undefined }; let variables: Map = new Map(); let tmpVregs: Array = new Array(); @@ -178,7 +178,7 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { } }); - // pop the current loopenv and create a new loopenv before next iteration + // pop the current loopenv and create a new loopenv before the next iteration pandaGen.popLexicalEnv(stmt); pandaGen.createLexEnv(stmt, loopEnv, loopScope); variables.forEach((reg, varInfo) => { diff --git a/ts2panda/src/statement/returnStatement.ts b/ts2panda/src/statement/returnStatement.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/statement/switchStatement.ts b/ts2panda/src/statement/switchStatement.ts old mode 100755 new mode 100644 index e7ff82377c4afebdba8a458ce0d5191be1c8fbc5..3bf95465fb0cbeeb77944b52fbe297d4dfc6135d --- a/ts2panda/src/statement/switchStatement.ts +++ b/ts2panda/src/statement/switchStatement.ts @@ -41,8 +41,10 @@ export class SwitchBase { let caseLabel = new Label(); this.caseLabels.push(caseLabel); } - // switchStatements doesn't have continue target - // so we use the uplevel continue label as it's continue target. + /** + * switchStatements doesn't have continue target + * so we use the uplevel continue label as it's continue target. + */ let labelTarget = new LabelTarget(switchEndLabel, LabelTarget.getCloseContinueTarget()); LabelTarget.pushLabelTarget(labelTarget); LabelTarget.updateName2LabelTarget(stmt.parent, labelTarget); diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts old mode 100755 new mode 100644 index 0511e2e989d084d70c52778d327c7614814e3870..6107c014533de7d417e574d15db0263670f81620 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -346,8 +346,8 @@ export class TryBuilderWithForOf extends TryBuilderBase { private compileIteratorNext(stmt: ts.ForOfStatement, pandagen: PandaGen, iterator: IteratorRecord, resultObj: VReg) { pandagen.call(stmt, [iterator.getNextMethod(), iterator.getObject()], true); pandagen.storeAccumulator(stmt, resultObj); - // Support Async Await further + // Support Async Await further pandagen.throwIfNotObject(stmt, resultObj); } } diff --git a/ts2panda/src/strictMode.ts b/ts2panda/src/strictMode.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/syntaxCheckHelper.ts b/ts2panda/src/syntaxCheckHelper.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts old mode 100755 new mode 100644 index 57d77bd6106147fe97e97ace46e364b335c5e6b8..a9fe751ddab39b9e7381d23f1d016fc1a18b7791 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -323,8 +323,7 @@ function checkBreakOrContinueStatement(node: ts.BreakOrContinueStatement) { } else { diagnosticCode = DiagnosticCode.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; } - } - else { + } else { if (node.kind == ts.SyntaxKind.BreakStatement) { diagnosticCode = DiagnosticCode.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement; } else { @@ -764,7 +763,6 @@ const enum OuterExpressionKinds { TypeAssertions = 1 << 1, NonNullAssertions = 1 << 2, PartiallyEmittedExpressions = 1 << 3, - Assertions = TypeAssertions | NonNullAssertions, All = Parentheses | Assertions | PartiallyEmittedExpressions } diff --git a/ts2panda/src/syntaxCheckerForStrcitMode.ts b/ts2panda/src/syntaxCheckerForStrcitMode.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts old mode 100755 new mode 100644 diff --git a/ts2panda/src/variable.ts b/ts2panda/src/variable.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/binary.test.ts b/ts2panda/tests/binary.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/builtIns.test.ts b/ts2panda/tests/builtIns.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/conditions.test.ts b/ts2panda/tests/conditions.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/declaration.test.ts b/ts2panda/tests/declaration.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/elementAccess.test.ts b/ts2panda/tests/elementAccess.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/hoist.test.ts b/ts2panda/tests/hoist.test.ts old mode 100755 new mode 100644 index dc01758611a49da6251525e4b128b455057df4ac..bc5d49f7b2934f8bc099e6d5e84f60b013739c6e --- a/ts2panda/tests/hoist.test.ts +++ b/ts2panda/tests/hoist.test.ts @@ -89,7 +89,7 @@ describe("HoistTest", function() { expect(checkInstructions(insns, expected)).to.be.true; }); - // case 4: In case that two function declared directly in global scope with a same name, hoist the later one. + // case 4: In case that two function declared directly in global scope with the same name, hoist the later one. it('case 4', function() { let snippetCompiler = new SnippetCompiler(); snippetCompiler.compile(`function a() {}; function a() {}`); diff --git a/ts2panda/tests/intrinsicExpander.test.ts b/ts2panda/tests/intrinsicExpander.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/lexenv.test.ts b/ts2panda/tests/lexenv.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/literal.test.ts b/ts2panda/tests/literal.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/loops.test.ts b/ts2panda/tests/loops.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/otherExpressions.test.ts b/ts2panda/tests/otherExpressions.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/otherStatements.test.ts b/ts2panda/tests/otherStatements.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/pandagen.test.ts b/ts2panda/tests/pandagen.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/propertyAccess.test.ts b/ts2panda/tests/propertyAccess.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/regAllocator.test.ts b/ts2panda/tests/regAllocator.test.ts old mode 100755 new mode 100644 index 304b3969eed29d5fb510c6a7cc65a5f517e3ffee..0a35621cf62783eff8806dcee7705ff2bc5a3e35 --- a/ts2panda/tests/regAllocator.test.ts +++ b/ts2panda/tests/regAllocator.test.ts @@ -91,15 +91,15 @@ describe("RegAllocator", function() { }); it("make spill for SrcDst register", function() { - /* the only possible instruction whose operand register type could be SrcDstVReg is INCI, + /* the only possible instruction whose operand register type could be SrcDstVReg is INCI, * but we do not use it at all by now */ expect(true).to.be.true; }); it("make spill for CalliDynRange", function () { - /* since the bitwitdh for CalliDynRange source register is 16 now, we do not need to make spill at all. - but later 16 might be changed to 8, then spill operation will be needed in some cases. this testcase is desgined + /* since the bitwidth for CalliDynRange source register is 16 now, we do not need to make spill at all. + but later 16 might be changed to 8, then spill operation will be needed in some cases. this testcase is designed for 8bits constraints. */ let string = ""; diff --git a/ts2panda/tests/returnStatement.test.ts b/ts2panda/tests/returnStatement.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/scope.test.ts b/ts2panda/tests/scope.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/strictmode/function.js b/ts2panda/tests/strictmode/function.js old mode 100755 new mode 100644 index 962a1641036f03e29f89d4c9c10d9c4371f5ee47..bde7776c4cf398c0e55079277c5b0f6c12d16c38 --- a/ts2panda/tests/strictmode/function.js +++ b/ts2panda/tests/strictmode/function.js @@ -16,12 +16,12 @@ function add(a,b) { "use strict"; var x = 12; - return a+b+x; + return a + b + x; } function sub(a,b) { var y = 12; - return a+b-y; + return a + b - y; } var z = 13; \ No newline at end of file diff --git a/ts2panda/tests/tryCatch.test.ts b/ts2panda/tests/tryCatch.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/unary.test.ts b/ts2panda/tests/unary.test.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tests/utils/asthelper.ts b/ts2panda/tests/utils/asthelper.ts old mode 100755 new mode 100644 index 1ede68032d8649bed436ec626c4b7e3ea183eec1..de869a4650c04676d99d8d9b5c4ae9d2ffb19998 --- a/ts2panda/tests/utils/asthelper.ts +++ b/ts2panda/tests/utils/asthelper.ts @@ -21,9 +21,9 @@ export function creatAstFromSnippet(snippet: string): ts.SourceFile { return sourceFile; } -/* it would be tricky here to use relative path, so please use absolute path to instead. - For how to use this function please reference example_asthelper.ts -*/ +/** It would be tricky here to use relative path, so please use an absolute path instead. + * For how to use this function, please refer to example_asthelper.ts + */ export function creatAstFromFile(fileName: string): ts.SourceFile { let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, true); return sourceFile; diff --git a/ts2panda/tests/utils/base.ts b/ts2panda/tests/utils/base.ts old mode 100755 new mode 100644 index 6c8b2dc62c91ee55bfb683a4831c38b369146a3e..b4185ef75dfe70be3afdc8ba94ca133ac6570a9d --- a/ts2panda/tests/utils/base.ts +++ b/ts2panda/tests/utils/base.ts @@ -158,7 +158,7 @@ export function compileMainSnippet(snippet: string, pandaGen?: PandaGen, scope?: let compileUnits = compileAllSnippet(snippet, passes); if (compileUnits.length != 1 && !compileFunc) { - throw new Error("Error: pls use compileMainSnippet1 for multi function compile"); + throw new Error("Error: please use compileMainSnippet1 for multi function compile"); } // only return main function diff --git a/ts2panda/tests/utils/example_asthelper.ts b/ts2panda/tests/utils/example_asthelper.ts old mode 100755 new mode 100644 diff --git a/ts2panda/tools/astPrinter.ts b/ts2panda/tools/astPrinter.ts old mode 100755 new mode 100644 index 2950ef1bd80144a7faf10948e3f13934101d0abf..4a1a16be72af87731d7db1853684a7f46a643b2a --- a/ts2panda/tools/astPrinter.ts +++ b/ts2panda/tools/astPrinter.ts @@ -77,7 +77,7 @@ export namespace AST { } function isFile(node: any): node is ts.SourceFile { - return ((typeof (node) === "object") && ("kind" in node) && (node.kind == 290)); + return ((typeof (node) === "object") && ("kind" in node) && (node.kind == ts.SyntaxKind.SourceFile)); } function Array2String(name: (undefined | string), array: ts.Node[], tab: number): string {