From 01ad868dd1965ac25ca84561ad8bd830a0da6c5e Mon Sep 17 00:00:00 2001 From: changjiaxing Date: Sat, 19 Feb 2022 11:34:51 +0800 Subject: [PATCH] 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 | 5 +++++ ts2panda/src/compiler.ts | 2 ++ ts2panda/src/expression/bigIntLiteral.ts | 24 ++++++++++++++++++++++++ ts2panda/src/pandagen.ts | 8 +++++++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ts2panda/src/expression/bigIntLiteral.ts diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 4f195377993..54107147038 100755 --- a/ts2panda/src/base/bcGenUtil.ts +++ b/ts2panda/src/base/bcGenUtil.ts @@ -101,6 +101,7 @@ import { EcmaStclasstoglobalrecord, EcmaStconsttoglobalrecord, EcmaStlettoglobalrecord, + EcmaLdbigint, VReg } from "../irnodes"; @@ -429,4 +430,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 b323fc7b57b..be4e0254120 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -37,6 +37,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 @@ -778,6 +779,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 00000000000..32575be578c --- /dev/null +++ b/ts2panda/src/expression/bigIntLiteral.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 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 d7b0bfceb7e..dbd7e6c93ea 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -101,7 +101,8 @@ import { throwThrowNotExists, throwUndefinedIfHole, tryLoadGlobalByName, - tryStoreGlobalByName + tryStoreGlobalByName, + loadAccumulatorBigInt } from "./base/bcGenUtil"; import { LiteralBuffer } from "./base/literal"; import { getParamLengthOfFunc } from "./base/util"; @@ -1253,6 +1254,11 @@ 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