affinirum 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +214 -151
  2. package/dst/Affinirum.js +24 -15
  3. package/dst/Atom.d.ts +3 -1
  4. package/dst/Constant.js +1 -1
  5. package/dst/Functions.js +7 -4
  6. package/dst/Keywords.js +4 -4
  7. package/dst/ParserState.d.ts +2 -1
  8. package/dst/ParserState.js +22 -5
  9. package/dst/Type.d.ts +11 -7
  10. package/dst/Type.js +113 -38
  11. package/dst/Value.d.ts +1 -0
  12. package/dst/Value.js +19 -1
  13. package/dst/atom/ArrayAtom.d.ts +7 -3
  14. package/dst/atom/ArrayAtom.js +50 -8
  15. package/dst/atom/FunctionAtom.d.ts +4 -1
  16. package/dst/atom/FunctionAtom.js +65 -15
  17. package/dst/atom/ObjectAtom.d.ts +7 -5
  18. package/dst/atom/ObjectAtom.js +35 -13
  19. package/dst/atom/PrimitiveAtom.d.ts +3 -1
  20. package/dst/atom/PrimitiveAtom.js +10 -1
  21. package/dst/cjs/Affinirum.js +24 -15
  22. package/dst/cjs/Constant.js +1 -1
  23. package/dst/cjs/Functions.js +6 -3
  24. package/dst/cjs/Keywords.js +4 -4
  25. package/dst/cjs/ParserState.js +22 -5
  26. package/dst/cjs/Type.js +113 -38
  27. package/dst/cjs/Value.js +21 -0
  28. package/dst/cjs/atom/ArrayAtom.js +50 -8
  29. package/dst/cjs/atom/FunctionAtom.js +65 -15
  30. package/dst/cjs/atom/ObjectAtom.js +35 -13
  31. package/dst/cjs/atom/PrimitiveAtom.js +10 -1
  32. package/dst/cjs/native/Aggregable.js +2 -1
  33. package/dst/cjs/native/Array.js +10 -8
  34. package/dst/cjs/native/Boolean.js +5 -4
  35. package/dst/cjs/native/Enumerable.js +5 -4
  36. package/dst/cjs/native/Float.js +9 -8
  37. package/dst/cjs/native/Integer.js +23 -15
  38. package/dst/cjs/native/Iterable.js +2 -1
  39. package/dst/cjs/native/Number.js +18 -33
  40. package/dst/cjs/native/Object.js +2 -1
  41. package/dst/cjs/native/String.js +3 -2
  42. package/dst/cjs/native/Timestamp.js +2 -1
  43. package/dst/cjs/native/notation/IP.js +3 -2
  44. package/dst/cjs/node/ArrayNode.js +6 -6
  45. package/dst/cjs/node/CallNode.js +27 -23
  46. package/dst/cjs/node/CastNode.js +42 -0
  47. package/dst/cjs/node/ObjectNode.js +2 -4
  48. package/dst/cjs/node/SwitchNode.js +3 -1
  49. package/dst/cjs/node/VariableNode.js +3 -1
  50. package/dst/native/Aggregable.js +2 -1
  51. package/dst/native/Array.js +10 -8
  52. package/dst/native/Boolean.d.ts +1 -0
  53. package/dst/native/Boolean.js +4 -3
  54. package/dst/native/Enumerable.js +5 -4
  55. package/dst/native/Float.d.ts +2 -0
  56. package/dst/native/Float.js +8 -7
  57. package/dst/native/Integer.d.ts +5 -1
  58. package/dst/native/Integer.js +20 -14
  59. package/dst/native/Iterable.js +2 -1
  60. package/dst/native/Number.d.ts +0 -3
  61. package/dst/native/Number.js +17 -32
  62. package/dst/native/Object.js +2 -1
  63. package/dst/native/String.js +3 -2
  64. package/dst/native/Timestamp.js +2 -1
  65. package/dst/native/notation/IP.js +3 -2
  66. package/dst/node/ArrayNode.d.ts +1 -1
  67. package/dst/node/ArrayNode.js +6 -6
  68. package/dst/node/CallNode.js +27 -23
  69. package/dst/node/CastNode.d.ts +15 -0
  70. package/dst/node/CastNode.js +38 -0
  71. package/dst/node/ObjectNode.d.ts +1 -1
  72. package/dst/node/ObjectNode.js +2 -4
  73. package/dst/node/SwitchNode.js +3 -1
  74. package/dst/node/VariableNode.js +3 -1
  75. package/package.json +5 -4
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constString = exports.funcReplaceWith = exports.funcSplit = exports.funcUpperCase = exports.funcLowerCase = exports.funcTrimEnd = exports.funcTrimStart = exports.funcTrim = exports.funcCharCode = exports.funcChar = exports.funcEndsWith = exports.funcStartsWith = exports.funcUnlike = exports.funcLike = exports.encodeString = exports.endsWithString = exports.startsWithString = exports.containsString = exports.equateStrings = exports.replaceWith = exports.isHexadecimalSymbol = exports.isTimeSymbol = exports.isDateSymbol = exports.isDateTimeSeparatorSymbol = exports.isTimeSeparatorSymbol = exports.isDateSeparatorSymbol = exports.isTokenSymbol = exports.isTokenStartSymbol = exports.isAlphanumericSymbol = exports.isNumericSymbol = exports.isSignSymbol = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const Integer_js_1 = require("./Integer.js");
6
7
  const isSignSymbol = (c) => c === "+" || c === "-";
7
8
  exports.isSignSymbol = isSignSymbol;
8
9
  const isNumericSymbol = (c) => c >= "0" && c <= "9";
@@ -223,14 +224,14 @@ exports.funcChar = new Constant_js_1.Constant((value, pos) => value == null
223
224
  : value.charAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalString, [Type_js_1.Type.String, Type_js_1.Type.Integer]));
224
225
  exports.funcCharCode = new Constant_js_1.Constant((value, pos) => value == null
225
226
  ? undefined
226
- : value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.String, Type_js_1.Type.Float]));
227
+ : (0, Integer_js_1.createInteger)(value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos))), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.String, Type_js_1.Type.Integer]));
227
228
  exports.funcTrim = new Constant_js_1.Constant((value) => value?.trim(), typeStringMutator);
228
229
  exports.funcTrimStart = new Constant_js_1.Constant((value) => value?.trimStart(), typeStringMutator);
229
230
  exports.funcTrimEnd = new Constant_js_1.Constant((value) => value?.trimEnd(), typeStringMutator);
230
231
  exports.funcLowerCase = new Constant_js_1.Constant((value) => value?.toLowerCase(), typeStringMutator);
231
232
  exports.funcUpperCase = new Constant_js_1.Constant((value) => value?.toUpperCase(), typeStringMutator);
232
233
  exports.funcSplit = new Constant_js_1.Constant((value, separator = " ") => value?.split(separator) ?? [], Type_js_1.Type.functionType(Type_js_1.Type.arrayType([Type_js_1.Type.String]), [Type_js_1.Type.String, Type_js_1.Type.OptionalString]));
233
- exports.funcReplaceWith = new Constant_js_1.Constant((value, replacement, ...search) => (0, exports.replaceWith)(value, replacement, ...search.flat()), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.String, typeStringOrArray], true));
234
+ exports.funcReplaceWith = new Constant_js_1.Constant((value, replacement, search) => (0, exports.replaceWith)(value, replacement, ...search.flat()), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.String, Type_js_1.Type.arrayType([typeStringOrArray])], true));
234
235
  const funcAlphanum = new Constant_js_1.Constant((value) => {
235
236
  if (!value) {
236
237
  return undefined;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constTimestamp = exports.funcSecondsSince = exports.funcMinutesSince = exports.funcHoursSince = exports.funcDaysSince = exports.funcEpochTime = exports.funcMillisecond = exports.funcSecond = exports.funcMinute = exports.funcHour = exports.funcDay = exports.funcWeekdayIndex = exports.funcMonthIndex = exports.funcMonth = exports.funcYear = exports.formatTimestamp = exports.decodeTimestamp = exports.encodeTimestamp = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const Integer_js_1 = require("./Integer.js");
6
7
  const typeTimestampPart = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalBoolean]);
7
8
  const typeTimestampSince = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Timestamp, Type_js_1.Type.Timestamp]);
8
9
  const encodeTimestamp = (value, encoding = "i64") => {
@@ -84,7 +85,7 @@ exports.funcHour = new Constant_js_1.Constant((value, utc = false) => value ? Bi
84
85
  exports.funcMinute = new Constant_js_1.Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCMinutes() : value.getMinutes()) : undefined, typeTimestampPart);
85
86
  exports.funcSecond = new Constant_js_1.Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCSeconds() : value.getSeconds()) : undefined, typeTimestampPart);
86
87
  exports.funcMillisecond = new Constant_js_1.Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCMilliseconds() : value.getMilliseconds()) : undefined, typeTimestampPart);
87
- exports.funcEpochTime = new Constant_js_1.Constant((value, epoch = new Date(0)) => value ? BigInt.asIntN(64, BigInt(value.getTime() - epoch.getTime())) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalTimestamp]));
88
+ exports.funcEpochTime = new Constant_js_1.Constant((value, epoch = new Date(0)) => value ? (0, Integer_js_1.boundInteger)(BigInt(value.getTime() - epoch.getTime())) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalTimestamp]));
88
89
  exports.funcDaysSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 86400000.0, typeTimestampSince);
89
90
  exports.funcHoursSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 3600000.0, typeTimestampSince);
90
91
  exports.funcMinutesSince = new Constant_js_1.Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 60000.0, typeTimestampSince);
@@ -195,7 +195,8 @@ class IPSet {
195
195
  }
196
196
  }
197
197
  }
198
- const funcMatchIP = new Constant_js_1.Constant((values, ...search) => {
198
+ const typeStringOrArray = Type_js_1.Type.union(Type_js_1.Type.String, Type_js_1.Type.arrayType([Type_js_1.Type.String]));
199
+ const funcMatchIP = new Constant_js_1.Constant((values, search) => {
199
200
  try {
200
201
  const ipset = new IPSet().add(values);
201
202
  for (const ip of search.flat()) {
@@ -209,7 +210,7 @@ const funcMatchIP = new Constant_js_1.Constant((values, ...search) => {
209
210
  }
210
211
  catch { }
211
212
  return false;
212
- }, Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Array, Type_js_1.Type.union(Type_js_1.Type.String, Type_js_1.Type.Array)], true));
213
+ }, Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.arrayType([Type_js_1.Type.String]), Type_js_1.Type.arrayType([typeStringOrArray])], true));
213
214
  const funcEncodeIP = new Constant_js_1.Constant((value) => {
214
215
  if (value == null) {
215
216
  return Buffer_js_1.EmptyBuffer;
@@ -8,23 +8,23 @@ const Type_js_1 = require("../Type.js");
8
8
  class ArrayNode extends Node_js_1.Node {
9
9
  _subnodes;
10
10
  _type;
11
- constructor(frame, _subnodes, generic = false) {
11
+ constructor(frame, _subnodes) {
12
12
  super(frame);
13
13
  this._subnodes = _subnodes;
14
- this._type = generic
15
- ? Type_js_1.Type.Array
16
- : Type_js_1.Type.arrayType(_subnodes.map((i) => i.type));
14
+ this._type = Type_js_1.Type.arrayType(_subnodes.map((i) => i.type));
17
15
  }
18
16
  get type() {
19
17
  return this._type;
20
18
  }
21
19
  compile(type) {
22
- this._type = this.reduceType(type);
23
20
  let constant = true;
24
21
  for (let i = 0; i < this._subnodes.length; ++i) {
25
- this._subnodes[i] = this._subnodes[i].compile(Type_js_1.Type.Unknown);
22
+ const valType = type.arrayAtomValType(i);
23
+ this._subnodes[i] = this._subnodes[i].compile(valType);
26
24
  constant &&= this._subnodes[i].constant;
27
25
  }
26
+ this._type = Type_js_1.Type.arrayType(this._subnodes.map((node) => node.type));
27
+ this._type = this.reduceType(type);
28
28
  if (constant) {
29
29
  return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
30
30
  }
@@ -5,6 +5,7 @@ const Node_js_1 = require("../Node.js");
5
5
  const Constant_js_1 = require("../Constant.js");
6
6
  const ConstantNode_js_1 = require("./ConstantNode.js");
7
7
  const ArrayNode_js_1 = require("./ArrayNode.js");
8
+ const Value_js_1 = require("../Value.js");
8
9
  const Type_js_1 = require("../Type.js");
9
10
  const JumpException_js_1 = require("../JumpException.js");
10
11
  class CallNode extends Node_js_1.Node {
@@ -17,7 +18,7 @@ class CallNode extends Node_js_1.Node {
17
18
  this._subnodes = _subnodes;
18
19
  const functionAtoms = this._fnode.type.functionAtoms(Type_js_1.Type.Unknown, this._subnodes.length);
19
20
  if (!functionAtoms.length) {
20
- this.throwError(`function ${this._fnode.type} does not take ${this._subnodes.length} arguments)`);
21
+ this.throwError(`value of type ${this._fnode.type} cannot be called with ${this._subnodes.length} argument(s)`);
21
22
  }
22
23
  this._type = Type_js_1.Type.union(...functionAtoms.map((i) => i.retType));
23
24
  }
@@ -26,29 +27,32 @@ class CallNode extends Node_js_1.Node {
26
27
  }
27
28
  compile(type) {
28
29
  this._fnode = this._fnode.compile(this._fnode.type);
29
- const functionAtoms = this._fnode.type.functionAtoms(type, this._subnodes.length);
30
- if (!functionAtoms.length) {
31
- this.throwError(`function ${this._fnode.type} does not take ${this._subnodes.length} arguments returning ${type})`);
30
+ const functionAtoms_ = this._fnode.type.functionAtoms(type, this._subnodes.length);
31
+ let functionAtoms = functionAtoms_.filter((atom) => !atom.isVariadic);
32
+ if (!functionAtoms.length || !this._subnodes.every((node, index) => node.type.intersect(Type_js_1.Type.union(...functionAtoms.map((atom) => atom.paramType(index) ?? Type_js_1.Type.Unknown))))) {
33
+ functionAtoms = functionAtoms_.filter((atom) => atom.isVariadic);
34
+ }
35
+ if (!functionAtoms.length || !this._subnodes.every((node, index) => node.type.intersect(Type_js_1.Type.union(...functionAtoms.map((atom) => atom.paramType(index) ?? Type_js_1.Type.Unknown))))) {
36
+ this.throwError(`value of type ${this._fnode.type} cannot be called with ${this._subnodes.length} argument(s) and return a type compatible with ${type}`);
32
37
  }
33
38
  this._type = Type_js_1.Type.union(...functionAtoms.map((i) => i.retType));
34
- if (this._fnode.constant) {
35
- let constant = true;
36
- for (let i = 0; i < this._subnodes.length; ++i) {
37
- const argTypes = functionAtoms.map((a) => a.argType(i));
38
- const argType = Type_js_1.Type.union(...argTypes.filter((t) => t != null));
39
- this._subnodes[i] = this._subnodes[i].compile(argType);
40
- constant &&= this._subnodes[i].constant;
41
- }
42
- if (constant) {
43
- return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
44
- }
39
+ const arity = functionAtoms[0].isVariadic
40
+ ? Math.max(...functionAtoms.map((atom) => atom.arity))
41
+ : 0;
42
+ if (arity > 0) {
43
+ const frame = this._subnodes[arity - 1].starts();
44
+ const vnodes = this._subnodes.splice(arity - 1);
45
+ this._subnodes.push(new ArrayNode_js_1.ArrayNode(frame.ends(vnodes[vnodes.length - 1]), vnodes));
45
46
  }
46
- else {
47
- const arity = functionAtoms.filter((i) => i.isVariadic).map((i) => i.arity).reduce((acc, val) => Math.max(acc, val), 0);
48
- if (arity > 0) {
49
- const frame = this._subnodes[arity - 1].starts();
50
- this._subnodes = this._subnodes.slice(0, arity - 1).concat(new ArrayNode_js_1.ArrayNode(frame.ends(this._subnodes[this._subnodes.length - 1]), this._subnodes.slice(arity - 1)));
51
- }
47
+ let constant = this._fnode.constant;
48
+ for (let i = 0; i < this._subnodes.length; ++i) {
49
+ const argTypes = functionAtoms.map((a) => a.argType(i));
50
+ const argType = Type_js_1.Type.union(...argTypes.filter((t) => t != null));
51
+ this._subnodes[i] = this._subnodes[i].compile(argType);
52
+ constant &&= this._subnodes[i].constant;
53
+ }
54
+ if (constant) {
55
+ return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
52
56
  }
53
57
  return this;
54
58
  }
@@ -58,12 +62,12 @@ class CallNode extends Node_js_1.Node {
58
62
  this.throwError(`function expected not ${Type_js_1.Type.of(func)}`);
59
63
  }
60
64
  try {
61
- return func(...this._subnodes.map((node) => node.evaluate()));
65
+ return (0, Value_js_1.normalize)(func(...this._subnodes.map((node) => node.evaluate())));
62
66
  }
63
67
  catch (e) {
64
68
  if (e instanceof JumpException_js_1.JumpException) {
65
69
  if (e.jump === "return") {
66
- return e.value;
70
+ return (0, Value_js_1.normalize)(e.value);
67
71
  }
68
72
  if (e.jump === "stop" || e.jump === "next") {
69
73
  throw this.throwError(`unexpected ${e.jump} jump`);
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CastNode = void 0;
4
+ const Node_js_1 = require("../Node.js");
5
+ const Type_js_1 = require("../Type.js");
6
+ class CastNode extends Node_js_1.Node {
7
+ _subnode;
8
+ _target;
9
+ _type;
10
+ constructor(frame, _subnode, _target) {
11
+ super(frame);
12
+ this._subnode = _subnode;
13
+ this._target = _target;
14
+ this._type = _target;
15
+ }
16
+ get type() {
17
+ return this._type;
18
+ }
19
+ compile(type) {
20
+ this._subnode = this._subnode.compile(Type_js_1.Type.Unknown);
21
+ if (!this._subnode.type.intersect(this._target)) {
22
+ this.throwError(`cannot cast type ${this._subnode.type} to ${this._target}`);
23
+ }
24
+ this._type = this._target;
25
+ this._type = this.reduceType(type);
26
+ return this;
27
+ }
28
+ evaluate() {
29
+ const value = this._subnode.evaluate();
30
+ if (!this._type.acceptValue(value)) {
31
+ this.throwError(`cannot cast value of type ${Type_js_1.Type.of(value)} to ${this._type}`);
32
+ }
33
+ return value;
34
+ }
35
+ get constant() {
36
+ return this._subnode.constant;
37
+ }
38
+ toString(ident = 0) {
39
+ return `${super.toString(ident)} cast node target <${this._target}>:\n${this._subnode.toString(ident + 1)}`;
40
+ }
41
+ }
42
+ exports.CastNode = CastNode;
@@ -8,12 +8,10 @@ const Type_js_1 = require("../Type.js");
8
8
  class ObjectNode extends Node_js_1.Node {
9
9
  _subnodes;
10
10
  _type;
11
- constructor(frame, _subnodes, generic = false) {
11
+ constructor(frame, _subnodes) {
12
12
  super(frame);
13
13
  this._subnodes = _subnodes;
14
- this._type = generic
15
- ? Type_js_1.Type.Object
16
- : Type_js_1.Type.objectType(Object.fromEntries(_subnodes.filter(([i]) => i instanceof ConstantNode_js_1.ConstantNode && i.constant).map(([k, v]) => [k.evaluate(), v.type])));
14
+ this._type = Type_js_1.Type.objectType(_subnodes.filter(([i]) => i instanceof ConstantNode_js_1.ConstantNode && i.constant).map(([k, v]) => [k.evaluate(), v.type]));
17
15
  }
18
16
  get type() {
19
17
  return this._type;
@@ -37,7 +37,9 @@ class SwitchNode extends Node_js_1.Node {
37
37
  return this;
38
38
  }
39
39
  evaluate() {
40
- return this._cnode.evaluate() ? this._subnodes[0].evaluate() : this._subnodes[1].evaluate();
40
+ return this._cnode.evaluate()
41
+ ? this._subnodes[0].evaluate()
42
+ : this._subnodes[1].evaluate();
41
43
  }
42
44
  toString(ident = 0) {
43
45
  const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
@@ -19,7 +19,9 @@ class VariableNode extends Node_js_1.Node {
19
19
  return this;
20
20
  }
21
21
  evaluate() {
22
- return this._subnode ? this._variable.value = this._subnode.evaluate() : this._variable.value;
22
+ return this._subnode
23
+ ? this._variable.value = this._subnode.evaluate()
24
+ : this._variable.value;
23
25
  }
24
26
  toString(ident = 0) {
25
27
  return this._subnode
@@ -1,6 +1,7 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  import { concatBuffers } from "./Buffer.js";
4
+ import { boundInteger } from "./Integer.js";
4
5
  export const aggregate = (value1, value2) => {
5
6
  if (value1 == null || value2 == null) {
6
7
  return undefined;
@@ -15,7 +16,7 @@ export const aggregate = (value1, value2) => {
15
16
  };
16
17
  const add = (value1, value2) => {
17
18
  if (typeof value1 === "bigint" && typeof value2 === "bigint") {
18
- return BigInt.asIntN(64, value1 + value2);
19
+ return boundInteger(value1 + value2);
19
20
  }
20
21
  if ((typeof value1 === "number" || typeof value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
21
22
  return Number(value1) + Number(value2);
@@ -1,11 +1,12 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
+ import { boundInteger } from "./Integer.js";
3
4
  import { equate } from "./Unknown.js";
4
5
  const typePredicate = Type.functionType(Type.Boolean, [Type.Unknown, Type.OptionalInteger, Type.OptionalArray]);
5
6
  const typeItemFinder = Type.functionType(Type.Unknown, [Type.Array, typePredicate]);
6
7
  const typeIndexFinder = Type.functionType(Type.OptionalInteger, [Type.Array, typePredicate]);
7
8
  const typeConditionSet = Type.functionType(Type.Boolean, [Type.Array, typePredicate]);
8
- const typeVariadicInsert = Type.functionType(Type.Array, [Type.Array, Type.Unknown], true);
9
+ const typeVariadicInsert = Type.functionType(Type.Array, [Type.Array, Type.Array], true);
9
10
  const typeArrayOperator = Type.functionType(Type.Array, [Type.Array, Type.Array]);
10
11
  export const funcFirst = new Constant((value, predicate) => value?.find((v, i, a) => predicate(v, BigInt(i), a)), typeItemFinder);
11
12
  export const funcLast = new Constant((value, predicate) => {
@@ -24,7 +25,7 @@ export const funcFirstIndex = new Constant((value, predicate) => {
24
25
  return undefined;
25
26
  }
26
27
  const ix = value.findIndex((v, i, a) => predicate(v, BigInt(i), a));
27
- return ix < 0 ? undefined : BigInt.asIntN(64, BigInt(ix));
28
+ return ix < 0 ? undefined : boundInteger(BigInt(ix));
28
29
  }, typeIndexFinder);
29
30
  export const funcLastIndex = new Constant((value, predicate) => {
30
31
  if (value == null) {
@@ -32,7 +33,7 @@ export const funcLastIndex = new Constant((value, predicate) => {
32
33
  }
33
34
  for (let i = value.length - 1; i >= 0; i--) {
34
35
  if (predicate(value[i], BigInt(i), value)) {
35
- return BigInt.asIntN(64, BigInt(i));
36
+ return boundInteger(BigInt(i));
36
37
  }
37
38
  }
38
39
  return undefined;
@@ -57,18 +58,19 @@ export const funcCompose = new Constant((value, callback) => {
57
58
  }
58
59
  return obj;
59
60
  }, Type.functionType(Type.Object, [Type.Array, Type.functionType(Type.Unknown, [Type.Object, Type.String, Type.OptionalInteger, Type.OptionalArray])]));
60
- export const funcPrepend = new Constant((value, ...items) => {
61
+ export const funcPrepend = new Constant((value, items) => {
61
62
  value?.unshift(items);
62
63
  return value;
63
64
  }, typeVariadicInsert);
64
- export const funcAppend = new Constant((value, ...items) => {
65
+ export const funcAppend = new Constant((value, items) => {
65
66
  value?.push(items);
66
67
  return value;
67
68
  }, typeVariadicInsert);
68
- const funcJoin = new Constant((...values) => values.flat(Infinity), Type.functionType(Type.Array, [Type.Array], true));
69
+ const funcJoin = new Constant((values) => values.flat(Infinity), Type.functionType(Type.Array, [Type.arrayType([Type.Array])], true));
69
70
  const funcRange = new Constant((value1, value2) => {
70
- const min = value1 < value2 ? value1 : value2;
71
- const max = value1 > value2 ? value1 : value2;
71
+ const v1 = boundInteger(value1);
72
+ const v2 = boundInteger(value2);
73
+ const [min, max] = v1 < v2 ? [v1, v2] : [v2, v1];
72
74
  return [...Array(Number(max - min)).keys()].map((i) => BigInt(i) + min);
73
75
  }, Type.functionType(Type.Array, [Type.Integer, Type.Integer]));
74
76
  const funcUnique = new Constant((value) => {
@@ -2,4 +2,5 @@ import { Constant } from "../Constant.js";
2
2
  export declare const funcOr: Constant;
3
3
  export declare const funcAnd: Constant;
4
4
  export declare const funcNot: Constant;
5
+ export declare const funcBoolean: Constant;
5
6
  export declare const constBoolean: any;
@@ -1,9 +1,9 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  const typeBooleanOrArray = Type.union(Type.Boolean, Type.arrayType([Type.Boolean]));
4
- const typeBooleanLogic = Type.functionType(Type.Boolean, [typeBooleanOrArray], true);
5
- export const funcOr = new Constant((...values) => values.flat().some((v) => v), typeBooleanLogic);
6
- export const funcAnd = new Constant((...values) => values.flat().every((v) => v), typeBooleanLogic);
4
+ const typeBooleanLogic = Type.functionType(Type.Boolean, [Type.arrayType([typeBooleanOrArray])], true);
5
+ export const funcOr = new Constant((values) => values.flat().some((v) => v), typeBooleanLogic);
6
+ export const funcAnd = new Constant((values) => values.flat().every((v) => v), typeBooleanLogic);
7
7
  export const funcNot = new Constant((value) => !value, Type.functionType(Type.Boolean, [Type.Boolean]));
8
8
  const funcDecodeBoolean = new Constant((value, byteOffset) => {
9
9
  const offset = byteOffset == null ? 0 : Number(byteOffset);
@@ -16,6 +16,7 @@ const funcParseBoolean = new Constant((value) => {
16
16
  const v = value.toLowerCase();
17
17
  return v === "true" ? true : v === "false" ? false : undefined;
18
18
  }, Type.functionType(Type.OptionalBoolean, [Type.OptionalString]));
19
+ export const funcBoolean = new Constant((value) => typeof value === "bigint" ? value !== 0n : Boolean(Number(value)), Type.union(Type.functionType(Type.Boolean, [Type.Timestamp]), Type.functionType(Type.Boolean, [Type.Float]), Type.functionType(Type.Boolean, [Type.Integer])));
19
20
  export const constBoolean = Object.assign(Object.create(null), {
20
21
  Or: funcOr,
21
22
  And: funcAnd,
@@ -1,12 +1,13 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  import { aggregate } from "./Aggregable.js";
4
+ const typeEnumerableArray = Type.arrayType([Type.Enumerable]);
4
5
  export const funcSlice = new Constant((value, start = 0n, end) => value == null
5
6
  ? undefined
6
7
  : value.slice(Number(start), end == null ? undefined : Number(end)), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.String, [Type.String, Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.Array, [Type.Array, Type.OptionalInteger, Type.OptionalInteger])));
7
- export const funcSplice = new Constant((value, start, remove, ...inject) => value == null
8
+ export const funcSplice = new Constant((value, start, remove, inject) => value == null
8
9
  ? undefined
9
- : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, Type.Integer, Type.Enumerable], true), Type.functionType(Type.String, [Type.String, Type.Integer, Type.Integer, Type.Enumerable], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, Type.Integer, Type.Enumerable], true)));
10
- export const funcInject = new Constant((value, start, ...inject) => value == null
10
+ : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, Type.Integer, typeEnumerableArray], true), Type.functionType(Type.String, [Type.String, Type.Integer, Type.Integer, typeEnumerableArray], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, Type.Integer, typeEnumerableArray], true)));
11
+ export const funcInject = new Constant((value, start, inject) => value == null
11
12
  ? undefined
12
- : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, Type.Enumerable], true), Type.functionType(Type.String, [Type.String, Type.Integer, Type.Enumerable], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, Type.Enumerable], true)));
13
+ : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, typeEnumerableArray], true), Type.functionType(Type.String, [Type.String, Type.Integer, typeEnumerableArray], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, typeEnumerableArray], true)));
@@ -1,3 +1,5 @@
1
+ import { Constant } from "../Constant.js";
1
2
  export type FloatEncoding = "f32" | "f32le" | "f64" | "f64le";
2
3
  export declare const encodeFloat: (value: number, encoding?: FloatEncoding) => ArrayBuffer;
4
+ export declare const funcFloat: Constant;
3
5
  export declare const constFloat: any;
@@ -39,12 +39,12 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
39
39
  default: throw new Error(`${encoding} encoding not supported`);
40
40
  }
41
41
  };
42
- const typeNumberOrArray = Type.union(Type.Float, Type.arrayType([Type.Float]));
43
- const typeAggregator = Type.functionType(Type.Float, [typeNumberOrArray], true);
44
- const typeTransform = Type.functionType(Type.Float, [Type.Float]);
45
- const funcSum = new Constant((...values) => values.flat().reduce((acc, val) => acc + Number(val), 0), typeAggregator);
46
- const funcMin = new Constant((...values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
47
- const funcMax = new Constant((...values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
42
+ const typeNumberOrArray = Type.union(Type.Number, Type.arrayType([Type.Number]));
43
+ const typeAggregator = Type.functionType(Type.Float, [Type.arrayType([typeNumberOrArray])], true);
44
+ const typeTransform = Type.functionType(Type.Float, [Type.Number]);
45
+ const funcSum = new Constant((values) => values.flat().reduce((acc, val) => acc + Number(val), 0), typeAggregator);
46
+ const funcMin = new Constant((values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
47
+ const funcMax = new Constant((values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
48
48
  const funcExponent = new Constant((value) => Math.exp(Number(value)), typeTransform);
49
49
  const funcLogarithm = new Constant((value) => Math.log(Number(value)), typeTransform);
50
50
  const funcAbs = new Constant((value) => Math.abs(Number(value)), typeTransform);
@@ -52,9 +52,10 @@ const funcCeil = new Constant((value) => Math.ceil(Number(value)), typeTransform
52
52
  const funcFloor = new Constant((value) => Math.floor(Number(value)), typeTransform);
53
53
  const funcRound = new Constant((value) => Math.round(Number(value)), typeTransform);
54
54
  const funcTruncate = new Constant((value) => Math.trunc(Number(value)), typeTransform);
55
- const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), Type.functionType(Type.Float, [Type.Float]), false);
55
+ const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), typeTransform, false);
56
56
  const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
57
57
  const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType(Type.OptionalFloat, [Type.OptionalString]));
58
+ export const funcFloat = new Constant((value) => Number(value), Type.union(Type.functionType(Type.Float, [Type.Boolean]), Type.functionType(Type.Float, [Type.Timestamp]), Type.functionType(Type.Float, [Type.Integer])));
58
59
  export const constFloat = Object.assign(Object.create(null), {
59
60
  NAN: new Constant(Number.NaN),
60
61
  PositiveInfinity: new Constant(Number.POSITIVE_INFINITY),
@@ -1,3 +1,7 @@
1
- export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le" | "n64" | "n64le";
1
+ import { Constant } from "../Constant.js";
2
+ export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le";
3
+ export declare const boundInteger: (value: bigint) => bigint;
4
+ export declare const createInteger: (value?: number) => bigint | undefined;
2
5
  export declare const encodeInteger: (value: bigint, encoding?: IntegerEncoding) => ArrayBuffer;
6
+ export declare const funcInteger: Constant;
3
7
  export declare const constInteger: any;
@@ -1,5 +1,18 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
+ export const boundInteger = (value) => BigInt.asIntN(64, value);
4
+ export const createInteger = (value) => {
5
+ if (value == null || Number.isNaN(value)) {
6
+ return undefined;
7
+ }
8
+ if (value === Number.NEGATIVE_INFINITY) {
9
+ return -0x8000000000000000n;
10
+ }
11
+ if (value === Number.POSITIVE_INFINITY) {
12
+ return 0x7fffffffffffffffn;
13
+ }
14
+ return boundInteger(BigInt(Math.trunc(value)));
15
+ };
3
16
  export const encodeInteger = (value, encoding = "i64") => {
4
17
  let bits = "";
5
18
  for (let i = 0; i < encoding.length; ++i) {
@@ -46,12 +59,6 @@ export const encodeInteger = (value, encoding = "i64") => {
46
59
  case "i64le":
47
60
  dv.setBigInt64(0, value, true);
48
61
  break;
49
- case "n64":
50
- dv.setBigUint64(0, value);
51
- break;
52
- case "n64le":
53
- dv.setBigUint64(0, value, true);
54
- break;
55
62
  default: throw new Error(`${encoding} encoding not supported`);
56
63
  }
57
64
  return dv.buffer;
@@ -74,25 +81,24 @@ const decodeInteger = (value, encoding = "i64", byteOffset) => {
74
81
  case "n16le": return BigInt(dv.getUint16(0, true));
75
82
  case "n32": return BigInt(dv.getUint32(0));
76
83
  case "n32le": return BigInt(dv.getUint32(0, true));
77
- case "n64": return dv.getBigUint64(0);
78
- case "n64le": return dv.getBigUint64(0, true);
79
84
  default: throw new Error(`${encoding} encoding not supported`);
80
85
  }
81
86
  };
82
87
  const typeIntegerOrArray = Type.union(Type.Integer, Type.arrayType([Type.Integer]));
83
- const typeAggregator = Type.functionType(Type.Integer, [typeIntegerOrArray], true);
84
- const funcSum = new Constant((...values) => BigInt.asIntN(64, values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
85
- const funcMin = new Constant((...values) => BigInt.asIntN(64, values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
86
- const funcMax = new Constant((...values) => BigInt.asIntN(64, values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
87
- const funcRandomInteger = new Constant((value) => value == null ? undefined : BigInt.asIntN(64, BigInt(Math.floor(Math.random() * Number(value)))), Type.functionType(Type.Integer, [Type.Integer]), false);
88
+ const typeAggregator = Type.functionType(Type.Integer, [Type.arrayType([typeIntegerOrArray])], true);
89
+ const funcSum = new Constant((values) => boundInteger(values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
90
+ const funcMin = new Constant((values) => boundInteger(values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
91
+ const funcMax = new Constant((values) => boundInteger(values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
92
+ const funcRandomInteger = new Constant((value) => value == null ? undefined : boundInteger(BigInt(Math.floor(Math.random() * Number(value)))), Type.functionType(Type.Integer, [Type.Integer]), false);
88
93
  const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalInteger, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
89
94
  const funcParseInteger = new Constant((value) => {
90
95
  try {
91
- return value ? BigInt.asIntN(64, BigInt(value)) : undefined;
96
+ return value ? boundInteger(BigInt(value)) : undefined;
92
97
  }
93
98
  catch { }
94
99
  return undefined;
95
100
  }, Type.functionType(Type.OptionalInteger, [Type.OptionalString]));
101
+ export const funcInteger = new Constant((value) => createInteger(Number(value)) ?? 0n, Type.union(Type.functionType(Type.Integer, [Type.Boolean]), Type.functionType(Type.Integer, [Type.Timestamp]), Type.functionType(Type.Integer, [Type.Float])));
96
102
  export const constInteger = Object.assign(Object.create(null), {
97
103
  Sum: funcSum,
98
104
  Min: funcMin,
@@ -2,7 +2,8 @@ import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  import { containsBuffer } from "./Buffer.js";
4
4
  import { containsString } from "./String.js";
5
- export const funcLength = new Constant((value) => BigInt.asIntN(64, BigInt(value == null
5
+ import { boundInteger } from "./Integer.js";
6
+ export const funcLength = new Constant((value) => boundInteger(BigInt(value == null
6
7
  ? 0
7
8
  : value instanceof ArrayBuffer
8
9
  ? value.byteLength
@@ -20,6 +20,3 @@ export declare const funcModulo: Constant;
20
20
  export declare const funcPower: Constant;
21
21
  export declare const funcRoot: Constant;
22
22
  export declare const funcNegate: Constant;
23
- export declare const funcCast: Constant;
24
- export declare const funcCastToFloat: Constant;
25
- export declare const funcCastToInteger: Constant;
@@ -1,5 +1,6 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
+ import { boundInteger } from "./Integer.js";
3
4
  export const formatNumber = (value, formatting) => {
4
5
  if (formatting) {
5
6
  const nformat = JSON.parse(`{${formatting}}`);
@@ -18,18 +19,6 @@ export const formatNumber = (value, formatting) => {
18
19
  ? `${value.toString()}.0`
19
20
  : value.toString();
20
21
  };
21
- const castToInteger = (value) => {
22
- if (value == null || Number.isNaN(value)) {
23
- return 0n;
24
- }
25
- if (value === Number.NEGATIVE_INFINITY) {
26
- return -0x8000000000000000n;
27
- }
28
- if (value === Number.POSITIVE_INFINITY) {
29
- return 0x7fffffffffffffffn;
30
- }
31
- return BigInt.asIntN(64, BigInt(Math.trunc(value)));
32
- };
33
22
  const typeComparator = Type.functionType(Type.Boolean, [Type.Number, Type.Number]);
34
23
  const typeOperator = Type.union(Type.functionType(Type.Float, [Type.Float, Type.Integer]), Type.functionType(Type.Float, [Type.Integer, Type.Float]), Type.functionType(Type.Integer, [Type.Integer, Type.Integer]));
35
24
  export const funcGreaterThan = new Constant((value1, value2) => value1 > value2, typeComparator);
@@ -37,40 +26,41 @@ export const funcLessThan = new Constant((value1, value2) => value1 < value2, ty
37
26
  export const funcGreaterOrEqual = new Constant((value1, value2) => value1 >= value2, typeComparator);
38
27
  export const funcLessOrEqual = new Constant((value1, value2) => value1 <= value2, typeComparator);
39
28
  export const funcSubtract = new Constant((value, subtrahend) => typeof value === "bigint" && typeof subtrahend === "bigint"
40
- ? BigInt.asIntN(64, value - subtrahend)
29
+ ? boundInteger(value - subtrahend)
41
30
  : Number(value) - Number(subtrahend), typeOperator);
42
31
  export const funcMultiply = new Constant((value1, value2) => typeof value1 === "bigint" && typeof value2 === "bigint"
43
- ? BigInt.asIntN(64, value1 * value2)
32
+ ? boundInteger(value1 * value2)
44
33
  : Number(value1) * Number(value2), typeOperator);
45
34
  export const funcDivide = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
46
- ? BigInt.asIntN(64, value / divisor)
35
+ ? boundInteger(value / divisor)
47
36
  : Number(value) / Number(divisor), typeOperator);
48
37
  export const funcRemainder = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
49
- ? BigInt.asIntN(64, value % divisor)
38
+ ? boundInteger(value % divisor)
50
39
  : Number(value) % Number(divisor), typeOperator);
51
40
  export const funcModulo = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
52
- ? BigInt.asIntN(64, (value % divisor + divisor) % divisor)
41
+ ? boundInteger((value % divisor + divisor) % divisor)
53
42
  : (Number(value) % Number(divisor) + Number(divisor)) % Number(divisor), typeOperator);
54
43
  export const funcPower = new Constant((value, exponent) => typeof value === "bigint" && typeof exponent === "bigint"
55
- ? BigInt.asIntN(64, value ** BigInt(exponent))
44
+ ? boundInteger(value ** BigInt(exponent))
56
45
  : Number(value) ** Number(exponent), typeOperator);
57
46
  export const funcRoot = new Constant((value, exponent) => {
58
47
  if (typeof value === "bigint" && typeof exponent === "bigint") {
59
- const e = BigInt(exponent);
60
- if (value < 0n && e % 2n === 0n) {
48
+ const v = boundInteger(value);
49
+ const e = boundInteger(exponent);
50
+ if (v < 0n && e % 2n === 0n) {
61
51
  return undefined;
62
52
  }
63
- if (value < 2n || e === 1n) {
64
- return value;
53
+ if (v <= 1n || e === 1n) {
54
+ return v;
65
55
  }
66
- let low = 0n, high = value, result = 0n;
56
+ let low = 0n, high = v, result = 0n;
67
57
  while (low <= high) {
68
58
  const mid = low + high >> 1n;
69
59
  const midPow = mid ** e;
70
- if (midPow === value) {
60
+ if (midPow === v) {
71
61
  return mid;
72
62
  }
73
- else if (midPow < value) {
63
+ else if (midPow < v) {
74
64
  result = mid;
75
65
  low = mid + 1n;
76
66
  }
@@ -78,13 +68,8 @@ export const funcRoot = new Constant((value, exponent) => {
78
68
  high = mid - 1n;
79
69
  }
80
70
  }
81
- return BigInt.asIntN(64, result);
71
+ return result;
82
72
  }
83
73
  return Math.pow(Number(value), 1 / Number(exponent));
84
74
  }, typeOperator);
85
- export const funcNegate = new Constant((value) => value == null ? undefined : typeof value === "number" ? -value : BigInt.asIntN(64, -value), Type.union(Type.functionType(Type.Float, [Type.Float]), Type.functionType(Type.Integer, [Type.Integer])));
86
- export const funcCast = new Constant((value) => typeof value !== "number"
87
- ? Number(value)
88
- : castToInteger(value), Type.union(Type.functionType(Type.Float, [Type.Integer]), Type.functionType(Type.Integer, [Type.Float])));
89
- export const funcCastToFloat = new Constant((value) => Number(value), Type.functionType(Type.Float, [Type.Integer]));
90
- export const funcCastToInteger = new Constant((value) => castToInteger(value), Type.functionType(Type.Integer, [Type.Float]));
75
+ export const funcNegate = new Constant((value) => value == null ? undefined : typeof value === "number" ? -value : boundInteger(-value), Type.union(Type.functionType(Type.Float, [Type.Float]), Type.functionType(Type.Integer, [Type.Integer])));