trebol 0.1.1 → 0.2.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 (300) hide show
  1. package/README.md +12 -1
  2. package/dist/cli.js +17097 -12238
  3. package/dist/fonts/OFL.txt +93 -0
  4. package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
  5. package/dist/fonts/inter-cyrillic.woff2 +0 -0
  6. package/dist/fonts/inter-greek-ext.woff2 +0 -0
  7. package/dist/fonts/inter-greek.woff2 +0 -0
  8. package/dist/fonts/inter-latin-ext.woff2 +0 -0
  9. package/dist/fonts/inter-latin.woff2 +0 -0
  10. package/dist/fonts/inter-vietnamese.woff2 +0 -0
  11. package/dist/lib/core/boot.js +12 -8
  12. package/dist/lib/core/eval.js +2 -2
  13. package/dist/lib/core/func.d.ts +4 -0
  14. package/dist/lib/core/machine/checks.d.ts +1 -0
  15. package/dist/lib/core/machine/checks.js +250 -0
  16. package/dist/lib/core/machine/events.d.ts +1 -0
  17. package/dist/lib/core/machine/events.js +365 -0
  18. package/dist/lib/core/machine/running.d.ts +1 -0
  19. package/dist/lib/core/machine/running.js +180 -0
  20. package/dist/lib/core/machine/shared.d.ts +1 -0
  21. package/dist/lib/core/machine/shared.js +123 -0
  22. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  23. package/dist/lib/core/machine/snapshot.js +244 -0
  24. package/dist/lib/core/machine/spec.d.ts +1 -0
  25. package/dist/lib/core/machine/spec.js +274 -0
  26. package/dist/lib/core/machine/words.d.ts +1 -0
  27. package/dist/lib/core/machine/words.js +98 -0
  28. package/dist/lib/core/machine.d.ts +1 -0
  29. package/dist/lib/core/machine.js +17 -0
  30. package/dist/lib/core/mezz.js +31 -0
  31. package/dist/lib/core/natives/control.js +2 -2
  32. package/dist/lib/core/natives/data.js +6 -1
  33. package/dist/lib/core/natives/series.js +59 -9
  34. package/dist/lib/core/natives/text.js +3 -1
  35. package/dist/lib/host/browser/calendar.d.ts +34 -0
  36. package/dist/lib/host/browser/calendar.js +268 -0
  37. package/dist/lib/host/browser/count.d.ts +15 -0
  38. package/dist/lib/host/browser/count.js +48 -0
  39. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  40. package/dist/lib/host/browser/dialogs.js +443 -0
  41. package/dist/lib/host/browser/drag.d.ts +70 -0
  42. package/dist/lib/host/browser/drag.js +268 -0
  43. package/dist/lib/host/browser/drawings.d.ts +30 -0
  44. package/dist/lib/host/browser/drawings.js +176 -0
  45. package/dist/lib/host/browser/events.d.ts +16 -0
  46. package/dist/lib/host/browser/events.js +125 -0
  47. package/dist/lib/host/browser/faces.d.ts +35 -0
  48. package/dist/lib/host/browser/faces.js +131 -0
  49. package/dist/lib/host/browser/fields.d.ts +16 -0
  50. package/dist/lib/host/browser/fields.js +322 -0
  51. package/dist/lib/host/browser/keys.d.ts +29 -0
  52. package/dist/lib/host/browser/keys.js +151 -0
  53. package/dist/lib/host/browser/lookup.d.ts +25 -0
  54. package/dist/lib/host/browser/lookup.js +275 -0
  55. package/dist/lib/host/browser/menus.d.ts +20 -0
  56. package/dist/lib/host/browser/menus.js +149 -0
  57. package/dist/lib/host/browser/mount.d.ts +92 -0
  58. package/dist/lib/host/browser/mount.js +448 -0
  59. package/dist/lib/host/browser/orbits.d.ts +90 -0
  60. package/dist/lib/host/browser/orbits.js +379 -0
  61. package/dist/lib/host/browser/page.d.ts +13 -0
  62. package/dist/lib/host/browser/page.js +35 -0
  63. package/dist/lib/host/browser/richtext.d.ts +19 -0
  64. package/dist/lib/host/browser/richtext.js +379 -0
  65. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  66. package/dist/lib/host/browser/row-faces.js +74 -0
  67. package/dist/lib/host/browser/screens.d.ts +37 -0
  68. package/dist/lib/host/browser/screens.js +140 -0
  69. package/dist/lib/host/browser/swipe.d.ts +31 -0
  70. package/dist/lib/host/browser/swipe.js +178 -0
  71. package/dist/lib/host/browser/sync.d.ts +24 -0
  72. package/dist/lib/host/browser/sync.js +450 -0
  73. package/dist/lib/host/browser/tables.d.ts +65 -0
  74. package/dist/lib/host/browser/tables.js +505 -0
  75. package/dist/lib/host/browser/times.d.ts +14 -0
  76. package/dist/lib/host/browser/times.js +114 -0
  77. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  78. package/dist/lib/host/browser/toolbars.js +129 -0
  79. package/dist/lib/host/browser/trees.d.ts +20 -0
  80. package/dist/lib/host/browser/trees.js +235 -0
  81. package/dist/lib/host/browser/uploads.d.ts +29 -0
  82. package/dist/lib/host/browser/uploads.js +370 -0
  83. package/dist/lib/host/browser/widget.d.ts +13 -0
  84. package/dist/lib/host/browser/widget.js +105 -0
  85. package/dist/lib/host/browser.d.ts +25 -0
  86. package/dist/lib/host/browser.js +129 -3964
  87. package/dist/lib/host/devlog.d.ts +11 -0
  88. package/dist/lib/host/devlog.js +13 -0
  89. package/dist/lib/host/devtools/console.d.ts +9 -0
  90. package/dist/lib/host/devtools/console.js +104 -0
  91. package/dist/lib/host/devtools/faces.d.ts +25 -0
  92. package/dist/lib/host/devtools/faces.js +169 -0
  93. package/dist/lib/host/devtools/log.d.ts +3 -0
  94. package/dist/lib/host/devtools/log.js +32 -0
  95. package/dist/lib/host/devtools/machines.d.ts +34 -0
  96. package/dist/lib/host/devtools/machines.js +212 -0
  97. package/dist/lib/host/devtools/read.d.ts +13 -0
  98. package/dist/lib/host/devtools/read.js +52 -0
  99. package/dist/lib/host/devtools/state.d.ts +90 -0
  100. package/dist/lib/host/devtools/state.js +123 -0
  101. package/dist/lib/host/devtools.d.ts +19 -0
  102. package/dist/lib/host/devtools.js +238 -0
  103. package/dist/lib/host/fonts/OFL.txt +93 -0
  104. package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  105. package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
  106. package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
  107. package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
  108. package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
  109. package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
  110. package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
  111. package/dist/lib/host/fonts.d.ts +11 -0
  112. package/dist/lib/host/fonts.js +30 -0
  113. package/dist/lib/host/icons.js +4 -0
  114. package/dist/lib/host/index.d.ts +5 -1
  115. package/dist/lib/host/index.js +110 -5
  116. package/dist/lib/host/js.d.ts +5 -0
  117. package/dist/lib/host/js.js +130 -0
  118. package/dist/lib/host/locale.d.ts +18 -0
  119. package/dist/lib/host/locale.js +75 -5
  120. package/dist/lib/host/markdown.d.ts +6 -0
  121. package/dist/lib/host/markdown.js +18 -0
  122. package/dist/lib/host/modules.d.ts +4 -0
  123. package/dist/lib/host/modules.js +157 -20
  124. package/dist/lib/host/motion.d.ts +32 -0
  125. package/dist/lib/host/motion.js +190 -0
  126. package/dist/lib/host/net.js +14 -3
  127. package/dist/lib/host/orbit.d.ts +121 -0
  128. package/dist/lib/host/orbit.js +374 -0
  129. package/dist/lib/host/palette.d.ts +17 -0
  130. package/dist/lib/host/palette.js +131 -0
  131. package/dist/lib/host/rows.d.ts +14 -0
  132. package/dist/lib/host/rows.js +29 -0
  133. package/dist/lib/host/scheduler.d.ts +8 -0
  134. package/dist/lib/host/scheduler.js +64 -36
  135. package/dist/lib/host/share.d.ts +31 -0
  136. package/dist/lib/host/share.js +134 -0
  137. package/dist/lib/host/theme/classic.d.ts +1 -0
  138. package/dist/lib/host/theme/classic.js +120 -0
  139. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  140. package/dist/lib/host/theme/cupertino.js +65 -0
  141. package/dist/lib/host/theme/data.d.ts +1 -0
  142. package/dist/lib/host/theme/data.js +109 -0
  143. package/dist/lib/host/theme/devtools.d.ts +1 -0
  144. package/dist/lib/host/theme/devtools.js +166 -0
  145. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  146. package/dist/lib/host/theme/dialogs.js +63 -0
  147. package/dist/lib/host/theme/fluent.d.ts +1 -0
  148. package/dist/lib/host/theme/fluent.js +64 -0
  149. package/dist/lib/host/theme/forms.d.ts +1 -0
  150. package/dist/lib/host/theme/forms.js +239 -0
  151. package/dist/lib/host/theme/fusion.d.ts +1 -0
  152. package/dist/lib/host/theme/fusion.js +66 -0
  153. package/dist/lib/host/theme/layout.d.ts +1 -0
  154. package/dist/lib/host/theme/layout.js +166 -0
  155. package/dist/lib/host/theme/media.d.ts +1 -0
  156. package/dist/lib/host/theme/media.js +106 -0
  157. package/dist/lib/host/theme/navigation.d.ts +1 -0
  158. package/dist/lib/host/theme/navigation.js +36 -0
  159. package/dist/lib/host/theme/panes.d.ts +1 -0
  160. package/dist/lib/host/theme/panes.js +99 -0
  161. package/dist/lib/host/theme/popups.d.ts +1 -0
  162. package/dist/lib/host/theme/popups.js +149 -0
  163. package/dist/lib/host/theme/responsive.d.ts +1 -0
  164. package/dist/lib/host/theme/responsive.js +103 -0
  165. package/dist/lib/host/theme/toasts.d.ts +1 -0
  166. package/dist/lib/host/theme/toasts.js +62 -0
  167. package/dist/lib/host/theme.js +19 -1179
  168. package/dist/lib/ui/dialect/events.trb +276 -0
  169. package/dist/lib/ui/dialect/faces.trb +135 -0
  170. package/dist/lib/ui/dialect/layout.trb +283 -0
  171. package/dist/lib/ui/dialect/palette.trb +87 -0
  172. package/dist/lib/ui/dialect/problems.trb +174 -0
  173. package/dist/lib/ui/dialect/reactions.trb +198 -0
  174. package/dist/lib/ui/dialect/rows.trb +208 -0
  175. package/dist/lib/ui/dialect/screens.trb +293 -0
  176. package/dist/lib/ui/dialect/steps.trb +203 -0
  177. package/dist/lib/ui/dialect/validation.trb +137 -0
  178. package/dist/lib/ui/dialect/view.trb +110 -0
  179. package/dist/lib/ui/dialect/walking.trb +98 -0
  180. package/dist/lib/ui/dialect/words.trb +70 -0
  181. package/dist/lib/ui/i18n.trb +23 -0
  182. package/dist/lib/ui/test.trb +12 -0
  183. package/dist/lib/ui/testing/actions.trb +421 -0
  184. package/dist/lib/ui/testing/faces.trb +148 -0
  185. package/dist/lib/ui/testing/server.trb +73 -0
  186. package/dist/lib/ui/ui.trb +25 -1234
  187. package/dist/trebol.js +4882 -1088
  188. package/editors/vscode/README.md +15 -0
  189. package/editors/vscode/language-configuration.json +28 -0
  190. package/editors/vscode/package.json +42 -0
  191. package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
  192. package/package.json +7 -3
  193. package/src/core/boot.ts +10 -7
  194. package/src/core/eval.ts +2 -2
  195. package/src/core/func.ts +4 -0
  196. package/src/core/machine/checks.ts +251 -0
  197. package/src/core/machine/events.ts +366 -0
  198. package/src/core/machine/running.ts +181 -0
  199. package/src/core/machine/shared.ts +124 -0
  200. package/src/core/machine/snapshot.ts +245 -0
  201. package/src/core/machine/spec.ts +275 -0
  202. package/src/core/machine/words.ts +99 -0
  203. package/src/core/machine.ts +20 -0
  204. package/src/core/mezz.ts +31 -0
  205. package/src/core/natives/control.ts +2 -2
  206. package/src/core/natives/data.ts +6 -1
  207. package/src/core/natives/parse.ts +1 -1
  208. package/src/core/natives/series.ts +55 -11
  209. package/src/core/natives/text.ts +2 -1
  210. package/src/host/browser/calendar.ts +264 -0
  211. package/src/host/browser/count.ts +48 -0
  212. package/src/host/browser/dialogs.ts +439 -0
  213. package/src/host/browser/drag.ts +278 -0
  214. package/src/host/browser/drawings.ts +178 -0
  215. package/src/host/browser/events.ts +117 -0
  216. package/src/host/browser/faces.ts +143 -0
  217. package/src/host/browser/fields.ts +315 -0
  218. package/src/host/browser/keys.ts +145 -0
  219. package/src/host/browser/lookup.ts +262 -0
  220. package/src/host/browser/menus.ts +146 -0
  221. package/src/host/browser/mount.ts +420 -0
  222. package/src/host/browser/orbits.ts +418 -0
  223. package/src/host/browser/page.ts +43 -0
  224. package/src/host/browser/richtext.ts +346 -0
  225. package/src/host/browser/row-faces.ts +75 -0
  226. package/src/host/browser/screens.ts +142 -0
  227. package/src/host/browser/swipe.ts +168 -0
  228. package/src/host/browser/sync.ts +354 -0
  229. package/src/host/browser/tables.ts +461 -0
  230. package/src/host/browser/times.ts +115 -0
  231. package/src/host/browser/toolbars.ts +126 -0
  232. package/src/host/browser/trees.ts +205 -0
  233. package/src/host/browser/uploads.ts +367 -0
  234. package/src/host/browser/widget.ts +103 -0
  235. package/src/host/browser.ts +128 -3747
  236. package/src/host/devlog.ts +16 -0
  237. package/src/host/devtools/console.ts +102 -0
  238. package/src/host/devtools/faces.ts +160 -0
  239. package/src/host/devtools/log.ts +34 -0
  240. package/src/host/devtools/machines.ts +208 -0
  241. package/src/host/devtools/read.ts +58 -0
  242. package/src/host/devtools/state.ts +148 -0
  243. package/src/host/devtools.ts +238 -0
  244. package/src/host/fonts/OFL.txt +93 -0
  245. package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  246. package/src/host/fonts/inter-cyrillic.woff2 +0 -0
  247. package/src/host/fonts/inter-greek-ext.woff2 +0 -0
  248. package/src/host/fonts/inter-greek.woff2 +0 -0
  249. package/src/host/fonts/inter-latin-ext.woff2 +0 -0
  250. package/src/host/fonts/inter-latin.woff2 +0 -0
  251. package/src/host/fonts/inter-vietnamese.woff2 +0 -0
  252. package/src/host/fonts.ts +40 -0
  253. package/src/host/icons.ts +4 -0
  254. package/src/host/index.ts +110 -5
  255. package/src/host/js.ts +127 -0
  256. package/src/host/locale.ts +71 -5
  257. package/src/host/markdown.ts +18 -0
  258. package/src/host/modules.ts +150 -22
  259. package/src/host/motion.ts +204 -0
  260. package/src/host/net.ts +13 -3
  261. package/src/host/orbit.ts +432 -0
  262. package/src/host/palette.ts +139 -0
  263. package/src/host/rows.ts +30 -0
  264. package/src/host/scheduler.ts +67 -36
  265. package/src/host/share.ts +168 -0
  266. package/src/host/theme/classic.ts +121 -0
  267. package/src/host/theme/cupertino.ts +66 -0
  268. package/src/host/theme/data.ts +110 -0
  269. package/src/host/theme/devtools.ts +167 -0
  270. package/src/host/theme/dialogs.ts +64 -0
  271. package/src/host/theme/fluent.ts +65 -0
  272. package/src/host/theme/forms.ts +240 -0
  273. package/src/host/theme/fusion.ts +67 -0
  274. package/src/host/theme/layout.ts +167 -0
  275. package/src/host/theme/media.ts +107 -0
  276. package/src/host/theme/navigation.ts +37 -0
  277. package/src/host/theme/panes.ts +100 -0
  278. package/src/host/theme/popups.ts +150 -0
  279. package/src/host/theme/responsive.ts +104 -0
  280. package/src/host/theme/toasts.ts +63 -0
  281. package/src/host/theme.ts +19 -1179
  282. package/src/ui/dialect/events.trb +276 -0
  283. package/src/ui/dialect/faces.trb +135 -0
  284. package/src/ui/dialect/layout.trb +283 -0
  285. package/src/ui/dialect/palette.trb +87 -0
  286. package/src/ui/dialect/problems.trb +174 -0
  287. package/src/ui/dialect/reactions.trb +198 -0
  288. package/src/ui/dialect/rows.trb +208 -0
  289. package/src/ui/dialect/screens.trb +293 -0
  290. package/src/ui/dialect/steps.trb +203 -0
  291. package/src/ui/dialect/validation.trb +137 -0
  292. package/src/ui/dialect/view.trb +110 -0
  293. package/src/ui/dialect/walking.trb +98 -0
  294. package/src/ui/dialect/words.trb +70 -0
  295. package/src/ui/i18n.trb +23 -0
  296. package/src/ui/test.trb +12 -0
  297. package/src/ui/testing/actions.trb +421 -0
  298. package/src/ui/testing/faces.trb +148 -0
  299. package/src/ui/testing/server.trb +73 -0
  300. package/src/ui/ui.trb +25 -1234
@@ -0,0 +1,93 @@
1
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) Inter-Italic[opsz,wght].ttf: Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -4,7 +4,7 @@
4
4
  // Hosts register their own natives (print, fetch...) before calling
5
5
  // `makeRuntime`; every registered native ends up in lib.
6
6
  import { K, KIND_NAMES, TYPESETS } from "./kinds.js";
7
- import { intern, canon } from "./symbols.js";
7
+ import { intern } from "./symbols.js";
8
8
  import { NONE, TRUE, FALSE, datatype, typeset, context } from "./values.js";
9
9
  import { ctxAdd, ctxFind, bindSeries } from "./ctx.js";
10
10
  import { load } from "./lexer.js";
@@ -23,6 +23,7 @@ import "./natives/csv.js";
23
23
  import "./natives/xml.js";
24
24
  import "./natives/parse.js";
25
25
  import { MEZZANINES } from "./mezz.js";
26
+ import { MACHINE } from "./machine.js";
26
27
  export function makeRuntime() {
27
28
  const lib = context();
28
29
  const set = (name, v) => {
@@ -40,7 +41,8 @@ export function makeRuntime() {
40
41
  for (const [name, bits] of Object.entries(TYPESETS))
41
42
  set(name, typeset(bits));
42
43
  for (const def of registeredNatives())
43
- set(def.name, { t: K.Native, p: def });
44
+ if (def.hidden !== true)
45
+ set(def.name, { t: K.Native, p: def });
44
46
  for (const [name, fn] of OPS) {
45
47
  const i = ctxFind(lib, intern(fn));
46
48
  if (i < 0)
@@ -48,12 +50,14 @@ export function makeRuntime() {
48
50
  set(name, { t: K.Op, p: { fn: lib.vals[i] } });
49
51
  }
50
52
  const rt = { lib, user: context([], [], lib) };
51
- const code = load(MEZZANINES, { file: 'mezzanines' });
52
- bindSeries(code.s, lib, true);
53
- const r = runSync(rt, code);
54
- // Mezzanines failing to load is a bug in Trebol itself.
55
- if (r.k === 'error')
56
- throw new Error(`mezzanines failed: ${errorMessage(r.e)}`);
53
+ for (const [file, src] of [['mezzanines', MEZZANINES], ['machine', MACHINE]]) {
54
+ const code = load(src, { file });
55
+ bindSeries(code.s, lib, true);
56
+ const r = runSync(rt, code);
57
+ // Mezzanines failing to load is a bug in Trebol itself.
58
+ if (r.k === 'error')
59
+ throw new Error(`${file} failed: ${errorMessage(r.e)}`);
60
+ }
57
61
  return rt;
58
62
  }
59
63
  /** Runs a block to completion; an `await` becomes an error. */
@@ -13,7 +13,7 @@
13
13
  // called again with the result; they never call the evaluator themselves.
14
14
  // Errors, `break`, `return` and `throw` travel as a `Thrown` that unwinds
15
15
  // frames until a native that traps it, or a function call for `return`.
16
- import { K, kindName, kindBit } from "./kinds.js";
16
+ import { K, kindName } from "./kinds.js";
17
17
  import { spell, canon } from "./symbols.js";
18
18
  import { NONE, UNSET, TRUE, string, blockOf, } from "./values.js";
19
19
  import { getWord, setWord, instantiate } from "./ctx.js";
@@ -30,7 +30,7 @@ export const T = { Error: 0, Break: 1, Continue: 2, Return: 3, Throw: 4 };
30
30
  * reports where the program called into the library, not the library's
31
31
  * insides: `fetch`, not the native it calls.
32
32
  */
33
- export const LIBRARY_FILES = new Set(['mezzanines']);
33
+ export const LIBRARY_FILES = new Set(['mezzanines', 'machine']);
34
34
  const inLibrary = (s) => s.file !== undefined && LIBRARY_FILES.has(s.file);
35
35
  /** True when the expression that made the call on top of the stack is library code. */
36
36
  function calledFromLibrary(t) {
@@ -51,6 +51,10 @@ export interface NativeDef {
51
51
  readonly specBlock: BlockCell;
52
52
  readonly id: number;
53
53
  readonly name: string;
54
+ /** Explicit data for natives the host makes after boot, such as which JavaScript function a call runs. */
55
+ readonly data?: number;
56
+ /** Kept out of lib: only the host hands out natives built on it. */
57
+ readonly hidden?: boolean;
54
58
  }
55
59
  /** The payload of an op! cell: the two-argument function it calls. */
56
60
  export interface OpDef {
@@ -0,0 +1 @@
1
+ export declare const CHECKS: string;
@@ -0,0 +1,250 @@
1
+ // Machines in Trebol (see machine.ts). The engine, part two: the ways out of a state, and the checks of a
2
+ // machine made: every state reached, no choose that hangs, the events it takes, its data.
3
+ export const CHECKS = String.raw `
4
+ ; from a to b [on e | on [e f] | on error] [where [...]] [set [...]]
5
+ ; from a choose [on e] [when [...] to b [set [...]] ... else to c [set [...]]]
6
+ ; from a select [...] [on e] [value to b [set [...]] ... else to c [set [...]]]
7
+ transition: function [m n here] [
8
+ t: make object! [
9
+ source: target: events: guard: set: choices: other: other-set: select: place: none
10
+ ]
11
+ t/place: here
12
+ spec: next here
13
+ unless any [word? first spec] [fail "from takes the name of a state" here]
14
+ t/source: first spec
15
+ spec: next spec
16
+ switch/default first spec [
17
+ to [
18
+ t/target: second spec
19
+ unless any [word? :t/target path? :t/target] [fail "to takes the name of a state" spec]
20
+ spec: skip spec 2
21
+ ]
22
+ choose [t/choices: copy [] spec: next spec]
23
+ select [
24
+ t/select: code m spec 'select
25
+ t/choices: copy []
26
+ spec: skip spec 2
27
+ ]
28
+ ] [fail "from takes to, choose or select after the name of a state" here]
29
+ if 'on = first spec [
30
+ e: second spec
31
+ case [
32
+ word? :e [t/events: reduce [e]]
33
+ all [block? :e not empty? e parse e [some word!]] [t/events: e]
34
+ true [fail "on takes the name of an event or a block of them" spec]
35
+ ]
36
+ spec: skip spec 2
37
+ ]
38
+ what: either t/select ['select] ['choose]
39
+ if t/choices [
40
+ unless block? first spec [
41
+ fail either t/select ["select takes a block of value to a state"] ["choose takes a block of when ... to"] here
42
+ ]
43
+ branches: first spec
44
+ spec: next spec
45
+ while [not tail? branches] [
46
+ at: branches
47
+ guard: none
48
+ case [
49
+ 'else = first branches [branches: next branches]
50
+ t/select [
51
+ guard: reduce [first branches]
52
+ foreach c t/choices [
53
+ if guard/1 = first c/1 [fail rejoin ["select has two branches for " mold guard/1] at]
54
+ ]
55
+ branches: next branches
56
+ ]
57
+ true [
58
+ unless 'when = first branches [fail "choose takes when [...] to a state, or else to a state" at]
59
+ guard: code m branches 'when
60
+ branches: skip branches 2
61
+ ]
62
+ ]
63
+ unless 'to = first branches [fail rejoin ["a branch of " what " takes to and a state"] at]
64
+ target: second branches
65
+ unless any [word? :target path? :target] [fail "to takes the name of a state" branches]
66
+ branches: skip branches 2
67
+ sets: none
68
+ if 'set = first branches [
69
+ sets: code m branches 'set
70
+ branches: skip branches 2
71
+ ]
72
+ either guard [
73
+ append/only t/choices reduce [guard target sets]
74
+ ] [
75
+ if t/other [fail rejoin [what " has two else"] at]
76
+ t/other: target t/other-set: sets
77
+ ]
78
+ ]
79
+ ]
80
+ if 'where = first spec [
81
+ unless t/events [fail "where goes after on; a transition with no event that may wait for a condition is a choose" spec]
82
+ t/guard: code m spec 'where
83
+ spec: skip spec 2
84
+ ]
85
+ if 'set = first spec [
86
+ t/set: code m spec 'set
87
+ spec: skip spec 2
88
+ ]
89
+ append n/transitions t
90
+ spec
91
+ ]
92
+
93
+ resolve: function [m n t] [
94
+ if n/parallel [fail rejoin ["the states of parallel " n/name " have no ways between them"] t/place]
95
+ unless id: child m n/id t/source [fail rejoin ["no state " t/source " here" suggest t/source state-names m] t/place]
96
+ t/source: id
97
+ if t/target [t/target: target m n t/target t/place]
98
+ if t/choices [
99
+ foreach c t/choices [poke c 2 target m n second c t/place]
100
+ if t/other [t/other: target m n t/other t/place]
101
+ ]
102
+ if t/events [
103
+ if all [find t/events 'timeout not has? m id [timeout]] [
104
+ fail rejoin ["on timeout leaves " second t/place ", which has no timeout"] t/place
105
+ ]
106
+ if all [find t/events 'done not has? m id [run invoke]] [
107
+ fail rejoin ["on done leaves " second t/place ", which has no run or invoke"] t/place
108
+ ]
109
+ if find t/events 'expired [
110
+ unless m/ttl [fail "on expired needs ttl at the top of the machine" t/place]
111
+ unless all [t/target select node m t/target 'final] [
112
+ fail "on expired goes to a final state" t/place
113
+ ]
114
+ ]
115
+ ]
116
+ if all [none? t/events none? t/choices] [
117
+ foreach o n/transitions [
118
+ if all [o <> t o/source = id none? o/events none? o/choices] [
119
+ fail rejoin ["two transitions with no event leave " second t/place] t/place
120
+ ]
121
+ ]
122
+ ]
123
+ ]
124
+
125
+ ; Whether a state or one inside it has one of the fields.
126
+ has?: function [m id fields] [
127
+ n: node m id
128
+ foreach f fields [if select n f [return true]]
129
+ foreach c n/children [if has? m c fields [return true]]
130
+ false
131
+ ]
132
+
133
+ ; Every state can be reached: from the initial ones, by the ways out of states that can.
134
+ check-reach: function [m] [
135
+ reach: make map! []
136
+ mark: function [id] [
137
+ if any [none? id select reach id] [exit]
138
+ put reach id true
139
+ n: node m id
140
+ if n/parent [mark n/parent]
141
+ either n/parallel [foreach c n/children [mark c]] [mark n/initial]
142
+ ]
143
+ mark 1
144
+ more: true
145
+ while [more] [
146
+ more: false
147
+ before: length? reach
148
+ foreach n m/nodes [
149
+ foreach t n/transitions [
150
+ if select reach t/source [
151
+ mark t/target
152
+ mark t/other
153
+ foreach c any [t/choices []] [mark second c]
154
+ ]
155
+ ]
156
+ ]
157
+ more: before < length? reach
158
+ ]
159
+ foreach n next m/nodes [
160
+ unless select reach n/id [fail rejoin ["no way leads to state " n/name] n/place]
161
+ ]
162
+ ]
163
+
164
+ ; A choose with no event and no else, out of a state with no other way out, may keep the machine there for good.
165
+ check-hang: function [m] [
166
+ foreach n m/nodes [
167
+ foreach t n/transitions [
168
+ if all [t/choices none? t/events none? t/other none? t/select] [
169
+ s: node m t/source
170
+ up: next chain m 1 t/source
171
+ out: false
172
+ foreach id up [if select node m id 'parallel [out: true]]
173
+ unless empty? s/children [out: true]
174
+ foreach o m/nodes [
175
+ foreach x o/transitions [
176
+ if all [x <> t find up x/source] [out: true]
177
+ ]
178
+ ]
179
+ unless out [
180
+ fail rejoin ["the machine may stay in " s/name " for good: give the choose an else, or the state another way out"] t/place
181
+ ]
182
+ ]
183
+ ]
184
+ ]
185
+ ]
186
+
187
+ ; The events some way or defer of the machine names; none if it takes any (ttl, on-activity).
188
+ events: function [m] [
189
+ if m/ttl [return none]
190
+ out: copy []
191
+ foreach n m/nodes [
192
+ if n/activity [return none]
193
+ append out n/defer
194
+ foreach t n/transitions [append out any [t/events []]]
195
+ ]
196
+ unique out
197
+ ]
198
+
199
+ ; Every timeout is taken by a transition on timeout from its state or one around it.
200
+ check-timeouts: function [m] [
201
+ foreach n m/nodes [
202
+ if n/timeout [
203
+ up: chain m 1 n/id
204
+ taken: false
205
+ foreach o m/nodes [
206
+ foreach t o/transitions [
207
+ if all [t/events find t/events 'timeout find up t/source] [taken: true]
208
+ ]
209
+ ]
210
+ unless taken [fail rejoin ["state " n/name " has a timeout and no transition on timeout"] n/place]
211
+ ]
212
+ ]
213
+ ]
214
+
215
+ target: function [m n name place] [
216
+ any [find-state m n/id name fail rejoin ["no state " mold name suggest either path? name [last name] [name] state-names m] place]
217
+ ]
218
+
219
+ ; The data a block reads or writes, for data/x where data has no x.
220
+ check-data: function [m] [
221
+ fields: data-fields m
222
+ walk: function [b sets] [
223
+ while [not tail? b] [
224
+ v: first b
225
+ case [
226
+ all [sets set-word? :v not find fields to word! v] [
227
+ fail rejoin ["data has no " to word! v suggest to word! v fields] b
228
+ ]
229
+ all [any [path? :v set-path? :v get-path? :v] 'data = first v] [
230
+ if all [word? second v not find fields second v] [
231
+ fail rejoin ["data has no " second v suggest second v fields] b
232
+ ]
233
+ ]
234
+ any [block? :v paren? :v] [walk v false]
235
+ ]
236
+ b: next b
237
+ ]
238
+ ]
239
+ foreach place m/code [walk second place 'set = first place]
240
+ foreach n m/nodes [
241
+ if all [path? n/timeout not find fields second n/timeout] [
242
+ fail rejoin ["data has no " second n/timeout suggest second n/timeout fields] n/place
243
+ ]
244
+ if all [n/in not find fields second n/in] [
245
+ fail rejoin ["data has no " second n/in suggest second n/in fields] n/place
246
+ ]
247
+ ]
248
+ ]
249
+
250
+ `;
@@ -0,0 +1 @@
1
+ export declare const EVENTS: string;