diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts old mode 100644 new mode 100755 index 3a841712106c3699266fe940552ce99ec81140c6..2f85e12acdab6f4ce3952d64e5729a4590d439fb --- 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 @@ -101,6 +101,7 @@ import { LdaStr, MovDyn, StaDyn, + EcmaLdbigint, VReg } from "../irnodes"; @@ -432,4 +433,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 d9619b894068cd474609184b3800b168457f13dc..2383c4b103f5aabf17958b10fc8d6656f8c05d1f 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 @@ -789,6 +790,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 0000000000000000000000000000000000000000..912769c0934134345fe57b3b7972faefcce93f7c --- /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 22c11bf961d0611a19fc2ca241460a9ed96ce6e3..cb1e5774afa7bb3104565e3a237d7fc6d2542ba2 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 @@ -100,7 +100,8 @@ import { throwThrowNotExists, throwUndefinedIfHole, tryLoadGlobalByName, - tryStoreGlobalByName + tryStoreGlobalByName, + loadAccumulatorBigInt } from "./base/bcGenUtil"; import { Literal, @@ -1252,6 +1253,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();