@jplorg/jpl 1.5.0 → 2.1.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 (320) hide show
  1. package/dist/esm/main.js +3474 -0
  2. package/dist/types/applyDefaults.d.ts +2 -0
  3. package/dist/types/builtins/funcContains.d.ts +3 -0
  4. package/dist/types/builtins/funcEndsWith.d.ts +3 -0
  5. package/dist/types/builtins/funcError.d.ts +3 -0
  6. package/dist/types/builtins/funcFromJSON.d.ts +3 -0
  7. package/dist/types/builtins/funcHas.d.ts +3 -0
  8. package/dist/types/builtins/funcIn.d.ts +3 -0
  9. package/dist/types/builtins/funcKeys.d.ts +3 -0
  10. package/dist/types/builtins/funcLength.d.ts +3 -0
  11. package/dist/types/builtins/funcNow.d.ts +3 -0
  12. package/dist/types/builtins/funcStartsWith.d.ts +3 -0
  13. package/dist/types/builtins/funcToJSON.d.ts +3 -0
  14. package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
  15. package/dist/types/builtins/funcToNumber.d.ts +3 -0
  16. package/dist/types/builtins/funcToString.d.ts +3 -0
  17. package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
  18. package/dist/types/builtins/funcTrim.d.ts +3 -0
  19. package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
  20. package/dist/types/builtins/funcTrimStart.d.ts +3 -0
  21. package/dist/types/builtins/funcType.d.ts +3 -0
  22. package/dist/types/builtins/funcVoid.d.ts +3 -0
  23. package/dist/types/builtins/index.d.ts +2 -0
  24. package/dist/types/builtins/internals.d.ts +1 -0
  25. package/dist/types/builtins/math.d.ts +17 -0
  26. package/dist/types/createSingleton.d.ts +1 -0
  27. package/dist/types/interpreter/index.d.ts +21 -0
  28. package/dist/types/interpreter/parse.d.ts +194 -0
  29. package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
  30. package/dist/types/interpreter/system.d.ts +3 -0
  31. package/dist/types/interpreter/util.d.ts +89 -0
  32. package/dist/types/library/apply.d.ts +32 -0
  33. package/dist/types/library/definition.d.ts +79 -0
  34. package/dist/types/library/errors/adaptErrors.d.ts +6 -0
  35. package/dist/types/library/errors/enclosure.d.ts +6 -0
  36. package/dist/types/library/errors/error.d.ts +6 -0
  37. package/dist/types/library/errors/execution.d.ts +12 -0
  38. package/dist/types/library/errors/fatal.d.ts +4 -0
  39. package/dist/types/library/errors/runtime.d.ts +46 -0
  40. package/dist/types/library/errors/syntax.d.ts +7 -0
  41. package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
  42. package/dist/types/library/index.d.ts +18 -0
  43. package/dist/types/library/mux.d.ts +19 -0
  44. package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
  45. package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
  46. package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
  47. package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
  48. package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
  49. package/dist/types/library/runtimeScope.d.ts +23 -0
  50. package/dist/types/library/runtimeSignal.d.ts +25 -0
  51. package/dist/types/library/types.d.ts +97 -0
  52. package/dist/types/main.d.ts +19 -0
  53. package/dist/types/program/handler.d.ts +12 -0
  54. package/dist/types/program/index.d.ts +40 -0
  55. package/dist/types/program/ops/index.d.ts +5 -0
  56. package/dist/types/program/ops/opAccess/index.d.ts +11 -0
  57. package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
  58. package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
  59. package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
  60. package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
  61. package/dist/types/program/ops/opAnd.d.ts +11 -0
  62. package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
  63. package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
  64. package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
  65. package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
  66. package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
  67. package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
  68. package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
  69. package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
  70. package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
  71. package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
  72. package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
  73. package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
  74. package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
  75. package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
  76. package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
  77. package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
  78. package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
  79. package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
  80. package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
  81. package/dist/types/program/ops/opComparison/index.d.ts +11 -0
  82. package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
  83. package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
  84. package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
  85. package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
  86. package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
  87. package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
  88. package/dist/types/program/ops/opConstant.d.ts +11 -0
  89. package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
  90. package/dist/types/program/ops/opConstantNull.d.ts +11 -0
  91. package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
  92. package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
  93. package/dist/types/program/ops/opIf.d.ts +11 -0
  94. package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
  95. package/dist/types/program/ops/opNegation.d.ts +11 -0
  96. package/dist/types/program/ops/opNot.d.ts +11 -0
  97. package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
  98. package/dist/types/program/ops/opNumber.d.ts +11 -0
  99. package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
  100. package/dist/types/program/ops/opOr.d.ts +11 -0
  101. package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
  102. package/dist/types/program/ops/opString.d.ts +11 -0
  103. package/dist/types/program/ops/opTry.d.ts +11 -0
  104. package/dist/types/program/ops/opVariable.d.ts +11 -0
  105. package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
  106. package/dist/types/program/ops/opVoid.d.ts +11 -0
  107. package/dist/types/program/ops/utils.d.ts +5 -0
  108. package/dist/types/program/params.d.ts +68 -0
  109. package/dist/types/runtime/index.d.ts +83 -0
  110. package/package.json +66 -49
  111. package/{repl.js → repl.ts} +85 -39
  112. package/lib/applyDefaults.js +0 -34
  113. package/lib/builtins/funcContains.js +0 -25
  114. package/lib/builtins/funcEndsWith.js +0 -21
  115. package/lib/builtins/funcError.js +0 -11
  116. package/lib/builtins/funcFromJSON.js +0 -26
  117. package/lib/builtins/funcHas.js +0 -24
  118. package/lib/builtins/funcIn.js +0 -24
  119. package/lib/builtins/funcKeys.js +0 -20
  120. package/lib/builtins/funcLength.js +0 -24
  121. package/lib/builtins/funcNow.js +0 -10
  122. package/lib/builtins/funcStartsWith.js +0 -21
  123. package/lib/builtins/funcToJSON.js +0 -10
  124. package/lib/builtins/funcToLowerCase.js +0 -17
  125. package/lib/builtins/funcToNumber.js +0 -26
  126. package/lib/builtins/funcToString.js +0 -10
  127. package/lib/builtins/funcToUpperCase.js +0 -17
  128. package/lib/builtins/funcTrim.js +0 -17
  129. package/lib/builtins/funcTrimEnd.js +0 -17
  130. package/lib/builtins/funcTrimStart.js +0 -17
  131. package/lib/builtins/funcType.js +0 -10
  132. package/lib/builtins/funcVoid.js +0 -10
  133. package/lib/builtins/index.js +0 -205
  134. package/lib/builtins/internals.js +0 -8
  135. package/lib/builtins/math.js +0 -40
  136. package/lib/builtins/native.js +0 -180
  137. package/lib/createSingleton.js +0 -14
  138. package/lib/index.js +0 -79
  139. package/lib/interpreter/index.js +0 -56
  140. package/lib/interpreter/parse.js +0 -2377
  141. package/lib/interpreter/parseFunction.js +0 -24
  142. package/lib/interpreter/system.js +0 -10
  143. package/lib/interpreter/util.js +0 -349
  144. package/lib/library/apply.js +0 -142
  145. package/lib/library/definition.js +0 -9
  146. package/lib/library/errors/adaptErrors.js +0 -34
  147. package/lib/library/errors/enclosure.js +0 -16
  148. package/lib/library/errors/error.js +0 -18
  149. package/lib/library/errors/execution.js +0 -20
  150. package/lib/library/errors/fatal.js +0 -15
  151. package/lib/library/errors/runtime.js +0 -78
  152. package/lib/library/errors/syntax.js +0 -17
  153. package/lib/library/functions.js +0 -82
  154. package/lib/library/index.js +0 -335
  155. package/lib/library/mux.js +0 -106
  156. package/lib/library/ops/index.js +0 -60
  157. package/lib/library/ops/op.js +0 -180
  158. package/lib/library/ops/opa.js +0 -41
  159. package/lib/library/ops/opc.js +0 -59
  160. package/lib/library/ops/opm.js +0 -50
  161. package/lib/library/ops/opu.js +0 -77
  162. package/lib/library/runtimeScope.js +0 -38
  163. package/lib/library/runtimeSignal.js +0 -72
  164. package/lib/library/types.js +0 -304
  165. package/lib/program/index.js +0 -101
  166. package/lib/program/ops/index.js +0 -61
  167. package/lib/program/ops/opAccess/index.js +0 -55
  168. package/lib/program/ops/opAccess/opaField.js +0 -50
  169. package/lib/program/ops/opAccess/opaFunction.js +0 -50
  170. package/lib/program/ops/opAccess/opaIter.js +0 -31
  171. package/lib/program/ops/opAccess/opaSlice.js +0 -44
  172. package/lib/program/ops/opAnd.js +0 -30
  173. package/lib/program/ops/opArrayConstructor.js +0 -20
  174. package/lib/program/ops/opAssignment/index.js +0 -90
  175. package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
  176. package/lib/program/ops/opAssignment/opaAssignIter.js +0 -69
  177. package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -99
  178. package/lib/program/ops/opAssignment/opuAddition.js +0 -31
  179. package/lib/program/ops/opAssignment/opuDivision.js +0 -31
  180. package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
  181. package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
  182. package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
  183. package/lib/program/ops/opAssignment/opuSet.js +0 -19
  184. package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
  185. package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
  186. package/lib/program/ops/opCalculation/index.js +0 -57
  187. package/lib/program/ops/opCalculation/opmAddition.js +0 -49
  188. package/lib/program/ops/opCalculation/opmDivision.js +0 -42
  189. package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
  190. package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
  191. package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
  192. package/lib/program/ops/opComparison/index.js +0 -59
  193. package/lib/program/ops/opComparison/opcEqual.js +0 -19
  194. package/lib/program/ops/opComparison/opcGreater.js +0 -19
  195. package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
  196. package/lib/program/ops/opComparison/opcLess.js +0 -19
  197. package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
  198. package/lib/program/ops/opComparison/opcUnequal.js +0 -19
  199. package/lib/program/ops/opConstant.js +0 -18
  200. package/lib/program/ops/opConstantFalse.js +0 -16
  201. package/lib/program/ops/opConstantNull.js +0 -16
  202. package/lib/program/ops/opConstantTrue.js +0 -16
  203. package/lib/program/ops/opFunctionDefinition.js +0 -21
  204. package/lib/program/ops/opIf.js +0 -38
  205. package/lib/program/ops/opInterpolatedString.js +0 -24
  206. package/lib/program/ops/opNegation.js +0 -25
  207. package/lib/program/ops/opNot.js +0 -16
  208. package/lib/program/ops/opNullCoalescence.js +0 -34
  209. package/lib/program/ops/opNumber.js +0 -18
  210. package/lib/program/ops/opObjectConstructor.js +0 -37
  211. package/lib/program/ops/opOr.js +0 -30
  212. package/lib/program/ops/opOutputConcat.js +0 -19
  213. package/lib/program/ops/opString.js +0 -18
  214. package/lib/program/ops/opTry.js +0 -37
  215. package/lib/program/ops/opVariable.js +0 -20
  216. package/lib/program/ops/opVariableDefinition.js +0 -24
  217. package/lib/program/ops/opVoid.js +0 -16
  218. package/lib/program/ops/utils.js +0 -35
  219. package/lib/runtime/index.js +0 -258
  220. package/src/applyDefaults.js +0 -35
  221. package/src/builtins/funcContains.js +0 -27
  222. package/src/builtins/funcEndsWith.js +0 -21
  223. package/src/builtins/funcError.js +0 -7
  224. package/src/builtins/funcFromJSON.js +0 -24
  225. package/src/builtins/funcHas.js +0 -25
  226. package/src/builtins/funcIn.js +0 -25
  227. package/src/builtins/funcKeys.js +0 -20
  228. package/src/builtins/funcLength.js +0 -26
  229. package/src/builtins/funcNow.js +0 -5
  230. package/src/builtins/funcStartsWith.js +0 -21
  231. package/src/builtins/funcToJSON.js +0 -5
  232. package/src/builtins/funcToLowerCase.js +0 -20
  233. package/src/builtins/funcToNumber.js +0 -25
  234. package/src/builtins/funcToString.js +0 -5
  235. package/src/builtins/funcToUpperCase.js +0 -20
  236. package/src/builtins/funcTrim.js +0 -16
  237. package/src/builtins/funcTrimEnd.js +0 -16
  238. package/src/builtins/funcTrimStart.js +0 -16
  239. package/src/builtins/funcType.js +0 -5
  240. package/src/builtins/funcVoid.js +0 -5
  241. package/src/builtins/index.js +0 -193
  242. package/src/builtins/internals.js +0 -9
  243. package/src/builtins/math.js +0 -44
  244. package/src/createSingleton.js +0 -9
  245. package/src/index.js +0 -44
  246. package/src/interpreter/index.js +0 -48
  247. package/src/interpreter/parse.js +0 -1473
  248. package/src/interpreter/system.js +0 -5
  249. package/src/interpreter/util.js +0 -237
  250. package/src/library/apply.js +0 -135
  251. package/src/library/definition.js +0 -3
  252. package/src/library/errors/adaptErrors.js +0 -28
  253. package/src/library/errors/enclosure.js +0 -11
  254. package/src/library/errors/error.js +0 -14
  255. package/src/library/errors/execution.js +0 -15
  256. package/src/library/errors/fatal.js +0 -10
  257. package/src/library/errors/runtime.js +0 -71
  258. package/src/library/errors/syntax.js +0 -12
  259. package/src/library/index.js +0 -41
  260. package/src/library/mux.js +0 -98
  261. package/src/library/runtimeScope.js +0 -35
  262. package/src/library/runtimeSignal.js +0 -67
  263. package/src/library/types.js +0 -299
  264. package/src/program/index.js +0 -114
  265. package/src/program/ops/index.js +0 -82
  266. package/src/program/ops/opAccess/index.js +0 -55
  267. package/src/program/ops/opAccess/opaField.js +0 -58
  268. package/src/program/ops/opAccess/opaFunction.js +0 -52
  269. package/src/program/ops/opAccess/opaIter.js +0 -31
  270. package/src/program/ops/opAccess/opaSlice.js +0 -58
  271. package/src/program/ops/opAnd.js +0 -32
  272. package/src/program/ops/opArrayConstructor.js +0 -16
  273. package/src/program/ops/opAssignment/index.js +0 -102
  274. package/src/program/ops/opAssignment/opaAssignField.js +0 -156
  275. package/src/program/ops/opAssignment/opaAssignIter.js +0 -74
  276. package/src/program/ops/opAssignment/opaAssignSlice.js +0 -157
  277. package/src/program/ops/opAssignment/opuAddition.js +0 -29
  278. package/src/program/ops/opAssignment/opuDivision.js +0 -29
  279. package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
  280. package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
  281. package/src/program/ops/opAssignment/opuRemainder.js +0 -29
  282. package/src/program/ops/opAssignment/opuSet.js +0 -15
  283. package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
  284. package/src/program/ops/opAssignment/opuUpdate.js +0 -15
  285. package/src/program/ops/opCalculation/index.js +0 -64
  286. package/src/program/ops/opCalculation/opmAddition.js +0 -63
  287. package/src/program/ops/opCalculation/opmDivision.js +0 -47
  288. package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
  289. package/src/program/ops/opCalculation/opmRemainder.js +0 -49
  290. package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
  291. package/src/program/ops/opComparison/index.js +0 -67
  292. package/src/program/ops/opComparison/opcEqual.js +0 -17
  293. package/src/program/ops/opComparison/opcGreater.js +0 -17
  294. package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
  295. package/src/program/ops/opComparison/opcLess.js +0 -17
  296. package/src/program/ops/opComparison/opcLessEqual.js +0 -17
  297. package/src/program/ops/opComparison/opcUnequal.js +0 -17
  298. package/src/program/ops/opConstant.js +0 -13
  299. package/src/program/ops/opConstantFalse.js +0 -11
  300. package/src/program/ops/opConstantNull.js +0 -11
  301. package/src/program/ops/opConstantTrue.js +0 -11
  302. package/src/program/ops/opFunctionDefinition.js +0 -17
  303. package/src/program/ops/opIf.js +0 -44
  304. package/src/program/ops/opInterpolatedString.js +0 -27
  305. package/src/program/ops/opNegation.js +0 -26
  306. package/src/program/ops/opNot.js +0 -11
  307. package/src/program/ops/opNullCoalescence.js +0 -36
  308. package/src/program/ops/opNumber.js +0 -13
  309. package/src/program/ops/opObjectConstructor.js +0 -40
  310. package/src/program/ops/opOr.js +0 -32
  311. package/src/program/ops/opOutputConcat.js +0 -17
  312. package/src/program/ops/opString.js +0 -13
  313. package/src/program/ops/opTry.js +0 -38
  314. package/src/program/ops/opVariable.js +0 -17
  315. package/src/program/ops/opVariableDefinition.js +0 -18
  316. package/src/program/ops/opVoid.js +0 -11
  317. package/src/program/ops/utils.js +0 -19
  318. package/src/runtime/index.js +0 -309
  319. /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
  320. /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
@@ -1,157 +0,0 @@
1
- import { JPLTypeError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- function shallowCompareArrays(a, b) {
5
- if (a.length !== b.length) return false;
6
- return a.every((v, i) => v === b[i]);
7
- }
8
-
9
- export default {
10
- /** { from: [op], to: [op], optional: boolean } */
11
- async op(runtime, input, target, params, scope, next) {
12
- const [froms, tos] = await Promise.all([
13
- runtime.executeInstructions(params.from ?? [], [input], scope),
14
- runtime.executeInstructions(params.to ?? [], [input], scope),
15
- ]);
16
-
17
- const ranges = runtime.muxOne(
18
- [runtime.unwrapValues(froms), runtime.unwrapValues(tos)],
19
- (from, to) => [from, to],
20
- );
21
-
22
- const iter = async (from, source) => {
23
- // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
24
- await undefined;
25
-
26
- scope.signal.checkHealth();
27
-
28
- if (from >= ranges.length) return [source];
29
-
30
- const v = runtime.unwrapValue(source);
31
- const tv = runtime.type(source);
32
- const [start, end] = ranges[from];
33
- const ts = runtime.type(start);
34
- const te = runtime.type(end);
35
- switch (tv) {
36
- case 'array':
37
- if (['number', 'null'].includes(ts) && ['number', 'null'].includes(te)) {
38
- return runtime.muxAll(
39
- [await next(v.slice(Math.trunc(start ?? 0), Math.trunc(end ?? v.length)))],
40
- async (output) => {
41
- if (output === undefined) return iter(from + 1, source);
42
- return iter(
43
- from + 1,
44
- await runtime.alterValue(source, (value) => {
45
- const result = runtime.unwrapValue(output);
46
- const tr = runtime.type(result);
47
- switch (tr) {
48
- case 'null':
49
- case 'array': {
50
- let s = Math.trunc(start ?? 0);
51
- let e = Math.trunc(end ?? value.length);
52
- s = s >= 0 ? Math.min(value.length, s) : Math.max(0, value.length + s);
53
- e = Math.max(
54
- s,
55
- e >= 0 ? Math.min(value.length, e) : Math.max(0, value.length + e),
56
- );
57
- if (shallowCompareArrays(value.slice(s, e), result ?? [])) return value;
58
- const c = [...value];
59
- c.splice(s, e - s, ...(result ?? []));
60
- return c;
61
- }
62
-
63
- default:
64
- }
65
-
66
- throw new JPLTypeError(
67
- 'cannot assign %s (%*<100v) to slice of %s (%*<100v)',
68
- tr,
69
- result,
70
- tv,
71
- value,
72
- );
73
- }),
74
- );
75
- },
76
- );
77
- }
78
- break;
79
-
80
- case 'string':
81
- if (['number', 'null'].includes(ts) && ['number', 'null'].includes(te)) {
82
- const chars = [...v];
83
- return runtime.muxAll(
84
- [
85
- await next(
86
- chars.slice(Math.trunc(start ?? 0), Math.trunc(end ?? chars.length)).join(''),
87
- ),
88
- ],
89
- async (output) => {
90
- if (output === undefined) return iter(from + 1, source);
91
- return iter(
92
- from + 1,
93
- await runtime.alterValue(source, (value) => {
94
- const result = runtime.unwrapValue(output);
95
- const tr = runtime.type(result);
96
- switch (tr) {
97
- case 'null':
98
- case 'string': {
99
- const chars = [...value];
100
- let s = Math.trunc(start ?? 0);
101
- let e = Math.trunc(end ?? chars.length);
102
- s = s >= 0 ? Math.min(chars.length, s) : Math.max(0, chars.length + s);
103
- e = Math.max(
104
- s,
105
- e >= 0 ? Math.min(chars.length, e) : Math.max(0, chars.length + e),
106
- );
107
- if (shallowCompareArrays(chars.slice(s, e), result ?? [])) return value;
108
- chars.splice(s, e - s, ...(result ?? []));
109
- return chars.join('');
110
- }
111
-
112
- default:
113
- }
114
-
115
- throw new JPLTypeError(
116
- 'cannot assign %s (%*<100v) to slice of %s (%*<100v)',
117
- tr,
118
- result,
119
- tv,
120
- value,
121
- );
122
- }),
123
- );
124
- },
125
- );
126
- }
127
- break;
128
-
129
- default:
130
- }
131
-
132
- if (params.optional) return iter(from + 1, source);
133
- throw new JPLTypeError(
134
- 'cannot slice %s (%*<100v) with %s (%*<100v) and %s (%*<100v) (assignment)',
135
- tv,
136
- v,
137
- ts,
138
- start,
139
- te,
140
- end,
141
- );
142
- };
143
-
144
- return runtime.muxOne([await iter(0, target)], (output) =>
145
- runtime.type(output) === 'null' ? undefined : output,
146
- );
147
- },
148
-
149
- /** { from: function, to: function, optional: boolean } */
150
- map(runtime, params) {
151
- return {
152
- from: call(params.from),
153
- to: call(params.to),
154
- optional: runtime.assertType(params.optional, 'boolean'),
155
- };
156
- },
157
- };
@@ -1,29 +0,0 @@
1
- import { OPM_ADDITION, OP_CALCULATION } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_CALCULATION,
11
- params: {
12
- pipe: constant(target),
13
- operations: [{ op: OPM_ADDITION, params: { by: params.pipe ?? [] } }],
14
- },
15
- },
16
- ],
17
- [input],
18
- scope,
19
- next,
20
- );
21
- },
22
-
23
- /** { pipe: function } */
24
- map(runtime, params) {
25
- return {
26
- pipe: call(params.pipe),
27
- };
28
- },
29
- };
@@ -1,29 +0,0 @@
1
- import { OPM_DIVISION, OP_CALCULATION } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_CALCULATION,
11
- params: {
12
- pipe: constant(target),
13
- operations: [{ op: OPM_DIVISION, params: { by: params.pipe ?? [] } }],
14
- },
15
- },
16
- ],
17
- [input],
18
- scope,
19
- next,
20
- );
21
- },
22
-
23
- /** { pipe: function } */
24
- map(runtime, params) {
25
- return {
26
- pipe: call(params.pipe),
27
- };
28
- },
29
- };
@@ -1,29 +0,0 @@
1
- import { OPM_MULTIPLICATION, OP_CALCULATION } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_CALCULATION,
11
- params: {
12
- pipe: constant(target),
13
- operations: [{ op: OPM_MULTIPLICATION, params: { by: params.pipe ?? [] } }],
14
- },
15
- },
16
- ],
17
- [input],
18
- scope,
19
- next,
20
- );
21
- },
22
-
23
- /** { pipe: function } */
24
- map(runtime, params) {
25
- return {
26
- pipe: call(params.pipe),
27
- };
28
- },
29
- };
@@ -1,26 +0,0 @@
1
- import { OP_NULL_COALESCENCE } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_NULL_COALESCENCE,
11
- params: { pipes: [constant(target), params.pipe ?? []] },
12
- },
13
- ],
14
- [input],
15
- scope,
16
- next,
17
- );
18
- },
19
-
20
- /** { pipe: function } */
21
- map(runtime, params) {
22
- return {
23
- pipe: call(params.pipe),
24
- };
25
- },
26
- };
@@ -1,29 +0,0 @@
1
- import { OPM_REMAINDER, OP_CALCULATION } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_CALCULATION,
11
- params: {
12
- pipe: constant(target),
13
- operations: [{ op: OPM_REMAINDER, params: { by: params.pipe ?? [] } }],
14
- },
15
- },
16
- ],
17
- [input],
18
- scope,
19
- next,
20
- );
21
- },
22
-
23
- /** { pipe: function } */
24
- map(runtime, params) {
25
- return {
26
- pipe: call(params.pipe),
27
- };
28
- },
29
- };
@@ -1,15 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { pipe: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, next);
7
- },
8
-
9
- /** { pipe: function } */
10
- map(runtime, params) {
11
- return {
12
- pipe: call(params.pipe),
13
- };
14
- },
15
- };
@@ -1,29 +0,0 @@
1
- import { OPM_SUBTRACTION, OP_CALCULATION } from '../../../library';
2
- import { call, constant } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(
8
- [
9
- {
10
- op: OP_CALCULATION,
11
- params: {
12
- pipe: constant(target),
13
- operations: [{ op: OPM_SUBTRACTION, params: { by: params.pipe ?? [] } }],
14
- },
15
- },
16
- ],
17
- [input],
18
- scope,
19
- next,
20
- );
21
- },
22
-
23
- /** { pipe: function } */
24
- map(runtime, params) {
25
- return {
26
- pipe: call(params.pipe),
27
- };
28
- },
29
- };
@@ -1,15 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { pipe: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.pipe ?? [], [target], scope, next);
7
- },
8
-
9
- /** { pipe: function } */
10
- map(runtime, params) {
11
- return {
12
- pipe: call(params.pipe),
13
- };
14
- },
15
- };
@@ -1,64 +0,0 @@
1
- import {
2
- JPLFatalError,
3
- OPM_ADDITION,
4
- OPM_DIVISION,
5
- OPM_MULTIPLICATION,
6
- OPM_REMAINDER,
7
- OPM_SUBTRACTION,
8
- } from '../../../library';
9
- import { call } from '../utils';
10
- import opmAddition from './opmAddition';
11
- import opmDivision from './opmDivision';
12
- import opmMultiplication from './opmMultiplication';
13
- import opmRemainder from './opmRemainder';
14
- import opmSubtraction from './opmSubtraction';
15
-
16
- export default {
17
- /** { pipe: [op], operations: [opm] } */
18
- op(runtime, input, params, scope, next) {
19
- const iter = async (from, value) => {
20
- // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
21
- await undefined;
22
-
23
- scope.signal.checkHealth();
24
-
25
- if (from >= (params.operations?.length ?? 0)) return next(value, scope);
26
-
27
- const { op, params: opParams } = params.operations[from];
28
- const operator = opms[op];
29
- if (!operator) throw new JPLFatalError(`invalid OPM '${op}'`);
30
-
31
- return operator.op(runtime, input, value, opParams ?? {}, scope, (output) =>
32
- iter(from + 1, output),
33
- );
34
- };
35
-
36
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) =>
37
- iter(0, output),
38
- );
39
- },
40
-
41
- /** { pipe: function, operations: [opm] } */
42
- map(runtime, params) {
43
- return {
44
- pipe: call(params.pipe),
45
- operations: runtime.muxOne([params.operations], ({ op, params: opParams }) => {
46
- const operator = opms[op];
47
- if (!operator) throw new JPLFatalError(`invalid OPM '${op}'`);
48
-
49
- return {
50
- op: runtime.assertType(op, 'string'),
51
- params: operator.map(runtime, opParams),
52
- };
53
- }),
54
- };
55
- },
56
- };
57
-
58
- const opms = {
59
- [OPM_ADDITION]: opmAddition,
60
- [OPM_DIVISION]: opmDivision,
61
- [OPM_MULTIPLICATION]: opmMultiplication,
62
- [OPM_REMAINDER]: opmRemainder,
63
- [OPM_SUBTRACTION]: opmSubtraction,
64
- };
@@ -1,63 +0,0 @@
1
- import { JPLTypeError, applyObject } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { by: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(params.by ?? [], [input], scope, async (by) =>
8
- next(
9
- await runtime.alterValue(target, (a) => {
10
- const b = runtime.unwrapValue(by);
11
-
12
- const ta = runtime.type(a);
13
- const tb = runtime.type(b);
14
-
15
- if (ta === 'null' || tb === 'null') {
16
- if (ta !== 'null') return a;
17
- if (tb !== 'null') return b;
18
- return null;
19
- }
20
-
21
- switch (ta) {
22
- case 'number':
23
- if (tb === 'number') return a + b;
24
- break;
25
-
26
- case 'array':
27
- if (tb === 'array') {
28
- if (b.length === 0) return a;
29
- if (a.length === 0) return b;
30
- return [...a, ...b];
31
- }
32
- break;
33
-
34
- case 'string':
35
- if (tb === 'string') return a + b;
36
- break;
37
-
38
- case 'object':
39
- if (tb === 'object') return applyObject(a, Object.entries(b));
40
- break;
41
-
42
- default:
43
- }
44
-
45
- throw new JPLTypeError(
46
- '%s (%*<100v) and %s (%*<100v) cannot be added together',
47
- ta,
48
- a,
49
- tb,
50
- b,
51
- );
52
- }),
53
- ),
54
- );
55
- },
56
-
57
- /** { by: function } */
58
- map(runtime, params) {
59
- return {
60
- by: call(params.by),
61
- };
62
- },
63
- };
@@ -1,47 +0,0 @@
1
- import { JPLTypeError, JPLZeroDivisionError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { by: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(params.by ?? [], [input], scope, async (by) =>
8
- next(
9
- await runtime.alterValue(target, (a) => {
10
- const b = runtime.unwrapValue(by);
11
-
12
- const ta = runtime.type(a);
13
- const tb = runtime.type(b);
14
-
15
- switch (ta) {
16
- case 'number':
17
- if (tb === 'number') {
18
- if (b === 0) {
19
- throw new JPLZeroDivisionError('%s (%*<100v) cannot be divided by zero', ta, a);
20
- }
21
- return a / b;
22
- }
23
- break;
24
-
25
- case 'string':
26
- if (tb === 'string') {
27
- if (b === '') return [...a];
28
- return a.split(b);
29
- }
30
- break;
31
-
32
- default:
33
- }
34
-
35
- throw new JPLTypeError('%s (%*<100v) cannot be divided by %s (%*<100v)', ta, a, tb, b);
36
- }),
37
- ),
38
- );
39
- },
40
-
41
- /** { by: function } */
42
- map(runtime, params) {
43
- return {
44
- by: call(params.by),
45
- };
46
- },
47
- };
@@ -1,52 +0,0 @@
1
- import { JPLTypeError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { by: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(params.by ?? [], [input], scope, async (by) =>
8
- next(
9
- await runtime.alterValue(target, (a) => {
10
- const b = runtime.unwrapValue(by);
11
-
12
- const ta = runtime.type(a);
13
- const tb = runtime.type(b);
14
-
15
- switch (ta) {
16
- case 'number':
17
- if (tb === 'number') return a * b;
18
- break;
19
-
20
- case 'string':
21
- if (tb === 'number') {
22
- if (b < 1) return null;
23
- return a.repeat(b);
24
- }
25
- break;
26
-
27
- case 'object':
28
- if (tb === 'object') return runtime.merge(a, b);
29
- break;
30
-
31
- default:
32
- }
33
-
34
- throw new JPLTypeError(
35
- '%s (%*<100v) and %s (%*<100v) cannot be multiplied together',
36
- ta,
37
- a,
38
- tb,
39
- b,
40
- );
41
- }),
42
- ),
43
- );
44
- },
45
-
46
- /** { by: function } */
47
- map(runtime, params) {
48
- return {
49
- by: call(params.by),
50
- };
51
- },
52
- };
@@ -1,49 +0,0 @@
1
- import { JPLTypeError, JPLZeroDivisionError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { by: [op] } */
6
- op(runtime, input, target, params, scope, next) {
7
- return runtime.executeInstructions(params.by ?? [], [input], scope, async (by) =>
8
- next(
9
- await runtime.alterValue(target, (a) => {
10
- const b = runtime.unwrapValue(by);
11
-
12
- const ta = runtime.type(a);
13
- const tb = runtime.type(b);
14
-
15
- switch (ta) {
16
- case 'number':
17
- if (tb === 'number') {
18
- if (b === 0)
19
- throw new JPLZeroDivisionError(
20
- '%s (%*<100v) cannot be divided by zero (remainder)',
21
- ta,
22
- a,
23
- );
24
- return a % b;
25
- }
26
- break;
27
-
28
- default:
29
- }
30
-
31
- throw new JPLTypeError(
32
- '%s (%*<100v) cannot be divided by %s (%*<100v) (remainder)',
33
- ta,
34
- a,
35
- tb,
36
- b,
37
- );
38
- }),
39
- ),
40
- );
41
- },
42
-
43
- /** { by: function } */
44
- map(runtime, params) {
45
- return {
46
- by: call(params.by),
47
- };
48
- },
49
- };