summaryrefslogtreecommitdiff
path: root/node_modules/@webassemblyjs/helper-numbers/src/index.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-11-01 20:49:36 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-11-01 20:49:36 +0800
commite99f950f5018cfe737c0d1150e50d97c6e6a4823 (patch)
tree16f329a1b22128ed67f3fcae15a9b0a030f2ccbf /node_modules/@webassemblyjs/helper-numbers/src/index.js
parentc5d8a744dd584749e0b920119b42e731e37e5f62 (diff)
update
Diffstat (limited to 'node_modules/@webassemblyjs/helper-numbers/src/index.js')
-rw-r--r--node_modules/@webassemblyjs/helper-numbers/src/index.js106
1 files changed, 0 insertions, 106 deletions
diff --git a/node_modules/@webassemblyjs/helper-numbers/src/index.js b/node_modules/@webassemblyjs/helper-numbers/src/index.js
deleted file mode 100644
index 773402e4..00000000
--- a/node_modules/@webassemblyjs/helper-numbers/src/index.js
+++ /dev/null
@@ -1,106 +0,0 @@
-// @flow
-
-import Long from "@xtuc/long";
-import parseHexFloat from "@webassemblyjs/floating-point-hex-parser";
-import { CompileError } from "@webassemblyjs/helper-api-error";
-
-export function parse32F(sourceString: string): number {
- if (isHexLiteral(sourceString)) {
- return parseHexFloat(sourceString);
- }
- if (isInfLiteral(sourceString)) {
- return sourceString[0] === "-" ? -1 : 1;
- }
- if (isNanLiteral(sourceString)) {
- return (
- (sourceString[0] === "-" ? -1 : 1) *
- (sourceString.includes(":")
- ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16)
- : 0x400000)
- );
- }
- return parseFloat(sourceString);
-}
-
-export function parse64F(sourceString: string): number {
- if (isHexLiteral(sourceString)) {
- return parseHexFloat(sourceString);
- }
- if (isInfLiteral(sourceString)) {
- return sourceString[0] === "-" ? -1 : 1;
- }
- if (isNanLiteral(sourceString)) {
- return (
- (sourceString[0] === "-" ? -1 : 1) *
- (sourceString.includes(":")
- ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16)
- : 0x8000000000000)
- );
- }
- if (isHexLiteral(sourceString)) {
- return parseHexFloat(sourceString);
- }
- return parseFloat(sourceString);
-}
-
-export function parse32I(sourceString: string): number {
- let value = 0;
- if (isHexLiteral(sourceString)) {
- value = ~~parseInt(sourceString, 16);
- } else if (isDecimalExponentLiteral(sourceString)) {
- throw new Error("This number literal format is yet to be implemented.");
- } else {
- value = parseInt(sourceString, 10);
- }
-
- return value;
-}
-
-export function parseU32(sourceString: string): number {
- const value = parse32I(sourceString);
- if (value < 0) {
- throw new CompileError("Illegal value for u32: " + sourceString);
- }
- return value;
-}
-
-export function parse64I(sourceString: string): LongNumber {
- // $FlowIgnore
- let long: Long;
- if (isHexLiteral(sourceString)) {
- long = Long.fromString(sourceString, false, 16);
- } else if (isDecimalExponentLiteral(sourceString)) {
- throw new Error("This number literal format is yet to be implemented.");
- } else {
- long = Long.fromString(sourceString);
- }
-
- return {
- high: long.high,
- low: long.low,
- };
-}
-
-const NAN_WORD = /^\+?-?nan/;
-const INF_WORD = /^\+?-?inf/;
-
-export function isInfLiteral(sourceString: string): boolean {
- return INF_WORD.test(sourceString.toLowerCase());
-}
-
-export function isNanLiteral(sourceString: string): boolean {
- return NAN_WORD.test(sourceString.toLowerCase());
-}
-
-function isDecimalExponentLiteral(sourceString: string): boolean {
- return (
- !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E")
- );
-}
-
-function isHexLiteral(sourceString: string): boolean {
- return (
- sourceString.substring(0, 2).toUpperCase() === "0X" ||
- sourceString.substring(0, 3).toUpperCase() === "-0X"
- );
-}