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