@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,72 +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
- switch (ta) {
16
- case 'number':
17
- if (tb === 'number') return a - b;
18
- break;
19
-
20
- case 'array':
21
- if (tb === 'array') {
22
- if (a.length === 0 || b.length === 0) return a;
23
- const filtered = a.filter((v) => !b.some((entry) => runtime.equals(v, entry)));
24
- return a.length === filtered.length ? a : filtered;
25
- }
26
- break;
27
-
28
- case 'string':
29
- if (tb === 'string') return a.replaceAll(b, '');
30
- break;
31
-
32
- case 'object':
33
- switch (tb) {
34
- case 'array': {
35
- if (b.length === 0) return a;
36
- return applyObject(
37
- a,
38
- Object.entries(a)
39
- .filter(([, v]) => b.some((entry) => runtime.equals(v, entry)))
40
- .map(([k]) => [k]),
41
- );
42
- }
43
-
44
- case 'string':
45
- return applyObject(a, [[b]]);
46
-
47
- default:
48
- }
49
- break;
50
-
51
- default:
52
- }
53
-
54
- throw new JPLTypeError(
55
- '%s (%*<100v) and %s (%*<100v) cannot be subtracted',
56
- ta,
57
- a,
58
- tb,
59
- b,
60
- );
61
- }),
62
- ),
63
- );
64
- },
65
-
66
- /** { by: function } */
67
- map(runtime, params) {
68
- return {
69
- by: call(params.by),
70
- };
71
- },
72
- };
@@ -1,67 +0,0 @@
1
- import {
2
- JPLFatalError,
3
- OPC_EQUAL,
4
- OPC_GREATER,
5
- OPC_GREATEREQUAL,
6
- OPC_LESS,
7
- OPC_LESSEQUAL,
8
- OPC_UNEQUAL,
9
- } from '../../../library';
10
- import { call } from '../utils';
11
- import opcEqual from './opcEqual';
12
- import opcGreater from './opcGreater';
13
- import opcGreaterEqual from './opcGreaterEqual';
14
- import opcLess from './opcLess';
15
- import opcLessEqual from './opcLessEqual';
16
- import opcUnequal from './opcUnequal';
17
-
18
- export default {
19
- /** { pipe: [op], comparisons: [opc] } */
20
- op(runtime, input, params, scope, next) {
21
- const iter = async (from, value) => {
22
- // 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.
23
- await undefined;
24
-
25
- scope.signal.checkHealth();
26
-
27
- if (from >= (params.comparisons?.length ?? 0)) return next(value, scope);
28
-
29
- const { op, params: opParams } = params.comparisons[from];
30
- const operator = opcs[op];
31
- if (!operator) throw new JPLFatalError(`invalid OPC '${op}'`);
32
-
33
- return operator.op(runtime, input, value, opParams ?? {}, scope, (output) =>
34
- iter(from + 1, output),
35
- );
36
- };
37
-
38
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) =>
39
- iter(0, output),
40
- );
41
- },
42
-
43
- /** { pipe: function, comparisons: [opc] } */
44
- map(runtime, params) {
45
- return {
46
- pipe: call(params.pipe),
47
- comparisons: runtime.muxOne([params.comparisons], ({ op, params: opParams }) => {
48
- const operator = opcs[op];
49
- if (!operator) throw new JPLFatalError(`invalid OPC '${op}'`);
50
-
51
- return {
52
- op: runtime.assertType(op, 'string'),
53
- params: operator.map(runtime, opParams),
54
- };
55
- }),
56
- };
57
- },
58
- };
59
-
60
- const opcs = {
61
- [OPC_EQUAL]: opcEqual,
62
- [OPC_GREATER]: opcGreater,
63
- [OPC_GREATEREQUAL]: opcGreaterEqual,
64
- [OPC_LESS]: opcLess,
65
- [OPC_LESSEQUAL]: opcLessEqual,
66
- [OPC_UNEQUAL]: opcUnequal,
67
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(runtime.equals(target, by)),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(runtime.compare(target, by) > 0),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(runtime.compare(target, by) >= 0),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(runtime.compare(target, by) < 0),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(runtime.compare(target, by) <= 0),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,17 +0,0 @@
1
- import { call } from '../utils';
2
-
3
- export default {
4
- /** { by: [op] } */
5
- op(runtime, input, target, params, scope, next) {
6
- return runtime.executeInstructions(params.by ?? [], [input], scope, (by) =>
7
- next(!runtime.equals(target, by)),
8
- );
9
- },
10
-
11
- /** { by: function } */
12
- map(runtime, params) {
13
- return {
14
- by: call(params.by),
15
- };
16
- },
17
- };
@@ -1,13 +0,0 @@
1
- export default {
2
- /** { value: any } */
3
- op(runtime, input, params, scope, next) {
4
- return next(params.value ?? null, scope);
5
- },
6
-
7
- /** { value: any } */
8
- map(runtime, params) {
9
- return {
10
- value: runtime.normalizeValue(params.value),
11
- };
12
- },
13
- };
@@ -1,11 +0,0 @@
1
- export default {
2
- /** {} */
3
- op(runtime, input, params, scope, next) {
4
- return next(false, scope);
5
- },
6
-
7
- /** {} */
8
- map() {
9
- return {};
10
- },
11
- };
@@ -1,11 +0,0 @@
1
- export default {
2
- /** {} */
3
- op(runtime, input, params, scope, next) {
4
- return next(null, scope);
5
- },
6
-
7
- /** {} */
8
- map() {
9
- return {};
10
- },
11
- };
@@ -1,11 +0,0 @@
1
- export default {
2
- /** {} */
3
- op(runtime, input, params, scope, next) {
4
- return next(true, scope);
5
- },
6
-
7
- /** {} */
8
- map() {
9
- return {};
10
- },
11
- };
@@ -1,17 +0,0 @@
1
- import { scopedFunction } from '../../library';
2
- import { call } from './utils';
3
-
4
- export default {
5
- /** { argNames: [string], pipe: [op] } */
6
- op(runtime, input, params, scope, next) {
7
- return next(scopedFunction(params.argNames ?? [], params.pipe ?? [], scope), scope);
8
- },
9
-
10
- /** { argNames: [string], pipe: function } */
11
- map(runtime, params) {
12
- return {
13
- argNames: runtime.muxOne([params.argNames], (entry) => runtime.assertType(entry, 'string')),
14
- pipe: call(params.pipe),
15
- };
16
- },
17
- };
@@ -1,44 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { ifs: [{ if: [op], then: [op] }], else: [op] } */
5
- op(runtime, input, params, scope, next) {
6
- const iter = async (from) => {
7
- // 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.
8
- await undefined;
9
-
10
- scope.signal.checkHealth();
11
-
12
- if (from >= (params.ifs?.length ?? 0)) {
13
- return runtime.executeInstructions(params.else ?? [], [input], scope, (output) =>
14
- next(output, scope),
15
- );
16
- }
17
-
18
- const condition = params.ifs[from];
19
-
20
- return runtime.executeInstructions(condition.if ?? [], [input], scope, (result) => {
21
- if (runtime.truthy(result)) {
22
- return runtime.executeInstructions(condition.then ?? [], [input], scope, (output) =>
23
- next(output, scope),
24
- );
25
- }
26
-
27
- return iter(from + 1);
28
- });
29
- };
30
-
31
- return iter(0);
32
- },
33
-
34
- /** { ifs: [{ if: function, then: function }], else: function } */
35
- map(runtime, params) {
36
- return {
37
- ifs: runtime.muxOne([params.ifs], (entry) => ({
38
- if: call(entry.if),
39
- then: call(entry.then),
40
- })),
41
- else: call(params.else),
42
- };
43
- },
44
- };
@@ -1,27 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { interpolations: [{ before: string, pipe: [op] }], after: string } */
5
- async op(runtime, input, params, scope, next) {
6
- const interpolations = await runtime.muxAsync([params.interpolations ?? []], (interpolation) =>
7
- runtime.executeInstructions(interpolation.pipe ?? [], [input], scope, (output) => [
8
- (interpolation.before ?? '') + runtime.stringifyJSON(output, true),
9
- ]),
10
- );
11
-
12
- return runtime.muxAll(interpolations, (...parts) =>
13
- next(parts.join('') + (params.after ?? ''), scope),
14
- );
15
- },
16
-
17
- /** { interpolations: [{ before: string, pipe: function }], after: string } */
18
- map(runtime, params) {
19
- return {
20
- interpolations: runtime.muxOne([params.interpolations], (entry) => ({
21
- before: runtime.assertType(entry.before, 'string'),
22
- pipe: call(entry.pipe),
23
- })),
24
- after: runtime.assertType(params.after, 'string'),
25
- };
26
- },
27
- };
@@ -1,26 +0,0 @@
1
- import { JPLTypeError } from '../../library';
2
-
3
- export default {
4
- /** {} */
5
- async op(runtime, input, params, scope, next) {
6
- return next(
7
- await runtime.alterValue(input, (value) => {
8
- const t = runtime.type(value);
9
- switch (t) {
10
- case 'number':
11
- return -value;
12
-
13
- default:
14
- }
15
-
16
- throw new JPLTypeError('%s (%*<100v) cannot be negated', t, value);
17
- }),
18
- scope,
19
- );
20
- },
21
-
22
- /** {} */
23
- map() {
24
- return {};
25
- },
26
- };
@@ -1,11 +0,0 @@
1
- export default {
2
- /** {} */
3
- op(runtime, input, params, scope, next) {
4
- return next(!runtime.truthy(input), scope);
5
- },
6
-
7
- /** {} */
8
- map() {
9
- return {};
10
- },
11
- };
@@ -1,36 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { pipes: [[op]] } */
5
- op(runtime, input, params, scope, next) {
6
- const iter = async (from) => {
7
- // 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.
8
- await undefined;
9
-
10
- scope.signal.checkHealth();
11
-
12
- if (from >= (params.pipes?.length ?? 0)) return next(null, scope);
13
-
14
- const pipe = params.pipes[from];
15
-
16
- return runtime.executeInstructions(pipe ?? [], [input], scope, (output) => {
17
- switch (runtime.type(output)) {
18
- case 'null':
19
- return iter(from + 1);
20
-
21
- default:
22
- return next(output, scope);
23
- }
24
- });
25
- };
26
-
27
- return iter(0);
28
- },
29
-
30
- /** { pipes: [function] } */
31
- map(runtime, params) {
32
- return {
33
- pipes: runtime.muxOne([params.pipes], (pipe) => call(pipe)),
34
- };
35
- },
36
- };
@@ -1,13 +0,0 @@
1
- export default {
2
- /** { number: number } */
3
- op(runtime, input, params, scope, next) {
4
- return next(params.number ?? 0, scope);
5
- },
6
-
7
- /** { number: number } */
8
- map(runtime, params) {
9
- return {
10
- number: runtime.assertType(params.number, 'number'),
11
- };
12
- },
13
- };
@@ -1,40 +0,0 @@
1
- import { JPLTypeError } from '../../library';
2
- import { call } from './utils';
3
-
4
- export default {
5
- /** { fields: [{ key: [op], value: [op], optional: boolean }] } */
6
- async op(runtime, input, params, scope, next) {
7
- const fields = await runtime.muxAsync([params.fields ?? []], async (field) => {
8
- const [keys, values] = await Promise.all([
9
- runtime.executeInstructions(field.key ?? [], [input], scope),
10
- runtime.executeInstructions(field.value ?? [], [input], scope),
11
- ]);
12
-
13
- return runtime.muxAll([runtime.unwrapValues(keys), values], (key, value) => {
14
- const t = runtime.type(key);
15
- switch (t) {
16
- case 'string':
17
- return [[key, value]];
18
-
19
- default:
20
- }
21
-
22
- if (field.optional) return [];
23
- throw new JPLTypeError('cannot use %s (%*<100v) as object key', t, key);
24
- });
25
- });
26
-
27
- return runtime.muxAll(fields, (...entries) => next(Object.fromEntries(entries), scope));
28
- },
29
-
30
- /** { fields: [{ key: function, value: function, optional: boolean }] } */
31
- map(runtime, params) {
32
- return {
33
- fields: runtime.muxOne([params.fields], (entry) => ({
34
- key: call(entry.key),
35
- value: call(entry.value),
36
- optional: runtime.assertType(entry.optional, 'boolean'),
37
- })),
38
- };
39
- },
40
- };
@@ -1,32 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { pipes: [[op]] } */
5
- op(runtime, input, params, scope, next) {
6
- const iter = async (from) => {
7
- // 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.
8
- await undefined;
9
-
10
- scope.signal.checkHealth();
11
-
12
- if (from >= (params.pipes?.length ?? 0)) return next(false, scope);
13
-
14
- const pipe = params.pipes[from];
15
-
16
- return runtime.executeInstructions(pipe ?? [], [input], scope, (output) => {
17
- if (runtime.truthy(output)) return next(true, scope);
18
-
19
- return iter(from + 1);
20
- });
21
- };
22
-
23
- return iter(0);
24
- },
25
-
26
- /** { pipes: [function] } */
27
- map(runtime, params) {
28
- return {
29
- pipes: runtime.muxOne([params.pipes], (pipe) => call(pipe)),
30
- };
31
- },
32
- };
@@ -1,17 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { pipes: [[op]] } */
5
- op(runtime, input, params, scope, next) {
6
- return runtime.muxAll([params.pipes ?? []], (pipe) =>
7
- runtime.executeInstructions(pipe ?? [], [input], scope, (output) => next(output, scope)),
8
- );
9
- },
10
-
11
- /** { pipes: [function] } */
12
- map(runtime, params) {
13
- return {
14
- pipes: runtime.muxOne([params.pipes], (value) => call(value)),
15
- };
16
- },
17
- };
@@ -1,13 +0,0 @@
1
- export default {
2
- /** { string: string } */
3
- op(runtime, input, params, scope, next) {
4
- return next(params.string ?? '', scope);
5
- },
6
-
7
- /** { string: string } */
8
- map(runtime, params) {
9
- return {
10
- string: runtime.assertType(params.string, 'string'),
11
- };
12
- },
13
- };
@@ -1,38 +0,0 @@
1
- import { JPLErrorEnclosure, JPLExecutionError } from '../../library';
2
- import { call } from './utils';
3
-
4
- export default {
5
- /** { try: [op], catch: [op] } */
6
- async op(runtime, input, params, scope, next) {
7
- const nextScope = scope.next({ signal: scope.signal.next() });
8
- try {
9
- return await runtime.executeInstructions(
10
- params.try ?? [],
11
- [input],
12
- nextScope,
13
- async (output) => {
14
- try {
15
- return await next(output, scope);
16
- } catch (err) {
17
- throw new JPLErrorEnclosure(err);
18
- }
19
- },
20
- );
21
- } catch (err) {
22
- if (JPLErrorEnclosure.is(err)) throw err.inner;
23
- if (!JPLExecutionError.is(err)) throw err;
24
- nextScope.signal.exit();
25
- return runtime.executeInstructions(params.catch ?? [], [err.value], scope, (output) =>
26
- next(output, scope),
27
- );
28
- }
29
- },
30
-
31
- /** { try: function, catch: function } */
32
- map(runtime, params) {
33
- return {
34
- try: call(params.try),
35
- catch: call(params.catch),
36
- };
37
- },
38
- };
@@ -1,17 +0,0 @@
1
- import { JPLReferenceError } from '../../library';
2
-
3
- export default {
4
- /** { name: string } */
5
- op(runtime, input, params, scope, next) {
6
- if (!Object.hasOwn(scope.vars, params.name ?? ''))
7
- throw new JPLReferenceError('%s is not defined', params.name ?? '');
8
- return next(scope.vars[params.name ?? ''], scope);
9
- },
10
-
11
- /** { name: string } */
12
- map(runtime, params) {
13
- return {
14
- name: runtime.assertType(params.name, 'string'),
15
- };
16
- },
17
- };
@@ -1,18 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { name: string, pipe: [op] } */
5
- op(runtime, input, params, scope, next) {
6
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) =>
7
- next(input, scope.next({ vars: { [params.name ?? '']: output } })),
8
- );
9
- },
10
-
11
- /** { name: string, pipe: function } */
12
- map(runtime, params) {
13
- return {
14
- name: runtime.assertType(params.name, 'string'),
15
- pipe: call(params.pipe),
16
- };
17
- },
18
- };
@@ -1,11 +0,0 @@
1
- export default {
2
- /** {} */
3
- op() {
4
- return [];
5
- },
6
-
7
- /** {} */
8
- map() {
9
- return {};
10
- },
11
- };