source: trip-planner-front/node_modules/@webassemblyjs/ast/lib/node-helpers.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.numberLiteralFromRaw = numberLiteralFromRaw;
7exports.instruction = instruction;
8exports.objectInstruction = objectInstruction;
9exports.withLoc = withLoc;
10exports.withRaw = withRaw;
11exports.funcParam = funcParam;
12exports.indexLiteral = indexLiteral;
13exports.memIndexLiteral = memIndexLiteral;
14
15var _helperNumbers = require("@webassemblyjs/helper-numbers");
16
17var _nodes = require("./nodes");
18
19function numberLiteralFromRaw(rawValue) {
20 var instructionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "i32";
21 var original = rawValue; // Remove numeric separators _
22
23 if (typeof rawValue === "string") {
24 rawValue = rawValue.replace(/_/g, "");
25 }
26
27 if (typeof rawValue === "number") {
28 return (0, _nodes.numberLiteral)(rawValue, String(original));
29 } else {
30 switch (instructionType) {
31 case "i32":
32 {
33 return (0, _nodes.numberLiteral)((0, _helperNumbers.parse32I)(rawValue), String(original));
34 }
35
36 case "u32":
37 {
38 return (0, _nodes.numberLiteral)((0, _helperNumbers.parseU32)(rawValue), String(original));
39 }
40
41 case "i64":
42 {
43 return (0, _nodes.longNumberLiteral)((0, _helperNumbers.parse64I)(rawValue), String(original));
44 }
45
46 case "f32":
47 {
48 return (0, _nodes.floatLiteral)((0, _helperNumbers.parse32F)(rawValue), (0, _helperNumbers.isNanLiteral)(rawValue), (0, _helperNumbers.isInfLiteral)(rawValue), String(original));
49 }
50 // f64
51
52 default:
53 {
54 return (0, _nodes.floatLiteral)((0, _helperNumbers.parse64F)(rawValue), (0, _helperNumbers.isNanLiteral)(rawValue), (0, _helperNumbers.isInfLiteral)(rawValue), String(original));
55 }
56 }
57 }
58}
59
60function instruction(id) {
61 var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
62 var namedArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
63 return (0, _nodes.instr)(id, undefined, args, namedArgs);
64}
65
66function objectInstruction(id, object) {
67 var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
68 var namedArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
69 return (0, _nodes.instr)(id, object, args, namedArgs);
70}
71/**
72 * Decorators
73 */
74
75
76function withLoc(n, end, start) {
77 var loc = {
78 start: start,
79 end: end
80 };
81 n.loc = loc;
82 return n;
83}
84
85function withRaw(n, raw) {
86 n.raw = raw;
87 return n;
88}
89
90function funcParam(valtype, id) {
91 return {
92 id: id,
93 valtype: valtype
94 };
95}
96
97function indexLiteral(value) {
98 // $FlowIgnore
99 var x = numberLiteralFromRaw(value, "u32");
100 return x;
101}
102
103function memIndexLiteral(value) {
104 // $FlowIgnore
105 var x = numberLiteralFromRaw(value, "u32");
106 return x;
107}
Note: See TracBrowser for help on using the repository browser.