From a0e76d1ee0799e82b1b844b8787de2b68489b069 Mon Sep 17 00:00:00 2001 From: zhuoli Date: Wed, 8 Sep 2021 17:58:34 +0800 Subject: [PATCH 1/9] Add globalRecord instructions Signed-off-by: zhuoli --- ts2panda/src/base/bcGenUtil.ts | 15 +++++++++++++ ts2panda/src/compiler.ts | 27 +++++++++++++++++++++++- ts2panda/src/pandagen.ts | 21 ++++++++++++++++++ ts2panda/src/statement/classStatement.ts | 12 ++++++++--- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 4af3dc4c5e..cf7c3534be 100755 --- a/ts2panda/src/base/bcGenUtil.ts +++ b/ts2panda/src/base/bcGenUtil.ts @@ -96,6 +96,9 @@ import { MovDyn, ResultType, StaDyn, + EcmaStclasstoglobalrecord, + EcmaStconsttoglobalrecord, + EcmaStlettoglobalrecord, VReg } from "../irnodes"; @@ -412,4 +415,16 @@ export function isFalse() { export function createRegExpWithLiteral(pattern: string, flags: number) { return new EcmaCreateregexpwithliteral(pattern, new Imm(ResultType.Int, flags)); +} + +export function stLetToGlobalRecord (name: string) { + return new EcmaStlettoglobalrecord(name); +} + +export function stConstToGlobalRecord (name: string) { + return new EcmaStconsttoglobalrecord(name); +} + +export function stClassToGlobalRecord (name: string) { + return new EcmaStclasstoglobalrecord(name); } \ No newline at end of file diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 7e6b56152f..aa859c3e8b 100755 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -1358,10 +1358,28 @@ export class Compiler { isDeclaration: boolean) { if (variable.v instanceof LocalVariable) { if (isDeclaration) { - if (variable.v.isLetOrConst()) { + if (variable.v.isLet()) { variable.v.initialize(); + if (variable.scope instanceof GlobalScope || variable.scope instanceof ModuleScope) { + this.pandaGen.stLetToGlobalRecord(node, variable.v.getName()); + return; + } + } else if (variable.v.isConst()) { + variable.v.initialize(); + if (variable.scope instanceof GlobalScope || variable.scope instanceof ModuleScope) { + this.pandaGen.stConstToGlobalRecord(node, variable.v.getName()); + return; + } + } + } + + if (variable.v.isLetOrConst()) { + if (variable.scope instanceof GlobalScope || variable.scope instanceof ModuleScope) { + this.pandaGen.tryStoreGlobalByName(node, variable.v.getName()); + return; } } + if (variable.scope && variable.level >= 0) { // inner most function will load outer env instead of new a lex env let scope = this.scope; let needSetLexVar: boolean = false; @@ -1394,6 +1412,13 @@ export class Compiler { if (variable.v instanceof ModuleVariable) { this.pandaGen.loadModuleVariable(node, variable.v.getModule(), variable.v.getExoticName()); } else if (variable.v instanceof LocalVariable) { + if (variable.v.isLetOrConst() || variable.v.isClass()) { + if (variable.scope instanceof GlobalScope || variable.scope instanceof ModuleScope) { + this.pandaGen.tryLoadGlobalByName(node, variable.v.getName()); + return; + } + } + if (variable.scope && variable.level >= 0) { // inner most function will load outer env instead of new a lex env let scope = this.scope; let needSetLexVar: boolean = false; diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index 807abbe611..7f638f4a17 100755 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -75,6 +75,9 @@ import { popLexicalEnv, returnUndefined, setObjectWithProto, + stClassToGlobalRecord, + stConstToGlobalRecord, + stLetToGlobalRecord, storeAccumulator, storeArraySpread, storeGlobalVar, @@ -1188,6 +1191,24 @@ export class PandaGen { ) } + stLetToGlobalRecord(node: ts.Node, string_id: string) { + this.add( + node, + stLetToGlobalRecord(string_id)); + } + + stConstToGlobalRecord(node: ts.Node, string_id: string) { + this.add( + node, + stConstToGlobalRecord(string_id)); + } + + stClassToGlobalRecord(node: ts.Node, string_id: string) { + this.add( + node, + stClassToGlobalRecord(string_id)); + } + private binaryRelation(node: ts.Node, op: BinaryOperator, lhs: VReg) { let falseLabel = new Label(); let endLabel = new Label(); diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index a0971a241a..c96903a6c2 100755 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -38,7 +38,9 @@ import { PandaGen } from "../pandagen"; import { Recorder } from "../recorder"; import { FunctionScope, + GlobalScope, LocalScope, + ModuleScope, Scope, VariableScope } from "../scope"; @@ -115,9 +117,13 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe if (stmt.name) { let className = jshelpers.getTextOfIdentifierOrLiteral(stmt.name); let classScope = compiler.getRecorder().getScopeOfNode(stmt); - let classInfo = classScope.find(className); - (classInfo.v).initialize(); - pandaGen.storeAccToLexEnv(stmt, classInfo.scope!, classInfo.level, classInfo.v!, true); + if (classScope.getParent() instanceof GlobalScope || classScope.getParent() instanceof ModuleScope) { + pandaGen.stClassToGlobalRecord(stmt, className); + } else { + let classInfo = classScope.find(className); + (classInfo.v).initialize(); + pandaGen.storeAccToLexEnv(stmt, classInfo.scope!, classInfo.level, classInfo.v!, true); + } } pandaGen.freeTemps(classReg, baseVreg); -- Gitee From ee3e3c4ffda611f50734409d362e77bbfe74df14 Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 10 Sep 2021 14:28:54 +0800 Subject: [PATCH 2/9] remove windows-version toolchains' built from full-build Signed-off-by: hufeng --- ts2panda/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/ts2panda/BUILD.gn b/ts2panda/BUILD.gn index 9b3a5ec493..e897cadf59 100755 --- a/ts2panda/BUILD.gn +++ b/ts2panda/BUILD.gn @@ -303,8 +303,6 @@ group("ark_ts2abc_build") { deps += [ "${ts2abc_root}:ts2abc_build(${buildtool_linux})", "${ts2abc_root}:ts2abc_build_ets(${buildtool_linux})", - "${ts2abc_root}:ts2abc_build_win(${buildtool_win})", - "${ts2abc_root}:ts2abc_build_win_ets(${buildtool_win})", ] } } -- Gitee From d30cb278aee76ed45990472ef14cad85d556935f Mon Sep 17 00:00:00 2001 From: zhuoli Date: Fri, 10 Sep 2021 15:20:17 +0800 Subject: [PATCH 3/9] Set 'use strick' as default compile mode Signed-off-by: zhuoli --- ts2panda/src/index.ts | 1 + ts2panda/src/strictMode.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 97771062d9..f778f0a75e 100755 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -81,6 +81,7 @@ namespace Compiler { module: ts.ModuleKind.CommonJS, strictNullChecks: true, skipLibCheck: true, + alwaysStrict: true }; } } diff --git a/ts2panda/src/strictMode.ts b/ts2panda/src/strictMode.ts index af844ada7a..80e27a1dc7 100755 --- a/ts2panda/src/strictMode.ts +++ b/ts2panda/src/strictMode.ts @@ -16,7 +16,7 @@ import * as ts from "typescript"; import jshelpers from "./jshelpers"; -let globalStrict = false; +let globalStrict = true; export function checkStrictModeStatementList(node: ts.Node): boolean { let statements; @@ -89,4 +89,4 @@ export function isStrictMode(node: ts.Node): boolean { } return checkStrictMode(node); -} \ No newline at end of file +} -- Gitee From 4e416f5b7d3ee58ba1e684b9caf5588f55177b7e Mon Sep 17 00:00:00 2001 From: zhuoli Date: Sat, 11 Sep 2021 09:33:03 +0800 Subject: [PATCH 4/9] fix global record for class expression Signed-off-by: zhuoli --- ts2panda/src/statement/classStatement.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index c96903a6c2..1eaffd17b6 100755 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -117,7 +117,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe if (stmt.name) { let className = jshelpers.getTextOfIdentifierOrLiteral(stmt.name); let classScope = compiler.getRecorder().getScopeOfNode(stmt); - if (classScope.getParent() instanceof GlobalScope || classScope.getParent() instanceof ModuleScope) { + if (!ts.isClassExpression(stmt) && (classScope.getParent() instanceof GlobalScope || classScope.getParent() instanceof ModuleScope)) { pandaGen.stClassToGlobalRecord(stmt, className); } else { let classInfo = classScope.find(className); -- Gitee From 6ecc6dbd4773b70d2e138882d3a5f4a14c39d101 Mon Sep 17 00:00:00 2001 From: hufeng Date: Sat, 11 Sep 2021 13:02:45 +0800 Subject: [PATCH 5/9] fix function illegel name for assembler Signed-off-by: hufeng --- ts2panda/src/compilerDriver.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index ccdcafeb2d..bcb99efba2 100755 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -313,14 +313,15 @@ export class CompilerDriver { * Runtime uses this name to bind code and a Function object */ getFuncInternalName(node: ts.SourceFile | ts.FunctionLikeDeclaration, recorder: Recorder): string { + let name: string; if (ts.isSourceFile(node)) { - return "func_main_0"; + name = "func_main_0"; } else if (ts.isConstructorDeclaration(node)) { let classNode = node.parent; - return this.getInternalNameForCtor(classNode); + name = this.getInternalNameForCtor(classNode); } else { let funcNode = node; - let name: string = (recorder.getScopeOfNode(funcNode)).getFuncName(); + name = (recorder.getScopeOfNode(funcNode)).getFuncName(); if (name == '') { return `#${this.getFuncId(funcNode)}#`; } @@ -339,13 +340,20 @@ export class CompilerDriver { throw new Error("the function name is missing from the name map"); } - return name; + if (name.lastIndexOf(".") != -1) { + name = `#${this.getFuncId(funcNode)}#` + } } + return name; } getInternalNameForCtor(node: ts.ClassLikeDeclaration) { let name = getClassNameForConstructor(node); - return `#${this.getFuncId(node)}#${name}`; + name = `#${this.getFuncId(node)}#${name}` + if (name.lastIndexOf(".") != -1) { + name = `#${this.getFuncId(node)}#` + } + return name; } writeBinaryFile(pandaGen: PandaGen) { -- Gitee From 5b00ffbf7ff2aaf88fe4d9cf0b40064bd4e7d8ef Mon Sep 17 00:00:00 2001 From: wanyanglan Date: Mon, 13 Sep 2021 11:12:01 +0800 Subject: [PATCH 6/9] delete JSON partial use cases Signed-off-by: wanyanglan --- test262/CI_tests.txt | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/test262/CI_tests.txt b/test262/CI_tests.txt index f5899057b5..999eca170d 100644 --- a/test262/CI_tests.txt +++ b/test262/CI_tests.txt @@ -1315,8 +1315,6 @@ built-ins/JSON/parse/length.js built-ins/JSON/parse/not-a-constructor.js built-ins/JSON/parse/reviver-array-get-prop-from-prototype.js built-ins/JSON/parse/reviver-array-non-configurable-prop-delete.js -built-ins/JSON/parse/reviver-object-get-prop-from-prototype.js -built-ins/JSON/parse/reviver-object-non-configurable-prop-delete.js built-ins/JSON/parse/S15.12.2_A1.js built-ins/JSON/parse/text-non-string-primitive.js built-ins/JSON/stringify/builtin.js @@ -1325,19 +1323,12 @@ built-ins/JSON/stringify/property-order.js built-ins/JSON/stringify/replacer-array-empty.js built-ins/JSON/stringify/replacer-array-order.js built-ins/JSON/stringify/replacer-array-string-object.js -built-ins/JSON/stringify/replacer-array-wrong-type.js -built-ins/JSON/stringify/replacer-function-object-deleted-property.js built-ins/JSON/stringify/replacer-function-result-undefined.js -built-ins/JSON/stringify/replacer-function-wrapper.js built-ins/JSON/stringify/space-number.js built-ins/JSON/stringify/space-number-range.js built-ins/JSON/stringify/space-string-range.js built-ins/JSON/stringify/value-array-proxy.js -built-ins/JSON/stringify/value-bigint-replacer.js -built-ins/JSON/stringify/value-bigint-tojson-receiver.js built-ins/JSON/stringify/value-function.js -built-ins/JSON/stringify/value-object-proxy.js -built-ins/JSON/stringify/value-string-escape-ascii.js built-ins/JSON/stringify/value-symbol.js built-ins/JSON/stringify/value-tojson-not-function.js built-ins/Date/TimeClip_negative_zero.js @@ -3978,4 +3969,4 @@ language/asi/S7.9_A6.2_T5.js language/asi/S7.9.2_A1_T7.js language/asi/S7.9_A5.7_T1.js language/asi/S7.9_A11_T4.js -language/asi/S7.9.2_A1_T5.js \ No newline at end of file +language/asi/S7.9.2_A1_T5.js -- Gitee From dca1fd7fd5dba5ea31b37706184d837ea9572029 Mon Sep 17 00:00:00 2001 From: zgy-ian Date: Sat, 11 Sep 2021 17:32:12 +0800 Subject: [PATCH 7/9] Modify the ts2abc compilation issue Signed-off-by: zgy-ian --- ts2panda/BUILD.gn | 8 ++++++++ ts2panda/scripts/run.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ts2panda/BUILD.gn b/ts2panda/BUILD.gn index 9b3a5ec493..d55f7e716f 100755 --- a/ts2panda/BUILD.gn +++ b/ts2panda/BUILD.gn @@ -25,6 +25,13 @@ ohos_copy("ts2abc_src") { module_install_name = "" } +ohos_copy("node_modules") { + sources = [ rebase_path("${node_modules}") ] + + outputs = [ target_out_dir + "/node_modules" ] + module_install_name = "" +} + ohos_copy("tsconfig_json") { sources = [ "${ts2abc_root}/tsconfig.json" ] @@ -65,6 +72,7 @@ ark_gen_file("ts2abc_irnodes_ts") { action("npm_run_build") { visibility = [ ":*" ] deps = [ + "$ts2abc_root:node_modules", "$ts2abc_root:ts2abc_diagnostic_ts", "$ts2abc_root:ts2abc_irnodes_ts", "$ts2abc_root:ts2abc_src", diff --git a/ts2panda/scripts/run.py b/ts2panda/scripts/run.py index 9a25349547..bb33dc1377 100755 --- a/ts2panda/scripts/run.py +++ b/ts2panda/scripts/run.py @@ -19,6 +19,7 @@ Description: Compile ark front-end code with tsc """ import os +import sys import subprocess import argparse import platform @@ -74,10 +75,8 @@ def node_modules(options): def npm_run_build(options): plat_form = options.platform - node_modules_dir = os.path.join(options.dist_dir, 'node_modules') - tsc = os.path.join(node_modules_dir, "typescript/bin/tsc") - - os.environ["NODE_PATH"] = node_modules_dir + os.chdir(options.dist_dir) + tsc = "node_modules/typescript/bin/tsc" if plat_form == "linux": cmd = [tsc, '-b', 'src'] @@ -90,8 +89,13 @@ def npm_run_build(options): run_command(cmd, options.dist_dir) -if __name__ == "__main__": +def main(): ARGS = parse_args() set_env(ARGS.node) - node_modules(ARGS) + if not os.path.exists(os.path.join(ARGS.dist_dir, "node_modules")): + node_modules(ARGS) npm_run_build(ARGS) + + +if __name__ == "__main__": + sys.exit(main()) -- Gitee From 6374bd666da34b8a91ec861356c10dd5c801fdb2 Mon Sep 17 00:00:00 2001 From: Han00000000 Date: Sat, 11 Sep 2021 17:30:26 +0800 Subject: [PATCH 8/9] fix docs issues Signed-off-by: Han00000000 Change-Id: Ic8f13d3606258504540831b6af4ce6431121f3a8 --- README.md | 30 ++++++++++++++++-------------- README_zh.md | 28 +++++++++++++++------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 056e1a5640..45229bb42b 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,31 @@ # ts2abc -- [Introduction](#section11660541593) -- [Directory Structure](#section161941989596) -- [Note](#section0446154755015) - - [Usage Guidelines](#section33105542504) - -- [Repositories Involved](#section1371113476307) +- [ts2abc ](#ts2abc-) + - [Introduction](#introduction) + - [Directory Structure](#directory-structure) + - [Note](#note) + - [Usage Guidelines](#usage-guidelines) + - [Repositories Involved](#repositories-involved) ## Introduction -As a module of the ARK platform, ts2abc is a front-end tool for JavaScript \(JS\) in the ARK compiler. It converts JS files into ARK bytecode files. +ts2abc is a front-end tool in the ARK Runtime Subsystem. It converts JavaScript(JS) files into ARK bytecode files. + +For more infomation, see: [ARK Runtime Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/ARK-Runtime-Subsystem.md). ## Directory Structure ``` /ark/ts2abc/ +├── test262 # scripts for configuration and running Test262 ├── ts2panda - ├── doc # Documents ├── scripts # Dependency scripts ├── src # Source code directory ├── templates # Ruby templates ├── tests # Unit test cases ├── tools # Tools provided by ts2abc └── ts2abc # ts2abc source code + ``` ## Note @@ -181,13 +184,12 @@ You can run **node --expose-gc _your\_path_\_to/index.js \[options\] _your\_f -## Repositories Involved - -[ARK Runtime Subsystem](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Subsystem.md) +For more infomation, please see: [ARK-Runtime-Usage-Guide](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide.md). -[ark/runtime\_core](https://gitee.com/openharmony/ark_runtime_core/blob/master/README.md) +## Repositories Involved -[ark/js\_runtime](https://gitee.com/openharmony/ark_js_runtime/blob/master/README.md) +[ark\_runtime\_core](https://gitee.com/openharmony/ark_runtime_core) -**[ark/ts2abc](README.md)** +[ark\_js\_runtime](https://gitee.com/openharmony/ark_js_runtime) +**[ark\_ts2abc](https://gitee.com/openharmony/ark_ts2abc)** diff --git a/README_zh.md b/README_zh.md index 4955793979..8bf1d569e9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,20 +1,23 @@ # ts2abc组件 -- [简介](#section11660541593) -- [目录](#section161941989596) -- [说明](#section0446154755015) - - [使用说明](#section33105542504) - -- [相关仓](#section1371113476307) +- [ts2abc组件](#ts2abc组件) + - [简介](#简介) + - [目录](#目录) + - [说明](#说明) + - [使用说明](#使用说明) + - [相关仓](#相关仓) ## 简介 -ts2abc组件是方舟平台的一个组件,其作为方舟编译器中JavaScript语言的前端工具,支持将JavaScript文件转换为方舟字节码文件。 +ts2abc组件是方舟运行时子系统的前端工具,支持将JavaScript文件转换为方舟字节码文件。 + +更多信息请参考:[方舟运行时子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/ARK-Runtime-Subsystem-zh.md) ## 目录 ``` /ark/ts2abc/ +├── test262 # Test262测试配置和运行脚本 ├── ts2panda ├── doc # 文档 ├── scripts # 依赖的脚本 @@ -181,13 +184,12 @@ ts2abc组件将JavaScript文件转换为方舟字节码文件,命令行格式 -## 相关仓 +更多使用说明请参考:[方舟运行时使用指南](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide-zh.md) -[方舟运行时子系统](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Subsystem-zh.md) - -[ark/runtime\_core](https://gitee.com/openharmony/ark_runtime_core/blob/master/README_zh.md) +## 相关仓 -[ark/js\_runtime](https://gitee.com/openharmony/ark_js_runtime/blob/master/README_zh.md) +[ark\_runtime\_core](https://gitee.com/openharmony/ark_runtime_core) -**[ark/ts2abc](README_zh.md)** +[ark\_js\_runtime](https://gitee.com/openharmony/ark_js_runtime) +**[ark\_ts2abc](https://gitee.com/openharmony/ark_ts2abc)** -- Gitee From 2cd5be5b3d4f7abe8dc7cb98a4f3670f58791709 Mon Sep 17 00:00:00 2001 From: ctw Date: Mon, 13 Sep 2021 16:26:46 +0800 Subject: [PATCH 9/9] 1. fix spelling issues; 2. delete unuseful blank lines; 3. fix comparing double to zero directly 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 aa859c3e8b..b87ad4cc6a --- 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 bcb99efba2..e8fa59c596 --- 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