From a3688ae673a3b57475cacc0cc13544e71a387e49 Mon Sep 17 00:00:00 2001 From: ctw Date: Mon, 13 Sep 2021 16:30:26 +0800 Subject: [PATCH] fix inner-source issues Signed-off-by: ctw --- test262/README.md | 25 +++++++++---------- test262/config.py | 2 +- test262/run_sunspider.py | 2 +- test262/run_test262.py | 5 ++-- test262/utils.py | 6 ++--- ts2panda/scripts/generate_plugin.py | 1 - ts2panda/scripts/run.py | 7 +++--- ts2panda/src/addVariable2Scope.ts | 0 ts2panda/src/assemblyDumper.ts | 0 ts2panda/src/astutils.ts | 0 ts2panda/src/base/iterator.ts | 4 +-- ts2panda/src/compiler.ts | 10 +++----- ts2panda/src/compilerDriver.ts | 4 ++- ts2panda/src/compilerStatistics.ts | 6 ++--- ts2panda/src/compilerUtils.ts | 6 +++-- ts2panda/src/debuginfo.ts | 1 - .../src/expression/arrayLiteralExpression.ts | 2 +- ts2panda/src/expression/callExpression.ts | 0 .../src/expression/memberAccessExpression.ts | 0 ts2panda/src/expression/metaProperty.ts | 0 ts2panda/src/expression/newExpression.ts | 0 ts2panda/src/expression/numericLiteral.ts | 7 +++--- .../src/expression/objectLiteralExpression.ts | 2 +- .../src/expression/parenthesizedExpression.ts | 0 ts2panda/src/expression/regularExpression.ts | 0 ts2panda/src/expression/stringLiteral.ts | 0 ts2panda/src/expression/templateExpression.ts | 0 ts2panda/src/expression/yieldExpression.ts | 0 ts2panda/src/function/asyncFunctionBuilder.ts | 2 +- ts2panda/src/hoisting.ts | 9 ++++--- ts2panda/src/index.ts | 0 ts2panda/src/intrinsicExpander.ts | 0 ts2panda/src/jshelpers.d.ts | 0 ts2panda/src/lexenv.ts | 0 ts2panda/src/log.ts | 0 ts2panda/src/modules.ts | 0 ts2panda/src/pandagen.ts | 0 ts2panda/src/pandasm.ts | 0 ts2panda/src/pass.ts | 0 ts2panda/src/pass/ICPass.ts | 1 + ts2panda/src/recorder.ts | 0 ts2panda/src/regAllocator.ts | 0 ts2panda/src/scope.ts | 14 ++++++----- ts2panda/src/statement/classStatement.ts | 0 ts2panda/src/statement/forOfStatement.ts | 0 ts2panda/src/statement/labelTarget.ts | 6 ++--- ts2panda/src/statement/loopStatement.ts | 8 +++--- ts2panda/src/statement/returnStatement.ts | 0 ts2panda/src/statement/switchStatement.ts | 6 +++-- ts2panda/src/statement/tryStatement.ts | 2 +- ts2panda/src/strictMode.ts | 0 ts2panda/src/syntaxCheckHelper.ts | 0 ts2panda/src/syntaxChecker.ts | 4 +-- ts2panda/src/syntaxCheckerForStrcitMode.ts | 0 ts2panda/src/ts2panda.ts | 0 ts2panda/src/variable.ts | 0 ts2panda/tests/binary.test.ts | 0 ts2panda/tests/builtIns.test.ts | 0 ts2panda/tests/conditions.test.ts | 0 ts2panda/tests/declaration.test.ts | 0 ts2panda/tests/elementAccess.test.ts | 0 ts2panda/tests/hoist.test.ts | 2 +- ts2panda/tests/intrinsicExpander.test.ts | 0 ts2panda/tests/lexenv.test.ts | 0 ts2panda/tests/literal.test.ts | 0 ts2panda/tests/loops.test.ts | 0 ts2panda/tests/otherExpressions.test.ts | 0 ts2panda/tests/otherStatements.test.ts | 0 ts2panda/tests/pandagen.test.ts | 0 ts2panda/tests/propertyAccess.test.ts | 0 ts2panda/tests/regAllocator.test.ts | 6 ++--- ts2panda/tests/returnStatement.test.ts | 0 ts2panda/tests/scope.test.ts | 0 ts2panda/tests/strictmode/function.js | 4 +-- ts2panda/tests/tryCatch.test.ts | 0 ts2panda/tests/unary.test.ts | 0 ts2panda/tests/utils/asthelper.ts | 6 ++--- ts2panda/tests/utils/base.ts | 2 +- ts2panda/tests/utils/example_asthelper.ts | 0 ts2panda/tools/astPrinter.ts | 2 +- 80 files changed, 81 insertions(+), 83 deletions(-) mode change 100755 => 100644 ts2panda/src/addVariable2Scope.ts mode change 100755 => 100644 ts2panda/src/assemblyDumper.ts mode change 100755 => 100644 ts2panda/src/astutils.ts mode change 100755 => 100644 ts2panda/src/base/iterator.ts mode change 100755 => 100644 ts2panda/src/compiler.ts mode change 100755 => 100644 ts2panda/src/compilerDriver.ts mode change 100755 => 100644 ts2panda/src/compilerStatistics.ts mode change 100755 => 100644 ts2panda/src/compilerUtils.ts mode change 100755 => 100644 ts2panda/src/debuginfo.ts mode change 100755 => 100644 ts2panda/src/expression/arrayLiteralExpression.ts mode change 100755 => 100644 ts2panda/src/expression/callExpression.ts mode change 100755 => 100644 ts2panda/src/expression/memberAccessExpression.ts mode change 100755 => 100644 ts2panda/src/expression/metaProperty.ts mode change 100755 => 100644 ts2panda/src/expression/newExpression.ts mode change 100755 => 100644 ts2panda/src/expression/numericLiteral.ts mode change 100755 => 100644 ts2panda/src/expression/objectLiteralExpression.ts mode change 100755 => 100644 ts2panda/src/expression/parenthesizedExpression.ts mode change 100755 => 100644 ts2panda/src/expression/regularExpression.ts mode change 100755 => 100644 ts2panda/src/expression/stringLiteral.ts mode change 100755 => 100644 ts2panda/src/expression/templateExpression.ts mode change 100755 => 100644 ts2panda/src/expression/yieldExpression.ts mode change 100755 => 100644 ts2panda/src/function/asyncFunctionBuilder.ts mode change 100755 => 100644 ts2panda/src/hoisting.ts mode change 100755 => 100644 ts2panda/src/index.ts mode change 100755 => 100644 ts2panda/src/intrinsicExpander.ts mode change 100755 => 100644 ts2panda/src/jshelpers.d.ts mode change 100755 => 100644 ts2panda/src/lexenv.ts mode change 100755 => 100644 ts2panda/src/log.ts mode change 100755 => 100644 ts2panda/src/modules.ts mode change 100755 => 100644 ts2panda/src/pandagen.ts mode change 100755 => 100644 ts2panda/src/pandasm.ts mode change 100755 => 100644 ts2panda/src/pass.ts mode change 100755 => 100644 ts2panda/src/pass/ICPass.ts mode change 100755 => 100644 ts2panda/src/recorder.ts mode change 100755 => 100644 ts2panda/src/regAllocator.ts mode change 100755 => 100644 ts2panda/src/scope.ts mode change 100755 => 100644 ts2panda/src/statement/classStatement.ts mode change 100755 => 100644 ts2panda/src/statement/forOfStatement.ts mode change 100755 => 100644 ts2panda/src/statement/labelTarget.ts mode change 100755 => 100644 ts2panda/src/statement/loopStatement.ts mode change 100755 => 100644 ts2panda/src/statement/returnStatement.ts mode change 100755 => 100644 ts2panda/src/statement/switchStatement.ts mode change 100755 => 100644 ts2panda/src/statement/tryStatement.ts mode change 100755 => 100644 ts2panda/src/strictMode.ts mode change 100755 => 100644 ts2panda/src/syntaxCheckHelper.ts mode change 100755 => 100644 ts2panda/src/syntaxChecker.ts mode change 100755 => 100644 ts2panda/src/syntaxCheckerForStrcitMode.ts mode change 100755 => 100644 ts2panda/src/ts2panda.ts mode change 100755 => 100644 ts2panda/src/variable.ts mode change 100755 => 100644 ts2panda/tests/binary.test.ts mode change 100755 => 100644 ts2panda/tests/builtIns.test.ts mode change 100755 => 100644 ts2panda/tests/conditions.test.ts mode change 100755 => 100644 ts2panda/tests/declaration.test.ts mode change 100755 => 100644 ts2panda/tests/elementAccess.test.ts mode change 100755 => 100644 ts2panda/tests/hoist.test.ts mode change 100755 => 100644 ts2panda/tests/intrinsicExpander.test.ts mode change 100755 => 100644 ts2panda/tests/lexenv.test.ts mode change 100755 => 100644 ts2panda/tests/literal.test.ts mode change 100755 => 100644 ts2panda/tests/loops.test.ts mode change 100755 => 100644 ts2panda/tests/otherExpressions.test.ts mode change 100755 => 100644 ts2panda/tests/otherStatements.test.ts mode change 100755 => 100644 ts2panda/tests/pandagen.test.ts mode change 100755 => 100644 ts2panda/tests/propertyAccess.test.ts mode change 100755 => 100644 ts2panda/tests/regAllocator.test.ts mode change 100755 => 100644 ts2panda/tests/returnStatement.test.ts mode change 100755 => 100644 ts2panda/tests/scope.test.ts mode change 100755 => 100644 ts2panda/tests/strictmode/function.js mode change 100755 => 100644 ts2panda/tests/tryCatch.test.ts mode change 100755 => 100644 ts2panda/tests/unary.test.ts mode change 100755 => 100644 ts2panda/tests/utils/asthelper.ts mode change 100755 => 100644 ts2panda/tests/utils/base.ts mode change 100755 => 100644 ts2panda/tests/utils/example_asthelper.ts mode change 100755 => 100644 ts2panda/tools/astPrinter.ts diff --git a/test262/README.md b/test262/README.md index c7ce6a86eb..d52468b8ba 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 2c3f28ba79..c521b973dd 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 73a64ff631..97752ef074 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 256a044b24..663fca577e 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 91ed1da527..2d62db1db5 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 996cabd9e3..306e9696d2 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 9a25349547..fd8c697470 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 748113e81e..b1d5efcee7 --- 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 7e6b56152f..4a3079a971 --- 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 ccdcafeb2d..0eeb3cd881 --- 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 3a868a94ce..71f1ef1c7e --- 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 689fd2615e..4e667e1758 --- 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 704e34fe58..527b8f0d50 --- 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 47921fe18f..1d16860880 --- 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 14991ea006..b20056c5d2 --- 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 ae87861761..574b8d9a6d --- 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 3d053e8557..63b68879fc --- 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 e2ffcc12a1..c18cab39dc --- 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 b3deb8eae4..e05499f05c --- 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 d327a0a44d..e2aa29a062 --- 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 d7400e0660..0ee16c2c1c --- 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 4302319c00..fc6b1247ae --- 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 e7ff82377c..3bf95465fb --- 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 0511e2e989..6107c01453 --- 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 57d77bd610..a9fe751dda --- 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 dc01758611..bc5d49f7b2 --- 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 304b3969ee..0a35621cf6 --- 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 962a164103..bde7776c4c --- 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 1ede68032d..de869a4650 --- 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 6c8b2dc62c..b4185ef75d --- 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 2950ef1bd8..4a1a16be72 --- 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 { -- Gitee