@rcrsr/rill 0.15.0 → 0.17.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 (316) hide show
  1. package/README.md +37 -21
  2. package/dist/ast-nodes.d.ts +2 -13
  3. package/dist/ast-nodes.js +0 -1
  4. package/dist/ast-unions.d.ts +0 -1
  5. package/dist/ast-unions.js +0 -1
  6. package/dist/constants.d.ts +0 -1
  7. package/dist/constants.js +0 -1
  8. package/dist/error-classes.d.ts +0 -1
  9. package/dist/error-classes.js +0 -1
  10. package/dist/error-formatter.d.ts +0 -1
  11. package/dist/error-formatter.js +0 -1
  12. package/dist/error-registry.d.ts +0 -1
  13. package/dist/error-registry.js +32 -1
  14. package/dist/ext/crypto/index.d.ts +3 -4
  15. package/dist/ext/crypto/index.js +66 -64
  16. package/dist/ext/exec/index.d.ts +3 -4
  17. package/dist/ext/exec/index.js +17 -12
  18. package/dist/ext/exec/runner.d.ts +0 -1
  19. package/dist/ext/exec/runner.js +0 -1
  20. package/dist/ext/fetch/index.d.ts +3 -4
  21. package/dist/ext/fetch/index.js +23 -49
  22. package/dist/ext/fetch/request.d.ts +0 -1
  23. package/dist/ext/fetch/request.js +0 -1
  24. package/dist/ext/fs/index.d.ts +3 -4
  25. package/dist/ext/fs/index.js +268 -266
  26. package/dist/ext/fs/sandbox.d.ts +0 -1
  27. package/dist/ext/fs/sandbox.js +0 -1
  28. package/dist/ext/kv/index.d.ts +3 -4
  29. package/dist/ext/kv/index.js +216 -215
  30. package/dist/ext/kv/store.d.ts +0 -1
  31. package/dist/ext/kv/store.js +2 -2
  32. package/dist/ext-parse-bridge.d.ts +10 -0
  33. package/dist/ext-parse-bridge.js +10 -0
  34. package/dist/generated/introspection-data.d.ts +1 -2
  35. package/dist/generated/introspection-data.js +385 -297
  36. package/dist/generated/version-data.d.ts +1 -2
  37. package/dist/generated/version-data.js +2 -3
  38. package/dist/highlight-map.d.ts +0 -1
  39. package/dist/highlight-map.js +0 -1
  40. package/dist/index.d.ts +15 -5
  41. package/dist/index.js +14 -6
  42. package/dist/lexer/errors.d.ts +0 -1
  43. package/dist/lexer/errors.js +0 -1
  44. package/dist/lexer/helpers.d.ts +0 -1
  45. package/dist/lexer/helpers.js +0 -1
  46. package/dist/lexer/index.d.ts +0 -1
  47. package/dist/lexer/index.js +0 -1
  48. package/dist/lexer/operators.d.ts +0 -1
  49. package/dist/lexer/operators.js +0 -1
  50. package/dist/lexer/readers.d.ts +0 -1
  51. package/dist/lexer/readers.js +0 -1
  52. package/dist/lexer/state.d.ts +0 -1
  53. package/dist/lexer/state.js +0 -1
  54. package/dist/lexer/tokenizer.d.ts +0 -1
  55. package/dist/lexer/tokenizer.js +0 -1
  56. package/dist/parser/helpers.d.ts +0 -1
  57. package/dist/parser/helpers.js +0 -1
  58. package/dist/parser/index.d.ts +0 -1
  59. package/dist/parser/index.js +0 -1
  60. package/dist/parser/parser-collect.d.ts +0 -1
  61. package/dist/parser/parser-collect.js +0 -1
  62. package/dist/parser/parser-control.d.ts +0 -1
  63. package/dist/parser/parser-control.js +0 -1
  64. package/dist/parser/parser-expr.d.ts +0 -1
  65. package/dist/parser/parser-expr.js +0 -1
  66. package/dist/parser/parser-extract.d.ts +0 -1
  67. package/dist/parser/parser-extract.js +0 -1
  68. package/dist/parser/parser-functions.d.ts +0 -1
  69. package/dist/parser/parser-functions.js +0 -1
  70. package/dist/parser/parser-literals.d.ts +0 -1
  71. package/dist/parser/parser-literals.js +4 -2
  72. package/dist/parser/parser-script.d.ts +0 -1
  73. package/dist/parser/parser-script.js +0 -1
  74. package/dist/parser/parser-shape.d.ts +2 -3
  75. package/dist/parser/parser-shape.js +8 -52
  76. package/dist/parser/parser-types.d.ts +28 -2
  77. package/dist/parser/parser-types.js +76 -13
  78. package/dist/parser/parser-use.d.ts +0 -1
  79. package/dist/parser/parser-use.js +7 -2
  80. package/dist/parser/parser-variables.d.ts +0 -1
  81. package/dist/parser/parser-variables.js +0 -1
  82. package/dist/parser/parser.d.ts +0 -1
  83. package/dist/parser/parser.js +0 -1
  84. package/dist/parser/state.d.ts +0 -1
  85. package/dist/parser/state.js +0 -1
  86. package/dist/runtime/core/callable.d.ts +59 -20
  87. package/dist/runtime/core/callable.js +188 -39
  88. package/dist/runtime/core/context.d.ts +0 -12
  89. package/dist/runtime/core/context.js +77 -77
  90. package/dist/runtime/core/equals.d.ts +0 -1
  91. package/dist/runtime/core/equals.js +35 -3
  92. package/dist/runtime/core/eval/base.d.ts +0 -1
  93. package/dist/runtime/core/eval/base.js +0 -1
  94. package/dist/runtime/core/eval/evaluator.d.ts +0 -1
  95. package/dist/runtime/core/eval/evaluator.js +0 -1
  96. package/dist/runtime/core/eval/index.d.ts +2 -3
  97. package/dist/runtime/core/eval/index.js +11 -1
  98. package/dist/runtime/core/eval/mixins/annotations.d.ts +0 -1
  99. package/dist/runtime/core/eval/mixins/annotations.js +0 -1
  100. package/dist/runtime/core/eval/mixins/closures.d.ts +0 -1
  101. package/dist/runtime/core/eval/mixins/closures.js +92 -70
  102. package/dist/runtime/core/eval/mixins/collections.d.ts +0 -1
  103. package/dist/runtime/core/eval/mixins/collections.js +9 -4
  104. package/dist/runtime/core/eval/mixins/control-flow.d.ts +0 -1
  105. package/dist/runtime/core/eval/mixins/control-flow.js +0 -1
  106. package/dist/runtime/core/eval/mixins/conversion.d.ts +0 -1
  107. package/dist/runtime/core/eval/mixins/conversion.js +196 -188
  108. package/dist/runtime/core/eval/mixins/core.d.ts +0 -1
  109. package/dist/runtime/core/eval/mixins/core.js +2 -3
  110. package/dist/runtime/core/eval/mixins/expressions.d.ts +0 -1
  111. package/dist/runtime/core/eval/mixins/expressions.js +35 -28
  112. package/dist/runtime/core/eval/mixins/extraction.d.ts +0 -1
  113. package/dist/runtime/core/eval/mixins/extraction.js +8 -9
  114. package/dist/runtime/core/eval/mixins/list-dispatch.d.ts +0 -1
  115. package/dist/runtime/core/eval/mixins/list-dispatch.js +0 -1
  116. package/dist/runtime/core/eval/mixins/literals.d.ts +0 -1
  117. package/dist/runtime/core/eval/mixins/literals.js +6 -10
  118. package/dist/runtime/core/eval/mixins/types.d.ts +2 -1
  119. package/dist/runtime/core/eval/mixins/types.js +231 -261
  120. package/dist/runtime/core/eval/mixins/use.d.ts +0 -1
  121. package/dist/runtime/core/eval/mixins/use.js +0 -1
  122. package/dist/runtime/core/eval/mixins/variables.d.ts +0 -1
  123. package/dist/runtime/core/eval/mixins/variables.js +16 -15
  124. package/dist/runtime/core/eval/types.d.ts +0 -1
  125. package/dist/runtime/core/eval/types.js +0 -1
  126. package/dist/runtime/core/execute.d.ts +0 -1
  127. package/dist/runtime/core/execute.js +0 -1
  128. package/dist/runtime/core/field-descriptor.d.ts +4 -5
  129. package/dist/runtime/core/field-descriptor.js +2 -2
  130. package/dist/runtime/core/introspection.d.ts +0 -1
  131. package/dist/runtime/core/introspection.js +6 -7
  132. package/dist/runtime/core/markers.d.ts +12 -0
  133. package/dist/runtime/core/markers.js +7 -0
  134. package/dist/runtime/core/resolvers.d.ts +0 -1
  135. package/dist/runtime/core/resolvers.js +0 -1
  136. package/dist/runtime/core/signals.d.ts +0 -1
  137. package/dist/runtime/core/signals.js +0 -1
  138. package/dist/runtime/core/type-registrations.d.ts +136 -0
  139. package/dist/runtime/core/type-registrations.js +749 -0
  140. package/dist/runtime/core/type-structures.d.ts +128 -0
  141. package/dist/runtime/core/type-structures.js +12 -0
  142. package/dist/runtime/core/types.d.ts +15 -4
  143. package/dist/runtime/core/types.js +0 -1
  144. package/dist/runtime/core/values.d.ts +88 -146
  145. package/dist/runtime/core/values.js +466 -470
  146. package/dist/runtime/ext/builtins.d.ts +0 -1
  147. package/dist/runtime/ext/builtins.js +125 -80
  148. package/dist/runtime/ext/extensions.d.ts +30 -125
  149. package/dist/runtime/ext/extensions.js +0 -94
  150. package/dist/runtime/ext/test-context.d.ts +28 -0
  151. package/dist/runtime/ext/test-context.js +154 -0
  152. package/dist/runtime/index.d.ts +22 -9
  153. package/dist/runtime/index.js +18 -5
  154. package/dist/signature-parser.d.ts +2 -3
  155. package/dist/signature-parser.js +19 -17
  156. package/dist/source-location.d.ts +0 -1
  157. package/dist/source-location.js +0 -1
  158. package/dist/token-types.d.ts +0 -1
  159. package/dist/token-types.js +0 -1
  160. package/dist/types.d.ts +0 -1
  161. package/dist/types.js +0 -1
  162. package/dist/value-types.d.ts +15 -12
  163. package/dist/value-types.js +0 -1
  164. package/package.json +2 -1
  165. package/dist/ast-nodes.d.ts.map +0 -1
  166. package/dist/ast-nodes.js.map +0 -1
  167. package/dist/ast-unions.d.ts.map +0 -1
  168. package/dist/ast-unions.js.map +0 -1
  169. package/dist/constants.d.ts.map +0 -1
  170. package/dist/constants.js.map +0 -1
  171. package/dist/error-classes.d.ts.map +0 -1
  172. package/dist/error-classes.js.map +0 -1
  173. package/dist/error-formatter.d.ts.map +0 -1
  174. package/dist/error-formatter.js.map +0 -1
  175. package/dist/error-registry.d.ts.map +0 -1
  176. package/dist/error-registry.js.map +0 -1
  177. package/dist/ext/crypto/index.d.ts.map +0 -1
  178. package/dist/ext/crypto/index.js.map +0 -1
  179. package/dist/ext/exec/index.d.ts.map +0 -1
  180. package/dist/ext/exec/index.js.map +0 -1
  181. package/dist/ext/exec/runner.d.ts.map +0 -1
  182. package/dist/ext/exec/runner.js.map +0 -1
  183. package/dist/ext/fetch/index.d.ts.map +0 -1
  184. package/dist/ext/fetch/index.js.map +0 -1
  185. package/dist/ext/fetch/request.d.ts.map +0 -1
  186. package/dist/ext/fetch/request.js.map +0 -1
  187. package/dist/ext/fs/index.d.ts.map +0 -1
  188. package/dist/ext/fs/index.js.map +0 -1
  189. package/dist/ext/fs/sandbox.d.ts.map +0 -1
  190. package/dist/ext/fs/sandbox.js.map +0 -1
  191. package/dist/ext/kv/index.d.ts.map +0 -1
  192. package/dist/ext/kv/index.js.map +0 -1
  193. package/dist/ext/kv/store.d.ts.map +0 -1
  194. package/dist/ext/kv/store.js.map +0 -1
  195. package/dist/generated/introspection-data.d.ts.map +0 -1
  196. package/dist/generated/introspection-data.js.map +0 -1
  197. package/dist/generated/version-data.d.ts.map +0 -1
  198. package/dist/generated/version-data.js.map +0 -1
  199. package/dist/highlight-map.d.ts.map +0 -1
  200. package/dist/highlight-map.js.map +0 -1
  201. package/dist/index.d.ts.map +0 -1
  202. package/dist/index.js.map +0 -1
  203. package/dist/lexer/errors.d.ts.map +0 -1
  204. package/dist/lexer/errors.js.map +0 -1
  205. package/dist/lexer/helpers.d.ts.map +0 -1
  206. package/dist/lexer/helpers.js.map +0 -1
  207. package/dist/lexer/index.d.ts.map +0 -1
  208. package/dist/lexer/index.js.map +0 -1
  209. package/dist/lexer/operators.d.ts.map +0 -1
  210. package/dist/lexer/operators.js.map +0 -1
  211. package/dist/lexer/readers.d.ts.map +0 -1
  212. package/dist/lexer/readers.js.map +0 -1
  213. package/dist/lexer/state.d.ts.map +0 -1
  214. package/dist/lexer/state.js.map +0 -1
  215. package/dist/lexer/tokenizer.d.ts.map +0 -1
  216. package/dist/lexer/tokenizer.js.map +0 -1
  217. package/dist/parser/helpers.d.ts.map +0 -1
  218. package/dist/parser/helpers.js.map +0 -1
  219. package/dist/parser/index.d.ts.map +0 -1
  220. package/dist/parser/index.js.map +0 -1
  221. package/dist/parser/parser-collect.d.ts.map +0 -1
  222. package/dist/parser/parser-collect.js.map +0 -1
  223. package/dist/parser/parser-control.d.ts.map +0 -1
  224. package/dist/parser/parser-control.js.map +0 -1
  225. package/dist/parser/parser-expr.d.ts.map +0 -1
  226. package/dist/parser/parser-expr.js.map +0 -1
  227. package/dist/parser/parser-extract.d.ts.map +0 -1
  228. package/dist/parser/parser-extract.js.map +0 -1
  229. package/dist/parser/parser-functions.d.ts.map +0 -1
  230. package/dist/parser/parser-functions.js.map +0 -1
  231. package/dist/parser/parser-literals.d.ts.map +0 -1
  232. package/dist/parser/parser-literals.js.map +0 -1
  233. package/dist/parser/parser-script.d.ts.map +0 -1
  234. package/dist/parser/parser-script.js.map +0 -1
  235. package/dist/parser/parser-shape.d.ts.map +0 -1
  236. package/dist/parser/parser-shape.js.map +0 -1
  237. package/dist/parser/parser-types.d.ts.map +0 -1
  238. package/dist/parser/parser-types.js.map +0 -1
  239. package/dist/parser/parser-use.d.ts.map +0 -1
  240. package/dist/parser/parser-use.js.map +0 -1
  241. package/dist/parser/parser-variables.d.ts.map +0 -1
  242. package/dist/parser/parser-variables.js.map +0 -1
  243. package/dist/parser/parser.d.ts.map +0 -1
  244. package/dist/parser/parser.js.map +0 -1
  245. package/dist/parser/state.d.ts.map +0 -1
  246. package/dist/parser/state.js.map +0 -1
  247. package/dist/runtime/core/callable.d.ts.map +0 -1
  248. package/dist/runtime/core/callable.js.map +0 -1
  249. package/dist/runtime/core/context.d.ts.map +0 -1
  250. package/dist/runtime/core/context.js.map +0 -1
  251. package/dist/runtime/core/equals.d.ts.map +0 -1
  252. package/dist/runtime/core/equals.js.map +0 -1
  253. package/dist/runtime/core/eval/base.d.ts.map +0 -1
  254. package/dist/runtime/core/eval/base.js.map +0 -1
  255. package/dist/runtime/core/eval/evaluator.d.ts.map +0 -1
  256. package/dist/runtime/core/eval/evaluator.js.map +0 -1
  257. package/dist/runtime/core/eval/index.d.ts.map +0 -1
  258. package/dist/runtime/core/eval/index.js.map +0 -1
  259. package/dist/runtime/core/eval/mixins/annotations.d.ts.map +0 -1
  260. package/dist/runtime/core/eval/mixins/annotations.js.map +0 -1
  261. package/dist/runtime/core/eval/mixins/closures.d.ts.map +0 -1
  262. package/dist/runtime/core/eval/mixins/closures.js.map +0 -1
  263. package/dist/runtime/core/eval/mixins/collections.d.ts.map +0 -1
  264. package/dist/runtime/core/eval/mixins/collections.js.map +0 -1
  265. package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +0 -1
  266. package/dist/runtime/core/eval/mixins/control-flow.js.map +0 -1
  267. package/dist/runtime/core/eval/mixins/conversion.d.ts.map +0 -1
  268. package/dist/runtime/core/eval/mixins/conversion.js.map +0 -1
  269. package/dist/runtime/core/eval/mixins/core.d.ts.map +0 -1
  270. package/dist/runtime/core/eval/mixins/core.js.map +0 -1
  271. package/dist/runtime/core/eval/mixins/expressions.d.ts.map +0 -1
  272. package/dist/runtime/core/eval/mixins/expressions.js.map +0 -1
  273. package/dist/runtime/core/eval/mixins/extraction.d.ts.map +0 -1
  274. package/dist/runtime/core/eval/mixins/extraction.js.map +0 -1
  275. package/dist/runtime/core/eval/mixins/list-dispatch.d.ts.map +0 -1
  276. package/dist/runtime/core/eval/mixins/list-dispatch.js.map +0 -1
  277. package/dist/runtime/core/eval/mixins/literals.d.ts.map +0 -1
  278. package/dist/runtime/core/eval/mixins/literals.js.map +0 -1
  279. package/dist/runtime/core/eval/mixins/types.d.ts.map +0 -1
  280. package/dist/runtime/core/eval/mixins/types.js.map +0 -1
  281. package/dist/runtime/core/eval/mixins/use.d.ts.map +0 -1
  282. package/dist/runtime/core/eval/mixins/use.js.map +0 -1
  283. package/dist/runtime/core/eval/mixins/variables.d.ts.map +0 -1
  284. package/dist/runtime/core/eval/mixins/variables.js.map +0 -1
  285. package/dist/runtime/core/eval/types.d.ts.map +0 -1
  286. package/dist/runtime/core/eval/types.js.map +0 -1
  287. package/dist/runtime/core/execute.d.ts.map +0 -1
  288. package/dist/runtime/core/execute.js.map +0 -1
  289. package/dist/runtime/core/field-descriptor.d.ts.map +0 -1
  290. package/dist/runtime/core/field-descriptor.js.map +0 -1
  291. package/dist/runtime/core/introspection.d.ts.map +0 -1
  292. package/dist/runtime/core/introspection.js.map +0 -1
  293. package/dist/runtime/core/resolvers.d.ts.map +0 -1
  294. package/dist/runtime/core/resolvers.js.map +0 -1
  295. package/dist/runtime/core/signals.d.ts.map +0 -1
  296. package/dist/runtime/core/signals.js.map +0 -1
  297. package/dist/runtime/core/types.d.ts.map +0 -1
  298. package/dist/runtime/core/types.js.map +0 -1
  299. package/dist/runtime/core/values.d.ts.map +0 -1
  300. package/dist/runtime/core/values.js.map +0 -1
  301. package/dist/runtime/ext/builtins.d.ts.map +0 -1
  302. package/dist/runtime/ext/builtins.js.map +0 -1
  303. package/dist/runtime/ext/extensions.d.ts.map +0 -1
  304. package/dist/runtime/ext/extensions.js.map +0 -1
  305. package/dist/runtime/index.d.ts.map +0 -1
  306. package/dist/runtime/index.js.map +0 -1
  307. package/dist/signature-parser.d.ts.map +0 -1
  308. package/dist/signature-parser.js.map +0 -1
  309. package/dist/source-location.d.ts.map +0 -1
  310. package/dist/source-location.js.map +0 -1
  311. package/dist/token-types.d.ts.map +0 -1
  312. package/dist/token-types.js.map +0 -1
  313. package/dist/types.d.ts.map +0 -1
  314. package/dist/types.js.map +0 -1
  315. package/dist/value-types.d.ts.map +0 -1
  316. package/dist/value-types.js.map +0 -1
@@ -56,7 +56,13 @@ Parser.prototype.parseUseExpr = function () {
56
56
  let typeRef = null;
57
57
  let closureAnnotation = null;
58
58
  if (check(this.state, TOKEN_TYPES.COLON)) {
59
- if (peek(this.state, 1).type === TOKEN_TYPES.PIPE_BAR) {
59
+ if (peek(this.state, 1).type === TOKEN_TYPES.OR) {
60
+ // Zero-param closure annotation: :||
61
+ advance(this.state); // consume :
62
+ advance(this.state); // consume || (OR token)
63
+ closureAnnotation = [];
64
+ }
65
+ else if (peek(this.state, 1).type === TOKEN_TYPES.PIPE_BAR) {
60
66
  // Closure annotation: :|param: type, ...|
61
67
  advance(this.state); // consume :
62
68
  advance(this.state); // consume opening |
@@ -93,4 +99,3 @@ Parser.prototype.parseUseExpr = function () {
93
99
  span: makeSpan(start, current(this.state).span.end),
94
100
  };
95
101
  };
96
- //# sourceMappingURL=parser-use.js.map
@@ -17,4 +17,3 @@ declare module './parser.js' {
17
17
  parseDefaultValue(): BodyNode;
18
18
  }
19
19
  }
20
- //# sourceMappingURL=parser-variables.d.ts.map
@@ -175,4 +175,3 @@ Parser.prototype.parseDefaultValue = function () {
175
175
  }
176
176
  return this.parsePipeChain();
177
177
  };
178
- //# sourceMappingURL=parser-variables.js.map
@@ -46,4 +46,3 @@ export declare class Parser {
46
46
  */
47
47
  get errors(): ParseError[];
48
48
  }
49
- //# sourceMappingURL=parser.d.ts.map
@@ -51,4 +51,3 @@ export class Parser {
51
51
  return this.state.errors;
52
52
  }
53
53
  }
54
- //# sourceMappingURL=parser.js.map
@@ -43,4 +43,3 @@ export declare function skipNewlines(state: ParserState): void;
43
43
  export declare function skipNewlinesIfFollowedBy(state: ParserState, tokenType: string): boolean;
44
44
  /** @internal */
45
45
  export declare function makeSpan(start: SourceLocation, end: SourceLocation): SourceSpan;
46
- //# sourceMappingURL=state.d.ts.map
@@ -150,4 +150,3 @@ function generateHint(expectedType, actualToken) {
150
150
  export function makeSpan(start, end) {
151
151
  return { start, end };
152
152
  }
153
- //# sourceMappingURL=state.js.map
@@ -17,10 +17,10 @@
17
17
  *
18
18
  * [ASSUMPTION] validateDefaultValueType _functionName Parameter
19
19
  * - Parameter accepted but unused (prefixed with _ to satisfy eslint)
20
- * - Kept for API consistency with validateCallableArgs signature
20
+ * - Kept for API consistency with marshalArgs signature
21
21
  */
22
22
  import type { BodyNode, SourceLocation } from '../../types.js';
23
- import type { RillType, RillTypeValue, RillValue } from './values.js';
23
+ import type { TypeStructure, RillTypeValue, RillValue } from './values.js';
24
24
  interface RuntimeContextLike {
25
25
  readonly parent?: RuntimeContextLike | undefined;
26
26
  readonly variables: Map<string, RillValue>;
@@ -31,7 +31,7 @@ interface RuntimeContextLike {
31
31
  * Callable function signature.
32
32
  * Used for both host-provided functions and runtime callables.
33
33
  */
34
- export type CallableFn = (args: RillValue[], ctx: RuntimeContextLike, location?: SourceLocation) => RillValue | Promise<RillValue>;
34
+ export type CallableFn = (args: Record<string, RillValue>, ctx: RuntimeContextLike, location?: SourceLocation) => RillValue | Promise<RillValue>;
35
35
  /**
36
36
  * Unified parameter definition for all callable types (script closures and host functions).
37
37
  *
@@ -42,7 +42,7 @@ export type CallableFn = (args: RillValue[], ctx: RuntimeContextLike, location?:
42
42
  */
43
43
  export interface RillParam {
44
44
  readonly name: string;
45
- readonly type: RillType | undefined;
45
+ readonly type: TypeStructure | undefined;
46
46
  readonly defaultValue: RillValue | undefined;
47
47
  readonly annotations: Record<string, RillValue>;
48
48
  }
@@ -57,6 +57,8 @@ export interface RillFunction {
57
57
  readonly fn: CallableFn;
58
58
  readonly annotations?: Record<string, RillValue>;
59
59
  readonly returnType: RillTypeValue;
60
+ /** When true, RILL-R003 generic receiver validation is skipped for this method. */
61
+ readonly skipReceiverValidation?: boolean;
60
62
  }
61
63
  /** Common fields for all callable types */
62
64
  interface CallableBase {
@@ -112,6 +114,16 @@ export declare function isApplicationCallable(value: RillValue): value is Applic
112
114
  * @param isProperty If true, auto-invokes when accessed from dict (property-style)
113
115
  */
114
116
  export declare function callable(fn: CallableFn, isProperty?: boolean): ApplicationCallable;
117
+ /**
118
+ * Convert a RillFunction to an ApplicationCallable.
119
+ *
120
+ * Validates the input and produces a callable value accepted by the loader.
121
+ * Pure function with no side effects.
122
+ *
123
+ * @param def - Host function definition to convert
124
+ * @returns ApplicationCallable with __type, kind, isProperty, and preserved annotations
125
+ */
126
+ export declare function toCallable(def: RillFunction, isProperty?: boolean): ApplicationCallable;
115
127
  /** Type guard for dict (plain object, not array, not callable, not tuple) */
116
128
  export declare function isDict(value: RillValue): value is Record<string, RillValue>;
117
129
  /** Format a callable for display */
@@ -129,19 +141,19 @@ export declare function formatCallable(callable: RillCallable): string;
129
141
  */
130
142
  export declare function callableEquals(a: ScriptCallable, b: ScriptCallable, valueEquals?: (a: RillValue, b: RillValue) => boolean): boolean;
131
143
  /**
132
- * Build a RillType closure variant from a closure's parameter list.
144
+ * Build a TypeStructure closure variant from a closure's parameter list.
133
145
  *
134
146
  * Called at closure creation time to build the structural type for `$fn.^input`.
135
147
  * - Typed params use param.type directly when present
136
- * - Untyped params (type: undefined) map to { type: 'any' }
137
- * - Return type is always { type: 'any' }
148
+ * - Untyped params (type: undefined) map to { kind: 'any' }
149
+ * - Return type is always { kind: 'any' }
138
150
  *
139
151
  * No validation: parser already validates type names.
140
152
  *
141
153
  * @param params - Closure parameter definitions (RillParam[])
142
- * @returns Frozen RillType with closure variant
154
+ * @returns Frozen TypeStructure with closure variant
143
155
  */
144
- export declare function paramsToStructuralType(params: readonly RillParam[]): RillType;
156
+ export declare function paramsToStructuralType(params: readonly RillParam[]): TypeStructure;
145
157
  /**
146
158
  * Validate defaultValue type matches declared parameter type.
147
159
  *
@@ -154,19 +166,46 @@ export declare function paramsToStructuralType(params: readonly RillParam[]): Ri
154
166
  */
155
167
  export declare function validateDefaultValueType(param: RillParam, _functionName: string): void;
156
168
  /**
157
- * Validate arguments against RillParam[] using structural type matching.
169
+ * Options for marshalArgs error reporting.
170
+ */
171
+ export interface MarshalOptions {
172
+ /** Function name included in error messages */
173
+ readonly functionName: string;
174
+ /** Source location for error reporting */
175
+ readonly location: SourceLocation | undefined;
176
+ }
177
+ /**
178
+ * Hydrate missing dict/ordered field-level defaults into a value.
179
+ *
180
+ * When a param has type `dict(a: string = "x", b: number)` and the caller
181
+ * passes `[b: 2]`, this fills in `a` with its default `"x"`. Fields without
182
+ * defaults are left absent so Stage 3 catches them with RILL-R001.
183
+ *
184
+ * Pure function: no class context, no evaluator, no side effects.
185
+ */
186
+ export declare function hydrateFieldDefaults(value: RillValue, type: TypeStructure): RillValue;
187
+ /**
188
+ * Unified marshaling entry point for all 3 invocation paths.
189
+ *
190
+ * Builds a named argument map from positional args, hydrates defaults,
191
+ * type-checks each field, and returns a Record<string, RillValue>.
192
+ *
193
+ * Stages:
194
+ * 1. Excess args check (RILL-R045)
195
+ * 2. Default hydration + missing required check (RILL-R044)
196
+ * 2.5. Dict/ordered field-level default hydration
197
+ * 3. Type check per field (RILL-R001)
158
198
  *
159
- * Single validation path for all callable kinds (host, built-in, script).
160
- * Uses structuralTypeMatches for type checking when param.type is defined.
161
- * Skips type check when param.type is undefined (any-typed).
162
- * Applies defaultValue in-place on the args array before validation.
199
+ * Preconditions (enforced by caller):
200
+ * - args contains already-evaluated RillValue[]
201
+ * - pipe value already inserted as first element by caller
202
+ * - boundDict already prepended as first element by caller
203
+ * - params is defined (caller skips marshalArgs for untyped callables)
163
204
  *
164
- * @param args - Arguments array (mutated in-place when defaults applied)
205
+ * @param args - Positional arguments (already evaluated)
165
206
  * @param params - Parameter definitions
166
- * @param functionName - Function name for error messages
167
- * @param location - Source location for error reporting
168
- * @throws RuntimeError with RILL-R001 on validation failure
207
+ * @param options - Error context: functionName and location
208
+ * @returns Named argument map keyed by param name
169
209
  */
170
- export declare function validateCallableArgs(args: RillValue[], params: readonly RillParam[], functionName: string, location?: SourceLocation): void;
210
+ export declare function marshalArgs(args: RillValue[], params: readonly RillParam[], options?: MarshalOptions): Record<string, RillValue>;
171
211
  export {};
172
- //# sourceMappingURL=callable.d.ts.map
@@ -17,11 +17,11 @@
17
17
  *
18
18
  * [ASSUMPTION] validateDefaultValueType _functionName Parameter
19
19
  * - Parameter accepted but unused (prefixed with _ to satisfy eslint)
20
- * - Kept for API consistency with validateCallableArgs signature
20
+ * - Kept for API consistency with marshalArgs signature
21
21
  */
22
22
  import { RuntimeError } from '../../types.js';
23
23
  import { astEquals } from './equals.js';
24
- import { formatValue, formatStructuralType, inferType, isTuple, paramToTypeTuple, structuralTypeEquals, structuralTypeMatches, anyTypeValue, } from './values.js';
24
+ import { formatValue, formatStructure, inferType, isOrdered, createOrdered, copyValue, isTuple, paramToFieldDef, structureEquals, structureMatches, anyTypeValue, hasCollectionFields, emptyForType, } from './values.js';
25
25
  /** Type guard for any callable */
26
26
  export function isCallable(value) {
27
27
  return (typeof value === 'object' &&
@@ -61,6 +61,35 @@ export function callable(fn, isProperty = false) {
61
61
  isProperty,
62
62
  };
63
63
  }
64
+ /**
65
+ * Convert a RillFunction to an ApplicationCallable.
66
+ *
67
+ * Validates the input and produces a callable value accepted by the loader.
68
+ * Pure function with no side effects.
69
+ *
70
+ * @param def - Host function definition to convert
71
+ * @returns ApplicationCallable with __type, kind, isProperty, and preserved annotations
72
+ */
73
+ export function toCallable(def, isProperty = false) {
74
+ if (def == null) {
75
+ throw new TypeError('RillFunction cannot be null or undefined');
76
+ }
77
+ if (typeof def.fn !== 'function') {
78
+ throw new TypeError('RillFunction.fn must be a function');
79
+ }
80
+ if (!Array.isArray(def.params)) {
81
+ throw new TypeError('RillFunction.params must be an array');
82
+ }
83
+ return {
84
+ __type: 'callable',
85
+ kind: 'application',
86
+ isProperty,
87
+ fn: def.fn,
88
+ params: def.params,
89
+ returnType: def.returnType,
90
+ annotations: def.annotations ?? {},
91
+ };
92
+ }
64
93
  /** Type guard for dict (plain object, not array, not callable, not tuple) */
65
94
  export function isDict(value) {
66
95
  return (typeof value === 'object' &&
@@ -116,14 +145,14 @@ export function callableEquals(a, b, valueEquals = (x, y) => formatValue(x) ===
116
145
  return false;
117
146
  if (ap.name !== bp.name)
118
147
  return false;
119
- // Compare type via structuralTypeEquals; absent type (any-typed) matches absent type
148
+ // Compare type via structureEquals; absent type (any-typed) matches absent type
120
149
  if (ap.type === undefined && bp.type !== undefined)
121
150
  return false;
122
151
  if (ap.type !== undefined && bp.type === undefined)
123
152
  return false;
124
153
  if (ap.type !== undefined &&
125
154
  bp.type !== undefined &&
126
- !structuralTypeEquals(ap.type, bp.type))
155
+ !structureEquals(ap.type, bp.type))
127
156
  return false;
128
157
  if (!valueEquals(ap.defaultValue ?? null, bp.defaultValue ?? null)) {
129
158
  return false;
@@ -146,24 +175,24 @@ export function callableEquals(a, b, valueEquals = (x, y) => formatValue(x) ===
146
175
  return true;
147
176
  }
148
177
  /**
149
- * Build a RillType closure variant from a closure's parameter list.
178
+ * Build a TypeStructure closure variant from a closure's parameter list.
150
179
  *
151
180
  * Called at closure creation time to build the structural type for `$fn.^input`.
152
181
  * - Typed params use param.type directly when present
153
- * - Untyped params (type: undefined) map to { type: 'any' }
154
- * - Return type is always { type: 'any' }
182
+ * - Untyped params (type: undefined) map to { kind: 'any' }
183
+ * - Return type is always { kind: 'any' }
155
184
  *
156
185
  * No validation: parser already validates type names.
157
186
  *
158
187
  * @param params - Closure parameter definitions (RillParam[])
159
- * @returns Frozen RillType with closure variant
188
+ * @returns Frozen TypeStructure with closure variant
160
189
  */
161
190
  export function paramsToStructuralType(params) {
162
- const closureParams = params.map((param) => paramToTypeTuple(param.name, param.type ?? { type: 'any' }, param.defaultValue));
191
+ const closureParams = params.map((param) => paramToFieldDef(param.name, param.type ?? { kind: 'any' }, param.defaultValue));
163
192
  return Object.freeze({
164
- type: 'closure',
193
+ kind: 'closure',
165
194
  params: closureParams,
166
- ret: { type: 'any' },
195
+ ret: { kind: 'any' },
167
196
  });
168
197
  }
169
198
  /**
@@ -182,61 +211,180 @@ export function validateDefaultValueType(param, _functionName) {
182
211
  // Skip validation when type is undefined (any-typed, all defaults valid)
183
212
  if (param.type === undefined)
184
213
  return;
185
- if (!structuralTypeMatches(param.defaultValue, param.type)) {
214
+ if (!structureMatches(param.defaultValue, param.type)) {
186
215
  const actualType = inferType(param.defaultValue);
187
- const expectedType = formatStructuralType(param.type);
216
+ const expectedType = formatStructure(param.type);
188
217
  throw new Error(`Invalid defaultValue for parameter '${param.name}': expected ${expectedType}, got ${actualType}`);
189
218
  }
190
219
  }
191
220
  /**
192
- * Validate arguments against RillParam[] using structural type matching.
221
+ * Hydrate missing dict/ordered field-level defaults into a value.
222
+ *
223
+ * When a param has type `dict(a: string = "x", b: number)` and the caller
224
+ * passes `[b: 2]`, this fills in `a` with its default `"x"`. Fields without
225
+ * defaults are left absent so Stage 3 catches them with RILL-R001.
226
+ *
227
+ * Pure function: no class context, no evaluator, no side effects.
228
+ */
229
+ export function hydrateFieldDefaults(value, type) {
230
+ if (type.kind === 'dict' && type.fields && isDict(value)) {
231
+ const t = type;
232
+ const dictValue = value;
233
+ // Seed with all input entries so extra keys survive (structural match allows extras)
234
+ const result = { ...dictValue };
235
+ for (const [fieldName, fieldDef] of Object.entries(t.fields)) {
236
+ if (fieldName in dictValue) {
237
+ result[fieldName] = hydrateFieldDefaults(dictValue[fieldName], fieldDef.type);
238
+ }
239
+ else if (fieldDef.defaultValue !== undefined) {
240
+ result[fieldName] = hydrateFieldDefaults(copyValue(fieldDef.defaultValue), fieldDef.type);
241
+ }
242
+ else if (hasCollectionFields(fieldDef.type)) {
243
+ result[fieldName] = hydrateFieldDefaults(emptyForType(fieldDef.type), fieldDef.type);
244
+ }
245
+ // Missing without default and not collection: leave absent for Stage 3
246
+ }
247
+ return result;
248
+ }
249
+ if (type.kind === 'ordered' &&
250
+ type.fields &&
251
+ isOrdered(value)) {
252
+ const t = type;
253
+ const lookup = new Map(value.entries.map(([k, v]) => [k, v]));
254
+ const fieldNames = new Set(t.fields.map((f) => f.name ?? ''));
255
+ const resultEntries = [];
256
+ for (const field of t.fields) {
257
+ const name = field.name ?? '';
258
+ if (lookup.has(name)) {
259
+ resultEntries.push([
260
+ name,
261
+ hydrateFieldDefaults(lookup.get(name), field.type),
262
+ ]);
263
+ }
264
+ else if (field.defaultValue !== undefined) {
265
+ resultEntries.push([
266
+ name,
267
+ hydrateFieldDefaults(copyValue(field.defaultValue), field.type),
268
+ ]);
269
+ }
270
+ else if (hasCollectionFields(field.type)) {
271
+ resultEntries.push([
272
+ name,
273
+ hydrateFieldDefaults(emptyForType(field.type), field.type),
274
+ ]);
275
+ }
276
+ // Missing without default and not collection: leave absent for Stage 3
277
+ }
278
+ // Append extra entries not declared in type.fields (structural match allows extras)
279
+ for (const [k, v] of value.entries) {
280
+ if (!fieldNames.has(k)) {
281
+ resultEntries.push([k, v]);
282
+ }
283
+ }
284
+ return createOrdered(resultEntries);
285
+ }
286
+ if (type.kind === 'tuple' &&
287
+ type.elements &&
288
+ isTuple(value)) {
289
+ const elements = type.elements;
290
+ const entries = value.entries;
291
+ // All fields present: recurse into nested types for present positions
292
+ if (entries.length >= elements.length) {
293
+ const resultEntries = elements.map((el, i) => hydrateFieldDefaults(entries[i], el.type));
294
+ // Preserve any extra trailing entries beyond the type definition
295
+ for (let i = elements.length; i < entries.length; i++) {
296
+ resultEntries.push(entries[i]);
297
+ }
298
+ return { __rill_tuple: true, entries: resultEntries };
299
+ }
300
+ // Value shorter: fill missing trailing positions with defaults
301
+ const resultEntries = [];
302
+ for (let i = 0; i < elements.length; i++) {
303
+ const el = elements[i];
304
+ if (i < entries.length) {
305
+ resultEntries.push(hydrateFieldDefaults(entries[i], el.type));
306
+ }
307
+ else if (el.defaultValue !== undefined) {
308
+ resultEntries.push(hydrateFieldDefaults(copyValue(el.defaultValue), el.type));
309
+ }
310
+ else if (hasCollectionFields(el.type)) {
311
+ resultEntries.push(hydrateFieldDefaults(emptyForType(el.type), el.type));
312
+ }
313
+ // Missing without default and not collection: leave absent (shorter tuple) for Stage 3
314
+ }
315
+ return { __rill_tuple: true, entries: resultEntries };
316
+ }
317
+ return value;
318
+ }
319
+ /**
320
+ * Unified marshaling entry point for all 3 invocation paths.
193
321
  *
194
- * Single validation path for all callable kinds (host, built-in, script).
195
- * Uses structuralTypeMatches for type checking when param.type is defined.
196
- * Skips type check when param.type is undefined (any-typed).
197
- * Applies defaultValue in-place on the args array before validation.
322
+ * Builds a named argument map from positional args, hydrates defaults,
323
+ * type-checks each field, and returns a Record<string, RillValue>.
198
324
  *
199
- * @param args - Arguments array (mutated in-place when defaults applied)
325
+ * Stages:
326
+ * 1. Excess args check (RILL-R045)
327
+ * 2. Default hydration + missing required check (RILL-R044)
328
+ * 2.5. Dict/ordered field-level default hydration
329
+ * 3. Type check per field (RILL-R001)
330
+ *
331
+ * Preconditions (enforced by caller):
332
+ * - args contains already-evaluated RillValue[]
333
+ * - pipe value already inserted as first element by caller
334
+ * - boundDict already prepended as first element by caller
335
+ * - params is defined (caller skips marshalArgs for untyped callables)
336
+ *
337
+ * @param args - Positional arguments (already evaluated)
200
338
  * @param params - Parameter definitions
201
- * @param functionName - Function name for error messages
202
- * @param location - Source location for error reporting
203
- * @throws RuntimeError with RILL-R001 on validation failure
339
+ * @param options - Error context: functionName and location
340
+ * @returns Named argument map keyed by param name
204
341
  */
205
- export function validateCallableArgs(args, params, functionName, location) {
206
- // Check for excess arguments
342
+ export function marshalArgs(args, params, options) {
343
+ const functionName = options?.functionName ?? '<anonymous>';
344
+ const location = options?.location;
345
+ // Stage 1: Excess args check
207
346
  if (args.length > params.length) {
208
- throw new RuntimeError('RILL-R001', `Function '${functionName}' expects ${params.length} arguments, got ${args.length}`, location, {
347
+ throw new RuntimeError('RILL-R045', `Function expects ${params.length} arguments, got ${args.length}`, location, {
209
348
  functionName,
210
349
  expectedCount: params.length,
211
350
  actualCount: args.length,
212
351
  });
213
352
  }
214
- // Validate each parameter
353
+ const result = {};
354
+ // Stage 2 + 3: Hydrate defaults, check required, type-check
215
355
  for (let i = 0; i < params.length; i++) {
216
356
  const param = params[i];
217
357
  if (param === undefined)
218
358
  continue;
219
- let arg = args[i];
220
- // Apply defaultValue in-place for missing arguments
221
- if (arg === undefined) {
359
+ let value = args[i];
360
+ // Hydrate default when no positional arg was supplied
361
+ if (value === undefined) {
222
362
  if (param.defaultValue !== undefined) {
223
- arg = param.defaultValue;
224
- args[i] = arg;
363
+ value = param.defaultValue;
364
+ }
365
+ else if (param.type !== undefined && hasCollectionFields(param.type)) {
366
+ // Collection-typed param with field-level defaults: synthesize empty
367
+ // collection so Stage 2.5 (hydrateFieldDefaults) can fill in defaults
368
+ value = emptyForType(param.type);
225
369
  }
226
370
  else {
227
- // Missing required argument
228
- throw new RuntimeError('RILL-R001', `Missing required argument '${param.name}' for function '${functionName}'`, location, {
371
+ // Stage 2: Missing required parameter
372
+ throw new RuntimeError('RILL-R044', `Missing argument for parameter '${param.name}'`, location, {
229
373
  functionName,
230
374
  paramName: param.name,
231
375
  });
232
376
  }
233
377
  }
234
- // Type check via structuralTypeMatches when param.type is defined
378
+ // Stage 2.5: Hydrate dict/ordered field-level defaults
379
+ if (param.type !== undefined) {
380
+ value = hydrateFieldDefaults(value, param.type);
381
+ }
382
+ // Stage 3: Type check when param.type is defined
235
383
  if (param.type !== undefined) {
236
- if (!structuralTypeMatches(arg, param.type)) {
237
- const expectedType = formatStructuralType(param.type);
238
- const actualType = inferType(arg);
239
- throw new RuntimeError('RILL-R001', `Type mismatch in ${functionName}: parameter '${param.name}' expects ${expectedType}, got ${actualType}`, location, {
384
+ if (!structureMatches(value, param.type)) {
385
+ const expectedType = formatStructure(param.type);
386
+ const actualType = inferType(value);
387
+ throw new RuntimeError('RILL-R001', `Parameter type mismatch: ${param.name} expects ${expectedType}, got ${actualType}`, location, {
240
388
  functionName,
241
389
  paramName: param.name,
242
390
  expectedType,
@@ -244,6 +392,7 @@ export function validateCallableArgs(args, params, functionName, location) {
244
392
  });
245
393
  }
246
394
  }
395
+ result[param.name] = value;
247
396
  }
397
+ return result;
248
398
  }
249
- //# sourceMappingURL=callable.js.map
@@ -6,18 +6,7 @@
6
6
  */
7
7
  import type { RuntimeContext, RuntimeOptions } from './types.js';
8
8
  import { type RillValue } from './values.js';
9
- import { type RillFunction } from './callable.js';
10
9
  export declare const UNVALIDATED_METHOD_PARAMS: Set<string>;
11
- export declare const UNVALIDATED_METHOD_RECEIVERS: Set<string>;
12
- /**
13
- * Build a ReadonlyMap of frozen ApplicationCallable dicts from an array of
14
- * [typeName, methods] pairs. Accepts pairs (not a plain object) so the same
15
- * typeName can appear more than once — duplicate method names across entries
16
- * for the same type trigger an Error (EC-6).
17
- *
18
- * Re-exported from the public barrel index for host integration use.
19
- */
20
- export declare function buildTypeMethodDicts(pairs: Array<[string, Record<string, RillFunction>]>): ReadonlyMap<string, Readonly<Record<string, RillValue>>>;
21
10
  /**
22
11
  * Create a runtime context for script execution.
23
12
  * This is the main entry point for configuring the Rill runtime.
@@ -62,4 +51,3 @@ export declare function pushCallFrame(ctx: RuntimeContext, frame: import('../../
62
51
  * Pop frame from call stack after function/closure returns.
63
52
  */
64
53
  export declare function popCallFrame(ctx: RuntimeContext): void;
65
- //# sourceMappingURL=context.d.ts.map