diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 4f195377993e283eddb3c9dc4ad6dcd08b555bf1..5410714703804c239f4f61d1a87d00d1c9fd69d7 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 b323fc7b57b1b4b19bf7d1b31ca0b52fa3ff48bd..be4e0254120f1f82f525b320b92f304f622e311f 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 0000000000000000000000000000000000000000..32575be578c2aa02acf57fd40203d27150291e28 --- /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 d7b0bfceb7e66f4b1721e37373cd78d29550fcc6..dbd7e6c93eab6d09cc9f82bf9f1501c93cc998a4 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();