From 842e715b7901472911346d0a8cf89125b6c7cbde Mon Sep 17 00:00:00 2001 From: changjiaxing Date: Fri, 4 Mar 2022 10:13:17 +0800 Subject: [PATCH 1/2] Signed-off-by: changjiaxing Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch master Your branch is up to date with 'origin/master'. --- ts2panda/src/base/bcGenUtil.ts | 7 ++++++- ts2panda/src/compiler.ts | 4 +++- ts2panda/src/expression/bigIntLiteral.ts | 24 ++++++++++++++++++++++++ ts2panda/src/pandagen.ts | 11 +++++++++-- 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 ts2panda/src/expression/bigIntLiteral.ts diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 04dd4d9de3..9e2758caff 100755 --- a/ts2panda/src/base/bcGenUtil.ts +++ b/ts2panda/src/base/bcGenUtil.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -100,6 +100,7 @@ import { EcmaStclasstoglobalrecord, EcmaStconsttoglobalrecord, EcmaStlettoglobalrecord, + EcmaLdbigint, VReg } from "../irnodes"; @@ -428,4 +429,8 @@ export function stConstToGlobalRecord (name: string) { export function stClassToGlobalRecord (name: string) { return new EcmaStclasstoglobalrecord(name); +} + +export function loadAccumulatorBigInt(value: string): IRNode { + return new EcmaLdbigint(value); } \ No newline at end of file diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index a8057b1eca..e4e83fce79 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -38,6 +38,7 @@ import { CompilerDriver } from "./compilerDriver"; import { DebugInfo, NodeKind } from "./debuginfo"; import { DiagnosticCode, DiagnosticError } from "./diagnostic"; import { compileArrayLiteralExpression } from "./expression/arrayLiteralExpression"; +import { compileBigIntLiteral } from "./expression/bigIntLiteral"; import { compileCallExpression, getHiddenParameters @@ -782,6 +783,7 @@ export class Compiler { compileNumericLiteral(this.pandaGen, expr); break; case ts.SyntaxKind.BigIntLiteral: // line 35 + compileBigIntLiteral(this.pandaGen, expr); break; case ts.SyntaxKind.StringLiteral: // line 36 compileStringLiteral(this.pandaGen, expr); diff --git a/ts2panda/src/expression/bigIntLiteral.ts b/ts2panda/src/expression/bigIntLiteral.ts new file mode 100644 index 0000000000..912769c093 --- /dev/null +++ b/ts2panda/src/expression/bigIntLiteral.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ts from "typescript"; +import * as jshelpers from "../jshelpers"; +import { PandaGen } from "../pandagen"; + +export function compileBigIntLiteral(pandaGen: PandaGen, lit: ts.BigIntLiteral) { + let text = jshelpers.getTextOfIdentifierOrLiteral(lit); + text = text.substring(0, text.length-1); + pandaGen.loadAccumulatorBigInt(lit, text); +} \ No newline at end of file diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index a40bbe240d..a44b72eaf7 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -101,7 +101,8 @@ import { throwThrowNotExists, throwUndefinedIfHole, tryLoadGlobalByName, - tryStoreGlobalByName + tryStoreGlobalByName, + loadAccumulatorBigInt } from "./base/bcGenUtil"; import { LiteralBuffer } from "./base/literal"; import { getParamLengthOfFunc } from "./base/util"; @@ -1234,6 +1235,12 @@ export class PandaGen { node, stClassToGlobalRecord(string_id)); } + + loadAccumulatorBigInt(node: ts.Node | NodeKind, str: string) { + this.add( + node, + loadAccumulatorBigInt(str)); + } private binaryRelation(node: ts.Node, op: BinaryOperator, lhs: VReg) { let falseLabel = new Label(); -- Gitee From a9c72cc15cf89e3ec077182c8e0b90734d7d7b45 Mon Sep 17 00:00:00 2001 From: changjiaxing Date: Mon, 7 Mar 2022 13:26:22 +0800 Subject: [PATCH 2/2] Signed-off-by: changjiaxing Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch master --- ts2panda/src/base/bcGenUtil.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 9e2758caff..91cf023bb0 100755 --- a/ts2panda/src/base/bcGenUtil.ts +++ b/ts2panda/src/base/bcGenUtil.ts @@ -57,12 +57,16 @@ import { EcmaLdsuperbyname, EcmaLdsuperbyvalue, EcmaNewlexenvdyn, + EcmaNewlexenvwithnamedyn, EcmaNewobjdynrange, EcmaPoplexenvdyn, EcmaReturnundefined, EcmaSetobjectwithproto, EcmaStarrayspread, + EcmaStclasstoglobalrecord, + EcmaStconsttoglobalrecord, EcmaStglobalvar, + EcmaStlettoglobalrecord, EcmaStlexvardyn, EcmaStmodulevar, EcmaStobjbyindex, @@ -70,8 +74,8 @@ import { EcmaStobjbyvalue, EcmaStownbyindex, EcmaStownbyname, - EcmaStownbyvalue, EcmaStownbynamewithnameset, + EcmaStownbyvalue, EcmaStownbyvaluewithnameset, EcmaStsuperbyname, EcmaStsuperbyvalue, @@ -97,9 +101,6 @@ import { LdaStr, MovDyn, StaDyn, - EcmaStclasstoglobalrecord, - EcmaStconsttoglobalrecord, - EcmaStlettoglobalrecord, EcmaLdbigint, VReg } from "../irnodes"; -- Gitee