3 Object.defineProperty(exports, "__esModule", {
6 exports.parse32F = parse32F;
7 exports.parse64F = parse64F;
8 exports.parse32I = parse32I;
9 exports.parseU32 = parseU32;
10 exports.parse64I = parse64I;
11 exports.isInfLiteral = isInfLiteral;
12 exports.isNanLiteral = isNanLiteral;
14 var _long = _interopRequireDefault(require("@xtuc/long"));
16 var _floatingPointHexParser = _interopRequireDefault(require("@webassemblyjs/floating-point-hex-parser"));
18 var _helperApiError = require("@webassemblyjs/helper-api-error");
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22 function parse32F(sourceString) {
23 if (isHexLiteral(sourceString)) {
24 return (0, _floatingPointHexParser.default)(sourceString);
27 if (isInfLiteral(sourceString)) {
28 return sourceString[0] === "-" ? -1 : 1;
31 if (isNanLiteral(sourceString)) {
32 return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000);
35 return parseFloat(sourceString);
38 function parse64F(sourceString) {
39 if (isHexLiteral(sourceString)) {
40 return (0, _floatingPointHexParser.default)(sourceString);
43 if (isInfLiteral(sourceString)) {
44 return sourceString[0] === "-" ? -1 : 1;
47 if (isNanLiteral(sourceString)) {
48 return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000);
51 if (isHexLiteral(sourceString)) {
52 return (0, _floatingPointHexParser.default)(sourceString);
55 return parseFloat(sourceString);
58 function parse32I(sourceString) {
61 if (isHexLiteral(sourceString)) {
62 value = ~~parseInt(sourceString, 16);
63 } else if (isDecimalExponentLiteral(sourceString)) {
64 throw new Error("This number literal format is yet to be implemented.");
66 value = parseInt(sourceString, 10);
72 function parseU32(sourceString) {
73 var value = parse32I(sourceString);
76 throw new _helperApiError.CompileError("Illegal value for u32: " + sourceString);
82 function parse64I(sourceString) {
85 if (isHexLiteral(sourceString)) {
86 long = _long.default.fromString(sourceString, false, 16);
87 } else if (isDecimalExponentLiteral(sourceString)) {
88 throw new Error("This number literal format is yet to be implemented.");
90 long = _long.default.fromString(sourceString);
99 var NAN_WORD = /^\+?-?nan/;
100 var INF_WORD = /^\+?-?inf/;
102 function isInfLiteral(sourceString) {
103 return INF_WORD.test(sourceString.toLowerCase());
106 function isNanLiteral(sourceString) {
107 return NAN_WORD.test(sourceString.toLowerCase());
110 function isDecimalExponentLiteral(sourceString) {
111 return !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E");
114 function isHexLiteral(sourceString) {
115 return sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X";