Compare commits
141 Commits
Author | SHA1 | Date |
---|---|---|
Emery Hemingway | a2c723914b | |
Emery Hemingway | 99e4d760cf | |
Emery Hemingway | c21fdb5003 | |
Emery Hemingway | cdc59b7641 | |
Emery Hemingway | 85522a4c3c | |
Emery Hemingway | b6f7e90b95 | |
Emery Hemingway | 8dca5d4663 | |
Emery Hemingway | 42b7c9544a | |
Emery Hemingway | a4c816ef66 | |
Emery Hemingway | 7bbcdb7e77 | |
Emery Hemingway | 18dd022830 | |
Emery Hemingway | 730ce695de | |
Emery Hemingway | 48410aa94a | |
Emery Hemingway | 1bc4f872a9 | |
Emery Hemingway | f4e1e053c5 | |
Emery Hemingway | 9b70fb9b36 | |
Emery Hemingway | 347e1b5766 | |
Emery Hemingway | 24364187f2 | |
Emery Hemingway | 2901d3dbd8 | |
Emery Hemingway | 39dbe6fb63 | |
Emery Hemingway | cef56c78d6 | |
Emery Hemingway | 86be600ccf | |
Emery Hemingway | 3a8e729e89 | |
Emery Hemingway | aa7e224298 | |
Emery Hemingway | 49741ade4f | |
Emery Hemingway | 5646c10efa | |
Emery Hemingway | e08c7f3d37 | |
Emery Hemingway | 317167ea49 | |
Emery Hemingway | 7ab4611824 | |
Emery Hemingway | 51ec8df124 | |
Emery Hemingway | 7d7d182868 | |
Emery Hemingway | 8f35a1256c | |
Emery Hemingway | 3a4dc1f133 | |
Emery Hemingway | 4fb0285190 | |
Emery Hemingway | 81792ac4ce | |
Emery Hemingway | 7e15b37f44 | |
Emery Hemingway | c99f0a60ab | |
Emery Hemingway | 5fc371d187 | |
Emery Hemingway | 06898e4ec1 | |
Emery Hemingway | 2aaa588f6a | |
Emery Hemingway | e0b569e465 | |
Emery Hemingway | 13d3995507 | |
Emery Hemingway | 6487ef65d0 | |
Emery Hemingway | 6a4854110c | |
Emery Hemingway | 464043c8bf | |
Emery Hemingway | 15637620f0 | |
Emery Hemingway | c2dce8a274 | |
Emery Hemingway | 1a3fdf2a5a | |
Emery Hemingway | c2e1e2e0fa | |
Emery Hemingway | 5f45f76452 | |
Emery Hemingway | 403e54878c | |
Emery Hemingway | 7c72ea5732 | |
Emery Hemingway | 2aee79662e | |
Emery Hemingway | 8b79dce5ba | |
Emery Hemingway | 6bcf039dc2 | |
Emery Hemingway | 217a6aacf3 | |
Emery Hemingway | aea9a2e4e6 | |
Emery Hemingway | 78d7efc712 | |
Emery Hemingway | 289754499c | |
Emery Hemingway | 4fe2173d81 | |
Emery Hemingway | 87e730bc5b | |
Emery Hemingway | 399fd4a30c | |
Emery Hemingway | bf8f7e9aaa | |
Emery Hemingway | d654195fb8 | |
Emery Hemingway | 76acf2cb67 | |
Emery Hemingway | 50b00827ce | |
Emery Hemingway | 81ce71d495 | |
Emery Hemingway | a3146f88a5 | |
Emery Hemingway | 9ca073d433 | |
Emery Hemingway | cd846d0d46 | |
Emery Hemingway | 82f2e8ee98 | |
Emery Hemingway | 1592fac3b1 | |
Emery Hemingway | 8ef95c0e1d | |
Emery Hemingway | a014362292 | |
Emery Hemingway | b8c1bec9cf | |
Emery Hemingway | cf395dbfa4 | |
Emery Hemingway | 9d975bab56 | |
Emery Hemingway | 15d2e8bfb4 | |
Emery Hemingway | eb5d4d9a57 | |
Emery Hemingway | 01f26caf7b | |
Emery Hemingway | e31069e41a | |
Emery Hemingway | fdf2994ec4 | |
Emery Hemingway | 0cee6670c9 | |
Emery Hemingway | 1ce96560f4 | |
Emery Hemingway | d365a1e6e5 | |
Emery Hemingway | 3e5d910d1a | |
Emery Hemingway | 50a77995bc | |
Emery Hemingway | 3e324e2de4 | |
Emery Hemingway | aadf7a3dc7 | |
Emery Hemingway | a2849b18c9 | |
Emery Hemingway | f3d6e578cb | |
Emery Hemingway | 39cb3790df | |
Emery Hemingway | 46dca031fa | |
Emery Hemingway | 79c621e979 | |
Emery Hemingway | a05cfa37eb | |
Emery Hemingway | d6a8b31812 | |
Emery Hemingway | a4ba81a481 | |
Emery Hemingway | 75d1e33bff | |
Emery Hemingway | 6b642645f9 | |
Emery Hemingway | 0e5637a6c3 | |
Emery Hemingway | 3e11884a91 | |
Emery Hemingway | 7721138bf4 | |
Emery Hemingway | 59ece65f3b | |
Emery Hemingway | 6d2a401a2b | |
Emery Hemingway | 19121e514c | |
Emery Hemingway | df52f72263 | |
Emery Hemingway | e48c62f448 | |
Emery Hemingway | 3cc3a48c82 | |
Emery Hemingway | c1c5333778 | |
Emery Hemingway | 1e107131d8 | |
Emery Hemingway | a0355637d8 | |
Emery Hemingway | c0cff79313 | |
Emery Hemingway | b5aa2a7b8f | |
Emery Hemingway | 8f6da89d69 | |
Emery Hemingway | 0954180321 | |
Emery Hemingway | 97d24aa971 | |
Emery Hemingway | 8a7cc884fe | |
Emery Hemingway | 23c69f63a5 | |
Emery Hemingway | 8bc0ee2ae5 | |
Emery Hemingway | 090b4d77ef | |
Emery Hemingway | 00609f3b6f | |
Emery Hemingway | 577490701a | |
Emery Hemingway | 843252ad61 | |
Emery Hemingway | ac2576f005 | |
Emery Hemingway | 311b614979 | |
Emery Hemingway | 5b373e3047 | |
Emery Hemingway | ec8e166099 | |
Emery Hemingway | a987f875a9 | |
Emery Hemingway | 57b99b20e7 | |
Emery Hemingway | 4a6e95bbce | |
Emery Hemingway | 3a04fc195b | |
Emery Hemingway | 6fcb76b1e9 | |
Emery Hemingway | 552e51899c | |
Emery Hemingway | b2994b6d05 | |
Emery Hemingway | d86ef24c01 | |
Emery Hemingway | dcd6bfe99b | |
Emery Hemingway | 35670b2727 | |
Emery Hemingway | 73d29da071 | |
Emery Hemingway | 66f435a279 | |
Emery Hemingway | 703bd7baea | |
Emery Hemingway | ce6d97c1d3 |
|
@ -1 +1,3 @@
|
||||||
/.direnv
|
/nim.cfg
|
||||||
|
*.check
|
||||||
|
*.run
|
||||||
|
|
19
README.md
19
README.md
|
@ -54,7 +54,8 @@ The Syndicate DSL can be entered using `runActor` which calls a Nim body with a
|
||||||
### Publish
|
### Publish
|
||||||
|
|
||||||
``` nim
|
``` nim
|
||||||
runActor("main") do (dataspace: Ref; turn: var Turn):
|
runActor("main") do (turn: Turn):
|
||||||
|
let dataspace = newDataspace()
|
||||||
let presenceHandle = publish(turn, dataspace, Present(username: "Judy"))
|
let presenceHandle = publish(turn, dataspace, Present(username: "Judy"))
|
||||||
# publish <Present "Judy"> to the dataspace
|
# publish <Present "Judy"> to the dataspace
|
||||||
# the assertion can be later retracted by handle
|
# the assertion can be later retracted by handle
|
||||||
|
@ -67,7 +68,8 @@ runActor("main") do (dataspace: Ref; turn: var Turn):
|
||||||
We can react to assertions and messages within dataspaces using [patterns](https://synit.org/book/glossary.html#dataspace-pattern). Patterns are constructed using a Nim type and the `?` operator. Again a Nim type is used rather than a raw Preserves for schema consistency.
|
We can react to assertions and messages within dataspaces using [patterns](https://synit.org/book/glossary.html#dataspace-pattern). Patterns are constructed using a Nim type and the `?` operator. Again a Nim type is used rather than a raw Preserves for schema consistency.
|
||||||
|
|
||||||
``` nim
|
``` nim
|
||||||
runActor("main") do (dataspace: Ref; turn: var Turn):
|
runActor("main") do (turn: Turn):
|
||||||
|
let dataspace = newDataspace()
|
||||||
during(turn, dataspace, ?Present) do (who: string):
|
during(turn, dataspace, ?Present) do (who: string):
|
||||||
# This body is active when the ?Present pattern is matched.
|
# This body is active when the ?Present pattern is matched.
|
||||||
# The Present type contains two atomic values that can be matched
|
# The Present type contains two atomic values that can be matched
|
||||||
|
@ -89,20 +91,15 @@ runActor("main") do (dataspace: Ref; turn: var Turn):
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### [test_chat](./tests/test_chat.nim)
|
### [test_chat](./tests/test_chat.nim)
|
||||||
Simple chat demo that is compatible with [chat.py](https://git.syndicate-lang.org/syndicate-lang/syndicate-py/src/branch/main/chat.py).
|
Simple chat demo that is compatible with [chat.py](https://git.syndicate-lang.org/syndicate-lang/syndicate-py/src/branch/main/chat.py).
|
||||||
```sh
|
```sh
|
||||||
nim c -r tests/test_chat.nim \
|
SYNDICATE_ROUTE='<route [<unix "/run/user/1000/dataspace">] [<ref {oid: "syndicate" sig: #x"69ca300c1dbfa08fba692102dd82311a"}>]>' nim c -r tests/test_chat.nim --user:fnord
|
||||||
--cap:'<ref {oid: "syndicate" sig: #x"69ca300c1dbfa08fba692102dd82311a"}>' \
|
|
||||||
--transport:'<tcp "127.0.0.1" 666>' \
|
|
||||||
--user:fnord
|
|
||||||
```
|
```
|
||||||
|
### [syndicate_utils](https://git.syndicate-lang.org/ehmry/syndicate_utils)
|
||||||
### [xdg_open_ng](https://git.syndicate-lang.org/ehmry/xdg_open_ng)
|
|
||||||
Messaging, UNIX sockets, dynamic configuration, [Syndicate server](https://synit.org/book/operation/system-bus.html) interaction.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This work has been supported by the [NLnet Foundation](https://nlnet.nl/) and the European Commission's [Next Generation Internet programme](https://www.ngi.eu/). The [Syndicate Actor Model](https://syndicate-lang.org/projects/2021/system-layer/) through the [NGI Zero PET](https://nlnet.nl/PET/) program and this library as a part of the [ERIS project](https://eris.codeberg.page/) through [NGI Assure](https://nlnet.nl/assure/).
|
This work has been supported by the [NLnet Foundation](https://nlnet.nl/) and the European Commission's [Next Generation Internet programme](https://www.ngi.eu/). The [Syndicate Actor Model](https://syndicate-lang.org/projects/2021/system-layer/) through the [NGI Zero PET](https://nlnet.nl/PET/) program and this library as a part of the [ERIS project](https://eris.codeberg.page/) through [NGI Assure](https://nlnet.nl/assure/).
|
||||||
|
|
||||||
[![NLnet](https://nlnet.nl/logo/banner.svg)](https://nlnet.nl/)
|
[![NLnet](./nlnet.svg)](https://nlnet.nl/)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
include_rules
|
||||||
|
: sbom.json |> !sbom-to-nix |> | ./<lock>
|
|
@ -1 +1,4 @@
|
||||||
|
PROJECT_DIR = $(TUP_CWD)
|
||||||
|
NIM_GROUPS += $(TUP_CWD)/<lock>
|
||||||
|
|
||||||
include depends.tup
|
include depends.tup
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
include ../preserves-nim/depends.tup
|
include ../preserves-nim/depends.tup
|
||||||
include ../taps/depends.tup
|
NIM = $(DIRENV) $(NIM)
|
||||||
NIM_FLAGS += --path:$(TUP_CWD)/../nim
|
NIM_FLAGS += --path:$(TUP_CWD)/src
|
||||||
NIM_FLAGS += --path:$(TUP_CWD)/../preserves-nim/src
|
|
||||||
NIM_FLAGS += --path:$(TUP_CWD)/../taps/src
|
|
||||||
NIM_FLAGS += --path:$(TUP_CWD)/../hashlib
|
|
||||||
NIM_GROUPS += $(TUP_CWD)/<protocol>
|
NIM_GROUPS += $(TUP_CWD)/<protocol>
|
||||||
|
NIM_GROUPS += $(TUP_CWD)/<schema>
|
||||||
|
NIM_LOCK_EXCLUDES += "syndicate"
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:serif="http://www.serif.com/" width="272" height="104" version="1.1" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<g transform="scale(0.25)">
|
||||||
|
<g>
|
||||||
|
<g>
|
||||||
|
<path d="M211.345,190.214c-1.137,4.372 -5.39,7.182 -9.858,6.513c-22.854,-3.548 -44.571,-15.066 -60.591,-34.158c-35.111,-41.843 -29.645,-104.32 12.199,-139.431c41.843,-35.111 104.32,-29.645 139.431,12.198c16.02,19.092 23.592,42.479 23.117,65.603c-0.117,4.516 -3.623,8.215 -8.126,8.575c-4.029,0.353 -8.046,0.928 -12.032,1.727c-2.662,0.545 -5.427,-0.168 -7.494,-1.933c-2.066,-1.764 -3.204,-4.383 -3.084,-7.098c0.798,-16.564 -4.394,-33.46 -15.884,-47.152c-24.226,-28.872 -67.335,-32.644 -96.207,-8.418c-28.872,24.227 -32.644,67.336 -8.417,96.208c11.489,13.693 27.226,21.74 43.677,23.832c2.694,0.353 5.075,1.928 6.454,4.269c1.378,2.341 1.6,5.187 0.602,7.714c-1.477,3.787 -2.741,7.643 -3.787,11.551Z" style="fill:#74aa00;"/>
|
||||||
|
<path d="M211.306,68.301c16.918,-2.983 33.074,8.33 36.057,25.247c2.983,16.917 -8.33,33.074 -25.247,36.057c-16.918,2.983 -33.074,-8.33 -36.057,-25.248c-2.983,-16.917 8.33,-33.073 25.247,-36.056Z"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<path d="M224.072,211.345c-4.372,-1.137 -7.183,-5.39 -6.513,-9.858c3.547,-22.854 15.066,-44.571 34.158,-60.591c41.843,-35.111 104.32,-29.645 139.431,12.199c35.111,41.843 29.645,104.32 -12.199,139.431c-19.091,16.02 -42.479,23.592 -65.602,23.117c-4.516,-0.117 -8.216,-3.623 -8.576,-8.126c-0.352,-4.029 -0.927,-8.046 -1.726,-12.032c-0.545,-2.662 0.168,-5.427 1.933,-7.494c1.764,-2.066 4.383,-3.204 7.098,-3.084c16.564,0.798 33.459,-4.394 47.152,-15.884c28.872,-24.226 32.644,-67.335 8.417,-96.207c-24.226,-28.872 -67.335,-32.644 -96.207,-8.417c-13.693,11.489 -21.74,27.226 -23.833,43.677c-0.352,2.694 -1.927,5.075 -4.268,6.454c-2.342,1.378 -5.188,1.6 -7.714,0.602c-3.787,-1.477 -7.644,-2.741 -11.551,-3.787Z" style="fill:#74aa00;"/>
|
||||||
|
<path d="M345.985,211.306c2.983,16.918 -8.33,33.074 -25.247,36.057c-16.918,2.983 -33.074,-8.33 -36.057,-25.247c-2.983,-16.918 8.33,-33.074 25.247,-36.057c16.918,-2.983 33.074,8.33 36.057,25.247Z"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<path d="M202.941,224.072c1.136,-4.372 5.389,-7.183 9.857,-6.513c22.855,3.547 44.572,15.066 60.592,34.158c35.11,41.843 29.644,104.32 -12.199,139.431c-41.843,35.111 -104.32,29.645 -139.431,-12.199c-16.02,-19.091 -23.593,-42.479 -23.117,-65.602c0.117,-4.516 3.622,-8.216 8.126,-8.576c4.029,-0.352 8.046,-0.927 12.032,-1.726c2.662,-0.545 5.427,0.168 7.493,1.933c2.067,1.764 3.205,4.383 3.084,7.098c-0.798,16.564 4.395,33.459 15.884,47.152c24.227,28.872 67.336,32.644 96.208,8.417c28.872,-24.226 32.643,-67.335 8.417,-96.207c-11.49,-13.693 -27.227,-21.74 -43.678,-23.833c-2.694,-0.352 -5.075,-1.927 -6.453,-4.268c-1.379,-2.342 -1.601,-5.188 -0.602,-7.714c1.477,-3.787 2.741,-7.644 3.787,-11.551Z" style="fill:#74aa00;"/>
|
||||||
|
<path d="M202.979,345.985c-16.917,2.983 -33.073,-8.33 -36.056,-25.247c-2.983,-16.918 8.329,-33.074 25.247,-36.057c16.917,-2.983 33.074,8.33 36.057,25.247c2.983,16.918 -8.33,33.074 -25.248,36.057Z"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<path d="M190.214,202.941c4.372,1.136 7.182,5.389 6.513,9.857c-3.548,22.855 -15.066,44.572 -34.158,60.592c-41.843,35.11 -104.32,29.644 -139.431,-12.199c-35.111,-41.843 -29.645,-104.32 12.198,-139.431c19.092,-16.02 42.479,-23.593 65.603,-23.117c4.516,0.117 8.215,3.622 8.575,8.126c0.353,4.029 0.928,8.046 1.727,12.032c0.545,2.662 -0.168,5.427 -1.933,7.493c-1.764,2.067 -4.383,3.205 -7.098,3.084c-16.564,-0.798 -33.46,4.395 -47.152,15.884c-28.872,24.227 -32.644,67.336 -8.418,96.208c24.227,28.872 67.336,32.643 96.208,8.417c13.693,-11.49 21.74,-27.227 23.832,-43.678c0.353,-2.694 1.928,-5.075 4.269,-6.453c2.341,-1.379 5.187,-1.601 7.714,-0.602c3.787,1.477 7.643,2.741 11.551,3.787Z" style="fill:#74aa00;"/>
|
||||||
|
<path d="M68.301,202.979c-2.983,-16.917 8.33,-33.073 25.247,-36.056c16.917,-2.983 33.074,8.329 36.057,25.247c2.983,16.917 -8.33,33.074 -25.248,36.057c-16.917,2.983 -33.073,-8.33 -36.056,-25.248Z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<g>
|
||||||
|
<path d="M467.416,259.709c-1.713,-0 -3.169,-0.6 -4.368,-1.799c-1.199,-1.199 -1.798,-2.654 -1.798,-4.367l0,-121.259c0,-1.713 0.599,-3.169 1.798,-4.368c1.199,-1.199 2.655,-1.798 4.368,-1.798l21.066,-0c1.713,-0 3.168,0.599 4.367,1.798c1.199,1.199 1.799,2.655 1.799,4.368l-0,10.533c4.453,-5.481 10.147,-10.062 17.084,-13.745c6.936,-3.682 15.543,-5.523 25.819,-5.523c10.447,-0 19.525,2.355 27.232,7.065c7.707,4.71 13.659,11.346 17.855,19.91c4.196,8.563 6.294,18.84 6.294,30.829l0,72.19c0,1.713 -0.599,3.168 -1.798,4.367c-1.199,1.199 -2.655,1.799 -4.368,1.799l-22.607,-0c-1.713,-0 -3.169,-0.6 -4.368,-1.799c-1.199,-1.199 -1.798,-2.654 -1.798,-4.367l-0,-70.649c-0,-9.934 -2.441,-17.727 -7.322,-23.378c-4.881,-5.652 -11.946,-8.478 -21.195,-8.478c-8.906,-0 -16.013,2.826 -21.323,8.478c-5.309,5.651 -7.964,13.444 -7.964,23.378l0,70.649c0,1.713 -0.599,3.168 -1.798,4.367c-1.199,1.199 -2.655,1.799 -4.368,1.799l-22.607,-0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M627.982,259.709c-1.713,-0 -3.169,-0.6 -4.368,-1.799c-1.199,-1.199 -1.798,-2.654 -1.798,-4.367l-0,-170.071c-0,-1.713 0.599,-3.169 1.798,-4.368c1.199,-1.199 2.655,-1.798 4.368,-1.798l21.323,-0c1.713,-0 3.168,0.599 4.367,1.798c1.199,1.199 1.799,2.655 1.799,4.368l-0,170.071c-0,1.713 -0.6,3.168 -1.799,4.367c-1.199,1.199 -2.654,1.799 -4.367,1.799l-21.323,-0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M695.805,259.709c-1.713,-0 -3.169,-0.6 -4.368,-1.799c-1.199,-1.199 -1.798,-2.654 -1.798,-4.367l0,-121.259c0,-1.713 0.599,-3.169 1.798,-4.368c1.199,-1.199 2.655,-1.798 4.368,-1.798l21.066,-0c1.713,-0 3.169,0.599 4.367,1.798c1.199,1.199 1.799,2.655 1.799,4.368l-0,10.533c4.453,-5.481 10.147,-10.062 17.084,-13.745c6.936,-3.682 15.543,-5.523 25.819,-5.523c10.447,-0 19.525,2.355 27.232,7.065c7.707,4.71 13.659,11.346 17.855,19.91c4.196,8.563 6.294,18.84 6.294,30.829l0,72.19c0,1.713 -0.599,3.168 -1.798,4.367c-1.199,1.199 -2.655,1.799 -4.368,1.799l-22.607,-0c-1.713,-0 -3.169,-0.6 -4.368,-1.799c-1.199,-1.199 -1.798,-2.654 -1.798,-4.367l-0,-70.649c-0,-9.934 -2.441,-17.727 -7.322,-23.378c-4.881,-5.652 -11.946,-8.478 -21.195,-8.478c-8.906,-0 -16.013,2.826 -21.323,8.478c-5.309,5.651 -7.964,13.444 -7.964,23.378l0,70.649c0,1.713 -0.599,3.168 -1.798,4.367c-1.199,1.199 -2.655,1.799 -4.368,1.799l-22.607,-0Z" style="fill:#74aa00;fill-rule:nonzero;"/>
|
||||||
|
<path d="M907.495,262.278c-19.011,-0 -34.083,-5.481 -45.215,-16.442c-11.133,-10.961 -17.128,-26.547 -17.984,-46.757c-0.171,-1.713 -0.257,-3.896 -0.257,-6.551c0,-2.655 0.086,-4.753 0.257,-6.294c0.685,-13.017 3.64,-24.192 8.863,-33.526c5.224,-9.335 12.46,-16.528 21.709,-21.581c9.248,-5.052 20.124,-7.578 32.627,-7.578c13.873,-0 25.519,2.869 34.939,8.606c9.42,5.738 16.528,13.702 21.323,23.892c4.796,10.191 7.194,21.966 7.194,35.325l-0,5.395c-0,1.713 -0.6,3.168 -1.799,4.367c-1.199,1.199 -2.74,1.799 -4.624,1.799l-85.293,-0l0,2.055c0.172,5.994 1.328,11.518 3.469,16.57c2.14,5.053 5.309,9.12 9.505,12.203c4.196,3.083 9.206,4.625 15.029,4.625c4.796,-0 8.82,-0.728 12.075,-2.184c3.254,-1.456 5.908,-3.126 7.964,-5.01c2.055,-1.884 3.511,-3.425 4.367,-4.624c1.541,-2.055 2.783,-3.297 3.725,-3.725c0.942,-0.428 2.355,-0.642 4.239,-0.642l22.094,-0c1.713,-0 3.126,0.513 4.239,1.541c1.113,1.028 1.584,2.312 1.413,3.854c-0.171,2.74 -1.584,6.08 -4.239,10.019c-2.655,3.939 -6.466,7.793 -11.432,11.561c-4.967,3.768 -11.176,6.893 -18.626,9.377c-7.45,2.483 -15.971,3.725 -25.562,3.725Zm-28.26,-80.925l56.776,-0l0,-0.771c0,-6.68 -1.113,-12.546 -3.339,-17.598c-2.227,-5.053 -5.481,-8.992 -9.763,-11.818c-4.282,-2.826 -9.42,-4.239 -15.414,-4.239c-5.995,0 -11.133,1.413 -15.414,4.239c-4.282,2.826 -7.494,6.765 -9.634,11.818c-2.141,5.052 -3.212,10.918 -3.212,17.598l0,0.771Z" style="fill:#74aa00;fill-rule:nonzero;"/>
|
||||||
|
<path d="M1058.04,259.709c-10.277,-0 -18.926,-1.799 -25.948,-5.395c-7.022,-3.597 -12.246,-8.949 -15.671,-16.057c-3.426,-7.108 -5.138,-15.971 -5.138,-26.59l-0,-58.317l-20.296,-0c-1.713,-0 -3.168,-0.6 -4.367,-1.799c-1.199,-1.198 -1.799,-2.74 -1.799,-4.624l0,-14.643c0,-1.713 0.6,-3.169 1.799,-4.368c1.199,-1.199 2.654,-1.798 4.367,-1.798l20.296,-0l-0,-42.646c-0,-1.713 0.556,-3.169 1.67,-4.368c1.113,-1.199 2.611,-1.798 4.495,-1.798l20.81,-0c1.713,-0 3.168,0.599 4.367,1.798c1.199,1.199 1.799,2.655 1.799,4.368l-0,42.646l32.113,-0c1.712,-0 3.168,0.599 4.367,1.798c1.199,1.199 1.798,2.655 1.798,4.368l0,14.643c0,1.884 -0.599,3.426 -1.798,4.624c-1.199,1.199 -2.655,1.799 -4.367,1.799l-32.113,-0l-0,55.748c-0,7.022 1.241,12.503 3.725,16.442c2.483,3.939 6.808,5.909 12.973,5.909l17.727,0c1.713,0 3.168,0.6 4.367,1.798c1.199,1.199 1.799,2.655 1.799,4.368l-0,15.928c-0,1.713 -0.6,3.168 -1.799,4.367c-1.199,1.199 -2.654,1.799 -4.367,1.799l-20.809,-0Z" style="fill:#74aa00;fill-rule:nonzero;"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<path d="M489.774,297.042c0.412,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l-0,5.963c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.657,0.45 -1.069,0.45l-16.819,0l0,7.707l15.694,-0c0.412,-0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.656 0.45,1.068l-0,5.963c-0,0.412 -0.15,0.769 -0.45,1.069c-0.3,0.3 -0.657,0.45 -1.069,0.45l-15.694,-0l0,12.15c0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.656,0.45 -1.069,0.45l-7.368,0c-0.413,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l-0,-36.338c-0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l25.706,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M542.48,296.48c3.563,-0 6.638,0.675 9.225,2.025c2.588,1.35 4.585,3.178 5.991,5.484c1.406,2.307 2.184,4.885 2.334,7.735c0.075,1.05 0.113,2.737 0.113,5.062c-0,2.288 -0.038,3.938 -0.113,4.95c-0.15,2.85 -0.928,5.428 -2.334,7.735c-1.406,2.306 -3.403,4.134 -5.991,5.484c-2.587,1.35 -5.662,2.025 -9.225,2.025c-3.562,-0 -6.637,-0.675 -9.225,-2.025c-2.587,-1.35 -4.584,-3.178 -5.99,-5.484c-1.407,-2.307 -2.185,-4.885 -2.335,-7.735c-0.075,-2.025 -0.112,-3.675 -0.112,-4.95c-0,-1.275 0.037,-2.962 0.112,-5.062c0.15,-2.85 0.928,-5.428 2.335,-7.735c1.406,-2.306 3.403,-4.134 5.99,-5.484c2.588,-1.35 5.663,-2.025 9.225,-2.025Zm7.144,15.525c-0.188,-1.988 -0.872,-3.572 -2.053,-4.753c-1.181,-1.181 -2.878,-1.772 -5.091,-1.772c-2.212,-0 -3.909,0.591 -5.09,1.772c-1.182,1.181 -1.866,2.765 -2.054,4.753c-0.112,1.237 -0.168,2.794 -0.168,4.669c-0,1.837 0.056,3.431 0.168,4.781c0.188,1.987 0.872,3.572 2.054,4.753c1.181,1.181 2.878,1.772 5.09,1.772c2.213,-0 3.91,-0.591 5.091,-1.772c1.181,-1.181 1.865,-2.766 2.053,-4.753c0.112,-1.35 0.169,-2.944 0.169,-4.781c-0,-1.875 -0.057,-3.432 -0.169,-4.669Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M627.868,297.042c0.412,0 0.768,0.15 1.068,0.45c0.3,0.3 0.45,0.657 0.45,1.069l0,22.444c0,3.375 -0.712,6.262 -2.137,8.662c-1.425,2.4 -3.422,4.219 -5.991,5.457c-2.568,1.237 -5.559,1.856 -8.972,1.856c-3.45,-0 -6.459,-0.619 -9.028,-1.856c-2.568,-1.238 -4.556,-3.057 -5.962,-5.457c-1.406,-2.4 -2.11,-5.287 -2.11,-8.662l0,-22.444c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.657,-0.45 1.069,-0.45l7.369,0c0.412,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l-0,22.219c-0,2.287 0.572,4.059 1.715,5.316c1.144,1.256 2.803,1.884 4.978,1.884c2.175,-0 3.835,-0.628 4.979,-1.884c1.143,-1.257 1.715,-3.029 1.715,-5.316l0,-22.219c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l7.369,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M691.43,336.417c-0.562,0 -1.05,-0.14 -1.462,-0.421c-0.413,-0.282 -0.694,-0.572 -0.844,-0.872l-12.881,-19.238l-0,19.013c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.657,0.45 -1.069,0.45l-7.369,0c-0.412,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l0,-36.338c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.657,-0.45 1.069,-0.45l5.85,0c0.563,0 1.05,0.141 1.463,0.422c0.412,0.282 0.693,0.572 0.843,0.872l12.882,19.238l-0,-19.013c-0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.068,-0.45l7.369,0c0.413,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l-0,36.338c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.656,0.45 -1.069,0.45l-5.85,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M768.83,312.736c0.075,2.1 0.113,3.45 0.113,4.05c-0,0.6 -0.038,1.913 -0.113,3.938c-0.112,3.075 -0.909,5.793 -2.39,8.156c-1.482,2.362 -3.516,4.209 -6.104,5.541c-2.587,1.331 -5.587,1.996 -9,1.996l-15.187,0c-0.413,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l0,-36.338c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l14.906,0c3.413,0 6.441,0.666 9.085,1.997c2.643,1.332 4.725,3.188 6.243,5.569c1.519,2.381 2.335,5.091 2.447,8.128Zm-23.794,-6.694l0,21.375l6.019,0c4.725,0 7.181,-2.156 7.369,-6.468c0.075,-2.175 0.112,-3.6 0.112,-4.275c0,-0.75 -0.037,-2.138 -0.112,-4.163c-0.113,-2.137 -0.816,-3.75 -2.109,-4.837c-1.294,-1.088 -3.141,-1.632 -5.541,-1.632l-5.738,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M835.936,334.336c0.15,0.375 0.225,0.656 0.225,0.844c0,0.337 -0.121,0.628 -0.365,0.872c-0.244,0.244 -0.535,0.365 -0.872,0.365l-7.088,0c-0.637,0 -1.134,-0.14 -1.49,-0.421c-0.356,-0.282 -0.591,-0.61 -0.703,-0.985l-1.575,-4.669l-14.963,0l-1.575,4.669c-0.112,0.375 -0.347,0.703 -0.703,0.985c-0.356,0.281 -0.853,0.421 -1.491,0.421l-7.087,0c-0.338,0 -0.628,-0.121 -0.872,-0.365c-0.244,-0.244 -0.366,-0.535 -0.366,-0.872c0,-0.188 0.075,-0.469 0.225,-0.844l12.263,-35.437c0.187,-0.525 0.487,-0.966 0.9,-1.322c0.412,-0.356 0.956,-0.535 1.631,-0.535l9.113,0c0.675,0 1.218,0.179 1.631,0.535c0.412,0.356 0.712,0.797 0.9,1.322l12.262,35.437Zm-14.793,-12.712l-4.557,-13.5l-4.556,13.5l9.113,-0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M898.599,297.042c0.412,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l-0,5.963c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.657,0.45 -1.069,0.45l-9.9,0l-0,28.857c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.656,0.45 -1.069,0.45l-7.369,0c-0.412,0 -0.768,-0.15 -1.068,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l-0,-28.857l-9.9,0c-0.413,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l-0,-5.963c-0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l30.206,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M935.668,336.417c-0.413,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l-0,-36.338c-0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l7.368,0c0.413,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l0,36.338c0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.656,0.45 -1.069,0.45l-7.368,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M997.655,296.48c3.563,-0 6.638,0.675 9.225,2.025c2.588,1.35 4.585,3.178 5.991,5.484c1.406,2.307 2.184,4.885 2.334,7.735c0.075,1.05 0.113,2.737 0.113,5.062c-0,2.288 -0.038,3.938 -0.113,4.95c-0.15,2.85 -0.928,5.428 -2.334,7.735c-1.406,2.306 -3.403,4.134 -5.991,5.484c-2.587,1.35 -5.662,2.025 -9.225,2.025c-3.562,-0 -6.637,-0.675 -9.225,-2.025c-2.587,-1.35 -4.584,-3.178 -5.99,-5.484c-1.407,-2.307 -2.185,-4.885 -2.335,-7.735c-0.075,-2.025 -0.112,-3.675 -0.112,-4.95c-0,-1.275 0.037,-2.962 0.112,-5.062c0.15,-2.85 0.928,-5.428 2.335,-7.735c1.406,-2.306 3.403,-4.134 5.99,-5.484c2.588,-1.35 5.663,-2.025 9.225,-2.025Zm7.144,15.525c-0.188,-1.988 -0.872,-3.572 -2.053,-4.753c-1.181,-1.181 -2.878,-1.772 -5.091,-1.772c-2.212,-0 -3.909,0.591 -5.09,1.772c-1.182,1.181 -1.866,2.765 -2.054,4.753c-0.112,1.237 -0.168,2.794 -0.168,4.669c-0,1.837 0.056,3.431 0.168,4.781c0.188,1.987 0.872,3.572 2.054,4.753c1.181,1.181 2.878,1.772 5.09,1.772c2.213,-0 3.91,-0.591 5.091,-1.772c1.181,-1.181 1.865,-2.766 2.053,-4.753c0.112,-1.35 0.169,-2.944 0.169,-4.781c-0,-1.875 -0.057,-3.432 -0.169,-4.669Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
<path d="M1076.35,336.417c-0.563,0 -1.05,-0.14 -1.463,-0.421c-0.412,-0.282 -0.693,-0.572 -0.843,-0.872l-12.882,-19.238l0,19.013c0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.656,0.45 -1.068,0.45l-7.369,0c-0.413,0 -0.769,-0.15 -1.069,-0.45c-0.3,-0.3 -0.45,-0.656 -0.45,-1.068l0,-36.338c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.656,-0.45 1.069,-0.45l5.85,0c0.562,0 1.05,0.141 1.462,0.422c0.413,0.282 0.694,0.572 0.844,0.872l12.881,19.238l0,-19.013c0,-0.412 0.15,-0.769 0.45,-1.069c0.3,-0.3 0.657,-0.45 1.069,-0.45l7.369,0c0.412,0 0.769,0.15 1.069,0.45c0.3,0.3 0.45,0.657 0.45,1.069l-0,36.338c-0,0.412 -0.15,0.768 -0.45,1.068c-0.3,0.3 -0.657,0.45 -1.069,0.45l-5.85,0Z" style="fill:#231f20;fill-rule:nonzero;"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 16 KiB |
|
@ -0,0 +1,538 @@
|
||||||
|
{
|
||||||
|
"bomFormat": "CycloneDX",
|
||||||
|
"specVersion": "1.6",
|
||||||
|
"metadata": {
|
||||||
|
"component": {
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/syndicate",
|
||||||
|
"name": "syndicate",
|
||||||
|
"description": "Syndicated actors for conversational concurrency",
|
||||||
|
"version": "20240628",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Emery Hemingway"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"license": {
|
||||||
|
"id": "Unlicense"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nim:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nim:backend",
|
||||||
|
"value": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/nimcrypto",
|
||||||
|
"name": "nimcrypto",
|
||||||
|
"version": "485f7b3cfa83c1beecc0e31be0e964d697aa74d7",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/cheatfate/nimcrypto/archive/485f7b3cfa83c1beecc0e31be0e964d697aa74d7.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/cheatfate/nimcrypto",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/fkrcpp8lzj2yi21na79xm63xk0ggnqsp-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "485f7b3cfa83c1beecc0e31be0e964d697aa74d7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1h3dzdbc9kacwpi10mj73yjglvn7kbizj1x8qc9099ax091cj5xn"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/cheatfate/nimcrypto/archive/485f7b3cfa83c1beecc0e31be0e964d697aa74d7.tar.gz"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/preserves",
|
||||||
|
"name": "preserves",
|
||||||
|
"version": "20240610",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/560a6417a30a2dff63f24b62498e9fcac2de8354.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://git.syndicate-lang.org/ehmry/preserves-nim.git",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/0sszsmz84ppwqsgda8cmli4lfh2mjmin-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "560a6417a30a2dff63f24b62498e9fcac2de8354"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "19r983fy7m54mlaj0adxdp8pxi1x8dp6phkcnr8rz5y5cwndfjx2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/560a6417a30a2dff63f24b62498e9fcac2de8354.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "20240610"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/sys",
|
||||||
|
"name": "sys",
|
||||||
|
"version": "4ef3b624db86e331ba334e705c1aa235d55b05e1",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/ehmry/nim-sys/archive/4ef3b624db86e331ba334e705c1aa235d55b05e1.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/ehmry/nim-sys.git",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/syhxsjlsdqfap0hk4qp3s6kayk8cqknd-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "4ef3b624db86e331ba334e705c1aa235d55b05e1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1q4qgw4an4mmmcbx48l6xk1jig1vc8p9cq9dbx39kpnb0890j32q"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/ehmry/nim-sys/archive/4ef3b624db86e331ba334e705c1aa235d55b05e1.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/taps",
|
||||||
|
"name": "taps",
|
||||||
|
"version": "20240405",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/8c8572cd971d1283e6621006b310993c632da247.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/nim_taps",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/6y14ia52kr7jyaa0izx37mlablmq9s65-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "8c8572cd971d1283e6621006b310993c632da247"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1dp166bv9x773jmfqppg5i3v3rilgff013vb11yzwcid9l7s3iy8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://git.sr.ht/~ehmry/nim_taps/archive/8c8572cd971d1283e6621006b310993c632da247.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "20240405"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/solo5_dispatcher",
|
||||||
|
"name": "solo5_dispatcher",
|
||||||
|
"version": "20240522",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/solo5_dispatcher/archive/cc64ef99416b22b12e4a076d33de9e25a163e57d.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/solo5_dispatcher",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/4jj467pg4hs6warhksb8nsxn9ykz8c7c-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "cc64ef99416b22b12e4a076d33de9e25a163e57d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1v9i9fqgx1g76yrmz2xwj9mxfwbjfpar6dsyygr68fv9031cqxq7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://git.sr.ht/~ehmry/solo5_dispatcher/archive/cc64ef99416b22b12e4a076d33de9e25a163e57d.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "20240522"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "pkg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/npeg",
|
||||||
|
"name": "npeg",
|
||||||
|
"version": "1.2.2",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/zevv/npeg/archive/ec0cc6e64ea4c62d2aa382b176a4838474238f8d.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/zevv/npeg.git",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/xpn694ibgipj8xak3j4bky6b3k0vp7hh-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "ec0cc6e64ea4c62d2aa382b176a4838474238f8d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1fi9ls3xl20bmv1ikillxywl96i9al6zmmxrbffx448gbrxs86kg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/zevv/npeg/archive/ec0cc6e64ea4c62d2aa382b176a4838474238f8d.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "1.2.2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/bigints",
|
||||||
|
"name": "bigints",
|
||||||
|
"version": "20231006",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/ehmry/nim-bigints/archive/86ea14d31eea9275e1408ca34e6bfe9c99989a96.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/ehmry/nim-bigints.git",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/jvrm392g8adfsgf36prgwkbyd7vh5jsw-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "86ea14d31eea9275e1408ca34e6bfe9c99989a96"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "15pcpmnk1bnw3k8769rjzcpg00nahyrypwbxs88jnwr4aczp99j4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/ehmry/nim-bigints/archive/86ea14d31eea9275e1408ca34e6bfe9c99989a96.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "20231006"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/cps",
|
||||||
|
"name": "cps",
|
||||||
|
"version": "0.10.4",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nim-works/cps/archive/2a4d771a715ba45cfba3a82fa625ae7ad6591c8b.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nim-works/cps",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/m9vpcf3dq6z2h1xpi1vlw0ycxp91s5p7-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "2a4d771a715ba45cfba3a82fa625ae7ad6591c8b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "0c62k5wpq9z9mn8cd4rm8jjc4z0xmnak4piyj5dsfbyj6sbdw2bf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/nim-works/cps/archive/2a4d771a715ba45cfba3a82fa625ae7ad6591c8b.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "0.10.4"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/stew",
|
||||||
|
"name": "stew",
|
||||||
|
"version": "3c91b8694e15137a81ec7db37c6c58194ec94a6a",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/status-im/nim-stew/archive/3c91b8694e15137a81ec7db37c6c58194ec94a6a.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/status-im/nim-stew",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/mqg8qzsbcc8xqabq2yzvlhvcyqypk72c-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "3c91b8694e15137a81ec7db37c6c58194ec94a6a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "17lfhfxp5nxvld78xa83p258y80ks5jb4n53152cdr57xk86y07w"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://github.com/status-im/nim-stew/archive/3c91b8694e15137a81ec7db37c6c58194ec94a6a.tar.gz"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "library",
|
||||||
|
"bom-ref": "pkg:nim/getdns",
|
||||||
|
"name": "getdns",
|
||||||
|
"version": "20230806",
|
||||||
|
"externalReferences": [
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/getdns-nim/archive/e4ae0992ed7c5540e6d498f3074d06c8f454a0b6.tar.gz",
|
||||||
|
"type": "source-distribution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://git.sr.ht/~ehmry/getdns-nim",
|
||||||
|
"type": "vcs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "nix:fod:method",
|
||||||
|
"value": "fetchzip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:path",
|
||||||
|
"value": "/nix/store/j8i20k9aarzppg4p234449140nnnaycq-source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:rev",
|
||||||
|
"value": "e4ae0992ed7c5540e6d498f3074d06c8f454a0b6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:sha256",
|
||||||
|
"value": "1dp53gndr6d9s9601dd5ipkiq94j53hlx46mxv8gpr8nd98bqysg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:url",
|
||||||
|
"value": "https://git.sr.ht/~ehmry/getdns-nim/archive/e4ae0992ed7c5540e6d498f3074d06c8f454a0b6.tar.gz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:ref",
|
||||||
|
"value": "20230806"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nix:fod:srcDir",
|
||||||
|
"value": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/syndicate",
|
||||||
|
"dependsOn": [
|
||||||
|
"pkg:nim/nimcrypto",
|
||||||
|
"pkg:nim/preserves",
|
||||||
|
"pkg:nim/sys",
|
||||||
|
"pkg:nim/taps",
|
||||||
|
"pkg:nim/solo5_dispatcher"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/nimcrypto",
|
||||||
|
"dependsOn": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/preserves",
|
||||||
|
"dependsOn": [
|
||||||
|
"pkg:nim/npeg",
|
||||||
|
"pkg:nim/bigints"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/sys",
|
||||||
|
"dependsOn": [
|
||||||
|
"pkg:nim/cps",
|
||||||
|
"pkg:nim/stew"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/taps",
|
||||||
|
"dependsOn": [
|
||||||
|
"pkg:nim/getdns",
|
||||||
|
"pkg:nim/sys",
|
||||||
|
"pkg:nim/cps",
|
||||||
|
"pkg:nim/solo5_dispatcher"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/solo5_dispatcher",
|
||||||
|
"dependsOn": [
|
||||||
|
"pkg:nim/cps"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/npeg",
|
||||||
|
"dependsOn": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/bigints",
|
||||||
|
"dependsOn": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/cps",
|
||||||
|
"dependsOn": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/stew",
|
||||||
|
"dependsOn": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref": "pkg:nim/getdns",
|
||||||
|
"dependsOn": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
12
shell.nix
12
shell.nix
|
@ -1,5 +1,7 @@
|
||||||
let
|
{ pkgs ? import <nixpkgs> { } }:
|
||||||
syndicate = builtins.getFlake "syndicate";
|
|
||||||
pkgs =
|
pkgs.buildNimPackage {
|
||||||
import <nixpkgs> { overlays = builtins.attrValues syndicate.overlays; };
|
name = "dummy";
|
||||||
in pkgs.nimPackages.syndicate
|
buildInputs = builtins.attrValues { inherit (pkgs) getdns solo5; };
|
||||||
|
nativeBuildInputs = builtins.attrValues { inherit (pkgs) pkg-config solo5; };
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
include_rules
|
include_rules
|
||||||
: foreach *.nim |> !nim_check |>
|
: foreach *.nim |> !nim-doc |>
|
||||||
|
|
|
@ -3,60 +3,49 @@
|
||||||
|
|
||||||
## This module implements the `Syndicate DSL <https://syndicate-lang.org/doc/syndicate/>`_.
|
## This module implements the `Syndicate DSL <https://syndicate-lang.org/doc/syndicate/>`_.
|
||||||
|
|
||||||
import std/[asyncdispatch, macros, tables, typetraits]
|
import std/[macros, tables, typetraits]
|
||||||
|
|
||||||
import preserves
|
import pkg/preserves
|
||||||
export fromPreserve, toPreserve
|
export fromPreserves, toPreserves
|
||||||
|
|
||||||
import ./syndicate/[actors, dataspaces, durings, patterns]
|
import ./syndicate/[actors, dataspaces, durings, patterns]
|
||||||
import ./syndicate/protocols/dataspace
|
import ./syndicate/protocols/dataspace
|
||||||
|
|
||||||
when defined(posix):
|
export actors, dataspace, dataspaces, patterns
|
||||||
from ./syndicate/relays import Tcp, Unix, connect, connectStdio
|
|
||||||
export Tcp, Unix, connect, connectStdio
|
|
||||||
|
|
||||||
export patterns
|
type Assertion* {.deprecated: "Assertion and Preserve[void] replaced by Value".} = Value
|
||||||
|
|
||||||
export Actor, Assertion, Facet, Handle, Cap, Ref, Symbol, Turn, TurnAction,
|
|
||||||
`$`, addCallback, analyse, asyncCheck, bootDataspace,
|
|
||||||
facet, future, inFacet, message, newDataspace, onStop, publish,
|
|
||||||
retract, replace, run, spawn, stop, stopActor, unembed, unpackLiterals
|
|
||||||
|
|
||||||
proc `!`*(typ: static typedesc): Pattern {.inline.} =
|
proc `!`*(typ: static typedesc): Pattern {.inline.} =
|
||||||
patterns.dropType(typ)
|
patterns.matchType(typ)
|
||||||
|
|
||||||
proc `?`*(typ: static typedesc): Pattern {.inline.} =
|
|
||||||
patterns.grabType(typ)
|
|
||||||
|
|
||||||
proc `?`*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern {.inline.} =
|
|
||||||
patterns.grab(typ, bindings)
|
|
||||||
|
|
||||||
proc `?`*(typ: static typedesc; bindings: sink openArray[(Assertion, Pattern)]): Pattern {.inline.} =
|
|
||||||
patterns.grab(typ, bindings)
|
|
||||||
|
|
||||||
proc `??`*(pat: Pattern; bindings: openArray[(int, Pattern)]): Pattern {.inline.} =
|
|
||||||
patterns.inject(pat, bindings)
|
|
||||||
|
|
||||||
proc `?`*[T](val: T): Pattern {.inline.} =
|
proc `?`*[T](val: T): Pattern {.inline.} =
|
||||||
patterns.grab[T](val)
|
patterns.drop[T](val)
|
||||||
|
|
||||||
|
proc `?:`*(typ: static typedesc): Pattern {.inline.} =
|
||||||
|
patterns.grabTypeFlat(typ)
|
||||||
|
|
||||||
|
proc `?:`*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern {.inline.} =
|
||||||
|
patterns.grab(typ, bindings)
|
||||||
|
|
||||||
|
proc `?:`*(typ: static typedesc; bindings: sink openArray[(Value, Pattern)]): Pattern {.inline.} =
|
||||||
|
patterns.grab(typ, bindings)
|
||||||
|
|
||||||
type
|
type
|
||||||
Observe* = dataspace.Observe[Cap]
|
PublishProc = proc (turn: Turn; v: Value; h: Handle) {.closure.}
|
||||||
PublishProc = proc (turn: var Turn; v: Assertion; h: Handle) {.closure, gcsafe.}
|
RetractProc = proc (turn: Turn; h: Handle) {.closure.}
|
||||||
RetractProc = proc (turn: var Turn; h: Handle) {.closure, gcsafe.}
|
MessageProc = proc (turn: Turn; v: Value) {.closure.}
|
||||||
MessageProc = proc (turn: var Turn; v: Assertion) {.closure, gcsafe.}
|
|
||||||
ClosureEntity = ref object of Entity
|
ClosureEntity = ref object of Entity
|
||||||
publishImpl: PublishProc
|
publishImpl*: PublishProc
|
||||||
retractImpl: RetractProc
|
retractImpl*: RetractProc
|
||||||
messageImpl: MessageProc
|
messageImpl*: MessageProc
|
||||||
|
|
||||||
method publish(e: ClosureEntity; turn: var Turn; a: AssertionRef; h: Handle) {.gcsafe.} =
|
method publish(e: ClosureEntity; turn: Turn; a: AssertionRef; h: Handle) =
|
||||||
if not e.publishImpl.isNil: e.publishImpl(turn, a.value, h)
|
if not e.publishImpl.isNil: e.publishImpl(turn, a.value, h)
|
||||||
|
|
||||||
method retract(e: ClosureEntity; turn: var Turn; h: Handle) {.gcsafe.} =
|
method retract(e: ClosureEntity; turn: Turn; h: Handle) =
|
||||||
if not e.retractImpl.isNil: e.retractImpl(turn, h)
|
if not e.retractImpl.isNil: e.retractImpl(turn, h)
|
||||||
|
|
||||||
method message(e: ClosureEntity; turn: var Turn; a: AssertionRef) {.gcsafe.} =
|
method message(e: ClosureEntity; turn: Turn; a: AssertionRef) =
|
||||||
if not e.messageImpl.isNil: e.messageImpl(turn, a.value)
|
if not e.messageImpl.isNil: e.messageImpl(turn, a.value)
|
||||||
|
|
||||||
proc argumentCount(handler: NimNode): int =
|
proc argumentCount(handler: NimNode): int =
|
||||||
|
@ -101,9 +90,9 @@ proc wrapPublishHandler(turn, handler: NimNode): NimNode =
|
||||||
handlerSym = genSym(nskProc, "publish")
|
handlerSym = genSym(nskProc, "publish")
|
||||||
bindingsSym = ident"bindings"
|
bindingsSym = ident"bindings"
|
||||||
quote do:
|
quote do:
|
||||||
proc `handlerSym`(`turn`: var Turn; `bindingsSym`: Assertion; `handleSym`: Handle) =
|
proc `handlerSym`(`turn`: Turn; `bindingsSym`: Value; `handleSym`: Handle) =
|
||||||
`varSection`
|
`varSection`
|
||||||
if fromPreserve(`valuesSym`, bindings):
|
if fromPreserves(`valuesSym`, bindings):
|
||||||
`publishBody`
|
`publishBody`
|
||||||
|
|
||||||
proc wrapMessageHandler(turn, handler: NimNode): NimNode =
|
proc wrapMessageHandler(turn, handler: NimNode): NimNode =
|
||||||
|
@ -113,9 +102,9 @@ proc wrapMessageHandler(turn, handler: NimNode): NimNode =
|
||||||
handlerSym = genSym(nskProc, "message")
|
handlerSym = genSym(nskProc, "message")
|
||||||
bindingsSym = ident"bindings"
|
bindingsSym = ident"bindings"
|
||||||
quote do:
|
quote do:
|
||||||
proc `handlerSym`(`turn`: var Turn; `bindingsSym`: Assertion) =
|
proc `handlerSym`(`turn`: Turn; `bindingsSym`: Value) =
|
||||||
`varSection`
|
`varSection`
|
||||||
if fromPreserve(`valuesSym`, bindings):
|
if fromPreserves(`valuesSym`, bindings):
|
||||||
`body`
|
`body`
|
||||||
|
|
||||||
proc wrapDuringHandler(turn, entryBody, exitBody: NimNode): NimNode =
|
proc wrapDuringHandler(turn, entryBody, exitBody: NimNode): NimNode =
|
||||||
|
@ -127,17 +116,17 @@ proc wrapDuringHandler(turn, entryBody, exitBody: NimNode): NimNode =
|
||||||
duringSym = genSym(nskProc, "during")
|
duringSym = genSym(nskProc, "during")
|
||||||
if exitBody.isNil:
|
if exitBody.isNil:
|
||||||
quote do:
|
quote do:
|
||||||
proc `duringSym`(`turn`: var Turn; `bindingsSym`: Assertion; `handleSym`: Handle): TurnAction =
|
proc `duringSym`(`turn`: Turn; `bindingsSym`: Value; `handleSym`: Handle): TurnAction =
|
||||||
`varSection`
|
`varSection`
|
||||||
if fromPreserve(`valuesSym`, `bindingsSym`):
|
if fromPreserves(`valuesSym`, `bindingsSym`):
|
||||||
`publishBody`
|
`publishBody`
|
||||||
else:
|
else:
|
||||||
quote do:
|
quote do:
|
||||||
proc `duringSym`(`turn`: var Turn; `bindingsSym`: Assertion; `handleSym`: Handle): TurnAction =
|
proc `duringSym`(`turn`: Turn; `bindingsSym`: Value; `handleSym`: Handle): TurnAction =
|
||||||
`varSection`
|
`varSection`
|
||||||
if fromPreserve(`valuesSym`, `bindingsSym`):
|
if fromPreserves(`valuesSym`, `bindingsSym`):
|
||||||
`publishBody`
|
`publishBody`
|
||||||
proc action(`turn`: var Turn) =
|
proc action(`turn`: Turn) =
|
||||||
`exitBody`
|
`exitBody`
|
||||||
result = action
|
result = action
|
||||||
|
|
||||||
|
@ -149,7 +138,7 @@ macro onPublish*(turn: untyped; ds: Cap; pattern: Pattern; handler: untyped) =
|
||||||
handlerSym = handlerProc[0]
|
handlerSym = handlerProc[0]
|
||||||
result = quote do:
|
result = quote do:
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments")
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`handlerProc`
|
`handlerProc`
|
||||||
discard observe(`turn`, `ds`, `pattern`, ClosureEntity(publishImpl: `handlerSym`))
|
discard observe(`turn`, `ds`, `pattern`, ClosureEntity(publishImpl: `handlerSym`))
|
||||||
|
|
||||||
|
@ -161,7 +150,7 @@ macro onMessage*(turn: untyped; ds: Cap; pattern: Pattern; handler: untyped) =
|
||||||
handlerSym = handlerProc[0]
|
handlerSym = handlerProc[0]
|
||||||
result = quote do:
|
result = quote do:
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments")
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`handlerProc`
|
`handlerProc`
|
||||||
discard observe(`turn`, `ds`, `pattern`, ClosureEntity(messageImpl: `handlerSym`))
|
discard observe(`turn`, `ds`, `pattern`, ClosureEntity(messageImpl: `handlerSym`))
|
||||||
|
|
||||||
|
@ -179,7 +168,7 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody, retractBody
|
||||||
callbackSym = callbackProc[0]
|
callbackSym = callbackProc[0]
|
||||||
result = quote do:
|
result = quote do:
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments")
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`callbackProc`
|
`callbackProc`
|
||||||
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
||||||
|
|
||||||
|
@ -191,15 +180,18 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
|
||||||
callbackSym = callbackProc[0]
|
callbackSym = callbackProc[0]
|
||||||
result = quote do:
|
result = quote do:
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments")
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`callbackProc`
|
`callbackProc`
|
||||||
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
||||||
|
|
||||||
type BootProc = proc (ds: Cap; turn: var Turn) {.gcsafe.}
|
when defined(solo5):
|
||||||
|
echo """
|
||||||
proc runActor*(name: string; bootProc: BootProc) =
|
______
|
||||||
## Run an `Actor` to completion.
|
/ \_\
|
||||||
let actor = bootDataspace(name, bootProc)
|
/ ,__/ \ ____ __
|
||||||
while not actor.future.finished:
|
/\__/ \, \ _______ ______ ____/ /_/________ / /____
|
||||||
waitFor sleepAsync(500)
|
\/ \__/ / / ___/ / / / __ \/ __ / / ___/ __ \/ __/ _ \
|
||||||
read(actor.future)
|
\ ' \__/ _\_ \/ /_/ / / / / /_/ / / /__/ /_/ / /_/ __/
|
||||||
|
\____/_/ /____/\__, /_/ /_/\____/_/\___/\__/_/\__/\___/
|
||||||
|
/____/
|
||||||
|
"""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
include_rules
|
include_rules
|
||||||
NIM_FLAGS += --path:$(TUP_CWD)/..
|
NIM_FLAGS += --path:$(TUP_CWD)/..
|
||||||
: foreach *.nim |> !nim_check |>
|
: patterns.nim |> !nim_check |>
|
||||||
: capabilities.nim |> !nim_bin |> $(BIN_DIR)/mint
|
: patterns.nim |> !nim_bin |>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,34 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
import std/[asyncdispatch, monotimes, times]
|
|
||||||
import preserves
|
|
||||||
import syndicate, syndicate/actors
|
|
||||||
|
|
||||||
import ../protocols/timer
|
|
||||||
from syndicate/protocols/dataspace import Observe
|
|
||||||
|
|
||||||
export timer
|
|
||||||
|
|
||||||
type Observe = dataspace.Observe[Cap]
|
|
||||||
|
|
||||||
proc now: float64 = getTime().toUnixFloat()
|
|
||||||
|
|
||||||
proc spawnTimers*(turn: var Turn; ds: Cap): Actor {.discardable.} =
|
|
||||||
## Spawn a timer actor.
|
|
||||||
spawn("timer", turn) do (turn: var Turn):
|
|
||||||
|
|
||||||
during(turn, ds, ?Observe(pattern: !LaterThan) ?? {0: grabLit()}) do (seconds: float64):
|
|
||||||
let period = seconds - now()
|
|
||||||
if period < 0.001:
|
|
||||||
discard publish(turn, ds, LaterThan(seconds: seconds))
|
|
||||||
else:
|
|
||||||
let facet = turn.facet
|
|
||||||
addTimer(int(period * 1_000), oneshot = true) do (fd: AsyncFD) -> bool:
|
|
||||||
run(facet) do (turn: var Turn):
|
|
||||||
discard publish(turn, ds, LaterThan(seconds: seconds))
|
|
||||||
|
|
||||||
template after*(turn: var Turn; ds: Cap; dur: Duration; act: untyped) =
|
|
||||||
## Execute `act` after some duration of time.
|
|
||||||
let later = now() + dur.inMilliseconds.float64 * 1_000.0
|
|
||||||
onPublish(turn, ds, ?LaterThan(seconds: later), act)
|
|
|
@ -4,7 +4,7 @@
|
||||||
## An unordered association of items to counts.
|
## An unordered association of items to counts.
|
||||||
## An item count may be negative, unlike CountTable.
|
## An item count may be negative, unlike CountTable.
|
||||||
|
|
||||||
import tables
|
import std/[assertions, tables]
|
||||||
|
|
||||||
type
|
type
|
||||||
ChangeDescription* = enum
|
ChangeDescription* = enum
|
||||||
|
@ -46,3 +46,5 @@ proc `$`*(bag: Bag): string =
|
||||||
if result.len > 1: result.add ' '
|
if result.len > 1: result.add ' '
|
||||||
result.add $x
|
result.add $x
|
||||||
result.add '}'
|
result.add '}'
|
||||||
|
|
||||||
|
export tables.contains, tables.del, tables.len
|
||||||
|
|
|
@ -6,64 +6,41 @@ runnableExamples:
|
||||||
let sturdy = mint()
|
let sturdy = mint()
|
||||||
check $sturdy == """<ref {oid: "syndicate" sig: #x"69ca300c1dbfa08fba692102dd82311a"}>"""
|
check $sturdy == """<ref {oid: "syndicate" sig: #x"69ca300c1dbfa08fba692102dd82311a"}>"""
|
||||||
|
|
||||||
import std/options
|
import
|
||||||
from std/sequtils import toSeq
|
std/[options, tables],
|
||||||
import hashlib/misc/blake2
|
pkg/nimcrypto/[blake2, hmac],
|
||||||
|
pkg/preserves,
|
||||||
import preserves
|
./protocols/sturdy
|
||||||
import ./protocols/sturdy
|
|
||||||
from ./actors import Cap
|
|
||||||
|
|
||||||
export `$`
|
export `$`
|
||||||
|
|
||||||
proc hmac(key, data: openarray[byte]): seq[byte] =
|
proc hmac(key, data: openarray[byte]): seq[byte] =
|
||||||
count[Hmac[BLAKE2S_256]](key, data).data[0..15].toSeq
|
result = newSeq[byte](32)
|
||||||
|
var ctx: HMAC[blake2_256]
|
||||||
|
ctx.init key
|
||||||
|
ctx.update data
|
||||||
|
discard ctx.finish result
|
||||||
|
result.setLen 16
|
||||||
|
|
||||||
proc mint*[T](key: openarray[byte]; oid: Preserve[T]): SturdyRef[T] =
|
proc mint*(key: openarray[byte]; oid: Value): SturdyRef =
|
||||||
SturdyRef[T](parameters: {
|
result.parameters.oid = oid
|
||||||
"oid": oid,
|
result.parameters.sig = hmac(key, oid.encode)
|
||||||
"sig": hmac(key, encode(oid)).toPreserve(T),
|
|
||||||
}.toDictionary,
|
|
||||||
)
|
|
||||||
|
|
||||||
proc mint*(): SturdyRef[Cap] =
|
proc mint*(): SturdyRef =
|
||||||
var key: array[16, byte]
|
var key: array[16, byte]
|
||||||
mint(key, toPreserve("syndicate", Cap))
|
mint(key, "syndicate".toPreserves)
|
||||||
|
|
||||||
proc attenuate*[T](r: SturdyRef[T]; caveats: seq[Caveat]): SturdyRef[T] =
|
proc attenuate*(r: SturdyRef; caveats: seq[Caveat]): SturdyRef =
|
||||||
result = SturdyRef[T](
|
if r.parameters.caveats.isSome:
|
||||||
oid: r.oid,
|
result.parameters.caveats = some(r.parameters.caveats.get & caveats.toPreserves)
|
||||||
caveatChain: r.caveatChain,
|
result.parameters.oid = r.parameters.oid
|
||||||
sig: hmac(r.sig, encode caveats))
|
result.parameters.sig = hmac(r.parameters.sig, caveats.toPreserves.encode)
|
||||||
result.caveatChain.add caveats
|
|
||||||
|
|
||||||
proc validate*[T](key: openarray[byte]; sturdy: SturdyRef[T]): bool =
|
proc validate*(key: openarray[byte]; sturdy: SturdyRef): bool =
|
||||||
let oid = step(sturdy.parameters, Symbol"oid")
|
var sig = hmac(key, sturdy.parameters.oid.encode)
|
||||||
if oid.isSome:
|
if sturdy.parameters.caveats.isSome:
|
||||||
let ctrl = step(sturdy.parameters, Symbol"sig")
|
for cav in sturdy.parameters.caveats.get:
|
||||||
if ctrl.isSome:
|
|
||||||
var sig = hmac(key, oid.get.encode)
|
|
||||||
let caveats = step(sturdy.parameters, Symbol"caveats")
|
|
||||||
if caveats.isSome and caveats.get.isSequence:
|
|
||||||
for cav in caveats.get.sequence:
|
|
||||||
sig = hmac(sig, encode cav)
|
sig = hmac(sig, encode cav)
|
||||||
result = (sig == ctrl.get.bytes)
|
result = (sig == sturdy.parameters.sig)
|
||||||
|
|
||||||
when isMainModule:
|
# mint utility moved to syndicate_utils/src/mintsturdyref.nim
|
||||||
from os import commandLineParams
|
|
||||||
|
|
||||||
var key: array[16, byte]
|
|
||||||
case readBytes(stdin, key, 0, 16)
|
|
||||||
of 16: discard
|
|
||||||
of 0: stderr.writeLine "using null key"
|
|
||||||
else: quit "expected sixteen bytes of key from stdin"
|
|
||||||
|
|
||||||
var oids: seq[Preserve[void]]
|
|
||||||
for p in commandLineParams():
|
|
||||||
add(oids, parsePreserves p)
|
|
||||||
if oids.len == 0: oids.add(toPreserve "syndicate")
|
|
||||||
|
|
||||||
for oid in oids:
|
|
||||||
let sturdy = mint(key, oid)
|
|
||||||
doAssert validate(key, sturdy)
|
|
||||||
stdout.writeLine(sturdy)
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import preserves
|
import
|
||||||
import options, sets, tables
|
std/[options, sets, tables],
|
||||||
|
pkg/preserves
|
||||||
|
|
||||||
type
|
type
|
||||||
Set = HashSet
|
Set = HashSet
|
||||||
|
@ -51,7 +52,7 @@ iterator observersOf[Sid, Oid](g: Graph[Sid, Oid]; oid: Oid): Sid =
|
||||||
if g.edgesForward.hasKey(oid):
|
if g.edgesForward.hasKey(oid):
|
||||||
for sid in g.edgesForward[oid]: yield sid
|
for sid in g.edgesForward[oid]: yield sid
|
||||||
|
|
||||||
proc repairDamage*[Sid, Oid](g: var Graph[Sid, Oid]; repairNode: proc (sid: Sid) {.gcsafe.}) =
|
proc repairDamage*[Sid, Oid](g: var Graph[Sid, Oid]; repairNode: proc (sid: Sid) {.closure.}) =
|
||||||
var repairedThisRound: Set[Oid]
|
var repairedThisRound: Set[Oid]
|
||||||
while true:
|
while true:
|
||||||
var workSet = move g.damagedNodes
|
var workSet = move g.damagedNodes
|
||||||
|
|
|
@ -1,45 +1,51 @@
|
||||||
# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[hashes, tables]
|
import
|
||||||
import preserves
|
std/[hashes, options, tables],
|
||||||
import ./actors, ./protocols/dataspace, ./skeletons
|
pkg/preserves,
|
||||||
|
./actors, ./protocols/dataspace, ./skeletons
|
||||||
|
|
||||||
from ./protocols/protocol import Handle
|
from ./protocols/protocol import Handle
|
||||||
|
|
||||||
type
|
type
|
||||||
Assertion = Preserve[Cap]
|
Assertion = Value
|
||||||
Observe = dataspace.Observe[Cap]
|
Observe = dataspace.Observe
|
||||||
Turn = actors.Turn
|
Turn = actors.Turn
|
||||||
|
|
||||||
Dataspace {.final.} = ref object of Entity
|
Dataspace {.final.} = ref object of Entity
|
||||||
index: Index
|
index: Index
|
||||||
handleMap: Table[Handle, Assertion]
|
handleMap: Table[Handle, Assertion]
|
||||||
|
|
||||||
method publish(ds: Dataspace; turn: var Turn; a: AssertionRef; h: Handle) {.gcsafe.} =
|
method publish(ds: Dataspace; turn: Turn; a: AssertionRef; h: Handle) =
|
||||||
if add(ds.index, turn, a.value):
|
if add(ds.index, turn, a.value):
|
||||||
var obs: Observe
|
var obs = a.value.preservesTo(Observe)
|
||||||
if obs.fromPreserve a.value:
|
if obs.isSome and obs.get.observer of Cap:
|
||||||
ds.index.add(turn, obs.pattern, obs.observer)
|
ds.index.add(turn, obs.get.pattern, Cap(obs.get.observer))
|
||||||
ds.handleMap[h] = a.value
|
ds.handleMap[h] = a.value
|
||||||
|
|
||||||
method retract(ds: Dataspace; turn: var Turn; h: Handle) {.gcsafe.} =
|
method retract(ds: Dataspace; turn: Turn; h: Handle) =
|
||||||
let v = ds.handleMap[h]
|
let v = ds.handleMap[h]
|
||||||
if remove(ds.index, turn, v):
|
if remove(ds.index, turn, v):
|
||||||
ds.handleMap.del h
|
ds.handleMap.del h
|
||||||
var obs: Observe
|
var obs = v.preservesTo(Observe)
|
||||||
if obs.fromPreserve v:
|
if obs.isSome and obs.get.observer of Cap:
|
||||||
ds.index.remove(turn, obs.pattern, obs.observer)
|
ds.index.remove(turn, obs.get.pattern, Cap(obs.get.observer))
|
||||||
|
|
||||||
method message(ds: Dataspace; turn: var Turn; a: AssertionRef) {.gcsafe.} =
|
method message(ds: Dataspace; turn: Turn; a: AssertionRef) =
|
||||||
ds.index.deliverMessage(turn, a.value)
|
ds.index.deliverMessage(turn, a.value)
|
||||||
|
|
||||||
proc newDataspace*(turn: var Turn): Cap =
|
proc newDataspace*(turn: Turn): Cap =
|
||||||
newCap(turn, Dataspace(index: initIndex()))
|
newCap(turn, Dataspace(index: initIndex()))
|
||||||
|
|
||||||
type BootProc = proc (ds: Cap; turn: var Turn) {.gcsafe.}
|
type BootProc = proc (turn: Turn; ds: Cap) {.closure.}
|
||||||
|
type DeprecatedBootProc = proc (ds: Cap; turn: Turn) {.closure.}
|
||||||
|
|
||||||
proc bootDataspace*(name: string; bootProc: BootProc): Actor =
|
proc bootDataspace*(name: string; bootProc: BootProc): Actor =
|
||||||
bootActor(name) do (turn: var Turn):
|
bootActor(name) do (turn: Turn):
|
||||||
discard turn.facet.preventInertCheck()
|
turn.preventInertCheck()
|
||||||
bootProc(newDataspace(turn), turn)
|
bootProc(turn, newDataspace(turn))
|
||||||
|
|
||||||
|
proc bootDataspace*(name: string; bootProc: DeprecatedBootProc): Actor {.deprecated.} =
|
||||||
|
bootDataspace(name) do (turn: Turn, ds: Cap):
|
||||||
|
bootProc(ds, turn)
|
||||||
|
|
|
@ -0,0 +1,398 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import
|
||||||
|
std/[httpcore, options, parseutils, sets, streams, strutils, tables, times, uri],
|
||||||
|
pkg/taps,
|
||||||
|
pkg/preserves,
|
||||||
|
../../syndicate, ../bags, ./timers, ../protocols/http
|
||||||
|
|
||||||
|
const
|
||||||
|
CRLF = "\x0d\x0a"
|
||||||
|
SP = { ' ', '\x09', '\x0b', '\x0c', '\x0d' }
|
||||||
|
SupportedVersion = "HTTP/1.1"
|
||||||
|
IMF = initTimeFormat"ddd, dd MMM yyyy HH:mm:ss"
|
||||||
|
|
||||||
|
when defined(posix):
|
||||||
|
proc echo(args: varargs[string, `$`]) {.used.} =
|
||||||
|
stderr.writeLine(args)
|
||||||
|
|
||||||
|
type
|
||||||
|
Driver = ref object
|
||||||
|
facet: Facet
|
||||||
|
ds, timers: Cap
|
||||||
|
sequenceNumber: BiggestInt
|
||||||
|
Session = ref object
|
||||||
|
facet: Facet
|
||||||
|
driver: Driver
|
||||||
|
conn: Connection
|
||||||
|
exch: Exchange
|
||||||
|
pendingLen: int
|
||||||
|
port: Port
|
||||||
|
Exchange = ref object of Entity
|
||||||
|
cap: Cap
|
||||||
|
ses: Session
|
||||||
|
# TODO: store what we need fom Session locally.
|
||||||
|
req: HttpRequest
|
||||||
|
binding: Option[HttpBinding]
|
||||||
|
stream: StringStream
|
||||||
|
contentType: string
|
||||||
|
contentLen: int
|
||||||
|
mode: HttpResponseKind
|
||||||
|
active: bool
|
||||||
|
|
||||||
|
proc badRequest(conn: Connection; msg: string) =
|
||||||
|
conn.send(SupportedVersion & " " & msg, endOfMessage = true)
|
||||||
|
|
||||||
|
proc extractQuery(s: var string): Table[Symbol, seq[QueryValue]] =
|
||||||
|
let start = succ skipUntil(s, '?')
|
||||||
|
if start < s.len:
|
||||||
|
var query = s[start..s.high]
|
||||||
|
s.setLen(pred start)
|
||||||
|
for key, val in uri.decodeQuery(query):
|
||||||
|
var list = result.getOrDefault(Symbol key)
|
||||||
|
list.add QueryValue(orKind: QueryValueKind.string, string: val)
|
||||||
|
result[Symbol key] = list
|
||||||
|
|
||||||
|
proc parseRequest(conn: Connection; exch: Exchange; text: string): int =
|
||||||
|
## Parse an `HttpRequest` request out of a `text` from a `Connection`.
|
||||||
|
var
|
||||||
|
token: string
|
||||||
|
off: int
|
||||||
|
|
||||||
|
template advanceSp =
|
||||||
|
let n = skipWhile(text, SP, off)
|
||||||
|
if n < 1:
|
||||||
|
badRequest(conn, "400 invalid request")
|
||||||
|
return
|
||||||
|
inc(off, n)
|
||||||
|
|
||||||
|
# method
|
||||||
|
off.inc parseUntil(text, token, SP, off)
|
||||||
|
exch.req.method = token.toLowerAscii.Symbol
|
||||||
|
advanceSp()
|
||||||
|
|
||||||
|
# target
|
||||||
|
if text[off] == '/': inc(off) #TODO: always a leading slash?
|
||||||
|
off.inc parseUntil(text, token, SP, off)
|
||||||
|
advanceSp()
|
||||||
|
|
||||||
|
block:
|
||||||
|
var version: string
|
||||||
|
off.inc parseUntil(text, version, SP, off)
|
||||||
|
advanceSp()
|
||||||
|
if version != SupportedVersion:
|
||||||
|
badRequest(conn, "400 version not supported")
|
||||||
|
return
|
||||||
|
|
||||||
|
exch.req.query = extractQuery(token)
|
||||||
|
|
||||||
|
if token != "":
|
||||||
|
exch.req.path = split(token, '/')
|
||||||
|
for p in exch.req.path.mitems:
|
||||||
|
# normalize the path
|
||||||
|
for i, c in p:
|
||||||
|
if c in {'A'..'Z'}:
|
||||||
|
p[i] = char c.ord + 0x20
|
||||||
|
|
||||||
|
exch.req.host = RequestHost(orKind: RequestHostKind.absent)
|
||||||
|
|
||||||
|
template advanceLine =
|
||||||
|
inc off, skipWhile(text, {'\x0d'}, off)
|
||||||
|
if text.high < off or text[off] != '\x0a':
|
||||||
|
badRequest(conn, "400 invalid request")
|
||||||
|
return
|
||||||
|
inc off, 1
|
||||||
|
|
||||||
|
advanceLine()
|
||||||
|
while off < text.len:
|
||||||
|
off.inc parseUntil(text, token, {'\x0d', '\x0a'}, off)
|
||||||
|
if token == "": break
|
||||||
|
advanceLine()
|
||||||
|
var
|
||||||
|
(key, vals) = httpcore.parseHeader(token)
|
||||||
|
k = key.toLowerAscii
|
||||||
|
v = exch.req.headers.getOrDefault(cast[Symbol](k))
|
||||||
|
for e in vals.mitems:
|
||||||
|
var e = e.move.toLowerAscii
|
||||||
|
case k
|
||||||
|
of "host":
|
||||||
|
exch.req.host = RequestHost(orKind: RequestHostKind.`present`, present: v)
|
||||||
|
of "content-length":
|
||||||
|
discard parseInt(e, exch.contentLen)
|
||||||
|
if exch.contentLen > (1 shl 23):
|
||||||
|
badRequest(conn, "413 Content Too Large")
|
||||||
|
if exch.contentLen > 0:
|
||||||
|
exch.req.body = Value(
|
||||||
|
kind: pkByteString, bytes: newSeqOfCap[byte](exch.contentLen))
|
||||||
|
of "content-type":
|
||||||
|
exch.contentType = e
|
||||||
|
if v == "":
|
||||||
|
v = e.toLowerAscii
|
||||||
|
else:
|
||||||
|
v.add ", "
|
||||||
|
v.add e.toLowerAscii
|
||||||
|
exch.req.headers[cast[Symbol](k)] = v
|
||||||
|
advanceLine()
|
||||||
|
result = off
|
||||||
|
|
||||||
|
proc len(chunk: Chunk): int =
|
||||||
|
case chunk.orKind
|
||||||
|
of ChunkKind.string: chunk.string.len
|
||||||
|
of ChunkKind.bytes: chunk.bytes.len
|
||||||
|
|
||||||
|
proc lenLine(chunk: Chunk): string =
|
||||||
|
result = chunk.len.toHex.strip(true, false, {'0'})
|
||||||
|
result.add CRLF
|
||||||
|
|
||||||
|
proc send[T: byte|char](ses: Session; data: openarray[T]) =
|
||||||
|
ses.conn.send(addr data[0], data.len, endOfMessage = false)
|
||||||
|
|
||||||
|
proc send(ses: Session; chunk: Chunk) =
|
||||||
|
case chunk.orKind
|
||||||
|
of ChunkKind.string:
|
||||||
|
ses.send(chunk.string)
|
||||||
|
of ChunkKind.bytes:
|
||||||
|
ses.send(chunk.bytes)
|
||||||
|
|
||||||
|
func isTrue(v: Value): bool = v.kind == pkBoolean and v.bool
|
||||||
|
|
||||||
|
proc dispatch(exch: Exchange; turn: Turn; res: HttpResponse) =
|
||||||
|
case res.orKind
|
||||||
|
of HttpResponseKind.status:
|
||||||
|
if exch.mode == res.orKind:
|
||||||
|
exch.active = true
|
||||||
|
exch.ses.conn.startBatch()
|
||||||
|
exch.stream.write(
|
||||||
|
SupportedVersion, " ", res.status.code, " ", res.status.message, CRLF &
|
||||||
|
# "connection: close" & CRLF &
|
||||||
|
# RFC9112 says we SHOULD support persistent connections.
|
||||||
|
"date: ", now().format(IMF), CRLF
|
||||||
|
# add Date header automatically - RFC 9110 Section 6.6.1.
|
||||||
|
)
|
||||||
|
exch.mode = HttpResponseKind.header
|
||||||
|
|
||||||
|
of HttpResponseKind.header:
|
||||||
|
if exch.mode == res.orKind:
|
||||||
|
exch.stream.write(res.header.name, ": ", res.header.value, CRLF)
|
||||||
|
|
||||||
|
of HttpResponseKind.chunk:
|
||||||
|
if res.chunk.chunk.len > 0:
|
||||||
|
if exch.mode == HttpResponseKind.header:
|
||||||
|
exch.stream.write("transfer-encoding: chunked" & CRLF & CRLF)
|
||||||
|
exch.ses.send(move exch.stream.data)
|
||||||
|
exch.mode = res.orKind
|
||||||
|
if exch.mode == res.orKind:
|
||||||
|
exch.ses.send(res.chunk.chunk.lenLine)
|
||||||
|
exch.ses.send(res.chunk.chunk)
|
||||||
|
exch.ses.send(CRLF)
|
||||||
|
|
||||||
|
of HttpResponseKind.done:
|
||||||
|
if exch.mode in {HttpResponseKind.header, HttpResponseKind.chunk}:
|
||||||
|
if exch.mode == HttpResponseKind.header:
|
||||||
|
exch.stream.write("content-length: ", $res.done.chunk.len & CRLF & CRLF)
|
||||||
|
exch.ses.send(move exch.stream.data)
|
||||||
|
if res.done.chunk.len > 0:
|
||||||
|
exch.ses.send(res.done.chunk)
|
||||||
|
elif exch.mode == HttpResponseKind.chunk:
|
||||||
|
exch.ses.send(res.done.chunk.lenLine)
|
||||||
|
if res.done.chunk.len > 0:
|
||||||
|
exch.ses.send(res.done.chunk)
|
||||||
|
exch.ses.send(CRLF & "0" & CRLF & CRLF)
|
||||||
|
exch.mode = res.orKind
|
||||||
|
exch.ses.conn.endBatch()
|
||||||
|
if exch.req.headers.getOrDefault(Symbol"connection") == "close":
|
||||||
|
exch.ses.conn.close()
|
||||||
|
stop(turn)
|
||||||
|
# stop the facet scoped to the exchange
|
||||||
|
# so that the response capability is withdrawn
|
||||||
|
|
||||||
|
proc scheduleTimeout(exch: Exchange; turn: Turn) =
|
||||||
|
const timeout = initDuration(seconds = 4)
|
||||||
|
after(turn, exch.ses.driver.timers, timeout) do (turn: Turn):
|
||||||
|
if not exch.active:
|
||||||
|
var res = HttpResponse(orKind: HttpResponseKind.status)
|
||||||
|
res.status.code = 504
|
||||||
|
res.status.message = "Binding timeout"
|
||||||
|
exch.dispatch(turn, res)
|
||||||
|
res = HttpResponse(orKind: HttpResponseKind.done)
|
||||||
|
exch.dispatch(turn, res)
|
||||||
|
# Use a HttpResponse to reuse logic.
|
||||||
|
|
||||||
|
method message(exch: Exchange; turn: Turn; a: AssertionRef) =
|
||||||
|
# Send responses back into a connection.
|
||||||
|
if a.value.isTrue:
|
||||||
|
# Sync message from dataspace.
|
||||||
|
exch.scheduleTimeout(turn)
|
||||||
|
if exch.binding.isSome:
|
||||||
|
# The best binding in the dataspace has been selected.
|
||||||
|
let handler = exch.binding.get.handler.unembed(Cap)
|
||||||
|
if handler.isSome:
|
||||||
|
# Send the handler the exchange capability.
|
||||||
|
if exch.contentType.startsWith "application/json":
|
||||||
|
if exch.req.body.isByteString:
|
||||||
|
var bodyBytes = exch.req.body.bytes.move
|
||||||
|
exch.req.body = cast[string](bodyBytes).parsePreserves
|
||||||
|
discard publish(turn, handler.get, HttpContext(
|
||||||
|
req: exch.req,
|
||||||
|
res: exch.cap.embed,
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
exch.binding.reset()
|
||||||
|
else:
|
||||||
|
var res: HttpResponse
|
||||||
|
if exch.mode != HttpResponseKind.done and res.fromPreserves a.value:
|
||||||
|
exch.dispatch(turn, res)
|
||||||
|
|
||||||
|
func `==`(s: string; rh: RequestHost): bool =
|
||||||
|
rh.orKind == RequestHostKind.present and rh.present == s
|
||||||
|
|
||||||
|
proc match(b: HttpBinding, r: HttpRequest): bool =
|
||||||
|
## Check if `HttpBinding` `b` matches `HttpRequest` `r`.
|
||||||
|
result =
|
||||||
|
(b.host.orKind == HostPatternKind.any or
|
||||||
|
b.host.host == r.host) and
|
||||||
|
(b.port == r.port) and
|
||||||
|
(b.method.orKind == MethodPatternKind.any or
|
||||||
|
b.method.specific == r.method)
|
||||||
|
if result:
|
||||||
|
for i, p in b.path:
|
||||||
|
if i > r.path.high: return false
|
||||||
|
case p.orKind
|
||||||
|
of PathPatternElementKind.wildcard: discard
|
||||||
|
of PathPatternElementKind.label:
|
||||||
|
if p.label != r.path[i]: return false
|
||||||
|
of PathPatternElementKind.rest:
|
||||||
|
return i == b.path.high
|
||||||
|
# return false if "..." isn't the last element
|
||||||
|
|
||||||
|
proc strongerThan(a, b: HttpBinding): bool =
|
||||||
|
## Check if `a` is a stronger `HttpBinding` than `b`.
|
||||||
|
result =
|
||||||
|
(a.host.orKind != b.host.orKind and
|
||||||
|
a.host.orKind == HostPatternKind.host) or
|
||||||
|
(a.method.orKind != b.method.orKind and
|
||||||
|
a.method.orKind == MethodPatternKind.specific)
|
||||||
|
if not result:
|
||||||
|
if a.path.len > b.path.len: return true
|
||||||
|
for i in b.path.low..a.path.high:
|
||||||
|
if a.path[i].orKind != b.path[i].orKind and
|
||||||
|
a.path[i].orKind == PathPatternElementKind.label:
|
||||||
|
return true
|
||||||
|
|
||||||
|
proc service(turn: Turn; exch: Exchange) =
|
||||||
|
## Service an HTTP message exchange.
|
||||||
|
let pat = grab(HttpBinding?:{
|
||||||
|
0: drop(), # match all hosts
|
||||||
|
1: ?exch.req.port,
|
||||||
|
2: drop(), # match all methods
|
||||||
|
3: drop(), # match all paths
|
||||||
|
4: drop(),
|
||||||
|
})
|
||||||
|
onPublish(turn, exch.ses.driver.ds, pat) do (b: HttpBinding):
|
||||||
|
if b.match exch.req:
|
||||||
|
if exch.binding.isNone or b.strongerThan exch.binding.get:
|
||||||
|
exch.binding = some b
|
||||||
|
# found a better binding
|
||||||
|
exch.cap = turn.newCap(exch)
|
||||||
|
sync(turn, exch.ses.driver.ds, exch.cap)
|
||||||
|
# When the sync returns we have seen all the bindings.
|
||||||
|
|
||||||
|
proc exchange(ses: Session) =
|
||||||
|
## Detach the current Exchange from the session
|
||||||
|
## and pass it into Syndicate.
|
||||||
|
ses.pendingLen = 0
|
||||||
|
var exch = move ses.exch
|
||||||
|
exch.ses = ses
|
||||||
|
ses.facet.run do (turn: Turn):
|
||||||
|
inFacet(turn) do (turn: Turn):
|
||||||
|
# start a new facet for this message exchange
|
||||||
|
preventInertCheck(turn)
|
||||||
|
exch.facet = turn.facet
|
||||||
|
exch.stream = newStringStream()
|
||||||
|
exch.mode = HttpResponseKind.status
|
||||||
|
turn.service(exch)
|
||||||
|
|
||||||
|
proc service(ses: Session) =
|
||||||
|
## Service a connection to an HTTP client.
|
||||||
|
const oneMiB = 1 shl 20
|
||||||
|
ses.facet.onStop do (turn: Turn):
|
||||||
|
close ses.conn
|
||||||
|
ses.conn.onClosed do ():
|
||||||
|
stop ses.facet
|
||||||
|
ses.conn.onReceivedPartial do (data: seq[byte]; ctx: MessageContext; eom: bool):
|
||||||
|
if ses.pendingLen == 0:
|
||||||
|
if ses.exch.isNil:
|
||||||
|
new ses.exch
|
||||||
|
let off = parseRequest(ses.conn, ses.exch, cast[string](data))
|
||||||
|
if off > 0:
|
||||||
|
assert not ses.exch.isNil
|
||||||
|
inc(ses.driver.sequenceNumber)
|
||||||
|
ses.exch.req.sequenceNumber = ses.driver.sequenceNumber
|
||||||
|
ses.exch.req.port = BiggestInt ses.port
|
||||||
|
ses.pendingLen = ses.exch.contentLen
|
||||||
|
if off < data.len:
|
||||||
|
let n = min(data.len - off, ses.pendingLen)
|
||||||
|
ses.exch.req.body.bytes.add data[off .. off+n.pred]
|
||||||
|
ses.pendingLen.dec n
|
||||||
|
else:
|
||||||
|
let n = min(data.len, ses.pendingLen)
|
||||||
|
ses.exch.req.body.bytes.add data[0..n.pred]
|
||||||
|
ses.pendingLen.dec n
|
||||||
|
assert ses.pendingLen >= 0, $ses.pendingLen
|
||||||
|
if ses.pendingLen == 0:
|
||||||
|
ses.exchange()
|
||||||
|
ses.conn.receive(maxLength = oneMiB)
|
||||||
|
else:
|
||||||
|
ses.conn.receive(maxLength=ses.pendingLen)
|
||||||
|
ses.conn.receive(maxLength =oneMiB)
|
||||||
|
|
||||||
|
proc newListener(port: Port): Listener =
|
||||||
|
var lp = newLocalEndpoint()
|
||||||
|
lp.with port
|
||||||
|
listen newPreconnection(local=[lp])
|
||||||
|
|
||||||
|
proc httpListen(turn: Turn; driver: Driver; port: Port): Listener =
|
||||||
|
let facet = turn.facet
|
||||||
|
var listener = newListener(port)
|
||||||
|
preventInertCheck(turn)
|
||||||
|
listener.onListenError do (err: ref Exception):
|
||||||
|
terminateFacet(facet, err)
|
||||||
|
facet.onStop do (turn: Turn):
|
||||||
|
stop listener
|
||||||
|
echo "listening for HTTP on port ", port
|
||||||
|
listener.onConnectionReceived do (conn: Connection):
|
||||||
|
driver.facet.run do (turn: Turn):
|
||||||
|
# start a new turn
|
||||||
|
linkActor(turn, "http-conn") do (turn: Turn):
|
||||||
|
preventInertCheck(turn)
|
||||||
|
let facet = turn.facet
|
||||||
|
conn.onConnectionError do (err: ref Exception):
|
||||||
|
terminateFacet(facet, err)
|
||||||
|
# terminate this actor on exception
|
||||||
|
# facet is scoped to the lifetime of the connection
|
||||||
|
service Session(
|
||||||
|
facet: turn.facet,
|
||||||
|
driver: driver,
|
||||||
|
conn: conn,
|
||||||
|
port: port,
|
||||||
|
)
|
||||||
|
listener
|
||||||
|
|
||||||
|
proc httpDriver(turn: Turn; ds: Cap) =
|
||||||
|
let driver = Driver(facet: turn.facet, ds: ds, timers: turn.newDataspace)
|
||||||
|
spawnTimerDriver(turn, driver.timers)
|
||||||
|
|
||||||
|
during(turn, driver.ds, HttpBinding?:{ 1: grab() }) do (port: BiggestInt):
|
||||||
|
publish(turn, ds, HttpListener(port: port))
|
||||||
|
|
||||||
|
# TODO: publish <http-service …>.
|
||||||
|
|
||||||
|
during(turn, driver.ds, ?:HttpListener) do (port: uint16):
|
||||||
|
let l = httpListen(turn, driver, Port port)
|
||||||
|
do:
|
||||||
|
stop(l)
|
||||||
|
|
||||||
|
proc spawnHttpDriver*(turn: Turn; ds: Cap): Actor {.discardable.} =
|
||||||
|
spawnActor(turn, "http-driver") do (turn: Turn):
|
||||||
|
httpDriver(turn, ds)
|
|
@ -0,0 +1,177 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import
|
||||||
|
std/[options, tables, times],
|
||||||
|
pkg/preserves,
|
||||||
|
../../syndicate, ../protocols/timer
|
||||||
|
|
||||||
|
when defined(solo5):
|
||||||
|
import solo5_dispatcher
|
||||||
|
else:
|
||||||
|
import pkg/sys/[handles, ioqueue]
|
||||||
|
|
||||||
|
export timer
|
||||||
|
|
||||||
|
when defined(solo5):
|
||||||
|
import solo5, solo5_dispatcher
|
||||||
|
|
||||||
|
proc wallFloat: float =
|
||||||
|
solo5_clock_wall().float / 1_000_000_000.0
|
||||||
|
|
||||||
|
type
|
||||||
|
TimerDriver = ref object
|
||||||
|
facet: Facet
|
||||||
|
## Owning facet of driver.
|
||||||
|
target: Cap
|
||||||
|
## Destination for LaterThan assertions.
|
||||||
|
deadlines: Table[float, Facet]
|
||||||
|
## Deadlines that other actors are observing.
|
||||||
|
|
||||||
|
proc spawnTimerDriver(facet: Facet; cap: Cap): TimerDriver =
|
||||||
|
TimerDriver(facet: facet, target: cap)
|
||||||
|
|
||||||
|
proc await(driver: TimerDriver; deadline: float) {.solo5dispatch.} =
|
||||||
|
yieldUntil(deadline)
|
||||||
|
let facet = driver.deadlines.getOrDefault(deadline)
|
||||||
|
if not facet.isNil:
|
||||||
|
# check if the deadline is still observed
|
||||||
|
proc turnWork(turn: Turn) =
|
||||||
|
discard publish(turn, driver.target, LaterThan(seconds: deadline))
|
||||||
|
run(facet, turnWork)
|
||||||
|
|
||||||
|
else:
|
||||||
|
import std/[oserrors, posix, sets]
|
||||||
|
type Time = posix.Time
|
||||||
|
|
||||||
|
{.pragma: timerfd, importc, header: "<sys/timerfd.h>".}
|
||||||
|
|
||||||
|
proc timerfd_create(clock_id: ClockId, flags: cint): cint {.timerfd.}
|
||||||
|
proc timerfd_settime(ufd: cint, flags: cint,
|
||||||
|
utmr: var Itimerspec, otmr: var Itimerspec): cint {.timerfd.}
|
||||||
|
|
||||||
|
var
|
||||||
|
TFD_NONBLOCK {.timerfd.}: cint
|
||||||
|
TFD_CLOEXEC {.timerfd.}: cint
|
||||||
|
TFD_TIMER_ABSTIME {.timerfd.}: cint
|
||||||
|
|
||||||
|
func toFloat(ts: Timespec): float =
|
||||||
|
ts.tv_sec.float + ts.tv_nsec.float / 1_000_000_000
|
||||||
|
|
||||||
|
func toTimespec(f: float): Timespec =
|
||||||
|
result.tv_sec = Time(f)
|
||||||
|
result.tv_nsec = clong(uint64(f * 1_000_000_000) mod 1_000_000_000)
|
||||||
|
|
||||||
|
proc wallFloat: float =
|
||||||
|
var ts: Timespec
|
||||||
|
if clock_gettime(CLOCK_REALTIME, ts) < 0:
|
||||||
|
raiseOSError(osLastError(), "clock_gettime")
|
||||||
|
ts.toFloat
|
||||||
|
|
||||||
|
type
|
||||||
|
TimerDriver = ref object
|
||||||
|
facet: Facet
|
||||||
|
## Owning facet of driver.
|
||||||
|
target: Cap
|
||||||
|
## Destination for LaterThan assertions.
|
||||||
|
deadlines: Table[float, Facet]
|
||||||
|
## Deadlines that other actors are observing.
|
||||||
|
timers: HashSet[cint]
|
||||||
|
# TODO: use a single timer descriptor
|
||||||
|
|
||||||
|
proc spawnTimerDriver(facet: Facet; cap: Cap): TimerDriver =
|
||||||
|
let driver = TimerDriver(facet: facet, target: cap)
|
||||||
|
facet.onStop do (turn: Turn):
|
||||||
|
for fd in driver.timers:
|
||||||
|
unregister(FD fd)
|
||||||
|
discard close(fd)
|
||||||
|
driver
|
||||||
|
|
||||||
|
proc await(driver: TimerDriver; deadline: float) {.asyncio.} =
|
||||||
|
## Run timer driver concurrently with actor.
|
||||||
|
let fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK or TFD_CLOEXEC)
|
||||||
|
if fd < 0:
|
||||||
|
raiseOSError(osLastError(), "failed to acquire timer descriptor")
|
||||||
|
var
|
||||||
|
old: Itimerspec
|
||||||
|
its = Itimerspec(it_value: deadline.toTimespec)
|
||||||
|
if timerfd_settime(fd, TFD_TIMER_ABSTIME, its, old) < 0:
|
||||||
|
raiseOSError(osLastError(), "failed to set timeout")
|
||||||
|
driver.timers.incl(fd)
|
||||||
|
while wallFloat() < deadline:
|
||||||
|
# Check if the timer is expired which
|
||||||
|
# could happen before waiting.
|
||||||
|
wait(FD fd, Read)
|
||||||
|
let facet = driver.deadlines.getOrDefault(deadline)
|
||||||
|
if not facet.isNil:
|
||||||
|
# Check if the deadline is still observed.
|
||||||
|
proc turnWork(turn: Turn) =
|
||||||
|
discard publish(turn, driver.target, LaterThan(seconds: deadline))
|
||||||
|
run(facet, turnWork)
|
||||||
|
discard close(fd)
|
||||||
|
driver.timers.excl(fd)
|
||||||
|
|
||||||
|
proc runTimer(driver: TimerDriver; peer: Cap; label: Value; start, deadline: float) {.asyncio.} =
|
||||||
|
## Run timer driver concurrently with actor.
|
||||||
|
assert start < deadline
|
||||||
|
let fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK or TFD_CLOEXEC)
|
||||||
|
if fd < 0:
|
||||||
|
raiseOSError(osLastError(), "failed to acquire timer descriptor")
|
||||||
|
var
|
||||||
|
old: Itimerspec
|
||||||
|
its = Itimerspec(it_value: deadline.toTimespec)
|
||||||
|
if timerfd_settime(fd, TFD_TIMER_ABSTIME, its, old) < 0:
|
||||||
|
raiseOSError(osLastError(), "failed to set timeout")
|
||||||
|
driver.timers.incl(fd)
|
||||||
|
var now = wallFloat()
|
||||||
|
while now < deadline:
|
||||||
|
# Check if the timer is expired which
|
||||||
|
# could happen before waiting.
|
||||||
|
wait(FD fd, Read)
|
||||||
|
now = wallFloat()
|
||||||
|
let facet = driver.deadlines.getOrDefault(deadline)
|
||||||
|
if not facet.isNil:
|
||||||
|
# Check if the deadline is still observed.
|
||||||
|
proc turnWork(turn: Turn) =
|
||||||
|
message(turn, peer, TimerExpired(label: label, seconds: now - start))
|
||||||
|
run(facet, turnWork)
|
||||||
|
discard close(fd)
|
||||||
|
driver.timers.excl(fd)
|
||||||
|
driver.deadlines.del deadline
|
||||||
|
|
||||||
|
proc spawnTimerDriver*(turn: Turn; ds: Cap): Actor {.discardable.} =
|
||||||
|
## Spawn a timer actor that responds to
|
||||||
|
## dataspace observations of timeouts on `ds`.
|
||||||
|
linkActor(turn, "timers") do (turn: Turn):
|
||||||
|
let driver = spawnTimerDriver(turn.facet, ds)
|
||||||
|
|
||||||
|
let laterThanPat = observePattern(!LaterThan, {@[0.toPreserves]: grabLit()})
|
||||||
|
during(turn, ds, laterThanPat) do (deadline: float):
|
||||||
|
driver.deadlines[deadline] = turn.facet
|
||||||
|
discard trampoline:
|
||||||
|
whelp await(driver, deadline)
|
||||||
|
do:
|
||||||
|
driver.deadlines.del deadline
|
||||||
|
|
||||||
|
during(turn, ds, SetTimer.grabType) do (req: SetTimer):
|
||||||
|
var
|
||||||
|
now = wallFloat()
|
||||||
|
deadline = req.seconds
|
||||||
|
let peer = req.peer.unembed Cap
|
||||||
|
if peer.isSome:
|
||||||
|
if req.kind == TimerKind.relative:
|
||||||
|
deadline = deadline + now
|
||||||
|
if deadline <= now:
|
||||||
|
message(turn, peer.get, TimerExpired(label: req.label))
|
||||||
|
else:
|
||||||
|
driver.deadlines[deadline] = turn.facet
|
||||||
|
discard trampoline:
|
||||||
|
whelp driver.runTimer(peer.get, req.label, now, deadline)
|
||||||
|
do:
|
||||||
|
driver.deadlines.del deadline
|
||||||
|
|
||||||
|
proc after*(turn: Turn; ds: Cap; dur: Duration; act: TurnAction) =
|
||||||
|
## Execute `act` after some duration of time.
|
||||||
|
var later = wallFloat() + dur.inMilliseconds.float / 1_000.0
|
||||||
|
onPublish(turn, ds, ?LaterThan(seconds: later)):
|
||||||
|
act(turn)
|
|
@ -1,18 +1,13 @@
|
||||||
# SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[hashes, tables]
|
import
|
||||||
import preserves
|
std/[hashes, tables],
|
||||||
import ./actors, ./patterns, ./protocols/dataspace
|
pkg/preserves,
|
||||||
|
./actors, ./patterns, ./protocols/dataspace
|
||||||
from ./protocols/protocol import Handle
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Observe = dataspace.Observe[Cap]
|
DuringProc* = proc (turn: Turn; a: Value; h: Handle): TurnAction
|
||||||
Turn = actors.Turn
|
|
||||||
|
|
||||||
type
|
|
||||||
DuringProc* = proc (turn: var Turn; a: Assertion; h: Handle): TurnAction {.gcsafe.}
|
|
||||||
DuringActionKind = enum null, dead, act
|
DuringActionKind = enum null, dead, act
|
||||||
DuringAction = object
|
DuringAction = object
|
||||||
case kind: DuringActionKind
|
case kind: DuringActionKind
|
||||||
|
@ -23,7 +18,8 @@ type
|
||||||
cb: DuringProc
|
cb: DuringProc
|
||||||
assertionMap: Table[Handle, DuringAction]
|
assertionMap: Table[Handle, DuringAction]
|
||||||
|
|
||||||
method publish(de: DuringEntity; turn: var Turn; a: AssertionRef; h: Handle) =
|
method publish(de: DuringEntity; turn: Turn; a: AssertionRef; h: Handle) =
|
||||||
|
discard inFacet(turn) do (turn: Turn):
|
||||||
let action = de.cb(turn, a.value, h)
|
let action = de.cb(turn, a.value, h)
|
||||||
# assert(not action.isNil "should have put in a no-op action")
|
# assert(not action.isNil "should have put in a no-op action")
|
||||||
let g = de.assertionMap.getOrDefault h
|
let g = de.assertionMap.getOrDefault h
|
||||||
|
@ -32,11 +28,12 @@ method publish(de: DuringEntity; turn: var Turn; a: AssertionRef; h: Handle) =
|
||||||
de.assertionMap[h] = DuringAction(kind: act, action: action)
|
de.assertionMap[h] = DuringAction(kind: act, action: action)
|
||||||
of dead:
|
of dead:
|
||||||
de.assertionMap.del h
|
de.assertionMap.del h
|
||||||
freshen(turn, action)
|
if not action.isNil:
|
||||||
|
action(turn)
|
||||||
of act:
|
of act:
|
||||||
raiseAssert("during: duplicate handle in publish: " & $h)
|
raiseAssert("during: duplicate handle in publish: " & $h)
|
||||||
|
|
||||||
method retract(de: DuringEntity; turn: var Turn; h: Handle) =
|
method retract(de: DuringEntity; turn: Turn; h: Handle) =
|
||||||
let g = de.assertionMap.getOrDefault h
|
let g = de.assertionMap.getOrDefault h
|
||||||
case g.kind
|
case g.kind
|
||||||
of null:
|
of null:
|
||||||
|
@ -50,5 +47,5 @@ method retract(de: DuringEntity; turn: var Turn; h: Handle) =
|
||||||
|
|
||||||
proc during*(cb: DuringProc): DuringEntity = DuringEntity(cb: cb)
|
proc during*(cb: DuringProc): DuringEntity = DuringEntity(cb: cb)
|
||||||
|
|
||||||
proc observe*(turn: var Turn; ds: Cap; pat: Pattern; e: Entity): Handle =
|
proc observe*(turn: Turn; ds: Cap; pat: Pattern; e: Entity): Handle =
|
||||||
publish(turn, ds, Observe(pattern: pat, observer: newCap(turn, e)))
|
publish(turn, ds, Observe(pattern: pat, observer: newCap(turn, e)))
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import std/[hashes, tables]
|
import std/[hashes, tables]
|
||||||
|
|
||||||
from ./actors import Cap, hash
|
import ./actors
|
||||||
from ./protocols/sturdy import Oid
|
from ./protocols/sturdy import Oid
|
||||||
|
|
||||||
proc hash(r: Cap): Hash = !$(r.relay.hash !& r.target.unsafeAddr.hash)
|
proc hash(r: Cap): Hash = !$(r.relay.hash !& r.target.unsafeAddr.hash)
|
||||||
|
|
|
@ -1,386 +1,505 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[algorithm, options, sequtils, tables, typetraits]
|
import
|
||||||
|
std/[assertions, options, sequtils, tables, typetraits],
|
||||||
|
pkg/preserves,
|
||||||
|
./protocols/[dataspacePatterns, dataspace]
|
||||||
|
|
||||||
import preserves
|
|
||||||
import ./protocols/dataspacePatterns
|
|
||||||
from ./actors import Cap
|
from ./actors import Cap
|
||||||
|
|
||||||
export dataspacePatterns.`$`, PatternKind, DCompoundKind, AnyAtomKind
|
export dataspacePatterns.`$`, AnyAtomKind, GroupTypeKind, PatternKind
|
||||||
|
|
||||||
type
|
type
|
||||||
Value = Preserve[Cap]
|
Pattern* = dataspacePatterns.Pattern
|
||||||
AnyAtom = dataspacePatterns.AnyAtom[Cap]
|
|
||||||
DBind = dataspacePatterns.DBind[Cap]
|
|
||||||
DCompound = dataspacePatterns.DCompound[Cap]
|
|
||||||
DCompoundArr = dataspacePatterns.DCompoundArr[Cap]
|
|
||||||
DCompoundDict = dataspacePatterns.DCompoundDict[Cap]
|
|
||||||
DCompoundRec = dataspacePatterns.DCompoundRec[Cap]
|
|
||||||
DLit = dataspacePatterns.DLit[Cap]
|
|
||||||
Pattern* = dataspacePatterns.Pattern[Cap]
|
|
||||||
|
|
||||||
iterator orderedEntries*(dict: DCompoundDict): (Value, Pattern) =
|
proc toPattern(b: sink PatternBind): Pattern =
|
||||||
## Iterate a `DCompoundDict` in Preserves order.
|
Pattern(orKind: PatternKind.`bind`, `bind`: b)
|
||||||
## Values captured from a dictionary are represented as an
|
|
||||||
## array of values ordered by their former key, so using an
|
|
||||||
## ordered iterator is sometimes essential.
|
|
||||||
var keys = dict.entries.keys.toSeq
|
|
||||||
sort(keys, preserves.cmp)
|
|
||||||
for k in keys:
|
|
||||||
yield(k, dict.entries.getOrDefault(k))
|
|
||||||
# getOrDefault doesn't raise and we know the keys will match
|
|
||||||
|
|
||||||
proc toPattern(d: sink DBind): Pattern =
|
proc toPattern(l: sink PatternLit): Pattern =
|
||||||
Pattern(orKind: PatternKind.DBind, dbind: d)
|
Pattern(orKind: PatternKind.`lit`, lit: l)
|
||||||
|
|
||||||
proc toPattern(d: sink DLit): Pattern =
|
proc toPattern(g: sink PatternGroup): Pattern =
|
||||||
Pattern(orKind: PatternKind.DLit, dlit: d)
|
Pattern(orKind: PatternKind.`group`, group: g)
|
||||||
|
|
||||||
proc toPattern(aa: sink AnyAtom): Pattern =
|
proc toPattern(a: sink AnyAtom): Pattern =
|
||||||
DLit(value: aa).toPattern
|
PatternLit(value: a).toPattern
|
||||||
|
|
||||||
proc toPattern(d: sink DCompound): Pattern =
|
proc grab*(p: sink Pattern): Pattern =
|
||||||
Pattern(orKind: PatternKind.DCompound, dcompound: d)
|
PatternBind(pattern: p).toPattern
|
||||||
|
|
||||||
proc toPattern(d: sink DCompoundRec): Pattern =
|
proc drop*(): Pattern = Pattern(orKind: PatternKind.`discard`)
|
||||||
DCompound(orKind: DCompoundKind.rec, rec: d).toPattern
|
|
||||||
|
|
||||||
proc toPattern(d: sink DCompoundArr): Pattern =
|
|
||||||
DCompound(orKind: DCompoundKind.arr, arr: d).toPattern
|
|
||||||
|
|
||||||
proc toPattern(d: sink DCompoundDict): Pattern =
|
|
||||||
DCompound(orKind: DCompoundKind.dict, dict: d).toPattern
|
|
||||||
|
|
||||||
proc drop*(): Pattern {.inline.} = Pattern(orKind: PatternKind.DDiscard)
|
|
||||||
## Create a pattern to match any value without capture.
|
## Create a pattern to match any value without capture.
|
||||||
|
|
||||||
proc grab*(): Pattern {.inline.} = DBind(pattern: drop()).toPattern
|
proc grab*(): Pattern = drop().grab()
|
||||||
## Create a pattern to capture any value.
|
## Create a pattern to capture any value.
|
||||||
|
|
||||||
proc grab*[T](pr: Preserve[T]): Pattern =
|
proc drop*(pr: Value): Pattern =
|
||||||
## Convert a `Preserve` value to a `Pattern`.
|
## Convert a `Preserve` value to a `Pattern`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
import preserves
|
import pkg/preserves
|
||||||
check:
|
check:
|
||||||
$(grab parsePreserves"""<foo "bar" #"00" [0 1 2.0] {maybe: #t} <_>>""") ==
|
$("""<foo "bar" #"00" [0 1 2.0] {maybe: #t} <_>>""".parsePreserves.drop) ==
|
||||||
"""<rec foo [<lit "bar"> <lit #"00"> <arr [<lit 0> <lit 1> <lit 2.0>]> <dict {maybe: <lit #t>}> <_>]>"""
|
"""<group <rec foo> {0: <lit "bar"> 1: <lit #"00"> 2: <group <arr> {0: <lit 0> 1: <lit 1> 2: <lit 2.0>}> 3: <group <dict> {maybe: <lit #t>}> 4: <_>}>"""
|
||||||
|
|
||||||
assert not pr.embedded
|
|
||||||
case pr.kind
|
case pr.kind
|
||||||
of pkBoolean:
|
of pkBoolean:
|
||||||
AnyAtom(orKind: AnyAtomKind.`bool`, bool: pr.bool).toPattern
|
AnyAtom(orKind: AnyAtomKind.`bool`, bool: pr.bool).toPattern
|
||||||
of pkFloat:
|
of pkFloat:
|
||||||
AnyAtom(orKind: AnyAtomKind.`float`, float: pr.float).toPattern
|
AnyAtom(orKind: AnyAtomKind.`double`, double: pr.float).toPattern
|
||||||
of pkDouble:
|
of pkRegister:
|
||||||
AnyAtom(orKind: AnyAtomKind.`double`, double: pr.double).toPattern
|
AnyAtom(orKind: AnyAtomKind.`int`, int: pr.register).toPattern
|
||||||
of pkSignedInteger:
|
of pkBigInt:
|
||||||
AnyAtom(orKind: AnyAtomKind.`int`, int: pr.int).toPattern
|
raiseAssert "cannot make a pattern over a big integer"
|
||||||
of pkString:
|
of pkString:
|
||||||
AnyAtom(orKind: AnyAtomKind.`string`, string: pr.string).toPattern
|
AnyAtom(orKind: AnyAtomKind.`string`, string: pr.string).toPattern
|
||||||
of pkByteString:
|
of pkByteString:
|
||||||
AnyAtom(orKind: AnyAtomKind.`bytes`, bytes: pr.bytes).toPattern
|
AnyAtom(orKind: AnyAtomKind.`bytes`, bytes: pr.bytes).toPattern
|
||||||
of pkSymbol:
|
of pkSymbol:
|
||||||
AnyAtom(orKind: AnyAtomKind.`symbol`, symbol: pr.symbol).toPattern
|
AnyAtom(orKind: AnyAtomKind.`symbol`, symbol: pr.symbol).toPattern
|
||||||
|
|
||||||
of pkRecord:
|
of pkRecord:
|
||||||
if (pr.isRecord("_") and pr.arity == 0) or (pr.isRecord("bind") and pr.arity == 1):
|
if pr.isRecord("_", 0):
|
||||||
drop()
|
drop()
|
||||||
|
elif pr.isRecord("bind", 1):
|
||||||
|
pr.fields[0].drop
|
||||||
else:
|
else:
|
||||||
DCompoundRec(
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.rec))
|
||||||
label: cast[Preserve[Cap]](pr.label), # TODO: don't cast like this
|
group.`type`.rec.label = pr.label
|
||||||
fields: map[Preserve[T], Pattern](pr.fields, grab)).toPattern
|
var i: int
|
||||||
|
for v in pr.fields:
|
||||||
|
group.entries[toPreserves i] = drop v
|
||||||
|
inc i
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
of pkSequence:
|
of pkSequence:
|
||||||
DCompoundArr(items: map(pr.sequence, grab)).toPattern
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.arr))
|
||||||
|
for i, v in pr.sequence:
|
||||||
|
group.entries[toPreserves i] = drop v
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
of pkSet:
|
of pkSet:
|
||||||
raiseAssert "cannot construct a pattern over a set literal"
|
raiseAssert "cannot construct a pattern over a set literal"
|
||||||
of pkDictionary:
|
|
||||||
var dict = DCompoundDict()
|
|
||||||
for key, val in pr.pairs: dict.entries[cast[Preserve[Cap]](key)] = grab val
|
|
||||||
dict.toPattern
|
|
||||||
of pkEmbedded:
|
|
||||||
# TODO: can patterns be constructed over embedded literals?
|
|
||||||
drop()
|
|
||||||
|
|
||||||
proc grab*[T](val: T): Pattern =
|
of pkDictionary:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.dict))
|
||||||
|
for key, val in pr.pairs:
|
||||||
|
group.entries[key] = drop val
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
|
of pkEmbedded:
|
||||||
|
if pr.embeddedRef.isNil: drop()
|
||||||
|
else:
|
||||||
|
AnyAtom(orKind: AnyAtomKind.`embedded`, embedded: pr.embeddedRef).toPattern
|
||||||
|
#else:
|
||||||
|
# raise newException(ValueError, "cannot generate a pattern for unhandled Value type")
|
||||||
|
|
||||||
|
proc drop*[T](x: T): Pattern =
|
||||||
## Construct a `Pattern` from value of type `T`.
|
## Construct a `Pattern` from value of type `T`.
|
||||||
|
## This proc is called `drop` because the value `x` is matched but discarded.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
check:
|
check:
|
||||||
$grab(true) == "<lit #t>"
|
$drop(true) == "<lit #t>"
|
||||||
$grab(3.14) == "<lit 3.14>"
|
$drop(3.14) == "<lit 3.14>"
|
||||||
$grab([0, 1, 2, 3]) == "<arr [<lit 0> <lit 1> <lit 2> <lit 3>]>"
|
$drop([0, 1, 2, 3]) == "<group <arr> {0: <lit 0> 1: <lit 1> 2: <lit 2> 3: <lit 3>}>"
|
||||||
grab (toPreserve(val, Cap))
|
drop(x.toPreserves)
|
||||||
|
|
||||||
proc patternOfType(typ: static typedesc; `bind`: static bool): Pattern =
|
proc grab*[T](x: T): Pattern {.
|
||||||
when typ is ref:
|
deprecated: "use drop unless you wish to capture the provided value".} =
|
||||||
patternOfType(pointerBase(typ), `bind`)
|
PatternBind(pattern: drop x).toPattern
|
||||||
elif typ.hasPreservesRecordPragma:
|
|
||||||
var rec = DCompoundRec(label: typ.recordLabel.tosymbol(Cap))
|
|
||||||
for _, f in fieldPairs(default typ):
|
|
||||||
add(rec.fields, patternOfType(typeof f, `bind`))
|
|
||||||
result = rec.toPattern
|
|
||||||
elif typ.hasPreservesDictionaryPragma:
|
|
||||||
var dict = DCompoundDict()
|
|
||||||
for key, val in fieldPairs(default typ):
|
|
||||||
dict.entries[toSymbol(key, Cap)] = patternOfType(typeof val, `bind`)
|
|
||||||
dict.toPattern
|
|
||||||
elif typ is tuple:
|
|
||||||
var arr = DCompoundArr()
|
|
||||||
for _, f in fieldPairs(default typ):
|
|
||||||
add(arr.items, patternOfType(typeof f, `bind`))
|
|
||||||
arr.toPattern
|
|
||||||
elif typ is array:
|
|
||||||
var arr = DCompoundArr()
|
|
||||||
arr.items.setLen(len(typ))
|
|
||||||
for e in arr.items.mitems: e = grab()
|
|
||||||
arr.toPattern
|
|
||||||
else:
|
|
||||||
if `bind`: grab()
|
|
||||||
else: drop()
|
|
||||||
|
|
||||||
proc grabType*(typ: static typedesc): Pattern =
|
proc grabTypeFlat*(typ: static typedesc): Pattern =
|
||||||
## Derive a `Pattern` from type `typ`.
|
## Derive a `Pattern` from type `typ`.
|
||||||
## This works for `tuple` and `object` types but in the
|
## This works for `tuple` and `object` types but in the
|
||||||
## general case will return a wildcard binding.
|
## general case will return a wildcard binding.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
import preserves
|
import pkg/preserves
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
check:
|
check:
|
||||||
$grabType(array[3, int]) ==
|
$grabTypeFlat(array[3, int]) ==
|
||||||
"""<arr [<bind <_>> <bind <_>> <bind <_>>]>"""
|
"""<group <arr> {0: <bind <_>> 1: <bind <_>> 2: <bind <_>> 3: <bind <_>>}>"""
|
||||||
type
|
type
|
||||||
Point = tuple[x: int; y: int]
|
Point = tuple[x: int; y: int]
|
||||||
Rect {.preservesRecord: "rect".} = tuple[a: Point; B: Point]
|
Rect {.preservesRecord: "rect".} = tuple[a: Point; B: Point]
|
||||||
ColoredRect {.preservesDictionary.} = tuple[color: string; rect: Rect]
|
ColoredRect {.preservesDictionary.} = tuple[color: string; rect: Rect]
|
||||||
check:
|
check:
|
||||||
$(grabType Point) ==
|
$(grabTypeFlat Point) ==
|
||||||
"<arr [<bind <_>> <bind <_>>]>"
|
"<group <arr> {0: <bind <_>> 1: <bind <_>>}>"
|
||||||
$(grabType Rect) ==
|
$(grabTypeFlat Rect) ==
|
||||||
"<rec rect [<arr [<bind <_>> <bind <_>>]> <arr [<bind <_>> <bind <_>>]>]>"
|
"<group <rec rect> {0: <group <arr> {0: <bind <_>> 1: <bind <_>>}> 1: <group <arr> {0: <bind <_>> 1: <bind <_>>}>}>"
|
||||||
$(grabType ColoredRect) ==
|
$(grabTypeFlat ColoredRect) ==
|
||||||
"<dict {color: <bind <_>> rect: <rec rect [<arr [<bind <_>> <bind <_>>]> <arr [<bind <_>> <bind <_>>]>]>}>"
|
"<group <dict> {color: <bind <_>> rect: <group <rec rect> {0: <group <arr> {0: <bind <_>> 1: <bind <_>>}> 1: <group <arr> {0: <bind <_>> 1: <bind <_>>}>}>}>"
|
||||||
patternOfType(typ, true)
|
when typ is ref:
|
||||||
|
grabTypeFlat(pointerBase(typ))
|
||||||
proc dropType*(typ: static typedesc): Pattern =
|
elif typ.hasPreservesRecordPragma:
|
||||||
## Derive a `Pattern` from type `typ` without any bindings.
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`rec`))
|
||||||
patternOfType(typ, false)
|
group.`type`.rec.label = typ.recordLabel.toSymbol
|
||||||
|
for _, f in fieldPairs(default typ):
|
||||||
|
group.entries[group.entries.len.toPreserves] = grabTypeFlat(typeof f)
|
||||||
|
group.toPattern
|
||||||
|
elif typ.hasPreservesDictionaryPragma:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`dict`))
|
||||||
|
for key, val in fieldPairs(default typ):
|
||||||
|
group.entries[key.toSymbol] = grabTypeFlat(typeof val)
|
||||||
|
group.toPattern
|
||||||
|
elif typ is tuple:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`arr`))
|
||||||
|
for _, f in fieldPairs(default typ):
|
||||||
|
group.entries[group.entries.len.toPreserves] = grabTypeFlat(typeof f)
|
||||||
|
group.toPattern
|
||||||
|
elif typ is array:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`arr`))
|
||||||
|
for i in 0..len(typ):
|
||||||
|
group.entries[toPreserves i] = grab()
|
||||||
|
group.toPattern
|
||||||
|
else:
|
||||||
|
grab()
|
||||||
|
|
||||||
proc fieldCount(T: typedesc): int =
|
proc fieldCount(T: typedesc): int =
|
||||||
for _, _ in fieldPairs(default T):
|
for _, _ in fieldPairs(default T):
|
||||||
inc result
|
inc result
|
||||||
|
|
||||||
proc match(bindings: sink openArray[(int, Pattern)]; i: int; pat: var Pattern): bool =
|
proc matchType*(typ: static typedesc): Pattern =
|
||||||
for (j, b) in bindings:
|
## Derive a `Pattern` from type `typ` without any bindings.
|
||||||
if i == j:
|
when typ is ref:
|
||||||
pat = b
|
matchType(pointerBase(typ))
|
||||||
return true
|
elif typ.hasPreservesRecordPragma:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`rec`))
|
||||||
|
group.`type`.rec.label = typ.recordLabel.toSymbol
|
||||||
|
for _, f in fieldPairs(default typ):
|
||||||
|
group.entries[group.entries.len.toPreserves] = matchType(typeof f)
|
||||||
|
group.toPattern
|
||||||
|
elif typ.hasPreservesDictionaryPragma:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`dict`))
|
||||||
|
for key, val in fieldPairs(default typ):
|
||||||
|
group.entries[key.toSymbol] = matchType(typeof val)
|
||||||
|
group.toPattern
|
||||||
|
elif typ is tuple:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`arr`))
|
||||||
|
for _, f in fieldPairs(default typ):
|
||||||
|
group.entries[group.entries.len.toPreserves] = matchType(typeof f)
|
||||||
|
group.toPattern
|
||||||
|
elif typ is array:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`arr`))
|
||||||
|
let elemPat = typ.default.elementType
|
||||||
|
for i in 0..typ.high:
|
||||||
|
group.entries[i.toPreserves] = elemPat
|
||||||
|
group.toPattern
|
||||||
|
else:
|
||||||
|
drop()
|
||||||
|
|
||||||
|
proc grabType*(typ: static typedesc): Pattern =
|
||||||
|
PatternBind(pattern: typ.matchType).toPattern
|
||||||
|
|
||||||
|
proc grabWithin*(T: static typedesc): Pattern =
|
||||||
|
## Construct a `Pattern` that binds the fields within type `T`.
|
||||||
|
result = matchType(T)
|
||||||
|
for entry in result.group.entries.mvalues:
|
||||||
|
case entry.orKind
|
||||||
|
of `discard`: entry = grab()
|
||||||
|
of `bind`, `lit`: discard
|
||||||
|
of `group`: entry = grab(entry)
|
||||||
|
|
||||||
|
proc grabWithinType*(T: static typedesc): Pattern {.
|
||||||
|
deprecated: "use grabWithin".} = grabWithin(T)
|
||||||
|
|
||||||
|
proc bindEntries(group: var PatternGroup; bindings: openArray[(int, Pattern)]) =
|
||||||
|
## Set `bindings` for a `group`.
|
||||||
|
for (i, pat) in bindings: group.entries[toPreserves i] = pat
|
||||||
|
|
||||||
proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
|
proc grab*(typ: static typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
|
||||||
## Construct a `Pattern` from type `typ` that selectively captures fields.
|
## Construct a `Pattern` from type `typ` with pattern `bindings` by integer offset.
|
||||||
runnableExamples:
|
when typ is ptr | ref:
|
||||||
import preserves
|
|
||||||
from std/unittest import check
|
|
||||||
type
|
|
||||||
Point = tuple[x: int; y: int]
|
|
||||||
Rect {.preservesRecord: "rect".} = tuple[a: Point; B: Point]
|
|
||||||
ColoredRect {.preservesDictionary.} = tuple[color: string; rect: Rect]
|
|
||||||
check:
|
|
||||||
$grab(Point, { 1: grab() }) == "<arr [<_> <bind <_>>]>"
|
|
||||||
$grab(Rect, { 0: grab() }) == "<rec rect [<bind <_>> <arr [<_> <_>]>]>"
|
|
||||||
when typ is ref:
|
|
||||||
grab(pointerBase(typ), bindings)
|
grab(pointerBase(typ), bindings)
|
||||||
elif typ.hasPreservesRecordPragma:
|
elif typ.hasPreservesRecordPragma:
|
||||||
var rec = DCompoundRec(label: typ.recordLabel.tosymbol(Cap))
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`rec`))
|
||||||
rec.fields.setLen(fieldCount typ)
|
group.`type`.rec.label = typ.recordLabel.toSymbol
|
||||||
var i: int
|
bindEntries(group, bindings)
|
||||||
for _, f in fieldPairs(default typ):
|
group.toPattern
|
||||||
if not match(bindings, i, rec.fields[i]):
|
|
||||||
rec.fields[i] = dropType(typeof f)
|
|
||||||
inc i
|
|
||||||
result = rec.toPattern
|
|
||||||
elif typ is tuple:
|
elif typ is tuple:
|
||||||
var arr = DCompoundArr()
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`arr`))
|
||||||
arr.items.setLen(fieldCount typ)
|
bindEntries(group, bindings)
|
||||||
var i: int
|
group.toPattern
|
||||||
for _, f in fieldPairs(default typ):
|
|
||||||
if not match(bindings, i, arr.items[i]):
|
|
||||||
arr.items[i] = dropType(typeof f)
|
|
||||||
inc i
|
|
||||||
result = arr.toPattern
|
|
||||||
else:
|
else:
|
||||||
{.error: "grab with bindings not implemented for " & $typ.}
|
{.error: "grab with indexed bindings not implemented for " & $typ.}
|
||||||
|
|
||||||
|
proc grab*(typ: static typedesc; bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||||
|
## Construct a `Pattern` from type `typ` with dictionary field `bindings`.
|
||||||
|
when typ.hasPreservesDictionaryPragma:
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`dict`))
|
||||||
|
for key, val in bindinds: group.entries[key] = val
|
||||||
|
group.toPattern
|
||||||
|
else:
|
||||||
|
{.error: "grab with dictionary bindings not implemented for " & $typ.}
|
||||||
|
|
||||||
proc grabLit*(): Pattern =
|
proc grabLit*(): Pattern =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
check:
|
check:
|
||||||
$grabLit() == """<rec lit [<bind <_>>]>"""
|
$grabLit() == """<group <rec lit> {0: <bind <_>>}>"""
|
||||||
grabType(dataspacePatterns.DLit[void])
|
grabTypeFlat(dataspacePatterns.PatternLit)
|
||||||
|
|
||||||
proc grabDict*(): Pattern =
|
proc grabDict*(): Pattern =
|
||||||
grabType(dataspacePatterns.DCompoundDict[void])
|
grabTypeFlat(dataspacePatterns.GroupTypeDict)
|
||||||
|
|
||||||
proc unpackLiterals*[E](pr: Preserve[E]): Preserve[E] =
|
proc unpackLiterals*(pr: Value): Value =
|
||||||
result = pr
|
result = pr
|
||||||
apply(result) do (pr: var Preserve[E]):
|
apply(result) do (pr: var Value):
|
||||||
if pr.isRecord("lit", 1) or pr.isRecord("dict", 1) or pr.isRecord("arr", 1) or pr.isRecord("set", 1):
|
if pr.isRecord("lit", 1) or pr.isRecord("dict", 1) or pr.isRecord("arr", 1) or pr.isRecord("set", 1):
|
||||||
pr = pr.record[0]
|
pr = pr.record[0]
|
||||||
|
|
||||||
proc inject*(pat: Pattern; bindings: openArray[(int, Pattern)]): Pattern =
|
proc inject*(pattern: sink Pattern; p: Pattern; path: varargs[Value, toPreserves]): Pattern =
|
||||||
## Construct a `Pattern` from `pat` with injected overrides from `bindings`.
|
## Inject `p` inside `pattern` at `path`.
|
||||||
## Injects are made at offsets indexed by the discard (`<_>`) patterns in `pat`.
|
## Injects are made at offsets indexed by the discard (`<_>`) patterns in `pat`.
|
||||||
proc inject(pat: Pattern; bindings: openArray[(int, Pattern)]; offset: var int): Pattern =
|
proc inject(pat: var Pattern; path: openarray[Value]) =
|
||||||
case pat.orKind
|
if len(path) == 0:
|
||||||
of PatternKind.DDiscard:
|
pat = p
|
||||||
result = pat
|
elif pat.orKind != PatternKind.`group`:
|
||||||
for (off, injection) in bindings:
|
raise newException(ValueError, "cannot inject along specified path")
|
||||||
if off == offset:
|
else:
|
||||||
result = injection
|
inject(pat.group.entries[path[0]], path[1..path.high])
|
||||||
break
|
result = pattern
|
||||||
inc offset
|
inject(result, path)
|
||||||
of PatternKind.DBind:
|
|
||||||
let bindOff = offset
|
|
||||||
result = pat
|
|
||||||
result.dbind.pattern = inject(pat.dbind.pattern, bindings, offset)
|
|
||||||
if result.orKind == PatternKind.DBind:
|
|
||||||
for (off, injection) in bindings:
|
|
||||||
if (off == bindOff) and (result.dbind.pattern == injection):
|
|
||||||
result = result.dbind.pattern
|
|
||||||
break # promote the injected pattern over the bind
|
|
||||||
of PatternKind.DLit:
|
|
||||||
result = pat
|
|
||||||
of PatternKind.DCompound:
|
|
||||||
result = pat
|
|
||||||
case pat.dcompound.orKind
|
|
||||||
of DCompoundKind.rec:
|
|
||||||
var fields = mapIt(pat.dcompound.rec.fields):
|
|
||||||
inject(it, bindings, offset)
|
|
||||||
result = DCompoundRec(label: result.dcompound.rec.label, fields: fields).toPattern
|
|
||||||
of DCompoundKind.arr:
|
|
||||||
var items = mapIt(pat.dcompound.arr.items):
|
|
||||||
inject(it, bindings, offset)
|
|
||||||
result = DCompoundArr(items: items).toPattern
|
|
||||||
of DCompoundKind.dict:
|
|
||||||
var dict = DCompoundDict()
|
|
||||||
for key, val in pat.dcompound.dict.entries:
|
|
||||||
dict.entries[key] = inject(val, bindings, offset)
|
|
||||||
result = toPattern(dict)
|
|
||||||
var offset = 0
|
|
||||||
inject(pat, bindings, offset)
|
|
||||||
|
|
||||||
proc inject*(pat: Pattern; bindings: openArray[(Preserve[Cap], Pattern)]): Pattern =
|
proc matchRecord*(label: Value, fields: varargs[Pattern]): Pattern =
|
||||||
## Inject `bindings` into a dictionary pattern.
|
|
||||||
assert pat.orKind == PatternKind.DCompound
|
|
||||||
assert pat.dcompound.orKind == DCompoundKind.dict
|
|
||||||
result = pat
|
|
||||||
for (key, val) in bindings:
|
|
||||||
result.dcompound.dict.entries[key] = val
|
|
||||||
|
|
||||||
proc grabRecord*(label: Preserve[Cap], fields: varargs[Pattern]): Pattern =
|
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
from std/unittest import check
|
from std/unittest import check
|
||||||
import syndicate/actors, preserves
|
import pkg/preserves
|
||||||
check:
|
check:
|
||||||
$grabRecord("Says".toSymbol(Cap), grab(), grab()) ==
|
$matchRecord("Says".toSymbol, grab(), grab()) ==
|
||||||
"""<rec Says [<bind <_>> <bind <_>>]>"""
|
"""<group <rec Says> {0: <bind <_>> 1: <bind <_>>}>"""
|
||||||
DCompoundRec(label: label, fields: fields.toSeq).toPattern
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`rec`))
|
||||||
|
group.`type`.rec.label = label
|
||||||
|
for i, f in fields: group.entries[toPreserves i] = f
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
|
proc matchRecord*(label: string; fields: varargs[Pattern]): Pattern =
|
||||||
|
matchRecord(label.toSymbol, fields)
|
||||||
|
|
||||||
|
proc grabRecord*(label: Value, fields: varargs[Pattern]): Pattern =
|
||||||
|
runnableExamples:
|
||||||
|
from std/unittest import check
|
||||||
|
import pkg/preserves
|
||||||
|
check:
|
||||||
|
$grabRecord("Says".toSymbol, grab(), grab()) ==
|
||||||
|
"""<bind <group <rec Says> {0: <bind <_>> 1: <bind <_>>}>>"""
|
||||||
|
grab(matchRecord(label, fields))
|
||||||
|
|
||||||
|
proc grabRecord*(label: Value, fields: sink openArray[(int, Pattern)]): Pattern =
|
||||||
|
runnableExamples:
|
||||||
|
from std/unittest import check
|
||||||
|
import pkg/preserves
|
||||||
|
check:
|
||||||
|
$grabRecord("Says".toSymbol, {3: grab(), 4: grab()}) ==
|
||||||
|
"""<group <rec Says> {3: <bind <_>> 4: <bind <_>>}>"""
|
||||||
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`rec`))
|
||||||
|
group.`type`.rec.label = label
|
||||||
|
for (i, p) in fields: group.entries[toPreserves i] = p
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
proc grabRecord*(label: string, fields: varargs[Pattern]): Pattern =
|
proc grabRecord*(label: string, fields: varargs[Pattern]): Pattern =
|
||||||
## Sugar for creating record patterns.
|
## Sugar for creating record patterns.
|
||||||
## `label` is converted to a symbol value.
|
## `label` is converted to a symbol value.
|
||||||
grabRecord(label.toSymbol(Cap), fields)
|
grabRecord(label.toSymbol, fields)
|
||||||
|
|
||||||
proc grabDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
|
proc matchDictionary*(bindings: sink openArray[(Value, Pattern)]): Pattern =
|
||||||
## Construct a pattern that grabs some dictionary pairs.
|
## Construct a pattern that grabs some dictionary pairs.
|
||||||
DCompoundDict(entries: bindings.toTable).toPattern
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`dict`))
|
||||||
|
for (key, val) in bindings: group.entries[key] = val
|
||||||
|
group.toPattern
|
||||||
|
|
||||||
proc grabDictionary*(bindings: sink openArray[(string, Pattern)]): Pattern =
|
proc matchDictionary*(bindings: sink openArray[(string, Pattern)]): Pattern =
|
||||||
## Construct a pattern that grabs some dictionary pairs.
|
## Construct a pattern that grabs some dictionary pairs.
|
||||||
## Keys are converted from strings to symbols.
|
## Keys are converted from strings to symbols.
|
||||||
result = DCompoundDict().toPattern
|
var group = PatternGroup(`type`: GroupType(orKind: GroupTypeKind.`dict`))
|
||||||
for (key, val) in bindings.items:
|
for (key, val) in bindings: group.entries[toSymbol key] = val
|
||||||
result.dcompound.dict.entries[key.toSymbol(Cap)] = val
|
group.toPattern
|
||||||
|
|
||||||
|
proc depattern(group: PatternGroup; values: var seq[Value]; index: var int): Value
|
||||||
|
|
||||||
|
proc depattern(pat: Pattern; values: var seq[Value]; index: var int): Value =
|
||||||
|
case pat.orKind
|
||||||
|
of PatternKind.`discard`:
|
||||||
|
discard
|
||||||
|
of PatternKind.`bind`:
|
||||||
|
if index < values.len:
|
||||||
|
result = move values[index]
|
||||||
|
inc index
|
||||||
|
of PatternKind.`lit`:
|
||||||
|
result = pat.`lit`.value.toPreserves
|
||||||
|
of PatternKind.`group`:
|
||||||
|
result = depattern(pat.group, values, index)
|
||||||
|
|
||||||
|
proc depattern(group: PatternGroup; values: var seq[Value]; index: var int): Value =
|
||||||
|
case group.`type`.orKind
|
||||||
|
of GroupTypeKind.rec:
|
||||||
|
result = initRecord(group.`type`.rec.label, group.entries.len)
|
||||||
|
var i: int
|
||||||
|
for key, val in group.entries:
|
||||||
|
if i.fromPreserves key:
|
||||||
|
result[i] = depattern(val, values, index)
|
||||||
|
of GroupTypeKind.arr:
|
||||||
|
result = initSequence(group.entries.len)
|
||||||
|
var i: int
|
||||||
|
for key, val in group.entries:
|
||||||
|
if i.fromPreserves key:
|
||||||
|
result[i] = depattern(val, values, index)
|
||||||
|
of GroupTypeKind.dict:
|
||||||
|
result = initDictionary(group.entries.len)
|
||||||
|
for key, val in group.entries:
|
||||||
|
result[key] = depattern(val, values, index)
|
||||||
|
|
||||||
|
proc depattern*(pat: Pattern; values: sink seq[Value]): Value =
|
||||||
|
## Convert a `Pattern` to a `Value` while replacing binds with `values`.
|
||||||
|
runnableExamples:
|
||||||
|
from std/unittest import check
|
||||||
|
import pkg/preserves
|
||||||
|
type Foo {.preservesRecord: "foo".} = object
|
||||||
|
a, b: int
|
||||||
|
let pat = grabTypeFlat Foo
|
||||||
|
let val = depattern(pat, @[1.toPreserves, 5.toPreserves])
|
||||||
|
check $val == "<foo 1 5>"
|
||||||
|
var index: int
|
||||||
|
depattern(pat, values, index)
|
||||||
|
|
||||||
|
type Literal*[T] = object
|
||||||
|
## A wrapper type to deserialize patterns to native values.
|
||||||
|
value*: T
|
||||||
|
|
||||||
|
proc fromPreservesHook*[T](lit: var Literal[T]; pr: Value): bool =
|
||||||
|
var pat: Pattern
|
||||||
|
pat.fromPreserves(pr) and lit.value.fromPreserves(depattern(pat, @[]))
|
||||||
|
|
||||||
|
proc toPreservesHook*[T](lit: Literal[T]): Value =
|
||||||
|
lit.value.grab.toPreserves
|
||||||
|
|
||||||
|
func isGroup(pat: Pattern): bool =
|
||||||
|
pat.orKind == PatternKind.`group`
|
||||||
|
|
||||||
|
func isMetaDict(pat: Pattern): bool =
|
||||||
|
pat.orKind == PatternKind.`group` and
|
||||||
|
pat.group.type.orKind == GroupTypeKind.dict
|
||||||
|
|
||||||
|
proc metaApply(result: var Pattern; pat: Pattern; path: openarray[Value], offset: int) =
|
||||||
|
if offset == path.len:
|
||||||
|
result = pat
|
||||||
|
elif result.isGroup and result.group.entries[1.toPreserves].isMetaDict:
|
||||||
|
if offset == path.high:
|
||||||
|
result.group.entries[1.toPreserves].group.entries[path[offset]] = pat
|
||||||
|
else:
|
||||||
|
metaApply(result.group.entries[1.toPreserves].group.entries[path[offset]], pat, path, succ offset)
|
||||||
|
else:
|
||||||
|
assert result.isGroup, "non-group: " & $result
|
||||||
|
assert result.group.entries[1.toPreserves].isMetaDict, "non-meta-dict: " & $result.group.entries[1.toPreserves]
|
||||||
|
raise newException(ValueError, "cannot inject into non-group pattern " & $result)
|
||||||
|
|
||||||
|
proc observePattern*(pat: Pattern): Pattern =
|
||||||
|
## Construct a pattern that matches an `Observe` assertion for `pat`.
|
||||||
|
runnableExamples:
|
||||||
|
import pkg/preserves
|
||||||
|
let
|
||||||
|
sample = parsePreserves"<sample>"
|
||||||
|
observation = sample.drop.observePattern
|
||||||
|
assert $observation ==
|
||||||
|
"<group <rec Observe> {0: <group <rec group> {0: <group <rec rec> {0: <lit sample>}> 1: <group <dict> {}>}> 1: <_>}>"
|
||||||
|
result = matchType Observe
|
||||||
|
result.group.entries[0.toPreserves] = pat.toPreserves.drop
|
||||||
|
|
||||||
|
proc observePattern*(pat: Pattern; injects: openarray[(seq[Value], Pattern)]): Pattern =
|
||||||
|
## Construct a pattern that matches an `Observe` assertion for `pat`
|
||||||
|
## and inject patterns along paths corresponding to the source pattern `pat`.
|
||||||
|
runnableExamples:
|
||||||
|
import pkg/preserves
|
||||||
|
let
|
||||||
|
v = parsePreserves"[ {} {a: #f b: #t } ]"
|
||||||
|
observation = v.drop.observePattern { @[1.toPreserves, "b".toSymbol]: grab() }
|
||||||
|
assert $observation ==
|
||||||
|
"<group <rec Observe> {0: <group <rec group> {0: <group <rec arr> {}> 1: <group <dict> {0: <group <rec group> {0: <group <rec dict> {}> 1: <group <dict> {}>}> 1: <group <rec group> {0: <group <rec dict> {}> 1: <group <dict> {a: <group <rec lit> {0: <lit #f>}> b: <bind <_>>}>}>}>}> 1: <_>}>"
|
||||||
|
result = matchType Observe
|
||||||
|
var meta = pat.toPreserves.drop
|
||||||
|
for (path, pat) in injects:
|
||||||
|
metaApply(meta, pat, path, 0)
|
||||||
|
result.group.entries[0.toPreserves] = meta
|
||||||
|
|
||||||
|
proc observePattern*(pat: Pattern; injects: openarray[(int, Pattern)]): Pattern =
|
||||||
|
## Sugar for observing patterns using record field offsets.
|
||||||
|
pat.observePattern injects.map do (pair: (int, Pattern)) -> (seq[Value], Pattern):
|
||||||
|
(@[pair[0].toPreserves], pair[1])
|
||||||
|
|
||||||
type
|
type
|
||||||
Path* = seq[Value]
|
Path* = seq[Value]
|
||||||
Paths* = seq[Path]
|
Paths* = seq[Path]
|
||||||
Captures* = seq[Value]
|
Captures* = seq[Value]
|
||||||
Analysis* = tuple
|
Analysis* = tuple
|
||||||
|
presentPaths: Paths
|
||||||
constPaths: Paths
|
constPaths: Paths
|
||||||
constValues: seq[Value]
|
constValues: seq[Value]
|
||||||
capturePaths: Paths
|
capturePaths: Paths
|
||||||
|
|
||||||
func walk(result: var Analysis; path: var Path; p: Pattern)
|
func walk(result: var Analysis; path: var Path; p: Pattern)
|
||||||
|
|
||||||
func walk(result: var Analysis; path: var Path; key: int|Value; pat: Pattern) =
|
func walk(result: var Analysis; path: var Path; key: Value; pat: Pattern) =
|
||||||
path.add(key.toPreserve(Cap))
|
path.add(key)
|
||||||
walk(result, path, pat)
|
walk(result, path, pat)
|
||||||
discard path.pop
|
discard path.pop
|
||||||
|
|
||||||
func walk(result: var Analysis; path: var Path; p: Pattern) =
|
func walk(result: var Analysis; path: var Path; p: Pattern) =
|
||||||
case p.orKind
|
case p.orKind
|
||||||
of PatternKind.DCompound:
|
of PatternKind.group:
|
||||||
case p.dcompound.orKind
|
for k, v in p.group.entries: walk(result, path, k, v)
|
||||||
of DCompoundKind.rec:
|
of PatternKind.`bind`:
|
||||||
for k, e in p.dcompound.rec.fields: walk(result, path, k, e)
|
|
||||||
of DCompoundKind.arr:
|
|
||||||
for k, e in p.dcompound.arr.items: walk(result, path, k, e)
|
|
||||||
of DCompoundKind.dict:
|
|
||||||
for k, e in p.dcompound.dict.orderedEntries: walk(result, path, k, e)
|
|
||||||
of PatternKind.DBind:
|
|
||||||
result.capturePaths.add(path)
|
result.capturePaths.add(path)
|
||||||
walk(result, path, p.dbind.pattern)
|
walk(result, path, p.`bind`.pattern)
|
||||||
of PatternKind.DDiscard: discard
|
of PatternKind.`discard`:
|
||||||
of PatternKind.DLit:
|
result.presentPaths.add(path)
|
||||||
|
of PatternKind.`lit`:
|
||||||
result.constPaths.add(path)
|
result.constPaths.add(path)
|
||||||
result.constValues.add(p.dlit.value.toPreserve(Cap))
|
result.constValues.add(p.`lit`.value.toPreserves)
|
||||||
|
|
||||||
func analyse*(p: Pattern): Analysis =
|
func analyse*(p: Pattern): Analysis =
|
||||||
var path: Path
|
var path: Path
|
||||||
walk(result, path, p)
|
walk(result, path, p)
|
||||||
|
|
||||||
func projectPath*(v: Value; path: Path): Option[Value] =
|
func checkPresence*(v: Value; present: Paths): bool =
|
||||||
result = some(v)
|
result = true
|
||||||
for index in path:
|
for path in present:
|
||||||
result = preserves.step(result.get, index)
|
if not result: break
|
||||||
if result.isNone: break
|
result = step(v, path).isSome
|
||||||
|
|
||||||
func projectPaths*(v: Value; paths: Paths): Option[Captures] =
|
func projectPaths*(v: Value; paths: Paths): Option[Captures] =
|
||||||
var res = newSeq[Value](paths.len)
|
var res = newSeq[Value](paths.len)
|
||||||
for i, path in paths:
|
for i, path in paths:
|
||||||
var vv = projectPath(v, path)
|
var vv = step(v, path)
|
||||||
if vv.isSome: res[i] = get(vv)
|
if vv.isSome: res[i] = get(vv)
|
||||||
else: return
|
else: return
|
||||||
some res
|
some res
|
||||||
|
|
||||||
func matches*(pat: Pattern; pr: Value): bool =
|
proc matches*(pat: Pattern; pr: Value): bool =
|
||||||
let analysis = analyse(pat)
|
let analysis = analyse(pat)
|
||||||
assert analysis.constPaths.len == analysis.constValues.len
|
assert analysis.constPaths.len == analysis.constValues.len
|
||||||
|
result = checkPresence(pr, analysis.presentPaths)
|
||||||
|
if result:
|
||||||
for i, path in analysis.constPaths:
|
for i, path in analysis.constPaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone : return false
|
if v.isNone: return false
|
||||||
if analysis.constValues[i] != v.get: return false
|
if analysis.constValues[i] != v.get: return false
|
||||||
for path in analysis.capturePaths:
|
for path in analysis.capturePaths:
|
||||||
if isNone projectPath(pr, path): return false
|
if step(pr, path).isNone: return false
|
||||||
true
|
|
||||||
|
|
||||||
func capture*(pat: Pattern; pr: Value): seq[Value] =
|
proc capture*(pat: Pattern; pr: Value): seq[Value] =
|
||||||
let analysis = analyse(pat)
|
let analysis = analyse(pat)
|
||||||
assert analysis.constPaths.len == analysis.constValues.len
|
assert analysis.constPaths.len == analysis.constValues.len
|
||||||
|
if checkPresence(pr, analysis.presentPaths):
|
||||||
for i, path in analysis.constPaths:
|
for i, path in analysis.constPaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone : return @[]
|
if v.isNone : return @[]
|
||||||
if analysis.constValues[i] != v.get: return @[]
|
if analysis.constValues[i] != v.get: return @[]
|
||||||
for path in analysis.capturePaths:
|
for path in analysis.capturePaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone: return @[]
|
if v.isNone: return @[]
|
||||||
result.add(get v)
|
result.add(get v)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let txt = readAll stdin
|
stdout.writeLine stdin.readAll.parsePreserves.grab
|
||||||
if txt != "":
|
|
||||||
let
|
|
||||||
v = parsePreserves(txt)
|
|
||||||
pat = grab v
|
|
||||||
stdout.writeLine(pat)
|
|
||||||
|
|
|
@ -5,7 +5,9 @@ modules += gatekeeper.nim
|
||||||
modules += http.nim
|
modules += http.nim
|
||||||
modules += noise.nim
|
modules += noise.nim
|
||||||
modules += protocol.nim
|
modules += protocol.nim
|
||||||
|
modules += rpc.nim
|
||||||
modules += service.nim
|
modules += service.nim
|
||||||
|
modules += stdenv.nim
|
||||||
modules += stream.nim
|
modules += stream.nim
|
||||||
modules += sturdy.nim
|
modules += sturdy.nim
|
||||||
modules += tcp.nim
|
modules += tcp.nim
|
||||||
|
@ -15,7 +17,7 @@ modules += transportAddress.nim
|
||||||
modules += worker.nim
|
modules += worker.nim
|
||||||
|
|
||||||
: ../../../../syndicate-protocols/schema-bundle.bin \
|
: ../../../../syndicate-protocols/schema-bundle.bin \
|
||||||
|> !preserves_schema_nim \
|
|> !preserves-schema-nim \
|
||||||
|> $(modules) | $(SYNDICATE_PROTOCOL)
|
|> $(modules) | $(SYNDICATE_PROTOCOL)
|
||||||
|
|
||||||
: foreach $(modules) | $(modules) |> !nim_check |>
|
: foreach $(modules) | $(modules) |> !nim_check |>
|
||||||
|
|
|
@ -3,12 +3,12 @@ import
|
||||||
preserves, dataspacePatterns
|
preserves, dataspacePatterns
|
||||||
|
|
||||||
type
|
type
|
||||||
Observe*[Cap] {.preservesRecord: "Observe".} = ref object
|
Observe* {.preservesRecord: "Observe".} = object
|
||||||
`pattern`*: dataspacePatterns.Pattern[Cap]
|
`pattern`*: dataspacePatterns.Pattern
|
||||||
`observer`*: Cap
|
`observer`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
proc `$`*[Cap](x: Observe[Cap]): string =
|
proc `$`*(x: Observe): string =
|
||||||
`$`(toPreserve(x, Cap))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: Observe[Cap]): seq[byte] =
|
proc encode*(x: Observe): seq[byte] =
|
||||||
encode(toPreserve(x, Cap))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -4,101 +4,83 @@ import
|
||||||
|
|
||||||
type
|
type
|
||||||
AnyAtomKind* {.pure.} = enum
|
AnyAtomKind* {.pure.} = enum
|
||||||
`bool`, `float`, `double`, `int`, `string`, `bytes`, `symbol`, `embedded`
|
`bool`, `double`, `int`, `string`, `bytes`, `symbol`, `embedded`
|
||||||
AnyAtomBool* = bool
|
`AnyAtom`* {.preservesOr.} = object
|
||||||
AnyAtomFloat* = float32
|
|
||||||
AnyAtomDouble* = float64
|
|
||||||
AnyAtomInt* = BiggestInt
|
|
||||||
AnyAtomString* = string
|
|
||||||
AnyAtomBytes* = seq[byte]
|
|
||||||
AnyAtomSymbol* = Symbol
|
|
||||||
AnyAtomEmbedded*[Cap] = Cap
|
|
||||||
`AnyAtom`*[Cap] {.preservesOr.} = object
|
|
||||||
case orKind*: AnyAtomKind
|
case orKind*: AnyAtomKind
|
||||||
of AnyAtomKind.`bool`:
|
of AnyAtomKind.`bool`:
|
||||||
`bool`*: AnyAtomBool
|
`bool`*: bool
|
||||||
|
|
||||||
of AnyAtomKind.`float`:
|
|
||||||
`float`*: AnyAtomFloat
|
|
||||||
|
|
||||||
of AnyAtomKind.`double`:
|
of AnyAtomKind.`double`:
|
||||||
`double`*: AnyAtomDouble
|
`double`*: float
|
||||||
|
|
||||||
of AnyAtomKind.`int`:
|
of AnyAtomKind.`int`:
|
||||||
`int`*: AnyAtomInt
|
`int`*: BiggestInt
|
||||||
|
|
||||||
of AnyAtomKind.`string`:
|
of AnyAtomKind.`string`:
|
||||||
`string`*: AnyAtomString
|
`string`*: string
|
||||||
|
|
||||||
of AnyAtomKind.`bytes`:
|
of AnyAtomKind.`bytes`:
|
||||||
`bytes`*: AnyAtomBytes
|
`bytes`*: seq[byte]
|
||||||
|
|
||||||
of AnyAtomKind.`symbol`:
|
of AnyAtomKind.`symbol`:
|
||||||
`symbol`*: AnyAtomSymbol
|
`symbol`*: Symbol
|
||||||
|
|
||||||
of AnyAtomKind.`embedded`:
|
of AnyAtomKind.`embedded`:
|
||||||
`embedded`*: AnyAtomEmbedded[Cap]
|
`embedded`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
|
|
||||||
DLit*[Cap] {.preservesRecord: "lit".} = object
|
GroupTypeKind* {.pure.} = enum
|
||||||
`value`*: AnyAtom[Cap]
|
|
||||||
|
|
||||||
DBind*[Cap] {.preservesRecord: "bind".} = ref object
|
|
||||||
`pattern`*: Pattern[Cap]
|
|
||||||
|
|
||||||
DDiscard* {.preservesRecord: "_".} = object
|
|
||||||
|
|
||||||
DCompoundKind* {.pure.} = enum
|
|
||||||
`rec`, `arr`, `dict`
|
`rec`, `arr`, `dict`
|
||||||
DCompoundRec*[Cap] {.preservesRecord: "rec".} = ref object
|
GroupTypeRec* {.preservesRecord: "rec".} = object
|
||||||
`label`*: Preserve[Cap]
|
`label`*: Value
|
||||||
`fields`*: seq[Pattern[Cap]]
|
|
||||||
|
|
||||||
DCompoundArr*[Cap] {.preservesRecord: "arr".} = ref object
|
GroupTypeArr* {.preservesRecord: "arr".} = object
|
||||||
`items`*: seq[Pattern[Cap]]
|
|
||||||
|
|
||||||
DCompoundDict*[Cap] {.preservesRecord: "dict".} = ref object
|
GroupTypeDict* {.preservesRecord: "dict".} = object
|
||||||
`entries`*: Table[Preserve[Cap], Pattern[Cap]]
|
|
||||||
|
|
||||||
`DCompound`*[Cap] {.preservesOr.} = ref object
|
`GroupType`* {.preservesOr.} = object
|
||||||
case orKind*: DCompoundKind
|
case orKind*: GroupTypeKind
|
||||||
of DCompoundKind.`rec`:
|
of GroupTypeKind.`rec`:
|
||||||
`rec`*: DCompoundRec[Cap]
|
`rec`*: GroupTypeRec
|
||||||
|
|
||||||
of DCompoundKind.`arr`:
|
of GroupTypeKind.`arr`:
|
||||||
`arr`*: DCompoundArr[Cap]
|
`arr`*: GroupTypeArr
|
||||||
|
|
||||||
of DCompoundKind.`dict`:
|
of GroupTypeKind.`dict`:
|
||||||
`dict`*: DCompoundDict[Cap]
|
`dict`*: GroupTypeDict
|
||||||
|
|
||||||
|
|
||||||
PatternKind* {.pure.} = enum
|
PatternKind* {.pure.} = enum
|
||||||
`DDiscard`, `DBind`, `DLit`, `DCompound`
|
`discard`, `bind`, `lit`, `group`
|
||||||
`Pattern`*[Cap] {.preservesOr.} = ref object
|
PatternDiscard* {.preservesRecord: "_".} = object
|
||||||
|
|
||||||
|
PatternBind* {.preservesRecord: "bind".} = object
|
||||||
|
`pattern`*: Pattern
|
||||||
|
|
||||||
|
PatternLit* {.preservesRecord: "lit".} = object
|
||||||
|
`value`*: AnyAtom
|
||||||
|
|
||||||
|
PatternGroup* {.preservesRecord: "group".} = object
|
||||||
|
`type`*: GroupType
|
||||||
|
`entries`*: Table[Value, Pattern]
|
||||||
|
|
||||||
|
`Pattern`* {.acyclic, preservesOr.} = ref object
|
||||||
case orKind*: PatternKind
|
case orKind*: PatternKind
|
||||||
of PatternKind.`DDiscard`:
|
of PatternKind.`discard`:
|
||||||
`ddiscard`*: DDiscard
|
`discard`*: PatternDiscard
|
||||||
|
|
||||||
of PatternKind.`DBind`:
|
of PatternKind.`bind`:
|
||||||
`dbind`*: DBind[Cap]
|
`bind`* {.preservesEmbedded.}: PatternBind
|
||||||
|
|
||||||
of PatternKind.`DLit`:
|
of PatternKind.`lit`:
|
||||||
`dlit`*: DLit[Cap]
|
`lit`* {.preservesEmbedded.}: PatternLit
|
||||||
|
|
||||||
of PatternKind.`DCompound`:
|
of PatternKind.`group`:
|
||||||
`dcompound`*: DCompound[Cap]
|
`group`* {.preservesEmbedded.}: PatternGroup
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[Cap](x: AnyAtom[Cap] | DLit[Cap] | DBind[Cap] | DCompound[Cap] |
|
proc `$`*(x: AnyAtom | GroupType | Pattern): string =
|
||||||
Pattern[Cap]): string =
|
`$`(toPreserves(x))
|
||||||
`$`(toPreserve(x, Cap))
|
|
||||||
|
|
||||||
proc encode*[Cap](x: AnyAtom[Cap] | DLit[Cap] | DBind[Cap] | DCompound[Cap] |
|
proc encode*(x: AnyAtom | GroupType | Pattern): seq[byte] =
|
||||||
Pattern[Cap]): seq[byte] =
|
encode(toPreserves(x))
|
||||||
encode(toPreserve(x, Cap))
|
|
||||||
|
|
||||||
proc `$`*(x: DDiscard): string =
|
|
||||||
`$`(toPreserve(x))
|
|
||||||
|
|
||||||
proc encode*(x: DDiscard): seq[byte] =
|
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -3,106 +3,101 @@ import
|
||||||
preserves
|
preserves
|
||||||
|
|
||||||
type
|
type
|
||||||
Bind*[Cap] {.preservesRecord: "bind".} = object
|
Bind* {.preservesRecord: "bind".} = object
|
||||||
`description`*: Description[Cap]
|
`description`*: Description
|
||||||
`target`*: Cap
|
`target`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`observer`*: BindObserver[Cap]
|
`observer`*: BindObserver
|
||||||
|
|
||||||
Route*[Cap] {.preservesRecord: "route".} = object
|
Route* {.preservesRecord: "route".} = object
|
||||||
`transports`*: seq[Preserve[Cap]]
|
`transports`*: seq[Value]
|
||||||
`pathSteps`* {.preservesTupleTail.}: seq[PathStep[Cap]]
|
`pathSteps`* {.preservesTupleTail.}: seq[PathStep]
|
||||||
|
|
||||||
BindObserverKind* {.pure.} = enum
|
BindObserverKind* {.pure.} = enum
|
||||||
`present`, `absent`
|
`absent`, `present`
|
||||||
BindObserverPresent*[Cap] = Cap
|
`BindObserver`* {.preservesOr.} = object
|
||||||
`BindObserver`*[Cap] {.preservesOr.} = object
|
|
||||||
case orKind*: BindObserverKind
|
case orKind*: BindObserverKind
|
||||||
of BindObserverKind.`present`:
|
|
||||||
`present`*: BindObserverPresent[Cap]
|
|
||||||
|
|
||||||
of BindObserverKind.`absent`:
|
of BindObserverKind.`absent`:
|
||||||
`absent`* {.preservesLiteral: "#f".}: bool
|
`absent`* {.preservesLiteral: "#f".}: bool
|
||||||
|
|
||||||
|
of BindObserverKind.`present`:
|
||||||
|
`present`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
TransportConnection*[Cap] {.preservesRecord: "connect-transport".} = object
|
|
||||||
`addr`*: Preserve[Cap]
|
|
||||||
`control`*: Cap
|
|
||||||
`resolved`*: Resolved[Cap]
|
|
||||||
|
|
||||||
Step*[Cap] = Preserve[Cap]
|
TransportConnection* {.preservesRecord: "connect-transport".} = object
|
||||||
ResolvedPathStep*[Cap] {.preservesRecord: "path-step".} = object
|
`addr`*: Value
|
||||||
`origin`*: Cap
|
`control`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`pathStep`*: PathStep[Cap]
|
`resolved`*: Resolved
|
||||||
`resolved`*: Resolved[Cap]
|
|
||||||
|
Step* = Value
|
||||||
|
ResolvedPathStep* {.preservesRecord: "path-step".} = object
|
||||||
|
`origin`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
`pathStep`*: PathStep
|
||||||
|
`resolved`*: Resolved
|
||||||
|
|
||||||
BoundKind* {.pure.} = enum
|
BoundKind* {.pure.} = enum
|
||||||
`bound`, `Rejected`
|
`Rejected`, `bound`
|
||||||
BoundBound*[Cap] {.preservesRecord: "bound".} = object
|
BoundBound* {.preservesRecord: "bound".} = object
|
||||||
`pathStep`*: PathStep[Cap]
|
`pathStep`*: PathStep
|
||||||
|
|
||||||
`Bound`*[Cap] {.preservesOr.} = object
|
`Bound`* {.preservesOr.} = object
|
||||||
case orKind*: BoundKind
|
case orKind*: BoundKind
|
||||||
of BoundKind.`bound`:
|
|
||||||
`bound`*: BoundBound[Cap]
|
|
||||||
|
|
||||||
of BoundKind.`Rejected`:
|
of BoundKind.`Rejected`:
|
||||||
`rejected`*: Rejected[Cap]
|
`rejected`*: Rejected
|
||||||
|
|
||||||
|
of BoundKind.`bound`:
|
||||||
|
`bound`*: BoundBound
|
||||||
|
|
||||||
|
|
||||||
ForceDisconnect* {.preservesRecord: "force-disconnect".} = object
|
ForceDisconnect* {.preservesRecord: "force-disconnect".} = object
|
||||||
|
|
||||||
Description*[Cap] = Preserve[Cap]
|
Description* = Value
|
||||||
Rejected*[Cap] {.preservesRecord: "rejected".} = object
|
Rejected* {.preservesRecord: "rejected".} = object
|
||||||
`detail`*: Preserve[Cap]
|
`detail`*: Value
|
||||||
|
|
||||||
Resolve*[Cap] {.preservesRecord: "resolve".} = object
|
Resolve* {.preservesRecord: "resolve".} = object
|
||||||
`step`*: Step[Cap]
|
`step`*: Step
|
||||||
`observer`*: Cap
|
`observer`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
ResolvedKind* {.pure.} = enum
|
ResolvedKind* {.pure.} = enum
|
||||||
`accepted`, `Rejected`
|
`Rejected`, `accepted`
|
||||||
ResolvedAccepted*[Cap] {.preservesRecord: "accepted".} = object
|
ResolvedAccepted* {.preservesRecord: "accepted".} = object
|
||||||
`responderSession`*: Cap
|
`responderSession`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
`Resolved`*[Cap] {.preservesOr.} = object
|
`Resolved`* {.preservesOr.} = object
|
||||||
case orKind*: ResolvedKind
|
case orKind*: ResolvedKind
|
||||||
of ResolvedKind.`accepted`:
|
|
||||||
`accepted`*: ResolvedAccepted[Cap]
|
|
||||||
|
|
||||||
of ResolvedKind.`Rejected`:
|
of ResolvedKind.`Rejected`:
|
||||||
`rejected`*: Rejected[Cap]
|
`rejected`*: Rejected
|
||||||
|
|
||||||
|
of ResolvedKind.`accepted`:
|
||||||
|
`accepted`* {.preservesEmbedded.}: ResolvedAccepted
|
||||||
|
|
||||||
|
|
||||||
TransportControl* = ForceDisconnect
|
TransportControl* = ForceDisconnect
|
||||||
ResolvePath*[Cap] {.preservesRecord: "resolve-path".} = object
|
ResolvePath* {.preservesRecord: "resolve-path".} = object
|
||||||
`route`*: Route[Cap]
|
`route`*: Route
|
||||||
`addr`*: Preserve[Cap]
|
`addr`*: Value
|
||||||
`control`*: Cap
|
`control`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`resolved`*: Resolved[Cap]
|
`resolved`*: Resolved
|
||||||
|
|
||||||
PathStep*[Cap] = Preserve[Cap]
|
PathStep* = Value
|
||||||
proc `$`*[Cap](x: Bind[Cap] | Route[Cap] | BindObserver[Cap] |
|
proc `$`*(x: Bind | Route | BindObserver | TransportConnection |
|
||||||
TransportConnection[Cap] |
|
ResolvedPathStep |
|
||||||
ResolvedPathStep[Cap] |
|
Bound |
|
||||||
Bound[Cap] |
|
ForceDisconnect |
|
||||||
Rejected[Cap] |
|
Rejected |
|
||||||
Resolve[Cap] |
|
Resolve |
|
||||||
Resolved[Cap] |
|
Resolved |
|
||||||
ResolvePath[Cap]): string =
|
TransportControl |
|
||||||
`$`(toPreserve(x, Cap))
|
ResolvePath): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: Bind[Cap] | Route[Cap] | BindObserver[Cap] |
|
proc encode*(x: Bind | Route | BindObserver | TransportConnection |
|
||||||
TransportConnection[Cap] |
|
ResolvedPathStep |
|
||||||
ResolvedPathStep[Cap] |
|
Bound |
|
||||||
Bound[Cap] |
|
ForceDisconnect |
|
||||||
Rejected[Cap] |
|
Rejected |
|
||||||
Resolve[Cap] |
|
Resolve |
|
||||||
Resolved[Cap] |
|
Resolved |
|
||||||
ResolvePath[Cap]): seq[byte] =
|
TransportControl |
|
||||||
encode(toPreserve(x, Cap))
|
ResolvePath): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
||||||
proc `$`*(x: ForceDisconnect | TransportControl): string =
|
|
||||||
`$`(toPreserve(x))
|
|
||||||
|
|
||||||
proc encode*(x: ForceDisconnect | TransportControl): seq[byte] =
|
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves, std/tables
|
||||||
|
|
||||||
|
type
|
||||||
|
HostPatternKind* {.pure.} = enum
|
||||||
|
`host`, `any`
|
||||||
|
`HostPattern`* {.preservesOr.} = object
|
||||||
|
case orKind*: HostPatternKind
|
||||||
|
of HostPatternKind.`host`:
|
||||||
|
`host`*: string
|
||||||
|
|
||||||
|
of HostPatternKind.`any`:
|
||||||
|
`any`* {.preservesLiteral: "#f".}: bool
|
||||||
|
|
||||||
|
|
||||||
|
HttpListener* {.preservesRecord: "http-listener".} = object
|
||||||
|
`port`*: BiggestInt
|
||||||
|
|
||||||
|
MethodPatternKind* {.pure.} = enum
|
||||||
|
`any`, `specific`
|
||||||
|
`MethodPattern`* {.preservesOr.} = object
|
||||||
|
case orKind*: MethodPatternKind
|
||||||
|
of MethodPatternKind.`any`:
|
||||||
|
`any`* {.preservesLiteral: "#f".}: bool
|
||||||
|
|
||||||
|
of MethodPatternKind.`specific`:
|
||||||
|
`specific`*: Symbol
|
||||||
|
|
||||||
|
|
||||||
|
MimeType* = Symbol
|
||||||
|
QueryValueKind* {.pure.} = enum
|
||||||
|
`string`, `file`
|
||||||
|
QueryValueFile* {.preservesRecord: "file".} = object
|
||||||
|
`filename`*: string
|
||||||
|
`headers`*: Headers
|
||||||
|
`body`*: seq[byte]
|
||||||
|
|
||||||
|
`QueryValue`* {.preservesOr.} = object
|
||||||
|
case orKind*: QueryValueKind
|
||||||
|
of QueryValueKind.`string`:
|
||||||
|
`string`*: string
|
||||||
|
|
||||||
|
of QueryValueKind.`file`:
|
||||||
|
`file`*: QueryValueFile
|
||||||
|
|
||||||
|
|
||||||
|
HttpRequest* {.preservesRecord: "http-request".} = object
|
||||||
|
`sequenceNumber`*: BiggestInt
|
||||||
|
`host`*: RequestHost
|
||||||
|
`port`*: BiggestInt
|
||||||
|
`method`*: Symbol
|
||||||
|
`path`*: seq[string]
|
||||||
|
`headers`*: Headers
|
||||||
|
`query`*: Table[Symbol, seq[QueryValue]]
|
||||||
|
`body`*: Value
|
||||||
|
|
||||||
|
Headers* = Table[Symbol, string]
|
||||||
|
HttpResponseKind* {.pure.} = enum
|
||||||
|
`status`, `header`, `chunk`, `done`
|
||||||
|
HttpResponseStatus* {.preservesRecord: "status".} = object
|
||||||
|
`code`*: BiggestInt
|
||||||
|
`message`*: string
|
||||||
|
|
||||||
|
HttpResponseHeader* {.preservesRecord: "header".} = object
|
||||||
|
`name`*: Symbol
|
||||||
|
`value`*: string
|
||||||
|
|
||||||
|
HttpResponseChunk* {.preservesRecord: "chunk".} = object
|
||||||
|
`chunk`*: Chunk
|
||||||
|
|
||||||
|
HttpResponseDone* {.preservesRecord: "done".} = object
|
||||||
|
`chunk`*: Chunk
|
||||||
|
|
||||||
|
`HttpResponse`* {.preservesOr.} = object
|
||||||
|
case orKind*: HttpResponseKind
|
||||||
|
of HttpResponseKind.`status`:
|
||||||
|
`status`*: HttpResponseStatus
|
||||||
|
|
||||||
|
of HttpResponseKind.`header`:
|
||||||
|
`header`*: HttpResponseHeader
|
||||||
|
|
||||||
|
of HttpResponseKind.`chunk`:
|
||||||
|
`chunk`*: HttpResponseChunk
|
||||||
|
|
||||||
|
of HttpResponseKind.`done`:
|
||||||
|
`done`*: HttpResponseDone
|
||||||
|
|
||||||
|
|
||||||
|
HttpService* {.preservesRecord: "http-service".} = object
|
||||||
|
`host`*: HostPattern
|
||||||
|
`port`*: BiggestInt
|
||||||
|
`method`*: MethodPattern
|
||||||
|
`path`*: PathPattern
|
||||||
|
|
||||||
|
HttpBinding* {.preservesRecord: "http-bind".} = object
|
||||||
|
`host`*: HostPattern
|
||||||
|
`port`*: BiggestInt
|
||||||
|
`method`*: MethodPattern
|
||||||
|
`path`*: PathPattern
|
||||||
|
`handler`* {.preservesEmbedded.}: Value
|
||||||
|
|
||||||
|
HttpContext* {.preservesRecord: "request".} = object
|
||||||
|
`req`*: HttpRequest
|
||||||
|
`res`* {.preservesEmbedded.}: Value
|
||||||
|
|
||||||
|
RequestHostKind* {.pure.} = enum
|
||||||
|
`absent`, `present`
|
||||||
|
`RequestHost`* {.preservesOr.} = object
|
||||||
|
case orKind*: RequestHostKind
|
||||||
|
of RequestHostKind.`absent`:
|
||||||
|
`absent`* {.preservesLiteral: "#f".}: bool
|
||||||
|
|
||||||
|
of RequestHostKind.`present`:
|
||||||
|
`present`*: string
|
||||||
|
|
||||||
|
|
||||||
|
PathPatternElementKind* {.pure.} = enum
|
||||||
|
`label`, `wildcard`, `rest`
|
||||||
|
`PathPatternElement`* {.preservesOr.} = object
|
||||||
|
case orKind*: PathPatternElementKind
|
||||||
|
of PathPatternElementKind.`label`:
|
||||||
|
`label`*: string
|
||||||
|
|
||||||
|
of PathPatternElementKind.`wildcard`:
|
||||||
|
`wildcard`* {.preservesLiteral: "_".}: bool
|
||||||
|
|
||||||
|
of PathPatternElementKind.`rest`:
|
||||||
|
`rest`* {.preservesLiteral: "|...|".}: bool
|
||||||
|
|
||||||
|
|
||||||
|
ChunkKind* {.pure.} = enum
|
||||||
|
`string`, `bytes`
|
||||||
|
`Chunk`* {.preservesOr.} = object
|
||||||
|
case orKind*: ChunkKind
|
||||||
|
of ChunkKind.`string`:
|
||||||
|
`string`*: string
|
||||||
|
|
||||||
|
of ChunkKind.`bytes`:
|
||||||
|
`bytes`*: seq[byte]
|
||||||
|
|
||||||
|
|
||||||
|
PathPattern* = seq[PathPatternElement]
|
||||||
|
proc `$`*(x: HostPattern | HttpListener | MethodPattern | MimeType | QueryValue |
|
||||||
|
HttpRequest |
|
||||||
|
Headers |
|
||||||
|
HttpResponse |
|
||||||
|
HttpService |
|
||||||
|
HttpBinding |
|
||||||
|
HttpContext |
|
||||||
|
RequestHost |
|
||||||
|
PathPatternElement |
|
||||||
|
Chunk |
|
||||||
|
PathPattern): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
|
proc encode*(x: HostPattern | HttpListener | MethodPattern | MimeType |
|
||||||
|
QueryValue |
|
||||||
|
HttpRequest |
|
||||||
|
Headers |
|
||||||
|
HttpResponse |
|
||||||
|
HttpService |
|
||||||
|
HttpBinding |
|
||||||
|
HttpContext |
|
||||||
|
RequestHost |
|
||||||
|
PathPatternElement |
|
||||||
|
Chunk |
|
||||||
|
PathPattern): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
|
@ -0,0 +1,139 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves, std/options
|
||||||
|
|
||||||
|
type
|
||||||
|
NoiseDescriptionDetail* = NoiseServiceSpec
|
||||||
|
NoisePreSharedKeysKind* {.pure.} = enum
|
||||||
|
`present`, `invalid`, `absent`
|
||||||
|
NoisePreSharedKeysPresent* {.preservesDictionary.} = object
|
||||||
|
`preSharedKeys`*: seq[seq[byte]]
|
||||||
|
|
||||||
|
NoisePreSharedKeysInvalid* {.preservesDictionary.} = object
|
||||||
|
`preSharedKeys`*: Value
|
||||||
|
|
||||||
|
NoisePreSharedKeysAbsent* {.preservesDictionary.} = object
|
||||||
|
|
||||||
|
`NoisePreSharedKeys`* {.preservesOr.} = object
|
||||||
|
case orKind*: NoisePreSharedKeysKind
|
||||||
|
of NoisePreSharedKeysKind.`present`:
|
||||||
|
`present`*: NoisePreSharedKeysPresent
|
||||||
|
|
||||||
|
of NoisePreSharedKeysKind.`invalid`:
|
||||||
|
`invalid`*: NoisePreSharedKeysInvalid
|
||||||
|
|
||||||
|
of NoisePreSharedKeysKind.`absent`:
|
||||||
|
`absent`*: NoisePreSharedKeysAbsent
|
||||||
|
|
||||||
|
|
||||||
|
SecretKeyFieldKind* {.pure.} = enum
|
||||||
|
`present`, `invalid`, `absent`
|
||||||
|
SecretKeyFieldPresent* {.preservesDictionary.} = object
|
||||||
|
`secretKey`*: seq[byte]
|
||||||
|
|
||||||
|
SecretKeyFieldInvalid* {.preservesDictionary.} = object
|
||||||
|
`secretKey`*: Value
|
||||||
|
|
||||||
|
SecretKeyFieldAbsent* {.preservesDictionary.} = object
|
||||||
|
|
||||||
|
`SecretKeyField`* {.preservesOr.} = object
|
||||||
|
case orKind*: SecretKeyFieldKind
|
||||||
|
of SecretKeyFieldKind.`present`:
|
||||||
|
`present`*: SecretKeyFieldPresent
|
||||||
|
|
||||||
|
of SecretKeyFieldKind.`invalid`:
|
||||||
|
`invalid`*: SecretKeyFieldInvalid
|
||||||
|
|
||||||
|
of SecretKeyFieldKind.`absent`:
|
||||||
|
`absent`*: SecretKeyFieldAbsent
|
||||||
|
|
||||||
|
|
||||||
|
SessionItemKind* {.pure.} = enum
|
||||||
|
`Initiator`, `Packet`
|
||||||
|
`SessionItem`* {.preservesOr.} = object
|
||||||
|
case orKind*: SessionItemKind
|
||||||
|
of SessionItemKind.`Initiator`:
|
||||||
|
`initiator`* {.preservesEmbedded.}: Initiator
|
||||||
|
|
||||||
|
of SessionItemKind.`Packet`:
|
||||||
|
`packet`*: Packet
|
||||||
|
|
||||||
|
|
||||||
|
NoiseProtocolKind* {.pure.} = enum
|
||||||
|
`present`, `invalid`, `absent`
|
||||||
|
NoiseProtocolPresent* {.preservesDictionary.} = object
|
||||||
|
`protocol`*: string
|
||||||
|
|
||||||
|
NoiseProtocolInvalid* {.preservesDictionary.} = object
|
||||||
|
`protocol`*: Value
|
||||||
|
|
||||||
|
NoiseProtocolAbsent* {.preservesDictionary.} = object
|
||||||
|
|
||||||
|
`NoiseProtocol`* {.preservesOr.} = object
|
||||||
|
case orKind*: NoiseProtocolKind
|
||||||
|
of NoiseProtocolKind.`present`:
|
||||||
|
`present`*: NoiseProtocolPresent
|
||||||
|
|
||||||
|
of NoiseProtocolKind.`invalid`:
|
||||||
|
`invalid`*: NoiseProtocolInvalid
|
||||||
|
|
||||||
|
of NoiseProtocolKind.`absent`:
|
||||||
|
`absent`*: NoiseProtocolAbsent
|
||||||
|
|
||||||
|
|
||||||
|
NoisePathStepDetail* = NoiseSpec
|
||||||
|
NoiseServiceSpecKey* = seq[byte]
|
||||||
|
NoiseServiceSpecPreSharedKeys* = Option[Value]
|
||||||
|
NoiseServiceSpecProtocol* = Option[Value]
|
||||||
|
NoiseServiceSpecSecretKey* = Option[Value]
|
||||||
|
`NoiseServiceSpec`* {.preservesDictionary.} = object
|
||||||
|
`key`*: seq[byte]
|
||||||
|
`preSharedKeys`*: Option[Value]
|
||||||
|
`protocol`*: Option[Value]
|
||||||
|
`secretKey`*: Option[Value]
|
||||||
|
`service`*: ServiceSelector
|
||||||
|
|
||||||
|
ServiceSelector* = Value
|
||||||
|
Initiator* {.preservesRecord: "initiator".} = object
|
||||||
|
`initiatorSession`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
|
NoiseStepDetail* = ServiceSelector
|
||||||
|
NoiseSpecKey* = seq[byte]
|
||||||
|
NoiseSpecPreSharedKeys* = Option[Value]
|
||||||
|
NoiseSpecProtocol* = Option[Value]
|
||||||
|
`NoiseSpec`* {.preservesDictionary.} = object
|
||||||
|
`key`*: seq[byte]
|
||||||
|
`preSharedKeys`*: Option[Value]
|
||||||
|
`protocol`*: Option[Value]
|
||||||
|
`service`*: ServiceSelector
|
||||||
|
|
||||||
|
PacketKind* {.pure.} = enum
|
||||||
|
`complete`, `fragmented`
|
||||||
|
`Packet`* {.preservesOr.} = object
|
||||||
|
case orKind*: PacketKind
|
||||||
|
of PacketKind.`complete`:
|
||||||
|
`complete`*: seq[byte]
|
||||||
|
|
||||||
|
of PacketKind.`fragmented`:
|
||||||
|
`fragmented`*: seq[seq[byte]]
|
||||||
|
|
||||||
|
|
||||||
|
proc `$`*(x: NoiseDescriptionDetail | NoisePreSharedKeys | SecretKeyField |
|
||||||
|
SessionItem |
|
||||||
|
NoiseProtocol |
|
||||||
|
NoisePathStepDetail |
|
||||||
|
NoiseServiceSpec |
|
||||||
|
Initiator |
|
||||||
|
NoiseSpec |
|
||||||
|
Packet): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
|
proc encode*(x: NoiseDescriptionDetail | NoisePreSharedKeys | SecretKeyField |
|
||||||
|
SessionItem |
|
||||||
|
NoiseProtocol |
|
||||||
|
NoisePathStepDetail |
|
||||||
|
NoiseServiceSpec |
|
||||||
|
Initiator |
|
||||||
|
NoiseSpec |
|
||||||
|
Packet): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
|
@ -5,36 +5,39 @@ import
|
||||||
type
|
type
|
||||||
Error* {.preservesRecord: "error".} = object
|
Error* {.preservesRecord: "error".} = object
|
||||||
`message`*: string
|
`message`*: string
|
||||||
`detail`*: Preserve[void]
|
`detail`*: Value
|
||||||
|
|
||||||
Turn* = seq[TurnEvent]
|
Turn* = seq[TurnEvent]
|
||||||
Message* {.preservesRecord: "message".} = object
|
Message* {.preservesRecord: "M".} = object
|
||||||
`body`*: Assertion
|
`body`*: Assertion
|
||||||
|
|
||||||
Retract* {.preservesRecord: "retract".} = object
|
Retract* {.preservesRecord: "R".} = object
|
||||||
`handle`*: Handle
|
`handle`*: Handle
|
||||||
|
|
||||||
Assert* {.preservesRecord: "assert".} = object
|
Assert* {.preservesRecord: "A".} = object
|
||||||
`assertion`*: Assertion
|
`assertion`*: Assertion
|
||||||
`handle`*: Handle
|
`handle`*: Handle
|
||||||
|
|
||||||
Extension* = Preserve[void]
|
Extension* = Value
|
||||||
Sync* {.preservesRecord: "sync".} = object
|
Sync* {.preservesRecord: "S".} = object
|
||||||
`peer`* {.preservesLiteral: "#!<lit #t>".}: tuple[]
|
`peer`* {.preservesEmbedded.}: Value
|
||||||
|
|
||||||
TurnEvent* {.preservesTuple.} = object
|
TurnEvent* {.preservesTuple.} = object
|
||||||
`oid`*: Oid
|
`oid`*: Oid
|
||||||
`event`*: Event
|
`event`*: Event
|
||||||
|
|
||||||
Oid* = BiggestInt
|
Oid* = BiggestInt
|
||||||
Assertion* = Preserve[void]
|
Assertion* = Value
|
||||||
Handle* = BiggestInt
|
Handle* = BiggestInt
|
||||||
PacketKind* {.pure.} = enum
|
PacketKind* {.pure.} = enum
|
||||||
`Turn`, `Error`, `Extension`
|
`Nop`, `Turn`, `Error`, `Extension`
|
||||||
`Packet`* {.preservesOr.} = object
|
`Packet`* {.preservesOr.} = object
|
||||||
case orKind*: PacketKind
|
case orKind*: PacketKind
|
||||||
|
of PacketKind.`Nop`:
|
||||||
|
`nop`* {.preservesLiteral: "#f".}: bool
|
||||||
|
|
||||||
of PacketKind.`Turn`:
|
of PacketKind.`Turn`:
|
||||||
`turn`*: Turn
|
`turn`* {.preservesEmbedded.}: Turn
|
||||||
|
|
||||||
of PacketKind.`Error`:
|
of PacketKind.`Error`:
|
||||||
`error`*: Error
|
`error`*: Error
|
||||||
|
@ -57,18 +60,18 @@ type
|
||||||
`message`*: Message
|
`message`*: Message
|
||||||
|
|
||||||
of EventKind.`Sync`:
|
of EventKind.`Sync`:
|
||||||
`sync`*: Sync
|
`sync`* {.preservesEmbedded.}: Sync
|
||||||
|
|
||||||
|
|
||||||
proc `$`*(x: Error | Turn | Message | Retract | Assert | Sync | TurnEvent | Oid |
|
proc `$`*(x: Error | Turn | Message | Retract | Assert | Sync | TurnEvent | Oid |
|
||||||
Handle |
|
Handle |
|
||||||
Packet |
|
Packet |
|
||||||
Event): string =
|
Event): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*(x: Error | Turn | Message | Retract | Assert | Sync | TurnEvent |
|
proc encode*(x: Error | Turn | Message | Retract | Assert | Sync | TurnEvent |
|
||||||
Oid |
|
Oid |
|
||||||
Handle |
|
Handle |
|
||||||
Packet |
|
Packet |
|
||||||
Event): seq[byte] =
|
Event): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves
|
||||||
|
|
||||||
|
type
|
||||||
|
Question* {.preservesRecord: "q".} = object
|
||||||
|
`request`*: Value
|
||||||
|
|
||||||
|
Answer* {.preservesRecord: "a".} = object
|
||||||
|
`request`*: Value
|
||||||
|
`response`*: Value
|
||||||
|
|
||||||
|
ResultKind* {.pure.} = enum
|
||||||
|
`ok`, `error`
|
||||||
|
ResultOk* {.preservesRecord: "ok".} = object
|
||||||
|
`value`*: Value
|
||||||
|
|
||||||
|
ResultError* {.preservesRecord: "error".} = object
|
||||||
|
`error`*: Value
|
||||||
|
|
||||||
|
`Result`* {.preservesOr.} = object
|
||||||
|
case orKind*: ResultKind
|
||||||
|
of ResultKind.`ok`:
|
||||||
|
`ok`*: ResultOk
|
||||||
|
|
||||||
|
of ResultKind.`error`:
|
||||||
|
`error`*: ResultError
|
||||||
|
|
||||||
|
|
||||||
|
proc `$`*(x: Question | Answer | Result): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
|
proc encode*(x: Question | Answer | Result): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
|
@ -5,8 +5,7 @@ import
|
||||||
type
|
type
|
||||||
StateKind* {.pure.} = enum
|
StateKind* {.pure.} = enum
|
||||||
`started`, `ready`, `failed`, `complete`, `userDefined`
|
`started`, `ready`, `failed`, `complete`, `userDefined`
|
||||||
StateUserDefined*[Cap] = Preserve[Cap]
|
`State`* {.preservesOr.} = object
|
||||||
`State`*[Cap] {.preservesOr.} = object
|
|
||||||
case orKind*: StateKind
|
case orKind*: StateKind
|
||||||
of StateKind.`started`:
|
of StateKind.`started`:
|
||||||
`started`* {.preservesLiteral: "started".}: bool
|
`started`* {.preservesLiteral: "started".}: bool
|
||||||
|
@ -21,40 +20,38 @@ type
|
||||||
`complete`* {.preservesLiteral: "complete".}: bool
|
`complete`* {.preservesLiteral: "complete".}: bool
|
||||||
|
|
||||||
of StateKind.`userDefined`:
|
of StateKind.`userDefined`:
|
||||||
`userdefined`*: StateUserDefined[Cap]
|
`userdefined`*: Value
|
||||||
|
|
||||||
|
|
||||||
ServiceObject*[Cap] {.preservesRecord: "service-object".} = object
|
ServiceObject* {.preservesRecord: "service-object".} = object
|
||||||
`serviceName`*: Preserve[Cap]
|
`serviceName`*: Value
|
||||||
`object`*: Preserve[Cap]
|
`object`*: Value
|
||||||
|
|
||||||
RequireService*[Cap] {.preservesRecord: "require-service".} = object
|
RequireService* {.preservesRecord: "require-service".} = object
|
||||||
`serviceName`*: Preserve[Cap]
|
`serviceName`*: Value
|
||||||
|
|
||||||
RestartService*[Cap] {.preservesRecord: "restart-service".} = object
|
RestartService* {.preservesRecord: "restart-service".} = object
|
||||||
`serviceName`*: Preserve[Cap]
|
`serviceName`*: Value
|
||||||
|
|
||||||
RunService*[Cap] {.preservesRecord: "run-service".} = object
|
RunService* {.preservesRecord: "run-service".} = object
|
||||||
`serviceName`*: Preserve[Cap]
|
`serviceName`*: Value
|
||||||
|
|
||||||
ServiceState*[Cap] {.preservesRecord: "service-state".} = object
|
ServiceState* {.preservesRecord: "service-state".} = object
|
||||||
`serviceName`*: Preserve[Cap]
|
`serviceName`*: Value
|
||||||
`state`*: State[Cap]
|
`state`*: State
|
||||||
|
|
||||||
ServiceDependency*[Cap] {.preservesRecord: "depends-on".} = object
|
ServiceDependency* {.preservesRecord: "depends-on".} = object
|
||||||
`depender`*: Preserve[Cap]
|
`depender`*: Value
|
||||||
`dependee`*: ServiceState[Cap]
|
`dependee`*: ServiceState
|
||||||
|
|
||||||
proc `$`*[Cap](x: State[Cap] | ServiceObject[Cap] | RequireService[Cap] |
|
proc `$`*(x: State | ServiceObject | RequireService | RestartService |
|
||||||
RestartService[Cap] |
|
RunService |
|
||||||
RunService[Cap] |
|
ServiceState |
|
||||||
ServiceState[Cap] |
|
ServiceDependency): string =
|
||||||
ServiceDependency[Cap]): string =
|
`$`(toPreserves(x))
|
||||||
`$`(toPreserve(x, Cap))
|
|
||||||
|
|
||||||
proc encode*[Cap](x: State[Cap] | ServiceObject[Cap] | RequireService[Cap] |
|
proc encode*(x: State | ServiceObject | RequireService | RestartService |
|
||||||
RestartService[Cap] |
|
RunService |
|
||||||
RunService[Cap] |
|
ServiceState |
|
||||||
ServiceState[Cap] |
|
ServiceDependency): seq[byte] =
|
||||||
ServiceDependency[Cap]): seq[byte] =
|
encode(toPreserves(x))
|
||||||
encode(toPreserve(x, Cap))
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves, sturdy, gatekeeper
|
||||||
|
|
||||||
|
type
|
||||||
|
StandardTransportKind* {.pure.} = enum
|
||||||
|
`wsUrl`, `other`
|
||||||
|
`StandardTransport`* {.preservesOr.} = object
|
||||||
|
case orKind*: StandardTransportKind
|
||||||
|
of StandardTransportKind.`wsUrl`:
|
||||||
|
`wsurl`*: string
|
||||||
|
|
||||||
|
of StandardTransportKind.`other`:
|
||||||
|
`other`*: Value
|
||||||
|
|
||||||
|
|
||||||
|
StandardRouteKind* {.pure.} = enum
|
||||||
|
`standard`, `general`
|
||||||
|
StandardRouteStandard* {.preservesTuple.} = object
|
||||||
|
`transports`*: seq[StandardTransport]
|
||||||
|
`key`*: seq[byte]
|
||||||
|
`service`*: Value
|
||||||
|
`sig`*: seq[byte]
|
||||||
|
`oid`*: Value
|
||||||
|
`caveats`* {.preservesTupleTail.}: seq[sturdy.Caveat]
|
||||||
|
|
||||||
|
`StandardRoute`* {.preservesOr.} = object
|
||||||
|
case orKind*: StandardRouteKind
|
||||||
|
of StandardRouteKind.`standard`:
|
||||||
|
`standard`*: StandardRouteStandard
|
||||||
|
|
||||||
|
of StandardRouteKind.`general`:
|
||||||
|
`general`*: gatekeeper.Route
|
||||||
|
|
||||||
|
|
||||||
|
proc `$`*(x: StandardTransport | StandardRoute): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
|
proc encode*(x: StandardTransport | StandardRoute): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
|
@ -5,11 +5,10 @@ import
|
||||||
type
|
type
|
||||||
CreditAmountKind* {.pure.} = enum
|
CreditAmountKind* {.pure.} = enum
|
||||||
`count`, `unbounded`
|
`count`, `unbounded`
|
||||||
CreditAmountCount* = BiggestInt
|
|
||||||
`CreditAmount`* {.preservesOr.} = object
|
`CreditAmount`* {.preservesOr.} = object
|
||||||
case orKind*: CreditAmountKind
|
case orKind*: CreditAmountKind
|
||||||
of CreditAmountKind.`count`:
|
of CreditAmountKind.`count`:
|
||||||
`count`*: CreditAmountCount
|
`count`*: BiggestInt
|
||||||
|
|
||||||
of CreditAmountKind.`unbounded`:
|
of CreditAmountKind.`unbounded`:
|
||||||
`unbounded`* {.preservesLiteral: "unbounded".}: bool
|
`unbounded`* {.preservesLiteral: "unbounded".}: bool
|
||||||
|
@ -18,76 +17,76 @@ type
|
||||||
StreamError* {.preservesRecord: "error".} = object
|
StreamError* {.preservesRecord: "error".} = object
|
||||||
`message`*: string
|
`message`*: string
|
||||||
|
|
||||||
StreamListenerError*[Cap] {.preservesRecord: "stream-listener-error".} = object
|
StreamListenerError* {.preservesRecord: "stream-listener-error".} = object
|
||||||
`spec`*: Preserve[Cap]
|
`spec`*: Value
|
||||||
`message`*: string
|
`message`*: string
|
||||||
|
|
||||||
StreamConnection*[Cap] {.preservesRecord: "stream-connection".} = object
|
StreamConnection* {.preservesRecord: "stream-connection".} = object
|
||||||
`source`*: Cap
|
`source`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`sink`*: Cap
|
`sink`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`spec`*: Preserve[Cap]
|
`spec`*: Value
|
||||||
|
|
||||||
`LineMode`* {.preservesOr, pure.} = enum
|
`LineMode`* {.preservesOr, pure.} = enum
|
||||||
`lf`, `crlf`
|
`lf`, `crlf`
|
||||||
SourceKind* {.pure.} = enum
|
SourceKind* {.pure.} = enum
|
||||||
`sink`, `StreamError`, `credit`
|
`sink`, `StreamError`, `credit`
|
||||||
SourceSink*[Cap] {.preservesRecord: "sink".} = object
|
SourceSink* {.preservesRecord: "sink".} = object
|
||||||
`controller`*: Cap
|
`controller`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
SourceCredit*[Cap] {.preservesRecord: "credit".} = object
|
SourceCredit* {.preservesRecord: "credit".} = object
|
||||||
`amount`*: CreditAmount
|
`amount`*: CreditAmount
|
||||||
`mode`*: Mode[Cap]
|
`mode`*: Mode
|
||||||
|
|
||||||
`Source`*[Cap] {.preservesOr.} = object
|
`Source`* {.acyclic, preservesOr.} = ref object
|
||||||
case orKind*: SourceKind
|
case orKind*: SourceKind
|
||||||
of SourceKind.`sink`:
|
of SourceKind.`sink`:
|
||||||
`sink`*: SourceSink[Cap]
|
`sink`* {.preservesEmbedded.}: SourceSink
|
||||||
|
|
||||||
of SourceKind.`StreamError`:
|
of SourceKind.`StreamError`:
|
||||||
`streamerror`*: StreamError
|
`streamerror`*: StreamError
|
||||||
|
|
||||||
of SourceKind.`credit`:
|
of SourceKind.`credit`:
|
||||||
`credit`*: SourceCredit[Cap]
|
`credit`*: SourceCredit
|
||||||
|
|
||||||
|
|
||||||
SinkKind* {.pure.} = enum
|
SinkKind* {.pure.} = enum
|
||||||
`source`, `StreamError`, `data`, `eof`
|
`source`, `StreamError`, `data`, `eof`
|
||||||
SinkSource*[Cap] {.preservesRecord: "source".} = object
|
SinkSource* {.preservesRecord: "source".} = object
|
||||||
`controller`*: Cap
|
`controller`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
|
|
||||||
SinkData*[Cap] {.preservesRecord: "data".} = object
|
SinkData* {.preservesRecord: "data".} = object
|
||||||
`payload`*: Preserve[Cap]
|
`payload`*: Value
|
||||||
`mode`*: Mode[Cap]
|
`mode`*: Mode
|
||||||
|
|
||||||
SinkEof* {.preservesRecord: "eof".} = object
|
SinkEof* {.preservesRecord: "eof".} = object
|
||||||
|
|
||||||
`Sink`*[Cap] {.preservesOr.} = object
|
`Sink`* {.acyclic, preservesOr.} = ref object
|
||||||
case orKind*: SinkKind
|
case orKind*: SinkKind
|
||||||
of SinkKind.`source`:
|
of SinkKind.`source`:
|
||||||
`source`*: SinkSource[Cap]
|
`source`* {.preservesEmbedded.}: SinkSource
|
||||||
|
|
||||||
of SinkKind.`StreamError`:
|
of SinkKind.`StreamError`:
|
||||||
`streamerror`*: StreamError
|
`streamerror`*: StreamError
|
||||||
|
|
||||||
of SinkKind.`data`:
|
of SinkKind.`data`:
|
||||||
`data`*: SinkData[Cap]
|
`data`*: SinkData
|
||||||
|
|
||||||
of SinkKind.`eof`:
|
of SinkKind.`eof`:
|
||||||
`eof`*: SinkEof
|
`eof`*: SinkEof
|
||||||
|
|
||||||
|
|
||||||
StreamListenerReady*[Cap] {.preservesRecord: "stream-listener-ready".} = object
|
StreamListenerReady* {.preservesRecord: "stream-listener-ready".} = object
|
||||||
`spec`*: Preserve[Cap]
|
`spec`*: Value
|
||||||
|
|
||||||
ModeKind* {.pure.} = enum
|
ModeKind* {.pure.} = enum
|
||||||
`bytes`, `lines`, `packet`, `object`
|
`bytes`, `lines`, `packet`, `object`
|
||||||
ModePacket* {.preservesRecord: "packet".} = object
|
ModePacket* {.preservesRecord: "packet".} = object
|
||||||
`size`*: BiggestInt
|
`size`*: BiggestInt
|
||||||
|
|
||||||
ModeObject*[Cap] {.preservesRecord: "object".} = object
|
ModeObject* {.preservesRecord: "object".} = object
|
||||||
`description`*: Preserve[Cap]
|
`description`*: Value
|
||||||
|
|
||||||
`Mode`*[Cap] {.preservesOr.} = object
|
`Mode`* {.preservesOr.} = object
|
||||||
case orKind*: ModeKind
|
case orKind*: ModeKind
|
||||||
of ModeKind.`bytes`:
|
of ModeKind.`bytes`:
|
||||||
`bytes`* {.preservesLiteral: "bytes".}: bool
|
`bytes`* {.preservesLiteral: "bytes".}: bool
|
||||||
|
@ -99,24 +98,20 @@ type
|
||||||
`packet`*: ModePacket
|
`packet`*: ModePacket
|
||||||
|
|
||||||
of ModeKind.`object`:
|
of ModeKind.`object`:
|
||||||
`object`*: ModeObject[Cap]
|
`object`*: ModeObject
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[Cap](x: StreamListenerError[Cap] | StreamConnection[Cap] | Source[Cap] |
|
proc `$`*(x: CreditAmount | StreamError | StreamListenerError | StreamConnection |
|
||||||
Sink[Cap] |
|
Source |
|
||||||
StreamListenerReady[Cap] |
|
Sink |
|
||||||
Mode[Cap]): string =
|
StreamListenerReady |
|
||||||
`$`(toPreserve(x, Cap))
|
Mode): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: StreamListenerError[Cap] | StreamConnection[Cap] |
|
proc encode*(x: CreditAmount | StreamError | StreamListenerError |
|
||||||
Source[Cap] |
|
StreamConnection |
|
||||||
Sink[Cap] |
|
Source |
|
||||||
StreamListenerReady[Cap] |
|
Sink |
|
||||||
Mode[Cap]): seq[byte] =
|
StreamListenerReady |
|
||||||
encode(toPreserve(x, Cap))
|
Mode): seq[byte] =
|
||||||
|
encode(toPreserves(x))
|
||||||
proc `$`*(x: CreditAmount | StreamError): string =
|
|
||||||
`$`(toPreserve(x))
|
|
||||||
|
|
||||||
proc encode*(x: CreditAmount | StreamError): seq[byte] =
|
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -1,149 +1,154 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
preserves, std/tables
|
preserves, std/tables, std/options
|
||||||
|
|
||||||
type
|
type
|
||||||
PCompoundKind* {.pure.} = enum
|
PCompoundKind* {.pure.} = enum
|
||||||
`rec`, `arr`, `dict`
|
`rec`, `arr`, `dict`
|
||||||
PCompoundRec*[Cap] {.preservesRecord: "rec".} = ref object
|
PCompoundRec* {.preservesRecord: "rec".} = object
|
||||||
`label`*: Preserve[Cap]
|
`label`*: Value
|
||||||
`fields`*: seq[Pattern[Cap]]
|
`fields`*: seq[Pattern]
|
||||||
|
|
||||||
PCompoundArr*[Cap] {.preservesRecord: "arr".} = ref object
|
PCompoundArr* {.preservesRecord: "arr".} = object
|
||||||
`items`*: seq[Pattern[Cap]]
|
`items`*: seq[Pattern]
|
||||||
|
|
||||||
PCompoundDict*[Cap] {.preservesRecord: "dict".} = ref object
|
PCompoundDict* {.preservesRecord: "dict".} = object
|
||||||
`entries`*: Table[Preserve[Cap], Pattern[Cap]]
|
`entries`*: Table[Value, Pattern]
|
||||||
|
|
||||||
`PCompound`*[Cap] {.preservesOr.} = ref object
|
`PCompound`* {.preservesOr.} = object
|
||||||
case orKind*: PCompoundKind
|
case orKind*: PCompoundKind
|
||||||
of PCompoundKind.`rec`:
|
of PCompoundKind.`rec`:
|
||||||
`rec`*: PCompoundRec[Cap]
|
`rec`*: PCompoundRec
|
||||||
|
|
||||||
of PCompoundKind.`arr`:
|
of PCompoundKind.`arr`:
|
||||||
`arr`*: PCompoundArr[Cap]
|
`arr`*: PCompoundArr
|
||||||
|
|
||||||
of PCompoundKind.`dict`:
|
of PCompoundKind.`dict`:
|
||||||
`dict`*: PCompoundDict[Cap]
|
`dict`*: PCompoundDict
|
||||||
|
|
||||||
|
|
||||||
Reject*[Cap] {.preservesRecord: "reject".} = ref object
|
Reject* {.preservesRecord: "reject".} = object
|
||||||
`pattern`*: Pattern[Cap]
|
`pattern`*: Pattern
|
||||||
|
|
||||||
CaveatsFieldKind* {.pure.} = enum
|
CaveatsFieldKind* {.pure.} = enum
|
||||||
`present`, `invalid`, `absent`
|
`present`, `invalid`, `absent`
|
||||||
CaveatsFieldPresent*[Cap] {.preservesDictionary.} = ref object
|
CaveatsFieldPresent* {.preservesDictionary.} = object
|
||||||
`caveats`*: seq[Caveat[Cap]]
|
`caveats`*: seq[Caveat]
|
||||||
|
|
||||||
CaveatsFieldInvalid*[Cap] {.preservesDictionary.} = object
|
CaveatsFieldInvalid* {.preservesDictionary.} = object
|
||||||
`caveats`*: Preserve[Cap]
|
`caveats`*: Value
|
||||||
|
|
||||||
CaveatsFieldAbsent* {.preservesDictionary.} = object
|
CaveatsFieldAbsent* {.preservesDictionary.} = object
|
||||||
|
|
||||||
`CaveatsField`*[Cap] {.preservesOr.} = ref object
|
`CaveatsField`* {.preservesOr.} = object
|
||||||
case orKind*: CaveatsFieldKind
|
case orKind*: CaveatsFieldKind
|
||||||
of CaveatsFieldKind.`present`:
|
of CaveatsFieldKind.`present`:
|
||||||
`present`*: CaveatsFieldPresent[Cap]
|
`present`*: CaveatsFieldPresent
|
||||||
|
|
||||||
of CaveatsFieldKind.`invalid`:
|
of CaveatsFieldKind.`invalid`:
|
||||||
`invalid`*: CaveatsFieldInvalid[Cap]
|
`invalid`*: CaveatsFieldInvalid
|
||||||
|
|
||||||
of CaveatsFieldKind.`absent`:
|
of CaveatsFieldKind.`absent`:
|
||||||
`absent`*: CaveatsFieldAbsent
|
`absent`*: CaveatsFieldAbsent
|
||||||
|
|
||||||
|
|
||||||
SturdyDescriptionDetail*[Cap] {.preservesDictionary.} = object
|
SturdyDescriptionDetail* {.preservesDictionary.} = object
|
||||||
`key`*: seq[byte]
|
`key`*: seq[byte]
|
||||||
`oid`*: Preserve[Cap]
|
`oid`*: Value
|
||||||
|
|
||||||
PAnd*[Cap] {.preservesRecord: "and".} = ref object
|
PAnd* {.preservesRecord: "and".} = object
|
||||||
`patterns`*: seq[Pattern[Cap]]
|
`patterns`*: seq[Pattern]
|
||||||
|
|
||||||
SturdyStepDetail*[Cap] = Parameters[Cap]
|
SturdyStepDetail* = Parameters
|
||||||
Rewrite*[Cap] {.preservesRecord: "rewrite".} = ref object
|
Rewrite* {.preservesRecord: "rewrite".} = object
|
||||||
`pattern`*: Pattern[Cap]
|
`pattern`*: Pattern
|
||||||
`template`*: Template[Cap]
|
`template`*: Template
|
||||||
|
|
||||||
|
ParametersCaveats* = Option[Value]
|
||||||
|
ParametersOid* = Value
|
||||||
|
ParametersSig* = seq[byte]
|
||||||
|
`Parameters`* {.preservesDictionary.} = object
|
||||||
|
`caveats`*: Option[Value]
|
||||||
|
`oid`*: Value
|
||||||
|
`sig`*: seq[byte]
|
||||||
|
|
||||||
Parameters*[Cap] = Preserve[Cap]
|
|
||||||
TRef* {.preservesRecord: "ref".} = object
|
TRef* {.preservesRecord: "ref".} = object
|
||||||
`binding`*: BiggestInt
|
`binding`*: BiggestInt
|
||||||
|
|
||||||
PBind*[Cap] {.preservesRecord: "bind".} = ref object
|
PBind* {.preservesRecord: "bind".} = object
|
||||||
`pattern`*: Pattern[Cap]
|
`pattern`*: Pattern
|
||||||
|
|
||||||
Lit*[Cap] {.preservesRecord: "lit".} = object
|
Lit* {.preservesRecord: "lit".} = object
|
||||||
`value`*: Preserve[Cap]
|
`value`*: Value
|
||||||
|
|
||||||
TCompoundKind* {.pure.} = enum
|
TCompoundKind* {.pure.} = enum
|
||||||
`rec`, `arr`, `dict`
|
`rec`, `arr`, `dict`
|
||||||
TCompoundRec*[Cap] {.preservesRecord: "rec".} = ref object
|
TCompoundRec* {.preservesRecord: "rec".} = object
|
||||||
`label`*: Preserve[Cap]
|
`label`*: Value
|
||||||
`fields`*: seq[Template[Cap]]
|
`fields`*: seq[Template]
|
||||||
|
|
||||||
TCompoundArr*[Cap] {.preservesRecord: "arr".} = ref object
|
TCompoundArr* {.preservesRecord: "arr".} = object
|
||||||
`items`*: seq[Template[Cap]]
|
`items`*: seq[Template]
|
||||||
|
|
||||||
TCompoundDict*[Cap] {.preservesRecord: "dict".} = ref object
|
TCompoundDict* {.preservesRecord: "dict".} = object
|
||||||
`entries`*: Table[Preserve[Cap], Template[Cap]]
|
`entries`*: Table[Value, Template]
|
||||||
|
|
||||||
`TCompound`*[Cap] {.preservesOr.} = ref object
|
`TCompound`* {.preservesOr.} = object
|
||||||
case orKind*: TCompoundKind
|
case orKind*: TCompoundKind
|
||||||
of TCompoundKind.`rec`:
|
of TCompoundKind.`rec`:
|
||||||
`rec`*: TCompoundRec[Cap]
|
`rec`*: TCompoundRec
|
||||||
|
|
||||||
of TCompoundKind.`arr`:
|
of TCompoundKind.`arr`:
|
||||||
`arr`*: TCompoundArr[Cap]
|
`arr`*: TCompoundArr
|
||||||
|
|
||||||
of TCompoundKind.`dict`:
|
of TCompoundKind.`dict`:
|
||||||
`dict`*: TCompoundDict[Cap]
|
`dict`*: TCompoundDict
|
||||||
|
|
||||||
|
|
||||||
SturdyPathStepDetail*[Cap] = Parameters[Cap]
|
SturdyPathStepDetail* = Parameters
|
||||||
`PAtom`* {.preservesOr, pure.} = enum
|
`PAtom`* {.preservesOr, pure.} = enum
|
||||||
`Boolean`, `Float`, `Double`, `SignedInteger`, `String`, `ByteString`,
|
`Boolean`, `Double`, `SignedInteger`, `String`, `ByteString`, `Symbol`
|
||||||
`Symbol`
|
|
||||||
PDiscard* {.preservesRecord: "_".} = object
|
PDiscard* {.preservesRecord: "_".} = object
|
||||||
|
|
||||||
TemplateKind* {.pure.} = enum
|
TemplateKind* {.pure.} = enum
|
||||||
`TAttenuate`, `TRef`, `Lit`, `TCompound`
|
`TAttenuate`, `TRef`, `Lit`, `TCompound`
|
||||||
`Template`*[Cap] {.preservesOr.} = ref object
|
`Template`* {.acyclic, preservesOr.} = ref object
|
||||||
case orKind*: TemplateKind
|
case orKind*: TemplateKind
|
||||||
of TemplateKind.`TAttenuate`:
|
of TemplateKind.`TAttenuate`:
|
||||||
`tattenuate`*: TAttenuate[Cap]
|
`tattenuate`*: TAttenuate
|
||||||
|
|
||||||
of TemplateKind.`TRef`:
|
of TemplateKind.`TRef`:
|
||||||
`tref`*: TRef
|
`tref`*: TRef
|
||||||
|
|
||||||
of TemplateKind.`Lit`:
|
of TemplateKind.`Lit`:
|
||||||
`lit`*: Lit[Cap]
|
`lit`*: Lit
|
||||||
|
|
||||||
of TemplateKind.`TCompound`:
|
of TemplateKind.`TCompound`:
|
||||||
`tcompound`*: TCompound[Cap]
|
`tcompound`*: TCompound
|
||||||
|
|
||||||
|
|
||||||
CaveatKind* {.pure.} = enum
|
CaveatKind* {.pure.} = enum
|
||||||
`Rewrite`, `Alts`, `Reject`, `unknown`
|
`Rewrite`, `Alts`, `Reject`, `unknown`
|
||||||
CaveatUnknown*[Cap] = Preserve[Cap]
|
`Caveat`* {.preservesOr.} = object
|
||||||
`Caveat`*[Cap] {.preservesOr.} = ref object
|
|
||||||
case orKind*: CaveatKind
|
case orKind*: CaveatKind
|
||||||
of CaveatKind.`Rewrite`:
|
of CaveatKind.`Rewrite`:
|
||||||
`rewrite`*: Rewrite[Cap]
|
`rewrite`*: Rewrite
|
||||||
|
|
||||||
of CaveatKind.`Alts`:
|
of CaveatKind.`Alts`:
|
||||||
`alts`*: Alts[Cap]
|
`alts`*: Alts
|
||||||
|
|
||||||
of CaveatKind.`Reject`:
|
of CaveatKind.`Reject`:
|
||||||
`reject`*: Reject[Cap]
|
`reject`*: Reject
|
||||||
|
|
||||||
of CaveatKind.`unknown`:
|
of CaveatKind.`unknown`:
|
||||||
`unknown`*: CaveatUnknown[Cap]
|
`unknown`*: Value
|
||||||
|
|
||||||
|
|
||||||
PNot*[Cap] {.preservesRecord: "not".} = ref object
|
PNot* {.preservesRecord: "not".} = object
|
||||||
`pattern`*: Pattern[Cap]
|
`pattern`*: Pattern
|
||||||
|
|
||||||
SturdyRef*[Cap] {.preservesRecord: "ref".} = ref object
|
SturdyRef* {.preservesRecord: "ref".} = object
|
||||||
`parameters`*: Parameters[Cap]
|
`parameters`*: Parameters
|
||||||
|
|
||||||
WireRefKind* {.pure.} = enum
|
WireRefKind* {.pure.} = enum
|
||||||
`mine`, `yours`
|
`mine`, `yours`
|
||||||
|
@ -151,32 +156,32 @@ type
|
||||||
`field0`* {.preservesLiteral: "0".}: tuple[]
|
`field0`* {.preservesLiteral: "0".}: tuple[]
|
||||||
`oid`*: Oid
|
`oid`*: Oid
|
||||||
|
|
||||||
WireRefYours*[Cap] {.preservesTuple.} = ref object
|
WireRefYours* {.preservesTuple.} = object
|
||||||
`field0`* {.preservesLiteral: "1".}: tuple[]
|
`field0`* {.preservesLiteral: "1".}: tuple[]
|
||||||
`oid`*: Oid
|
`oid`*: Oid
|
||||||
`attenuation`* {.preservesTupleTail.}: seq[Caveat[Cap]]
|
`attenuation`* {.preservesTupleTail.}: seq[Caveat]
|
||||||
|
|
||||||
`WireRef`*[Cap] {.preservesOr.} = ref object
|
`WireRef`* {.preservesOr.} = object
|
||||||
case orKind*: WireRefKind
|
case orKind*: WireRefKind
|
||||||
of WireRefKind.`mine`:
|
of WireRefKind.`mine`:
|
||||||
`mine`*: WireRefMine
|
`mine`*: WireRefMine
|
||||||
|
|
||||||
of WireRefKind.`yours`:
|
of WireRefKind.`yours`:
|
||||||
`yours`*: WireRefYours[Cap]
|
`yours`*: WireRefYours
|
||||||
|
|
||||||
|
|
||||||
TAttenuate*[Cap] {.preservesRecord: "attenuate".} = ref object
|
TAttenuate* {.preservesRecord: "attenuate".} = object
|
||||||
`template`*: Template[Cap]
|
`template`*: Template
|
||||||
`attenuation`*: seq[Caveat[Cap]]
|
`attenuation`*: seq[Caveat]
|
||||||
|
|
||||||
Oid* = BiggestInt
|
Oid* = BiggestInt
|
||||||
Alts*[Cap] {.preservesRecord: "or".} = ref object
|
Alts* {.preservesRecord: "or".} = object
|
||||||
`alternatives`*: seq[Rewrite[Cap]]
|
`alternatives`*: seq[Rewrite]
|
||||||
|
|
||||||
PatternKind* {.pure.} = enum
|
PatternKind* {.pure.} = enum
|
||||||
`PDiscard`, `PAtom`, `PEmbedded`, `PBind`, `PAnd`, `PNot`, `Lit`,
|
`PDiscard`, `PAtom`, `PEmbedded`, `PBind`, `PAnd`, `PNot`, `Lit`,
|
||||||
`PCompound`
|
`PCompound`
|
||||||
`Pattern`*[Cap] {.preservesOr.} = ref object
|
`Pattern`* {.acyclic, preservesOr.} = ref object
|
||||||
case orKind*: PatternKind
|
case orKind*: PatternKind
|
||||||
of PatternKind.`PDiscard`:
|
of PatternKind.`PDiscard`:
|
||||||
`pdiscard`*: PDiscard
|
`pdiscard`*: PDiscard
|
||||||
|
@ -188,57 +193,60 @@ type
|
||||||
`pembedded`* {.preservesLiteral: "Embedded".}: bool
|
`pembedded`* {.preservesLiteral: "Embedded".}: bool
|
||||||
|
|
||||||
of PatternKind.`PBind`:
|
of PatternKind.`PBind`:
|
||||||
`pbind`*: PBind[Cap]
|
`pbind`*: PBind
|
||||||
|
|
||||||
of PatternKind.`PAnd`:
|
of PatternKind.`PAnd`:
|
||||||
`pand`*: PAnd[Cap]
|
`pand`*: PAnd
|
||||||
|
|
||||||
of PatternKind.`PNot`:
|
of PatternKind.`PNot`:
|
||||||
`pnot`*: PNot[Cap]
|
`pnot`*: PNot
|
||||||
|
|
||||||
of PatternKind.`Lit`:
|
of PatternKind.`Lit`:
|
||||||
`lit`*: Lit[Cap]
|
`lit`*: Lit
|
||||||
|
|
||||||
of PatternKind.`PCompound`:
|
of PatternKind.`PCompound`:
|
||||||
`pcompound`*: PCompound[Cap]
|
`pcompound`*: PCompound
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[Cap](x: PCompound[Cap] | Reject[Cap] | CaveatsField[Cap] |
|
proc `$`*(x: PCompound | Reject | CaveatsField | SturdyDescriptionDetail | PAnd |
|
||||||
SturdyDescriptionDetail[Cap] |
|
SturdyStepDetail |
|
||||||
PAnd[Cap] |
|
Rewrite |
|
||||||
Rewrite[Cap] |
|
Parameters |
|
||||||
PBind[Cap] |
|
TRef |
|
||||||
Lit[Cap] |
|
PBind |
|
||||||
TCompound[Cap] |
|
Lit |
|
||||||
Template[Cap] |
|
TCompound |
|
||||||
Caveat[Cap] |
|
SturdyPathStepDetail |
|
||||||
PNot[Cap] |
|
PDiscard |
|
||||||
SturdyRef[Cap] |
|
Template |
|
||||||
WireRef[Cap] |
|
Caveat |
|
||||||
TAttenuate[Cap] |
|
PNot |
|
||||||
Alts[Cap] |
|
SturdyRef |
|
||||||
Pattern[Cap]): string =
|
WireRef |
|
||||||
`$`(toPreserve(x, Cap))
|
TAttenuate |
|
||||||
|
Oid |
|
||||||
|
Alts |
|
||||||
|
Pattern): string =
|
||||||
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: PCompound[Cap] | Reject[Cap] | CaveatsField[Cap] |
|
proc encode*(x: PCompound | Reject | CaveatsField | SturdyDescriptionDetail |
|
||||||
SturdyDescriptionDetail[Cap] |
|
PAnd |
|
||||||
PAnd[Cap] |
|
SturdyStepDetail |
|
||||||
Rewrite[Cap] |
|
Rewrite |
|
||||||
PBind[Cap] |
|
Parameters |
|
||||||
Lit[Cap] |
|
TRef |
|
||||||
TCompound[Cap] |
|
PBind |
|
||||||
Template[Cap] |
|
Lit |
|
||||||
Caveat[Cap] |
|
TCompound |
|
||||||
PNot[Cap] |
|
SturdyPathStepDetail |
|
||||||
SturdyRef[Cap] |
|
PDiscard |
|
||||||
WireRef[Cap] |
|
Template |
|
||||||
TAttenuate[Cap] |
|
Caveat |
|
||||||
Alts[Cap] |
|
PNot |
|
||||||
Pattern[Cap]): seq[byte] =
|
SturdyRef |
|
||||||
encode(toPreserve(x, Cap))
|
WireRef |
|
||||||
|
TAttenuate |
|
||||||
proc `$`*(x: TRef | PDiscard | Oid): string =
|
Oid |
|
||||||
`$`(toPreserve(x))
|
Alts |
|
||||||
|
Pattern): seq[byte] =
|
||||||
proc encode*(x: TRef | PDiscard | Oid): seq[byte] =
|
encode(toPreserves(x))
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ type
|
||||||
`host`*: string
|
`host`*: string
|
||||||
`port`*: BiggestInt
|
`port`*: BiggestInt
|
||||||
|
|
||||||
TcpPeerInfo*[Cap] {.preservesRecord: "tcp-peer".} = object
|
TcpPeerInfo* {.preservesRecord: "tcp-peer".} = object
|
||||||
`handle`*: Cap
|
`handle`* {.preservesEmbedded.}: EmbeddedRef
|
||||||
`local`*: TcpLocal
|
`local`*: TcpLocal
|
||||||
`remote`*: TcpRemote
|
`remote`*: TcpRemote
|
||||||
|
|
||||||
|
@ -16,14 +16,8 @@ type
|
||||||
`host`*: string
|
`host`*: string
|
||||||
`port`*: BiggestInt
|
`port`*: BiggestInt
|
||||||
|
|
||||||
proc `$`*[Cap](x: TcpPeerInfo[Cap]): string =
|
proc `$`*(x: TcpLocal | TcpPeerInfo | TcpRemote): string =
|
||||||
`$`(toPreserve(x, Cap))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: TcpPeerInfo[Cap]): seq[byte] =
|
proc encode*(x: TcpLocal | TcpPeerInfo | TcpRemote): seq[byte] =
|
||||||
encode(toPreserve(x, Cap))
|
encode(toPreserves(x))
|
||||||
|
|
||||||
proc `$`*(x: TcpLocal | TcpRemote): string =
|
|
||||||
`$`(toPreserve(x))
|
|
||||||
|
|
||||||
proc encode*(x: TcpLocal | TcpRemote): seq[byte] =
|
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -4,21 +4,22 @@ import
|
||||||
|
|
||||||
type
|
type
|
||||||
TimerExpired* {.preservesRecord: "timer-expired".} = object
|
TimerExpired* {.preservesRecord: "timer-expired".} = object
|
||||||
`label`*: Preserve[void]
|
`label`*: Value
|
||||||
`seconds`*: float64
|
`seconds`*: float
|
||||||
|
|
||||||
SetTimer* {.preservesRecord: "set-timer".} = object
|
SetTimer* {.preservesRecord: "set-timer".} = object
|
||||||
`label`*: Preserve[void]
|
`label`*: Value
|
||||||
`seconds`*: float64
|
`seconds`*: float
|
||||||
`kind`*: TimerKind
|
`kind`*: TimerKind
|
||||||
|
`peer`* {.preservesEmbedded.}: Value
|
||||||
|
|
||||||
`TimerKind`* {.preservesOr, pure.} = enum
|
`TimerKind`* {.preservesOr, pure.} = enum
|
||||||
`relative`, `absolute`, `clear`
|
`relative`, `absolute`, `clear`
|
||||||
LaterThan* {.preservesRecord: "later-than".} = object
|
LaterThan* {.preservesRecord: "later-than".} = object
|
||||||
`seconds`*: float64
|
`seconds`*: float
|
||||||
|
|
||||||
proc `$`*(x: TimerExpired | SetTimer | LaterThan): string =
|
proc `$`*(x: TimerExpired | SetTimer | LaterThan): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*(x: TimerExpired | SetTimer | LaterThan): seq[byte] =
|
proc encode*(x: TimerExpired | SetTimer | LaterThan): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -3,160 +3,160 @@ import
|
||||||
preserves, protocol
|
preserves, protocol
|
||||||
|
|
||||||
type
|
type
|
||||||
TargetedTurnEvent*[Cap] {.preservesRecord: "event".} = object
|
TargetedTurnEvent* {.preservesRecord: "event".} = object
|
||||||
`target`*: Target[Cap]
|
`target`*: Target
|
||||||
`detail`*: TurnEvent[Cap]
|
`detail`*: TurnEvent
|
||||||
|
|
||||||
`LinkedTaskReleaseReason`* {.preservesOr, pure.} = enum
|
`LinkedTaskReleaseReason`* {.preservesOr, pure.} = enum
|
||||||
`cancelled`, `normal`
|
`cancelled`, `normal`
|
||||||
TurnId*[Cap] = Preserve[Cap]
|
TurnId* = Value
|
||||||
AssertionDescriptionKind* {.pure.} = enum
|
AssertionDescriptionKind* {.pure.} = enum
|
||||||
`value`, `opaque`
|
`value`, `opaque`
|
||||||
AssertionDescriptionValue*[Cap] {.preservesRecord: "value".} = object
|
AssertionDescriptionValue* {.preservesRecord: "value".} = object
|
||||||
`value`*: Preserve[Cap]
|
`value`*: Value
|
||||||
|
|
||||||
AssertionDescriptionOpaque*[Cap] {.preservesRecord: "opaque".} = object
|
AssertionDescriptionOpaque* {.preservesRecord: "opaque".} = object
|
||||||
`description`*: Preserve[Cap]
|
`description`*: Value
|
||||||
|
|
||||||
`AssertionDescription`*[Cap] {.preservesOr.} = object
|
`AssertionDescription`* {.preservesOr.} = object
|
||||||
case orKind*: AssertionDescriptionKind
|
case orKind*: AssertionDescriptionKind
|
||||||
of AssertionDescriptionKind.`value`:
|
of AssertionDescriptionKind.`value`:
|
||||||
`value`*: AssertionDescriptionValue[Cap]
|
`value`*: AssertionDescriptionValue
|
||||||
|
|
||||||
of AssertionDescriptionKind.`opaque`:
|
of AssertionDescriptionKind.`opaque`:
|
||||||
`opaque`*: AssertionDescriptionOpaque[Cap]
|
`opaque`*: AssertionDescriptionOpaque
|
||||||
|
|
||||||
|
|
||||||
NameKind* {.pure.} = enum
|
NameKind* {.pure.} = enum
|
||||||
`anonymous`, `named`
|
`anonymous`, `named`
|
||||||
NameAnonymous* {.preservesRecord: "anonymous".} = object
|
NameAnonymous* {.preservesRecord: "anonymous".} = object
|
||||||
|
|
||||||
NameNamed*[Cap] {.preservesRecord: "named".} = object
|
NameNamed* {.preservesRecord: "named".} = object
|
||||||
`name`*: Preserve[Cap]
|
`name`*: Value
|
||||||
|
|
||||||
`Name`*[Cap] {.preservesOr.} = object
|
`Name`* {.preservesOr.} = object
|
||||||
case orKind*: NameKind
|
case orKind*: NameKind
|
||||||
of NameKind.`anonymous`:
|
of NameKind.`anonymous`:
|
||||||
`anonymous`*: NameAnonymous
|
`anonymous`*: NameAnonymous
|
||||||
|
|
||||||
of NameKind.`named`:
|
of NameKind.`named`:
|
||||||
`named`*: NameNamed[Cap]
|
`named`*: NameNamed
|
||||||
|
|
||||||
|
|
||||||
ActorId*[Cap] = Preserve[Cap]
|
ActorId* = Value
|
||||||
FacetId*[Cap] = Preserve[Cap]
|
FacetId* = Value
|
||||||
`FacetStopReason`* {.preservesOr, pure.} = enum
|
`FacetStopReason`* {.preservesOr, pure.} = enum
|
||||||
`explicitAction`, `inert`, `parentStopping`, `actorStopping`
|
`explicitAction`, `inert`, `parentStopping`, `actorStopping`
|
||||||
TaskId*[Cap] = Preserve[Cap]
|
TaskId* = Value
|
||||||
ActorActivationKind* {.pure.} = enum
|
ActorActivationKind* {.pure.} = enum
|
||||||
`start`, `turn`, `stop`
|
`start`, `turn`, `stop`
|
||||||
ActorActivationStart*[Cap] {.preservesRecord: "start".} = object
|
ActorActivationStart* {.preservesRecord: "start".} = object
|
||||||
`actorName`*: Name[Cap]
|
`actorName`*: Name
|
||||||
|
|
||||||
ActorActivationStop* {.preservesRecord: "stop".} = object
|
ActorActivationStop* {.preservesRecord: "stop".} = object
|
||||||
`status`*: ExitStatus
|
`status`*: ExitStatus
|
||||||
|
|
||||||
`ActorActivation`*[Cap] {.preservesOr.} = object
|
`ActorActivation`* {.preservesOr.} = object
|
||||||
case orKind*: ActorActivationKind
|
case orKind*: ActorActivationKind
|
||||||
of ActorActivationKind.`start`:
|
of ActorActivationKind.`start`:
|
||||||
`start`*: ActorActivationStart[Cap]
|
`start`*: ActorActivationStart
|
||||||
|
|
||||||
of ActorActivationKind.`turn`:
|
of ActorActivationKind.`turn`:
|
||||||
`turn`*: TurnDescription[Cap]
|
`turn`*: TurnDescription
|
||||||
|
|
||||||
of ActorActivationKind.`stop`:
|
of ActorActivationKind.`stop`:
|
||||||
`stop`*: ActorActivationStop
|
`stop`*: ActorActivationStop
|
||||||
|
|
||||||
|
|
||||||
Target*[Cap] {.preservesRecord: "entity".} = object
|
Target* {.preservesRecord: "entity".} = object
|
||||||
`actor`*: ActorId[Cap]
|
`actor`*: ActorId
|
||||||
`facet`*: FacetId[Cap]
|
`facet`*: FacetId
|
||||||
`oid`*: Oid[Cap]
|
`oid`*: Oid
|
||||||
|
|
||||||
TurnCauseKind* {.pure.} = enum
|
TurnCauseKind* {.pure.} = enum
|
||||||
`turn`, `cleanup`, `linkedTaskRelease`, `periodicActivation`, `delay`,
|
`turn`, `cleanup`, `linkedTaskRelease`, `periodicActivation`, `delay`,
|
||||||
`external`
|
`external`
|
||||||
TurnCauseTurn*[Cap] {.preservesRecord: "caused-by".} = object
|
TurnCauseTurn* {.preservesRecord: "caused-by".} = object
|
||||||
`id`*: TurnId[Cap]
|
`id`*: TurnId
|
||||||
|
|
||||||
TurnCauseCleanup* {.preservesRecord: "cleanup".} = object
|
TurnCauseCleanup* {.preservesRecord: "cleanup".} = object
|
||||||
|
|
||||||
TurnCauseLinkedTaskRelease*[Cap] {.preservesRecord: "linked-task-release".} = object
|
TurnCauseLinkedTaskRelease* {.preservesRecord: "linked-task-release".} = object
|
||||||
`id`*: TaskId[Cap]
|
`id`*: TaskId
|
||||||
`reason`*: LinkedTaskReleaseReason
|
`reason`*: LinkedTaskReleaseReason
|
||||||
|
|
||||||
TurnCausePeriodicActivation* {.preservesRecord: "periodic-activation".} = object
|
TurnCausePeriodicActivation* {.preservesRecord: "periodic-activation".} = object
|
||||||
`period`*: float64
|
`period`*: float
|
||||||
|
|
||||||
TurnCauseDelay*[Cap] {.preservesRecord: "delay".} = object
|
TurnCauseDelay* {.preservesRecord: "delay".} = object
|
||||||
`causingTurn`*: TurnId[Cap]
|
`causingTurn`*: TurnId
|
||||||
`amount`*: float64
|
`amount`*: float
|
||||||
|
|
||||||
TurnCauseExternal*[Cap] {.preservesRecord: "external".} = object
|
TurnCauseExternal* {.preservesRecord: "external".} = object
|
||||||
`description`*: Preserve[Cap]
|
`description`*: Value
|
||||||
|
|
||||||
`TurnCause`*[Cap] {.preservesOr.} = object
|
`TurnCause`* {.preservesOr.} = object
|
||||||
case orKind*: TurnCauseKind
|
case orKind*: TurnCauseKind
|
||||||
of TurnCauseKind.`turn`:
|
of TurnCauseKind.`turn`:
|
||||||
`turn`*: TurnCauseTurn[Cap]
|
`turn`*: TurnCauseTurn
|
||||||
|
|
||||||
of TurnCauseKind.`cleanup`:
|
of TurnCauseKind.`cleanup`:
|
||||||
`cleanup`*: TurnCauseCleanup
|
`cleanup`*: TurnCauseCleanup
|
||||||
|
|
||||||
of TurnCauseKind.`linkedTaskRelease`:
|
of TurnCauseKind.`linkedTaskRelease`:
|
||||||
`linkedtaskrelease`*: TurnCauseLinkedTaskRelease[Cap]
|
`linkedtaskrelease`*: TurnCauseLinkedTaskRelease
|
||||||
|
|
||||||
of TurnCauseKind.`periodicActivation`:
|
of TurnCauseKind.`periodicActivation`:
|
||||||
`periodicactivation`*: TurnCausePeriodicActivation
|
`periodicactivation`*: TurnCausePeriodicActivation
|
||||||
|
|
||||||
of TurnCauseKind.`delay`:
|
of TurnCauseKind.`delay`:
|
||||||
`delay`*: TurnCauseDelay[Cap]
|
`delay`*: TurnCauseDelay
|
||||||
|
|
||||||
of TurnCauseKind.`external`:
|
of TurnCauseKind.`external`:
|
||||||
`external`*: TurnCauseExternal[Cap]
|
`external`*: TurnCauseExternal
|
||||||
|
|
||||||
|
|
||||||
TurnEventKind* {.pure.} = enum
|
TurnEventKind* {.pure.} = enum
|
||||||
`assert`, `retract`, `message`, `sync`, `breakLink`
|
`assert`, `retract`, `message`, `sync`, `breakLink`
|
||||||
TurnEventAssert*[Cap] {.preservesRecord: "assert".} = object
|
TurnEventAssert* {.preservesRecord: "assert".} = object
|
||||||
`assertion`*: AssertionDescription[Cap]
|
`assertion`*: AssertionDescription
|
||||||
`handle`*: protocol.Handle
|
`handle`*: protocol.Handle
|
||||||
|
|
||||||
TurnEventRetract* {.preservesRecord: "retract".} = object
|
TurnEventRetract* {.preservesRecord: "retract".} = object
|
||||||
`handle`*: protocol.Handle
|
`handle`*: protocol.Handle
|
||||||
|
|
||||||
TurnEventMessage*[Cap] {.preservesRecord: "message".} = object
|
TurnEventMessage* {.preservesRecord: "message".} = object
|
||||||
`body`*: AssertionDescription[Cap]
|
`body`*: AssertionDescription
|
||||||
|
|
||||||
TurnEventSync*[Cap] {.preservesRecord: "sync".} = object
|
TurnEventSync* {.preservesRecord: "sync".} = object
|
||||||
`peer`*: Target[Cap]
|
`peer`*: Target
|
||||||
|
|
||||||
TurnEventBreakLink*[Cap] {.preservesRecord: "break-link".} = object
|
TurnEventBreakLink* {.preservesRecord: "break-link".} = object
|
||||||
`source`*: ActorId[Cap]
|
`source`*: ActorId
|
||||||
`handle`*: protocol.Handle
|
`handle`*: protocol.Handle
|
||||||
|
|
||||||
`TurnEvent`*[Cap] {.preservesOr.} = object
|
`TurnEvent`* {.preservesOr.} = object
|
||||||
case orKind*: TurnEventKind
|
case orKind*: TurnEventKind
|
||||||
of TurnEventKind.`assert`:
|
of TurnEventKind.`assert`:
|
||||||
`assert`*: TurnEventAssert[Cap]
|
`assert`*: TurnEventAssert
|
||||||
|
|
||||||
of TurnEventKind.`retract`:
|
of TurnEventKind.`retract`:
|
||||||
`retract`*: TurnEventRetract
|
`retract`*: TurnEventRetract
|
||||||
|
|
||||||
of TurnEventKind.`message`:
|
of TurnEventKind.`message`:
|
||||||
`message`*: TurnEventMessage[Cap]
|
`message`*: TurnEventMessage
|
||||||
|
|
||||||
of TurnEventKind.`sync`:
|
of TurnEventKind.`sync`:
|
||||||
`sync`*: TurnEventSync[Cap]
|
`sync`*: TurnEventSync
|
||||||
|
|
||||||
of TurnEventKind.`breakLink`:
|
of TurnEventKind.`breakLink`:
|
||||||
`breaklink`*: TurnEventBreakLink[Cap]
|
`breaklink`*: TurnEventBreakLink
|
||||||
|
|
||||||
|
|
||||||
TurnDescription*[Cap] {.preservesRecord: "turn".} = object
|
TurnDescription* {.preservesRecord: "turn".} = object
|
||||||
`id`*: TurnId[Cap]
|
`id`*: TurnId
|
||||||
`cause`*: TurnCause[Cap]
|
`cause`*: TurnCause
|
||||||
`actions`*: seq[ActionDescription[Cap]]
|
`actions`*: seq[ActionDescription]
|
||||||
|
|
||||||
ExitStatusKind* {.pure.} = enum
|
ExitStatusKind* {.pure.} = enum
|
||||||
`ok`, `Error`
|
`ok`, `Error`
|
||||||
|
@ -169,101 +169,95 @@ type
|
||||||
`error`*: protocol.Error
|
`error`*: protocol.Error
|
||||||
|
|
||||||
|
|
||||||
TraceEntry*[Cap] {.preservesRecord: "trace".} = object
|
TraceEntry* {.preservesRecord: "trace".} = object
|
||||||
`timestamp`*: float64
|
`timestamp`*: float
|
||||||
`actor`*: ActorId[Cap]
|
`actor`*: ActorId
|
||||||
`item`*: ActorActivation[Cap]
|
`item`*: ActorActivation
|
||||||
|
|
||||||
Oid*[Cap] = Preserve[Cap]
|
Oid* = Value
|
||||||
ActionDescriptionKind* {.pure.} = enum
|
ActionDescriptionKind* {.pure.} = enum
|
||||||
`dequeue`, `enqueue`, `dequeueInternal`, `enqueueInternal`, `spawn`, `link`,
|
`dequeue`, `enqueue`, `dequeueInternal`, `enqueueInternal`, `spawn`, `link`,
|
||||||
`facetStart`, `facetStop`, `linkedTaskStart`
|
`facetStart`, `facetStop`, `linkedTaskStart`
|
||||||
ActionDescriptionDequeue*[Cap] {.preservesRecord: "dequeue".} = object
|
ActionDescriptionDequeue* {.preservesRecord: "dequeue".} = object
|
||||||
`event`*: TargetedTurnEvent[Cap]
|
`event`*: TargetedTurnEvent
|
||||||
|
|
||||||
ActionDescriptionEnqueue*[Cap] {.preservesRecord: "enqueue".} = object
|
ActionDescriptionEnqueue* {.preservesRecord: "enqueue".} = object
|
||||||
`event`*: TargetedTurnEvent[Cap]
|
`event`*: TargetedTurnEvent
|
||||||
|
|
||||||
ActionDescriptionDequeueInternal*[Cap] {.preservesRecord: "dequeue-internal".} = object
|
ActionDescriptionDequeueInternal* {.preservesRecord: "dequeue-internal".} = object
|
||||||
`event`*: TargetedTurnEvent[Cap]
|
`event`*: TargetedTurnEvent
|
||||||
|
|
||||||
ActionDescriptionEnqueueInternal*[Cap] {.preservesRecord: "enqueue-internal".} = object
|
ActionDescriptionEnqueueInternal* {.preservesRecord: "enqueue-internal".} = object
|
||||||
`event`*: TargetedTurnEvent[Cap]
|
`event`*: TargetedTurnEvent
|
||||||
|
|
||||||
ActionDescriptionSpawn*[Cap] {.preservesRecord: "spawn".} = object
|
ActionDescriptionSpawn* {.preservesRecord: "spawn".} = object
|
||||||
`link`*: bool
|
`link`*: bool
|
||||||
`id`*: ActorId[Cap]
|
`id`*: ActorId
|
||||||
|
|
||||||
ActionDescriptionLink*[Cap] {.preservesRecord: "link".} = object
|
ActionDescriptionLink* {.preservesRecord: "link".} = object
|
||||||
`parentActor`*: ActorId[Cap]
|
`parentActor`*: ActorId
|
||||||
`childToParent`*: protocol.Handle
|
`childToParent`*: protocol.Handle
|
||||||
`childActor`*: ActorId[Cap]
|
`childActor`*: ActorId
|
||||||
`parentToChild`*: protocol.Handle
|
`parentToChild`*: protocol.Handle
|
||||||
|
|
||||||
ActionDescriptionFacetStart*[Cap] {.preservesRecord: "facet-start".} = object
|
ActionDescriptionFacetStart* {.preservesRecord: "facet-start".} = object
|
||||||
`path`*: seq[FacetId[Cap]]
|
`path`*: seq[FacetId]
|
||||||
|
|
||||||
ActionDescriptionFacetStop*[Cap] {.preservesRecord: "facet-stop".} = object
|
ActionDescriptionFacetStop* {.preservesRecord: "facet-stop".} = object
|
||||||
`path`*: seq[FacetId[Cap]]
|
`path`*: seq[FacetId]
|
||||||
`reason`*: FacetStopReason
|
`reason`*: FacetStopReason
|
||||||
|
|
||||||
ActionDescriptionLinkedTaskStart*[Cap] {.preservesRecord: "linked-task-start".} = object
|
ActionDescriptionLinkedTaskStart* {.preservesRecord: "linked-task-start".} = object
|
||||||
`taskName`*: Name[Cap]
|
`taskName`*: Name
|
||||||
`id`*: TaskId[Cap]
|
`id`*: TaskId
|
||||||
|
|
||||||
`ActionDescription`*[Cap] {.preservesOr.} = object
|
`ActionDescription`* {.preservesOr.} = object
|
||||||
case orKind*: ActionDescriptionKind
|
case orKind*: ActionDescriptionKind
|
||||||
of ActionDescriptionKind.`dequeue`:
|
of ActionDescriptionKind.`dequeue`:
|
||||||
`dequeue`*: ActionDescriptionDequeue[Cap]
|
`dequeue`*: ActionDescriptionDequeue
|
||||||
|
|
||||||
of ActionDescriptionKind.`enqueue`:
|
of ActionDescriptionKind.`enqueue`:
|
||||||
`enqueue`*: ActionDescriptionEnqueue[Cap]
|
`enqueue`*: ActionDescriptionEnqueue
|
||||||
|
|
||||||
of ActionDescriptionKind.`dequeueInternal`:
|
of ActionDescriptionKind.`dequeueInternal`:
|
||||||
`dequeueinternal`*: ActionDescriptionDequeueInternal[Cap]
|
`dequeueinternal`*: ActionDescriptionDequeueInternal
|
||||||
|
|
||||||
of ActionDescriptionKind.`enqueueInternal`:
|
of ActionDescriptionKind.`enqueueInternal`:
|
||||||
`enqueueinternal`*: ActionDescriptionEnqueueInternal[Cap]
|
`enqueueinternal`*: ActionDescriptionEnqueueInternal
|
||||||
|
|
||||||
of ActionDescriptionKind.`spawn`:
|
of ActionDescriptionKind.`spawn`:
|
||||||
`spawn`*: ActionDescriptionSpawn[Cap]
|
`spawn`*: ActionDescriptionSpawn
|
||||||
|
|
||||||
of ActionDescriptionKind.`link`:
|
of ActionDescriptionKind.`link`:
|
||||||
`link`*: ActionDescriptionLink[Cap]
|
`link`*: ActionDescriptionLink
|
||||||
|
|
||||||
of ActionDescriptionKind.`facetStart`:
|
of ActionDescriptionKind.`facetStart`:
|
||||||
`facetstart`*: ActionDescriptionFacetStart[Cap]
|
`facetstart`*: ActionDescriptionFacetStart
|
||||||
|
|
||||||
of ActionDescriptionKind.`facetStop`:
|
of ActionDescriptionKind.`facetStop`:
|
||||||
`facetstop`*: ActionDescriptionFacetStop[Cap]
|
`facetstop`*: ActionDescriptionFacetStop
|
||||||
|
|
||||||
of ActionDescriptionKind.`linkedTaskStart`:
|
of ActionDescriptionKind.`linkedTaskStart`:
|
||||||
`linkedtaskstart`*: ActionDescriptionLinkedTaskStart[Cap]
|
`linkedtaskstart`*: ActionDescriptionLinkedTaskStart
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[Cap](x: TargetedTurnEvent[Cap] | AssertionDescription[Cap] | Name[Cap] |
|
proc `$`*(x: TargetedTurnEvent | AssertionDescription | Name | ActorActivation |
|
||||||
ActorActivation[Cap] |
|
Target |
|
||||||
Target[Cap] |
|
TurnCause |
|
||||||
TurnCause[Cap] |
|
TurnEvent |
|
||||||
TurnEvent[Cap] |
|
TurnDescription |
|
||||||
TurnDescription[Cap] |
|
ExitStatus |
|
||||||
TraceEntry[Cap] |
|
TraceEntry |
|
||||||
ActionDescription[Cap]): string =
|
ActionDescription): string =
|
||||||
`$`(toPreserve(x, Cap))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: TargetedTurnEvent[Cap] | AssertionDescription[Cap] |
|
proc encode*(x: TargetedTurnEvent | AssertionDescription | Name |
|
||||||
Name[Cap] |
|
ActorActivation |
|
||||||
ActorActivation[Cap] |
|
Target |
|
||||||
Target[Cap] |
|
TurnCause |
|
||||||
TurnCause[Cap] |
|
TurnEvent |
|
||||||
TurnEvent[Cap] |
|
TurnDescription |
|
||||||
TurnDescription[Cap] |
|
ExitStatus |
|
||||||
TraceEntry[Cap] |
|
TraceEntry |
|
||||||
ActionDescription[Cap]): seq[byte] =
|
ActionDescription): seq[byte] =
|
||||||
encode(toPreserve(x, Cap))
|
encode(toPreserves(x))
|
||||||
|
|
||||||
proc `$`*(x: ExitStatus): string =
|
|
||||||
`$`(toPreserve(x))
|
|
||||||
|
|
||||||
proc encode*(x: ExitStatus): seq[byte] =
|
|
||||||
encode(toPreserve(x))
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ type
|
||||||
`port`*: BiggestInt
|
`port`*: BiggestInt
|
||||||
|
|
||||||
proc `$`*(x: WebSocket | Stdio | Unix | Tcp): string =
|
proc `$`*(x: WebSocket | Stdio | Unix | Tcp): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*(x: WebSocket | Stdio | Unix | Tcp): seq[byte] =
|
proc encode*(x: WebSocket | Stdio | Unix | Tcp): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -3,12 +3,12 @@ import
|
||||||
preserves
|
preserves
|
||||||
|
|
||||||
type
|
type
|
||||||
Instance*[Cap] {.preservesRecord: "Instance".} = object
|
Instance* {.preservesRecord: "Instance".} = object
|
||||||
`name`*: string
|
`name`*: string
|
||||||
`argument`*: Preserve[Cap]
|
`argument`*: Value
|
||||||
|
|
||||||
proc `$`*[Cap](x: Instance[Cap]): string =
|
proc `$`*(x: Instance): string =
|
||||||
`$`(toPreserve(x, Cap))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*[Cap](x: Instance[Cap]): seq[byte] =
|
proc encode*(x: Instance): seq[byte] =
|
||||||
encode(toPreserve(x, Cap))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[asyncdispatch, options, streams, tables]
|
import
|
||||||
import preserves
|
std/[options, sets, tables],
|
||||||
import ./actors, ./durings, ./membranes, ./protocols/[protocol, sturdy, transportAddress]
|
pkg/preserves,
|
||||||
|
../syndicate, ./durings, ./membranes, ./protocols/[gatekeeper, protocol, sturdy, transportAddress]
|
||||||
|
|
||||||
|
when defined(posix):
|
||||||
|
import ./capabilities
|
||||||
|
from std/os import getEnv, `/`
|
||||||
|
|
||||||
when defined(traceSyndicate):
|
when defined(traceSyndicate):
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
|
@ -15,30 +20,31 @@ else:
|
||||||
|
|
||||||
export `$`
|
export `$`
|
||||||
|
|
||||||
type Oid = sturdy.Oid
|
export Route, Stdio, Tcp, WebSocket, Unix
|
||||||
|
|
||||||
type
|
type
|
||||||
Value = Preserve[void]
|
Assertion = Value
|
||||||
Assertion = Preserve[Cap]
|
Event = protocol.Event
|
||||||
WireRef = sturdy.WireRef[void]
|
Handle = actors.Handle
|
||||||
|
Oid = sturdy.Oid
|
||||||
|
Turn = syndicate.Turn
|
||||||
|
WireRef = sturdy.WireRef
|
||||||
|
|
||||||
Turn = actors.Turn
|
PacketWriter = proc (turn: Turn; buf: seq[byte]) {.closure.}
|
||||||
|
RelaySetup = proc (turn: Turn; relay: Relay) {.closure.}
|
||||||
|
|
||||||
type
|
Relay* = ref object
|
||||||
PacketWriter = proc (pkt: sink Packet): Future[void] {.gcsafe.}
|
|
||||||
RelaySetup = proc (turn: var Turn; relay: Relay) {.gcsafe.}
|
|
||||||
|
|
||||||
Relay* = ref object of RootObj
|
|
||||||
facet: Facet
|
facet: Facet
|
||||||
inboundAssertions: Table[Handle,
|
inboundAssertions: Table[Handle,
|
||||||
tuple[localHandle: Handle, imported: seq[WireSymbol]]]
|
tuple[localHandle: Handle, imported: seq[WireSymbol]]]
|
||||||
outboundAssertions: Table[Handle, seq[WireSymbol]]
|
outboundAssertions: Table[Handle, seq[WireSymbol]]
|
||||||
|
pendingTurn: protocol.Turn
|
||||||
exported: Membrane
|
exported: Membrane
|
||||||
imported: Membrane
|
imported: Membrane
|
||||||
nextLocalOid: Oid
|
nextLocalOid: Oid
|
||||||
pendingTurn: protocol.Turn
|
wireBuf: BufferedDecoder
|
||||||
packetWriter: PacketWriter
|
packetWriter: PacketWriter
|
||||||
untrusted: bool
|
peer: Cap
|
||||||
|
|
||||||
SyncPeerEntity = ref object of Entity
|
SyncPeerEntity = ref object of Entity
|
||||||
relay: Relay
|
relay: Relay
|
||||||
|
@ -54,43 +60,46 @@ type
|
||||||
proc releaseCapOut(r: Relay; e: WireSymbol) =
|
proc releaseCapOut(r: Relay; e: WireSymbol) =
|
||||||
r.exported.drop e
|
r.exported.drop e
|
||||||
|
|
||||||
method publish(spe: SyncPeerEntity; t: var Turn; a: AssertionRef; h: Handle) =
|
method publish(spe: SyncPeerEntity; t: Turn; a: AssertionRef; h: Handle) =
|
||||||
spe.handleMap[h] = publish(t, spe.peer, a.value)
|
spe.handleMap[h] = publish(t, spe.peer, a.value)
|
||||||
|
|
||||||
method retract(se: SyncPeerEntity; t: var Turn; h: Handle) =
|
method retract(se: SyncPeerEntity; t: Turn; h: Handle) =
|
||||||
var other: Handle
|
var other: Handle
|
||||||
if se.handleMap.pop(h, other):
|
if se.handleMap.pop(h, other):
|
||||||
retract(t, other)
|
retract(t, other)
|
||||||
|
|
||||||
method message(se: SyncPeerEntity; t: var Turn; a: AssertionRef) =
|
method message(se: SyncPeerEntity; t: Turn; a: AssertionRef) =
|
||||||
if not se.e.isNil:
|
if not se.e.isNil:
|
||||||
se.relay.releaseCapOut(se.e)
|
se.relay.releaseCapOut(se.e)
|
||||||
message(t, se.peer, a.value)
|
message(t, se.peer, a.value)
|
||||||
|
|
||||||
method sync(se: SyncPeerEntity; t: var Turn; peer: Cap) =
|
method sync(se: SyncPeerEntity; t: Turn; peer: Cap) =
|
||||||
sync(t, se.peer, peer)
|
sync(t, se.peer, peer)
|
||||||
|
|
||||||
proc newSyncPeerEntity(r: Relay; p: Cap): SyncPeerEntity =
|
proc newSyncPeerEntity(r: Relay; p: Cap): SyncPeerEntity =
|
||||||
SyncPeerEntity(relay: r, peer: p)
|
SyncPeerEntity(relay: r, peer: p)
|
||||||
|
|
||||||
proc rewriteCapOut(relay: Relay; cap: Cap; exported: var seq[WireSymbol]): WireRef =
|
proc rewriteCapOut(relay: Relay; cap: Cap; exported: var seq[WireSymbol]): WireRef =
|
||||||
if cap.target of RelayEntity and cap.target.RelayEntity.relay == relay and cap.attenuation.len == 0:
|
if cap.target of RelayEntity and cap.target.RelayEntity.relay == relay and cap.caveats.len == 0:
|
||||||
WireRef(orKind: WireRefKind.yours, yours: WireRefYours[void](oid: cap.target.oid))
|
result = WireRef(orKind: WireRefKind.yours, yours: WireRefYours(oid: cap.target.oid))
|
||||||
else:
|
else:
|
||||||
var ws = grab(relay.exported, cap)
|
var ws = grab(relay.exported, cap)
|
||||||
if ws.isNil:
|
if ws.isNil:
|
||||||
ws = newWireSymbol(relay.exported, relay.nextLocalOid, cap)
|
ws = newWireSymbol(relay.exported, relay.nextLocalOid, cap)
|
||||||
inc relay.nextLocalOid
|
inc relay.nextLocalOid
|
||||||
exported.add ws
|
exported.add ws
|
||||||
WireRef(
|
result = WireRef(
|
||||||
orKind: WireRefKind.mine,
|
orKind: WireRefKind.mine,
|
||||||
mine: WireRefMine(oid: ws.oid))
|
mine: WireRefMine(oid: ws.oid))
|
||||||
|
|
||||||
proc rewriteOut(relay: Relay; v: Assertion):
|
proc rewriteOut(relay: Relay; v: Assertion):
|
||||||
tuple[rewritten: Value, exported: seq[WireSymbol]] {.gcsafe.} =
|
tuple[rewritten: Value, exported: seq[WireSymbol]] =
|
||||||
var exported: seq[WireSymbol]
|
var exported: seq[WireSymbol]
|
||||||
result.rewritten = contract(v) do (r: Cap) -> Value:
|
result.rewritten = mapEmbeds(v) do (pr: Value) -> Value:
|
||||||
rewriteCapOut(relay, r, exported).toPreserve
|
let o = pr.unembed(Cap); if o.isSome:
|
||||||
|
result = rewriteCapOut(relay, o.get, exported).toPreserves
|
||||||
|
result.embedded = true
|
||||||
|
else: result = pr
|
||||||
result.exported = exported
|
result.exported = exported
|
||||||
|
|
||||||
proc register(relay: Relay; v: Assertion; h: Handle): tuple[rewritten: Value, exported: seq[WireSymbol]] =
|
proc register(relay: Relay; v: Assertion; h: Handle): tuple[rewritten: Value, exported: seq[WireSymbol]] =
|
||||||
|
@ -102,50 +111,48 @@ proc deregister(relay: Relay; h: Handle) =
|
||||||
if relay.outboundAssertions.pop(h, outbound):
|
if relay.outboundAssertions.pop(h, outbound):
|
||||||
for e in outbound: releaseCapOut(relay, e)
|
for e in outbound: releaseCapOut(relay, e)
|
||||||
|
|
||||||
proc send(r: Relay; turn: var Turn; rOid: protocol.Oid; m: Event) =
|
proc send(relay: Relay; turn: Turn; rOid: protocol.Oid; m: Event) =
|
||||||
if r.pendingTurn.len == 0:
|
# TODO: don't send right away.
|
||||||
# If the pending queue is empty then schedule a packet
|
relay.pendingTurn.add TurnEvent(oid: rOid, event: m)
|
||||||
# to be sent after pending I/O is processed.
|
queueEffect(turn, relay.facet) do (turn: Turn):
|
||||||
callSoon do ():
|
if relay.pendingTurn.len > 0:
|
||||||
r.facet.run do (turn: var Turn):
|
|
||||||
var pkt = Packet(
|
var pkt = Packet(
|
||||||
orKind: PacketKind.Turn,
|
orKind: PacketKind.Turn,
|
||||||
turn: move r.pendingTurn)
|
turn: move relay.pendingTurn)
|
||||||
trace "C: ", pkt
|
trace "C: ", pkt
|
||||||
assert(not r.packetWriter.isNil, "missing packetWriter proc")
|
relay.packetWriter(turn, encode pkt)
|
||||||
asyncCheck(turn, r.packetWriter(pkt))
|
|
||||||
r.pendingTurn.add TurnEvent(oid: rOid, event: m)
|
|
||||||
|
|
||||||
proc send(re: RelayEntity; turn: var Turn; ev: Event) =
|
proc send(re: RelayEntity; turn: Turn; ev: Event) =
|
||||||
send(re.relay, turn, protocol.Oid re.oid, ev)
|
send(re.relay, turn, protocol.Oid re.oid, ev)
|
||||||
|
|
||||||
method publish(re: RelayEntity; t: var Turn; a: AssertionRef; h: Handle) {.gcsafe.} =
|
method publish(re: RelayEntity; t: Turn; a: AssertionRef; h: Handle) =
|
||||||
re.send(t, Event(
|
re.send(t, Event(
|
||||||
orKind: EventKind.Assert,
|
orKind: EventKind.Assert,
|
||||||
`assert`: protocol.Assert(
|
`assert`: protocol.Assert(
|
||||||
assertion: re.relay.register(a.value, h).rewritten,
|
assertion: re.relay.register(a.value, h).rewritten,
|
||||||
handle: h)))
|
handle: h)))
|
||||||
|
|
||||||
method retract(re: RelayEntity; t: var Turn; h: Handle) {.gcsafe.} =
|
method retract(re: RelayEntity; t: Turn; h: Handle) =
|
||||||
re.relay.deregister h
|
re.relay.deregister h
|
||||||
re.send(t, Event(
|
re.send(t, Event(
|
||||||
orKind: EventKind.Retract,
|
orKind: EventKind.Retract,
|
||||||
retract: Retract(handle: h)))
|
retract: Retract(handle: h)))
|
||||||
|
|
||||||
method message(re: RelayEntity; turn: var Turn; msg: AssertionRef) {.gcsafe.} =
|
method message(re: RelayEntity; turn: Turn; msg: AssertionRef) =
|
||||||
var (value, exported) = rewriteOut(re.relay, msg.value)
|
var (value, exported) = rewriteOut(re.relay, msg.value)
|
||||||
assert(len(exported) == 0, "cannot send a reference in a message")
|
assert(len(exported) == 0, "cannot send a reference in a message")
|
||||||
if len(exported) == 0:
|
if len(exported) == 0:
|
||||||
re.send(turn, Event(orKind: EventKind.Message, message: Message(body: value)))
|
re.send(turn, Event(orKind: EventKind.Message, message: Message(body: value)))
|
||||||
|
|
||||||
method sync(re: RelayEntity; turn: var Turn; peer: Cap) {.gcsafe.} =
|
method sync(re: RelayEntity; turn: Turn; peer: Cap) =
|
||||||
var
|
var
|
||||||
peerEntity = newSyncPeerEntity(re.relay, peer)
|
peerEntity = newSyncPeerEntity(re.relay, peer)
|
||||||
exported: seq[WireSymbol]
|
exported: seq[WireSymbol]
|
||||||
discard rewriteCapOut(re.relay, turn.newCap(peerEntity), exported)
|
wr = rewriteCapOut(re.relay, turn.newCap(peerEntity), exported)
|
||||||
# TODO: discard?
|
|
||||||
peerEntity.e = exported[0]
|
peerEntity.e = exported[0]
|
||||||
re.send(turn, Event(orKind: EventKind.Sync))
|
var ev = Event(orKind: EventKind.Sync)
|
||||||
|
ev.sync.peer = wr.toPreserves.embed
|
||||||
|
re.send(turn, ev)
|
||||||
|
|
||||||
proc newRelayEntity(label: string; r: Relay; o: Oid): RelayEntity =
|
proc newRelayEntity(label: string; r: Relay; o: Oid): RelayEntity =
|
||||||
RelayEntity(label: label, relay: r, oid: o)
|
RelayEntity(label: label, relay: r, oid: o)
|
||||||
|
@ -156,40 +163,41 @@ using
|
||||||
|
|
||||||
proc lookupLocal(relay; oid: Oid): Cap =
|
proc lookupLocal(relay; oid: Oid): Cap =
|
||||||
let sym = relay.exported.grab oid
|
let sym = relay.exported.grab oid
|
||||||
if sym.isNil: newInertCap()
|
if not sym.isNil:
|
||||||
else: sym.cap
|
result = sym.cap
|
||||||
|
|
||||||
proc isInert(r: Cap): bool =
|
|
||||||
r.target.isNil
|
|
||||||
|
|
||||||
proc rewriteCapIn(relay; facet; n: WireRef, imported: var seq[WireSymbol]): Cap =
|
proc rewriteCapIn(relay; facet; n: WireRef, imported: var seq[WireSymbol]): Cap =
|
||||||
case n.orKind
|
case n.orKind
|
||||||
of WireRefKind.mine:
|
of WireRefKind.mine:
|
||||||
var e = relay.imported.grab(n.mine.oid)
|
var e = relay.imported.grab(n.mine.oid)
|
||||||
if e.isNil: e = newWireSymbol(
|
if e.isNil:
|
||||||
|
e = newWireSymbol(
|
||||||
relay.imported,
|
relay.imported,
|
||||||
n.mine.oid,
|
n.mine.oid,
|
||||||
newCap(facet, newRelayEntity("rewriteCapIn", relay, n.mine.oid)))
|
newCap(facet, newRelayEntity("rewriteCapIn", relay, n.mine.oid)),
|
||||||
|
)
|
||||||
imported.add e
|
imported.add e
|
||||||
result = e.cap
|
result = e.cap
|
||||||
of WireRefKind.yours:
|
of WireRefKind.yours:
|
||||||
let r = relay.lookupLocal(n.yours.oid)
|
result = relay.lookupLocal(n.yours.oid)
|
||||||
if n.yours.attenuation.len == 0 or r.isInert: result = r
|
if result.isNil:
|
||||||
else: raiseAssert "attenuation not implemented"
|
result = newInertCap()
|
||||||
|
elif n.yours.attenuation.len > 0:
|
||||||
|
result = attenuate(result, n.yours.attenuation)
|
||||||
|
|
||||||
proc rewriteIn(relay; facet; v: Value):
|
proc rewriteIn(relay; facet; v: Value):
|
||||||
tuple[rewritten: Assertion; imported: seq[WireSymbol]] {.gcsafe.} =
|
tuple[rewritten: Assertion; imported: seq[WireSymbol]] =
|
||||||
var imported: seq[WireSymbol]
|
var imported: seq[WireSymbol]
|
||||||
result.rewritten = expand(v) do (pr: Value) -> Assertion:
|
result.rewritten = mapEmbeds(v) do (pr: Value) -> Value:
|
||||||
var wr: WireRef
|
let wr = pr.preservesTo WireRef; if wr.isSome:
|
||||||
if not fromPreserve(wr, pr):
|
result = rewriteCapIn(relay, facet, wr.get, imported).embed
|
||||||
raiseAssert "expansion of embedded value failed"
|
else:
|
||||||
rewriteCapIn(relay, facet, wr, imported).toPreserve(Cap)
|
result = pr
|
||||||
result.imported = imported
|
result.imported = imported
|
||||||
|
|
||||||
proc close(r: Relay) = discard
|
proc close(r: Relay) = discard
|
||||||
|
|
||||||
proc dispatch*(relay: Relay; turn: var Turn; cap: Cap; event: Event) {.gcsafe.} =
|
proc dispatch(relay: Relay; turn: Turn; cap: Cap; event: Event) =
|
||||||
case event.orKind
|
case event.orKind
|
||||||
of EventKind.Assert:
|
of EventKind.Assert:
|
||||||
let (a, imported) = rewriteIn(relay, turn.facet, event.assert.assertion)
|
let (a, imported) = rewriteIn(relay, turn.facet, event.assert.assertion)
|
||||||
|
@ -208,29 +216,26 @@ proc dispatch*(relay: Relay; turn: var Turn; cap: Cap; event: Event) {.gcsafe.}
|
||||||
turn.message(cap, a)
|
turn.message(cap, a)
|
||||||
|
|
||||||
of EventKind.Sync:
|
of EventKind.Sync:
|
||||||
discard # TODO
|
turn.sync(cap) do (turn: Turn):
|
||||||
#[
|
var
|
||||||
var imported: seq[WireSymbol]
|
(v, imported) = rewriteIn(relay, turn.facet, event.sync.peer)
|
||||||
let k = relay.rewriteCapIn(turn, evenr.sync.peer, imported)
|
peer = unembed(v, Cap)
|
||||||
turn.sync(cap) do (turn: var Turn):
|
if peer.isSome:
|
||||||
turn.message(k, true)
|
turn.message(get peer, true)
|
||||||
for e in imported: relay.imported.del e
|
for e in imported: relay.imported.drop e
|
||||||
]#
|
|
||||||
|
|
||||||
proc dispatch*(relay: Relay; v: Value) {.gcsafe.} =
|
proc dispatch(relay: Relay; v: Value) =
|
||||||
trace "S: ", v
|
trace "S: ", v
|
||||||
run(relay.facet) do (t: var Turn):
|
run(relay.facet) do (t: Turn):
|
||||||
var pkt: Packet
|
var pkt: Packet
|
||||||
if fromPreserve(pkt, v):
|
if pkt.fromPreserves(v):
|
||||||
case pkt.orKind
|
case pkt.orKind
|
||||||
of PacketKind.Turn:
|
of PacketKind.Turn:
|
||||||
# https://synit.org/book/protocol.html#turn-packets
|
# https://synit.org/book/protocol.html#turn-packets
|
||||||
for te in pkt.turn:
|
for te in pkt.turn:
|
||||||
let r = lookupLocal(relay, te.oid.Oid)
|
let r = lookupLocal(relay, te.oid.Oid)
|
||||||
if not r.isInert:
|
if not r.isNil:
|
||||||
dispatch(relay, t, r, te.event)
|
dispatch(relay, t, r, te.event)
|
||||||
else:
|
|
||||||
stderr.writeLine("discarding event for unknown Cap; ", te.event)
|
|
||||||
of PacketKind.Error:
|
of PacketKind.Error:
|
||||||
# https://synit.org/book/protocol.html#error-packets
|
# https://synit.org/book/protocol.html#error-packets
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
|
@ -239,183 +244,434 @@ proc dispatch*(relay: Relay; v: Value) {.gcsafe.} =
|
||||||
of PacketKind.Extension:
|
of PacketKind.Extension:
|
||||||
# https://synit.org/book/protocol.html#extension-packets
|
# https://synit.org/book/protocol.html#extension-packets
|
||||||
discard
|
discard
|
||||||
|
of PacketKind.Nop:
|
||||||
|
discard
|
||||||
else:
|
else:
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
stderr.writeLine("discarding undecoded packet ", v)
|
stderr.writeLine("discarding undecoded packet ", v)
|
||||||
|
|
||||||
|
proc recv(relay: Relay; buf: openarray[byte]; slice: Slice[int]) =
|
||||||
|
feed(relay.wireBuf, buf, slice)
|
||||||
|
var pr = decode(relay.wireBuf)
|
||||||
|
if pr.isSome: dispatch(relay, pr.get)
|
||||||
|
|
||||||
|
proc recv(relay: Relay; buf: openarray[byte]) {.used.} =
|
||||||
|
feed(relay.wireBuf, buf)
|
||||||
|
var pr = decode(relay.wireBuf)
|
||||||
|
if pr.isSome: dispatch(relay, pr.get)
|
||||||
|
|
||||||
type
|
type
|
||||||
RelayOptions* = object of RootObj
|
RelayOptions* = object of RootObj
|
||||||
packetWriter*: PacketWriter
|
packetWriter*: PacketWriter
|
||||||
untrusted*: bool
|
|
||||||
RelayActorOptions* = object of RelayOptions
|
RelayActorOptions* = object of RelayOptions
|
||||||
initialOid*: Option[Oid]
|
initialOid*: Option[Oid]
|
||||||
initialCap*: Cap
|
initialCap*: Cap
|
||||||
nextLocalOid*: Option[Oid]
|
nextLocalOid*: Option[Oid]
|
||||||
|
|
||||||
proc newRelay(turn: var Turn; opts: RelayOptions; setup: RelaySetup): Relay =
|
proc spawnRelay(name: string; turn: Turn; opts: RelayActorOptions; setup: RelaySetup) =
|
||||||
result = Relay(
|
linkActor(turn, name) do (turn: Turn):
|
||||||
|
turn.preventInertCheck()
|
||||||
|
let relay = Relay(
|
||||||
facet: turn.facet,
|
facet: turn.facet,
|
||||||
packetWriter: opts.packetWriter,
|
packetWriter: opts.packetWriter,
|
||||||
untrusted: opts.untrusted)
|
wireBuf: newBufferedDecoder(0),
|
||||||
discard result.facet.preventInertCheck()
|
)
|
||||||
setup(turn, result)
|
|
||||||
|
|
||||||
proc spawnRelay*(name: string; turn: var Turn; opts: RelayActorOptions; setup: RelaySetup): Future[Cap] =
|
|
||||||
var fut = newFuture[Cap]"spawnRelay"
|
|
||||||
discard spawn(name, turn) do (turn: var Turn):
|
|
||||||
let relay = newRelay(turn, opts, setup)
|
|
||||||
if not opts.initialCap.isNil:
|
if not opts.initialCap.isNil:
|
||||||
var exported: seq[WireSymbol]
|
var exported: seq[WireSymbol]
|
||||||
discard rewriteCapOut(relay, opts.initialCap, exported)
|
discard rewriteCapOut(relay, opts.initialCap, exported)
|
||||||
if opts.initialOid.isSome:
|
|
||||||
var imported: seq[WireSymbol]
|
|
||||||
var wr = WireRef(
|
|
||||||
orKind: WireRefKind.mine,
|
|
||||||
mine: WireRefMine(oid: opts.initialOid.get))
|
|
||||||
fut.complete rewriteCapIn(relay, turn.facet, wr, imported)
|
|
||||||
else:
|
|
||||||
fut.complete(nil)
|
|
||||||
opts.nextLocalOid.map do (oid: Oid):
|
opts.nextLocalOid.map do (oid: Oid):
|
||||||
relay.nextLocalOid =
|
relay.nextLocalOid =
|
||||||
if oid == 0.Oid: 1.Oid
|
if oid == 0.Oid: 1.Oid
|
||||||
else: oid
|
else: oid
|
||||||
fut
|
assert opts.initialOid.isSome
|
||||||
|
if opts.initialOid.isSome:
|
||||||
when defined(posix):
|
|
||||||
import std/asyncnet
|
|
||||||
from std/nativesockets import AF_INET, AF_UNIX, IPPROTO_TCP, SOCK_STREAM, Protocol
|
|
||||||
|
|
||||||
import protocols/gatekeeper
|
|
||||||
|
|
||||||
type ShutdownEntity* = ref object of Entity
|
|
||||||
|
|
||||||
method retract(e: ShutdownEntity; turn: var Turn; h: Handle) =
|
|
||||||
stopActor(turn)
|
|
||||||
|
|
||||||
type ConnectProc* = proc (turn: var Turn; ds: Cap) {.gcsafe.}
|
|
||||||
|
|
||||||
export Tcp
|
|
||||||
|
|
||||||
when defined(posix):
|
|
||||||
export Unix
|
|
||||||
|
|
||||||
proc connect*(turn: var Turn; socket: AsyncSocket; step: Preserve[Cap]; bootProc: ConnectProc) =
|
|
||||||
## Relay a dataspace over an open `AsyncSocket`.
|
|
||||||
## *`bootProc` may be called multiple times for multiple remote gatekeepers.*
|
|
||||||
proc socketWriter(packet: sink Packet): Future[void] =
|
|
||||||
socket.send(cast[string](encode(packet)))
|
|
||||||
const recvSize = 0x2000
|
|
||||||
var shutdownCap: Cap
|
|
||||||
let
|
|
||||||
reenable = turn.facet.preventInertCheck()
|
|
||||||
connectionClosedCap = newCap(turn, ShutdownEntity())
|
|
||||||
fut = newFuture[void]"connect"
|
|
||||||
discard bootActor("socket") do (turn: var Turn):
|
|
||||||
var ops = RelayActorOptions(
|
|
||||||
packetWriter: socketWriter,
|
|
||||||
initialOid: 0.Oid.some)
|
|
||||||
let refFut = spawnRelay("socket", turn, ops) do (turn: var Turn; relay: Relay):
|
|
||||||
let facet = turn.facet
|
|
||||||
var wireBuf = newBufferedDecoder(0)
|
|
||||||
proc recvCb(pktFut: Future[string]) {.gcsafe.} =
|
|
||||||
if pktFut.failed:
|
|
||||||
run(facet) do (turn: var Turn): stopActor(turn)
|
|
||||||
else:
|
|
||||||
var buf = pktFut.read
|
|
||||||
if buf.len == 0:
|
|
||||||
run(facet) do (turn: var Turn): stopActor(turn)
|
|
||||||
else:
|
|
||||||
feed(wireBuf, buf)
|
|
||||||
var (success, pr) = decode(wireBuf)
|
|
||||||
if success:
|
|
||||||
dispatch(relay, pr)
|
|
||||||
if not socket.isClosed:
|
|
||||||
socket.recv(recvSize).addCallback(recvCb)
|
|
||||||
socket.recv(recvSize).addCallback(recvCb)
|
|
||||||
turn.facet.actor.atExit do (turn: var Turn): close(socket)
|
|
||||||
discard publish(turn, connectionClosedCap, true)
|
|
||||||
shutdownCap = newCap(turn, ShutdownEntity())
|
|
||||||
addCallback(refFut) do ():
|
|
||||||
let gatekeeper = read refFut
|
|
||||||
run(gatekeeper.relay) do (turn: var Turn):
|
|
||||||
reenable()
|
|
||||||
discard publish(turn, shutdownCap, true)
|
|
||||||
proc duringCallback(turn: var Turn; a: Assertion; h: Handle): TurnAction =
|
|
||||||
let facet = inFacet(turn) do (turn: var Turn):
|
|
||||||
var
|
var
|
||||||
accepted: ResolvedAccepted[Cap]
|
imported: seq[WireSymbol]
|
||||||
rejected: Rejected[Cap]
|
wr = WireRef(
|
||||||
if fromPreserve(accepted, a):
|
orKind: WireRefKind.mine,
|
||||||
bootProc(turn, accepted.responderSession)
|
mine: WireRefMine(oid: opts.initialOid.get))
|
||||||
elif fromPreserve(rejected, a):
|
relay.peer = rewriteCapIn(relay, turn.facet, wr, imported)
|
||||||
fail(fut, newException(CatchableError, $rejected.detail))
|
assert not relay.peer.isNil
|
||||||
|
setup(turn, relay)
|
||||||
|
|
||||||
|
proc rejected(detail: Value): Resolved =
|
||||||
|
result = Resolved(orKind: ResolvedKind.Rejected)
|
||||||
|
result.rejected.detail = detail
|
||||||
|
|
||||||
|
proc accepted(cap: Cap): Resolved =
|
||||||
|
result = Resolved(orKind: ResolvedKind.accepted)
|
||||||
|
result.accepted.responderSession = cap
|
||||||
|
|
||||||
|
type ShutdownEntity = ref object of Entity
|
||||||
|
method retract(e: ShutdownEntity; turn: Turn; h: Handle) =
|
||||||
|
stopActor(e.facet)
|
||||||
|
|
||||||
|
when defined(posix) and not defined(nimdoc):
|
||||||
|
|
||||||
|
import std/[oserrors, posix]
|
||||||
|
import pkg/sys/[files, handles, ioqueue, sockets]
|
||||||
|
export transportAddress.Unix
|
||||||
|
|
||||||
|
type StdioEntity = ref object of Entity
|
||||||
|
relay: Relay
|
||||||
|
stdin: AsyncFile
|
||||||
|
alive: bool
|
||||||
|
|
||||||
|
method message(entity: StdioEntity; turn: Turn; ass: AssertionRef) =
|
||||||
|
if ass.value.preservesTo(ForceDisconnect).isSome:
|
||||||
|
entity.alive = false
|
||||||
|
|
||||||
|
proc loop(entity: StdioEntity) {.asyncio.} =
|
||||||
|
let buf = new seq[byte]
|
||||||
|
entity.alive = true
|
||||||
|
while entity.alive:
|
||||||
|
buf[].setLen(0x1000)
|
||||||
|
let n = read(entity.stdin, buf)
|
||||||
|
if n > 0:
|
||||||
|
entity.relay.recv(buf[], 0..<n)
|
||||||
else:
|
else:
|
||||||
fail(fut, newException(CatchableError, $a))
|
entity.alive = false
|
||||||
proc action(turn: var Turn) =
|
if n < 0: raiseOSError(osLastError())
|
||||||
stop(turn, facet)
|
stopActor(entity.facet)
|
||||||
result = action
|
|
||||||
discard publish(turn, gatekeeper, Resolve[Cap](
|
|
||||||
step: step,
|
|
||||||
observer: newCap(turn, during(duringCallback)),
|
|
||||||
))
|
|
||||||
fut.complete()
|
|
||||||
asyncCheck(turn, fut)
|
|
||||||
|
|
||||||
proc connect*(turn: var Turn; transport: Tcp; step: Preserve[Cap]; bootProc: ConnectProc) =
|
proc connectTransport(turn: Turn; ds: Cap; ta: transportAddress.Stdio) =
|
||||||
## Relay a dataspace over TCP.
|
## Connect to an external dataspace over stdio.
|
||||||
## *`bootProc` may be called multiple times for multiple remote gatekeepers.*
|
let localDataspace = newDataspace(turn)
|
||||||
let socket = newAsyncSocket(
|
proc stdoutWriter(turn: Turn; buf: seq[byte]) =
|
||||||
domain = AF_INET,
|
## Blocking write to stdout.
|
||||||
sockType = SOCK_STREAM,
|
let n = writeBytes(stdout, buf, 0, buf.len)
|
||||||
protocol = IPPROTO_TCP,
|
|
||||||
buffered = false)
|
|
||||||
let fut = connect(socket, transport.host, Port transport.port)
|
|
||||||
addCallback(fut, turn) do (turn: var Turn):
|
|
||||||
connect(turn, socket, step, bootProc)
|
|
||||||
|
|
||||||
proc connect*(turn: var Turn; transport: Unix; step: Preserve[Cap]; bootProc: ConnectProc) =
|
|
||||||
## Relay a dataspace over a UNIX socket.
|
|
||||||
## *`bootProc` may be called multiple times for multiple remote gatekeepers.*
|
|
||||||
let socket = newAsyncSocket(
|
|
||||||
domain = AF_UNIX,
|
|
||||||
sockType = SOCK_STREAM,
|
|
||||||
protocol = cast[Protocol](0),
|
|
||||||
buffered = false)
|
|
||||||
let fut = connectUnix(socket, transport.path)
|
|
||||||
addCallback(fut, turn) do (turn: var Turn):
|
|
||||||
connect(turn, socket, step, bootProc)
|
|
||||||
|
|
||||||
import std/asyncfile
|
|
||||||
|
|
||||||
const stdinReadSize = 128
|
|
||||||
|
|
||||||
proc connectStdio*(ds: Cap; turn: var Turn) =
|
|
||||||
## Connect to an external dataspace over stdin and stdout.
|
|
||||||
proc stdoutWriter(packet: sink Packet): Future[void] {.async.} =
|
|
||||||
var buf = encode(packet)
|
|
||||||
doAssert writeBytes(stdout, buf, 0, buf.len) == buf.len
|
|
||||||
flushFile(stdout)
|
flushFile(stdout)
|
||||||
|
if n != buf.len:
|
||||||
|
stopActor(turn)
|
||||||
var opts = RelayActorOptions(
|
var opts = RelayActorOptions(
|
||||||
packetWriter: stdoutWriter,
|
packetWriter: stdoutWriter,
|
||||||
initialCap: ds,
|
initialCap: localDataspace,
|
||||||
initialOid: 0.Oid.some)
|
initialOid: 0.Oid.some,
|
||||||
asyncCheck spawnRelay("stdio", turn, opts) do (turn: var Turn; relay: Relay):
|
)
|
||||||
|
spawnRelay("stdio", turn, opts) do (turn: Turn; relay: Relay):
|
||||||
let
|
let
|
||||||
facet = turn.facet
|
facet = turn.facet
|
||||||
asyncStdin = openAsync("/dev/stdin") # this is universal now?
|
fd = stdin.getOsFileHandle()
|
||||||
close(stdin)
|
flags = fcntl(fd.cint, F_GETFL, 0)
|
||||||
facet.actor.atExit do (turn: var Turn):
|
if flags < 0: raiseOSError(osLastError())
|
||||||
close(asyncStdin)
|
if fcntl(fd.cint, F_SETFL, flags or O_NONBLOCK) < 0:
|
||||||
var wireBuf = newBufferedDecoder(0)
|
raiseOSError(osLastError())
|
||||||
proc readCb(pktFut: Future[string]) {.gcsafe.} =
|
let entity = StdioEntity(
|
||||||
if not pktFut.failed:
|
facet: turn.facet, relay: relay, stdin: newAsyncFile(FD fd))
|
||||||
var buf = pktFut.read
|
onStop(entity.facet) do (turn: Turn):
|
||||||
if buf.len == 0:
|
entity.alive = false
|
||||||
run(facet) do (turn: var Turn): stopActor(turn)
|
close(entity.stdin)
|
||||||
|
# Close stdin to remove it from the ioqueue
|
||||||
|
discard trampoline:
|
||||||
|
whelp loop(entity)
|
||||||
|
publish(turn, ds, TransportConnection(
|
||||||
|
`addr`: ta.toPreserves,
|
||||||
|
control: newCap(entity, turn),
|
||||||
|
resolved: localDataspace.accepted,
|
||||||
|
))
|
||||||
|
|
||||||
|
proc connectStdio*(turn: Turn; ds: Cap) =
|
||||||
|
## Connect to an external dataspace over stdin and stdout.
|
||||||
|
connectTransport(turn, ds, transportAddress.Stdio())
|
||||||
|
|
||||||
|
type
|
||||||
|
TcpEntity = ref object of Entity
|
||||||
|
relay: Relay
|
||||||
|
sock: AsyncConn[sockets.Protocol.TCP]
|
||||||
|
alive: bool
|
||||||
|
|
||||||
|
UnixEntity = ref object of Entity
|
||||||
|
relay: Relay
|
||||||
|
sock: AsyncConn[sockets.Protocol.Unix]
|
||||||
|
alive: bool
|
||||||
|
|
||||||
|
SocketEntity = TcpEntity | UnixEntity
|
||||||
|
|
||||||
|
method message(entity: SocketEntity; turn: Turn; ass: AssertionRef) =
|
||||||
|
if ass.value.preservesTo(ForceDisconnect).isSome:
|
||||||
|
entity.alive = false
|
||||||
|
|
||||||
|
template bootSocketEntity() {.dirty.} =
|
||||||
|
proc setup(turn: Turn) {.closure.} =
|
||||||
|
proc kill(turn: Turn) =
|
||||||
|
if entity.alive:
|
||||||
|
entity.alive = false
|
||||||
|
close(entity.sock)
|
||||||
|
onStop(turn, kill)
|
||||||
|
var ass = TransportConnection(
|
||||||
|
`addr`: ta.toPreserves,
|
||||||
|
control: newCap(entity, turn),
|
||||||
|
resolved: entity.relay.peer.accepted,
|
||||||
|
)
|
||||||
|
publish(turn, ds, ass)
|
||||||
|
run(entity.relay.facet, setup)
|
||||||
|
let buf = new seq[byte]
|
||||||
|
entity.alive = true
|
||||||
|
while entity.alive:
|
||||||
|
buf[].setLen(0x1000)
|
||||||
|
let n = read(entity.sock, buf)
|
||||||
|
if n > 0:
|
||||||
|
entity.relay.recv(buf[], 0..<n)
|
||||||
else:
|
else:
|
||||||
feed(wireBuf, buf)
|
entity.alive = false
|
||||||
var (success, pr) = decode(wireBuf)
|
if n < 0: raiseOSError(osLastError())
|
||||||
if success:
|
stopActor(entity.facet)
|
||||||
dispatch(relay, pr)
|
# the socket closes when the actor is stopped
|
||||||
asyncStdin.read(stdinReadSize).addCallback(readCb)
|
|
||||||
asyncStdin.read(stdinReadSize).addCallback(readCb)
|
proc boot(entity: TcpEntity; ta: transportAddress.Tcp; ds: Cap) {.asyncio.} =
|
||||||
|
entity.sock = connectTcpAsync(ta.host, Port ta.port)
|
||||||
|
bootSocketEntity()
|
||||||
|
|
||||||
|
proc boot(entity: UnixEntity; ta: transportAddress.Unix; ds: Cap) {.asyncio.} =
|
||||||
|
entity.sock = connectUnixAsync(ta.path)
|
||||||
|
bootSocketEntity()
|
||||||
|
|
||||||
|
template spawnSocketRelay() {.dirty.} =
|
||||||
|
proc writeConn(turn: Turn; buf: seq[byte]) =
|
||||||
|
if entity.alive:
|
||||||
|
discard trampoline:
|
||||||
|
whelp write(entity.sock, buf)
|
||||||
|
var ops = RelayActorOptions(
|
||||||
|
packetWriter: writeConn,
|
||||||
|
initialOid: 0.Oid.some,
|
||||||
|
)
|
||||||
|
spawnRelay("socket", turn, ops) do (turn: Turn; relay: Relay):
|
||||||
|
entity.facet = turn.facet
|
||||||
|
entity.relay = relay
|
||||||
|
discard trampoline:
|
||||||
|
whelp boot(entity, ta, ds)
|
||||||
|
|
||||||
|
proc connectTransport(turn: Turn; ds: Cap; ta: transportAddress.Tcp) =
|
||||||
|
let entity = TcpEntity()
|
||||||
|
spawnSocketRelay()
|
||||||
|
|
||||||
|
proc connectTransport(turn: Turn; ds: Cap; ta: transportAddress.Unix) =
|
||||||
|
let entity = UnixEntity()
|
||||||
|
spawnSocketRelay()
|
||||||
|
|
||||||
|
elif defined(solo5):
|
||||||
|
|
||||||
|
import solo5_dispatcher
|
||||||
|
import taps
|
||||||
|
|
||||||
|
type
|
||||||
|
TcpEntity = ref object of Entity
|
||||||
|
relay: Relay
|
||||||
|
conn: Connection
|
||||||
|
decoder: BufferedDecoder
|
||||||
|
|
||||||
|
method message(entity: TcpEntity; turn: Turn; ass: AssertionRef) =
|
||||||
|
if ass.value.preservesTo(ForceDisconnect).isSome:
|
||||||
|
entity.conn.abort()
|
||||||
|
|
||||||
|
proc connectTransport(turn: Turn; ds: Cap; ta: transportAddress.Tcp) =
|
||||||
|
let entity = TcpEntity(facet: turn.facet)
|
||||||
|
|
||||||
|
proc writeConn(turn: Turn; buf: seq[byte]) =
|
||||||
|
assert not entity.conn.isNil
|
||||||
|
entity.conn.batch:
|
||||||
|
entity.conn.send(buf)
|
||||||
|
var ops = RelayActorOptions(
|
||||||
|
packetWriter: writeConn,
|
||||||
|
initialOid: 0.Oid.some,
|
||||||
|
)
|
||||||
|
spawnRelay("socket", turn, ops) do (turn: Turn; relay: Relay):
|
||||||
|
entity.facet = turn.facet
|
||||||
|
entity.relay = relay
|
||||||
|
|
||||||
|
var ep = newRemoteEndpoint()
|
||||||
|
if ta.host.isIpAddress:
|
||||||
|
ep.with ta.host.parseIpAddress
|
||||||
|
else:
|
||||||
|
ep.withHostname ta.host
|
||||||
|
ep.with ta.port.Port
|
||||||
|
|
||||||
|
var tp = newTransportProperties()
|
||||||
|
tp.require "reliability"
|
||||||
|
tp.ignore "congestion-control"
|
||||||
|
tp.ignore "preserve-order"
|
||||||
|
|
||||||
|
var preconn = newPreconnection(
|
||||||
|
remote=[ep], transport=tp.some)
|
||||||
|
entity.conn = preconn.initiate()
|
||||||
|
entity.facet.onStop do (turn: Turn):
|
||||||
|
entity.conn.close()
|
||||||
|
entity.conn.onConnectionError do (err: ref Exception):
|
||||||
|
run(entity.facet) do (turn: Turn):
|
||||||
|
terminate(turn, err)
|
||||||
|
entity.conn.onClosed():
|
||||||
|
stop(entity.facet)
|
||||||
|
entity.conn.onReceivedPartial do (data: seq[byte]; ctx: MessageContext; eom: bool):
|
||||||
|
entity.relay.recv(data)
|
||||||
|
if eom:
|
||||||
|
stop(entity.facet)
|
||||||
|
else:
|
||||||
|
entity.conn.receive()
|
||||||
|
entity.conn.onReady do ():
|
||||||
|
entity.facet.run do (turn: Turn):
|
||||||
|
publish(turn, ds, TransportConnection(
|
||||||
|
`addr`: ta.toPreserves,
|
||||||
|
control: newCap(entity, turn),
|
||||||
|
resolved: entity.relay.peer.accepted,
|
||||||
|
))
|
||||||
|
entity.conn.receive()
|
||||||
|
|
||||||
|
proc walk(turn: Turn; ds, origin: Cap; route: Route; transOff, stepOff: int) =
|
||||||
|
if stepOff < route.pathSteps.len:
|
||||||
|
let
|
||||||
|
step = route.pathSteps[stepOff]
|
||||||
|
rejectPat = ResolvedPathStep?:{
|
||||||
|
0: ?(origin.embed), 1: ?step, 2: ?:Rejected}
|
||||||
|
acceptPat = ResolvedPathStep?:{
|
||||||
|
0: ?(origin.embed), 1: ?step, 2: ?:ResolvedAccepted}
|
||||||
|
onPublish(turn, ds, rejectPat) do (detail: Value):
|
||||||
|
publish(turn, ds, ResolvePath(
|
||||||
|
route: route,
|
||||||
|
`addr`: route.transports[transOff],
|
||||||
|
resolved: detail.rejected,
|
||||||
|
))
|
||||||
|
during(turn, ds, acceptPat) do (next: Cap):
|
||||||
|
walk(turn, ds, next, route, transOff, stepOff.succ)
|
||||||
|
else:
|
||||||
|
publish(turn, ds, ResolvePath(
|
||||||
|
route: route,
|
||||||
|
`addr`: route.transports[transOff],
|
||||||
|
resolved: origin.accepted,
|
||||||
|
))
|
||||||
|
|
||||||
|
proc connectRoute(turn: Turn; ds: Cap; route: Route; transOff: int) =
|
||||||
|
let rejectPat = TransportConnection ?: {
|
||||||
|
0: ?route.transports[transOff],
|
||||||
|
2: ?:Rejected,
|
||||||
|
}
|
||||||
|
during(turn, ds, rejectPat) do (detail: Value):
|
||||||
|
publish(turn, ds, ResolvePath(
|
||||||
|
route: route,
|
||||||
|
`addr`: route.transports[transOff],
|
||||||
|
resolved: detail.rejected,
|
||||||
|
))
|
||||||
|
let acceptPat = TransportConnection?:{
|
||||||
|
0: ?route.transports[transOff],
|
||||||
|
2: ?:ResolvedAccepted,
|
||||||
|
}
|
||||||
|
onPublish(turn, ds, acceptPat) do (origin: Cap):
|
||||||
|
origin.relay.run do (turn: Turn):
|
||||||
|
# walk using the facet that manages the transport connection
|
||||||
|
walk(turn, ds, origin, route, transOff, 0)
|
||||||
|
|
||||||
|
type StepCallback = proc (turn: Turn; step: Value; origin: Cap; res: Resolved) {.closure.}
|
||||||
|
|
||||||
|
proc spawnStepResolver(turn: Turn; ds: Cap; stepType: Value; cb: StepCallback) =
|
||||||
|
let pat = observePattern(
|
||||||
|
ResolvedPathStep?:{1: grabRecord(stepType)},
|
||||||
|
{ @[0.toPreserves]: grabLit(), @[1.toPreserves]: grab() },
|
||||||
|
)
|
||||||
|
during(turn, ds, pat) do (origin: Cap; stepDetail: Literal[Value]):
|
||||||
|
proc duringCallback(turn: Turn; ass: Value; h: Handle): TurnAction =
|
||||||
|
var res: Resolved
|
||||||
|
if res.fromPreserves ass:
|
||||||
|
cb(turn, stepDetail.value, origin, res)
|
||||||
|
proc action(turn: Turn) =
|
||||||
|
stop(turn)
|
||||||
|
result = action
|
||||||
|
publish(turn, origin, Resolve(
|
||||||
|
step: stepDetail.value, observer: newCap(turn, during(duringCallback))))
|
||||||
|
|
||||||
|
proc spawnRelays*(turn: Turn; ds: Cap) =
|
||||||
|
## Spawn actors that manage routes and appease gatekeepers.
|
||||||
|
|
||||||
|
let transPat = observePattern(!TransportConnection, { @[0.toPreserves]: grab() })
|
||||||
|
# Use a generic pattern and type matching
|
||||||
|
# in the during handler because it is easy.
|
||||||
|
|
||||||
|
when defined(posix) and not defined(nimdoc):
|
||||||
|
let stdioPat = ?Observe(pattern: TransportConnection?:{0: ?:Stdio})
|
||||||
|
during(turn, ds, stdioPat) do:
|
||||||
|
connectTransport(turn, ds, Stdio())
|
||||||
|
|
||||||
|
# TODO: unix pattern
|
||||||
|
during(turn, ds, transPat) do (ta: Literal[transportAddress.Unix]):
|
||||||
|
try: connectTransport(turn, ds, ta.value)
|
||||||
|
except exceptions.IOError as e:
|
||||||
|
publish(turn, ds, TransportConnection(
|
||||||
|
`addr`: ta.toPreserve,
|
||||||
|
resolved: rejected(embed e),
|
||||||
|
))
|
||||||
|
|
||||||
|
# TODO: tcp pattern
|
||||||
|
during(turn, ds, transPat) do (ta: Literal[transportAddress.Tcp]):
|
||||||
|
try: connectTransport(turn, ds, ta.value)
|
||||||
|
except exceptions.IOError as e:
|
||||||
|
publish(turn, ds, TransportConnection(
|
||||||
|
`addr`: ta.toPreserves,
|
||||||
|
resolved: rejected(embed e),
|
||||||
|
))
|
||||||
|
|
||||||
|
let resolvePat = observePattern(!ResolvePath, {@[0.toPreserves]: grab()})
|
||||||
|
during(turn, ds, resolvePat) do (route: Literal[Route]):
|
||||||
|
for i, transAddr in route.value.transports:
|
||||||
|
connectRoute(turn, ds, route.value, i)
|
||||||
|
|
||||||
|
spawnStepResolver(turn, ds, "ref".toSymbol) do (
|
||||||
|
turn: Turn, step: Value, origin: Cap, res: Resolved):
|
||||||
|
publish(turn, ds, ResolvedPathStep(
|
||||||
|
origin: origin, pathStep: step, resolved: res))
|
||||||
|
|
||||||
|
type
|
||||||
|
BootProc* = proc (turn: Turn; ds: Cap) {.closure.}
|
||||||
|
|
||||||
|
proc resolve*(turn: Turn; ds: Cap; route: Route; bootProc: BootProc) =
|
||||||
|
## Resolve `route` within `ds` and call `bootProc` with resolved capabilities.
|
||||||
|
## If a resolved route is retracted then `bootProc` will be called again with
|
||||||
|
## the next available route.
|
||||||
|
var
|
||||||
|
destinations: OrderedSet[Cap]
|
||||||
|
activeDest: Cap
|
||||||
|
activeActor: Actor
|
||||||
|
proc bootActor(turn: Turn) =
|
||||||
|
assert activeActor.isNil
|
||||||
|
assert activeDest.isNil
|
||||||
|
for d in destinations:
|
||||||
|
activeDest = d
|
||||||
|
break
|
||||||
|
if not activeDest.isNil:
|
||||||
|
activeActor = linkActor(turn, "resolver") do (turn: Turn):
|
||||||
|
onStop(turn) do (turn: Turn):
|
||||||
|
activeActor = nil
|
||||||
|
activeDest = nil
|
||||||
|
bootActor(turn)
|
||||||
|
bootProc(turn, activeDest)
|
||||||
|
during(turn, ds, ResolvePath ?: {0: ?route, 3: ?:ResolvedAccepted}) do (dst: Cap):
|
||||||
|
destinations.incl dst
|
||||||
|
if activeDest.isNil:
|
||||||
|
bootActor(turn)
|
||||||
|
do:
|
||||||
|
destinations.excl dst
|
||||||
|
|
||||||
|
proc resolve*(turn: Turn; route: Route; bootProc: BootProc) =
|
||||||
|
## Resolve `route` and call `bootProc` with resolved capability.
|
||||||
|
let ds = turn.newDataspace()
|
||||||
|
resolve(turn, ds, route, bootProc)
|
||||||
|
spawnRelays(turn, ds)
|
||||||
|
|
||||||
|
when defined(posix):
|
||||||
|
const defaultRoute* = "<route [<stdio>]>"
|
||||||
|
|
||||||
|
proc envRoute*: Route =
|
||||||
|
## Get an route to a Syndicate capability from the calling environment.
|
||||||
|
## On UNIX this is the SYNDICATE_ROUTE environmental variable with a
|
||||||
|
## fallack to a defaultRoute_.
|
||||||
|
## See https://git.syndicate-lang.org/syndicate-lang/syndicate-protocols/raw/branch/main/schemas/gatekeeper.prs.
|
||||||
|
var text = getEnv("SYNDICATE_ROUTE", defaultRoute)
|
||||||
|
try:
|
||||||
|
if result.fromPreserves text.parsePreserves: return
|
||||||
|
except ValueError: discard
|
||||||
|
raise newException(ValueError, "failed to parse $SYNDICATE_ROUTE " & $text)
|
||||||
|
|
||||||
|
proc resolveEnvironment*(turn: Turn; bootProc: BootProc) =
|
||||||
|
## Resolve a capability from the calling environment
|
||||||
|
## and call `bootProc`. See envRoute_.
|
||||||
|
resolve(turn, envRoute(), bootProc)
|
||||||
|
|
||||||
|
# TODO: define a runActor that comes preloaded with relaying
|
||||||
|
|
|
@ -3,57 +3,39 @@
|
||||||
|
|
||||||
## https://git.syndicate-lang.org/syndicate-lang/syndicate-rkt/src/commit/90c4c60699069b496491b81ee63b5a45ffd638cb/syndicate/HOWITWORKS.md
|
## https://git.syndicate-lang.org/syndicate-lang/syndicate-rkt/src/commit/90c4c60699069b496491b81ee63b5a45ffd638cb/syndicate/HOWITWORKS.md
|
||||||
|
|
||||||
import std/[hashes, lists, options, sets, tables]
|
import
|
||||||
import preserves
|
std/[assertions, hashes, options, sets, tables],
|
||||||
import ./actors, ./bags, ./patterns
|
pkg/preserves,
|
||||||
import ./protocols/dataspacePatterns
|
./actors, ./bags, ./patterns,
|
||||||
|
./protocols/dataspacePatterns
|
||||||
|
|
||||||
type
|
type
|
||||||
DCompound = dataspacePatterns.DCompound[Cap]
|
Pattern = dataspacePatterns.Pattern
|
||||||
Pattern = dataspacePatterns.Pattern[Cap]
|
|
||||||
Value = Preserve[Cap]
|
|
||||||
Path = seq[Value]
|
Path = seq[Value]
|
||||||
ClassKind = enum classNone, classRecord, classSequence, classDictionary
|
ClassKind = enum classNone, classRecord, classSequence, classDictionary
|
||||||
Class = object
|
Class = object
|
||||||
kind: ClassKind
|
kind: ClassKind
|
||||||
label: Value
|
label: Value
|
||||||
arity: int
|
|
||||||
|
|
||||||
func classOf(v: Value): Class =
|
func classOf(v: Value): Class =
|
||||||
case v.kind
|
case v.kind
|
||||||
of pkRecord: Class(kind: classRecord, label: v.label, arity: v.arity)
|
of pkRecord: Class(kind: classRecord, label: v.label)
|
||||||
of pkSequence: Class(kind: classSequence, arity: v.len)
|
of pkSequence: Class(kind: classSequence)
|
||||||
of pkDictionary: Class(kind: classDictionary)
|
of pkDictionary: Class(kind: classDictionary)
|
||||||
else: Class(kind: classNone)
|
else: Class(kind: classNone)
|
||||||
|
|
||||||
proc classOf(p: Pattern): Class =
|
proc classOf(p: Pattern): Class =
|
||||||
if p.orKind == PatternKind.DCompound:
|
if p.orKind == PatternKind.group:
|
||||||
case p.dcompound.orKind
|
case p.group.type.orKind
|
||||||
of DCompoundKind.rec:
|
of GroupTypeKind.rec:
|
||||||
Class(kind: classRecord,
|
Class(kind: classRecord, label: p.group.`type`.rec.label)
|
||||||
label: p.dcompound.rec.label,
|
of GroupTypeKind.arr:
|
||||||
arity: p.dcompound.rec.fields.len)
|
Class(kind: classSequence)
|
||||||
of DCompoundKind.arr:
|
of GroupTypeKind.dict:
|
||||||
Class(kind: classSequence, arity: p.dcompound.arr.items.len)
|
|
||||||
of DCompoundKind.dict:
|
|
||||||
Class(kind: classDictionary)
|
Class(kind: classDictionary)
|
||||||
else:
|
else:
|
||||||
Class(kind: classNone)
|
Class(kind: classNone)
|
||||||
|
|
||||||
proc `$`(class: Class): string =
|
|
||||||
case class.kind
|
|
||||||
of classNone: result = "null"
|
|
||||||
of classRecord:
|
|
||||||
result.add($class.label)
|
|
||||||
result.add(':')
|
|
||||||
result.add($class.arity)
|
|
||||||
of classSequence:
|
|
||||||
result.add('[')
|
|
||||||
result.add($class.arity)
|
|
||||||
result.add(']')
|
|
||||||
of classDictionary:
|
|
||||||
result = "{…:…}"
|
|
||||||
|
|
||||||
type
|
type
|
||||||
EventKind = enum addedEvent, removedEvent, messageEvent
|
EventKind = enum addedEvent, removedEvent, messageEvent
|
||||||
|
|
||||||
|
@ -79,21 +61,19 @@ func isEmpty(leaf: Leaf): bool =
|
||||||
func isEmpty(cont: Continuation): bool =
|
func isEmpty(cont: Continuation): bool =
|
||||||
cont.cache.len == 0 and cont.leafMap.len == 0
|
cont.cache.len == 0 and cont.leafMap.len == 0
|
||||||
|
|
||||||
proc `$`(x: Leaf|Continuation): string =
|
|
||||||
cast[ByteAddress](x[].unsafeAddr).toHex
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ContinuationProc = proc (c: Continuation; v: Value) {.gcsafe.}
|
ContinuationProc = proc (c: Continuation; v: Value) {.closure.}
|
||||||
LeafProc = proc (l: Leaf; v: Value) {.gcsafe.}
|
LeafProc = proc (l: Leaf; v: Value) {.closure.}
|
||||||
ObserverProc = proc (turn: var Turn; group: ObserverGroup; vs: seq[Value]) {.gcsafe.}
|
ObserverProc = proc (turn: Turn; group: ObserverGroup; vs: seq[Value]) {.closure.}
|
||||||
|
|
||||||
proc getLeaves(cont: Continuation; constPaths: Paths): LeafMap =
|
proc getLeaves(cont: Continuation; presentPaths, constPaths: Paths): LeafMap =
|
||||||
result = cont.leafMap.getOrDefault(constPaths)
|
result = cont.leafMap.getOrDefault(constPaths)
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
new result
|
new result
|
||||||
cont.leafMap[constPaths] = result
|
cont.leafMap[constPaths] = result
|
||||||
assert not cont.isEmpty
|
assert not cont.isEmpty
|
||||||
for ass in cont.cache:
|
for ass in cont.cache:
|
||||||
|
# TODO: check presence
|
||||||
let key = projectPaths(ass, constPaths)
|
let key = projectPaths(ass, constPaths)
|
||||||
if key.isSome:
|
if key.isSome:
|
||||||
var leaf = result.getOrDefault(get key)
|
var leaf = result.getOrDefault(get key)
|
||||||
|
@ -118,9 +98,6 @@ type
|
||||||
func isEmpty(node: Node): bool =
|
func isEmpty(node: Node): bool =
|
||||||
node.continuation.isEmpty and node.edges.len == 0
|
node.continuation.isEmpty and node.edges.len == 0
|
||||||
|
|
||||||
proc `$`(node: Node): string =
|
|
||||||
$(cast[ByteAddress](unsafeAddr node[]) and 0xffffff)
|
|
||||||
|
|
||||||
type TermStack = seq[Value]
|
type TermStack = seq[Value]
|
||||||
|
|
||||||
proc push(stack: TermStack; val: Value): Termstack =
|
proc push(stack: TermStack; val: Value): Termstack =
|
||||||
|
@ -135,10 +112,10 @@ proc top(stack: TermStack): Value =
|
||||||
assert stack.len > 0
|
assert stack.len > 0
|
||||||
stack[stack.high]
|
stack[stack.high]
|
||||||
|
|
||||||
proc modify(node: Node; turn: var Turn; outerValue: Value; event: EventKind;
|
proc modify(node: Node; turn: Turn; outerValue: Value; event: EventKind;
|
||||||
modCont: ContinuationProc; modLeaf: LeafProc; modObs: ObserverProc) =
|
modCont: ContinuationProc; modLeaf: LeafProc; modObs: ObserverProc) =
|
||||||
|
|
||||||
proc walk(cont: Continuation; turn: var Turn) =
|
proc walk(cont: Continuation; turn: Turn) =
|
||||||
modCont(cont, outerValue)
|
modCont(cont, outerValue)
|
||||||
for constPaths, constValMap in cont.leafMap.pairs:
|
for constPaths, constValMap in cont.leafMap.pairs:
|
||||||
let constVals = projectPaths(outerValue, constPaths)
|
let constVals = projectPaths(outerValue, constPaths)
|
||||||
|
@ -163,9 +140,8 @@ proc modify(node: Node; turn: var Turn; outerValue: Value; event: EventKind;
|
||||||
constValMap.del(get constVals)
|
constValMap.del(get constVals)
|
||||||
|
|
||||||
|
|
||||||
proc walk(node: Node; turn: var Turn; termStack: TermStack) =
|
proc walk(node: Node; turn: Turn; termStack: TermStack) =
|
||||||
walk(node.continuation, turn)
|
walk(node.continuation, turn)
|
||||||
assert not node.isEmpty
|
|
||||||
for selector, table in node.edges:
|
for selector, table in node.edges:
|
||||||
let
|
let
|
||||||
nextStack = pop(termStack, selector.popCount)
|
nextStack = pop(termStack, selector.popCount)
|
||||||
|
@ -179,7 +155,7 @@ proc modify(node: Node; turn: var Turn; outerValue: Value; event: EventKind;
|
||||||
if event == removedEvent and nextNode.isEmpty:
|
if event == removedEvent and nextNode.isEmpty:
|
||||||
table.del(nextClass)
|
table.del(nextClass)
|
||||||
|
|
||||||
walk(node, turn, @[@[outerValue].toPreserve(Cap)])
|
walk(node, turn, @[@[outerValue].toPreserves])
|
||||||
|
|
||||||
proc getOrNew[A, B, C](t: var Table[A, TableRef[B, C]], k: A): TableRef[B, C] =
|
proc getOrNew[A, B, C](t: var Table[A, TableRef[B, C]], k: A): TableRef[B, C] =
|
||||||
result = t.getOrDefault(k)
|
result = t.getOrDefault(k)
|
||||||
|
@ -187,25 +163,13 @@ proc getOrNew[A, B, C](t: var Table[A, TableRef[B, C]], k: A): TableRef[B, C] =
|
||||||
result = newTable[B, C]()
|
result = newTable[B, C]()
|
||||||
t[k] = result
|
t[k] = result
|
||||||
|
|
||||||
iterator pairs(dc: DCompound): (Value, Pattern) =
|
|
||||||
case dc.orKind
|
|
||||||
of DCompoundKind.rec:
|
|
||||||
for i, p in dc.rec.fields:
|
|
||||||
yield (toPreserve(i, Cap), p,)
|
|
||||||
of DCompoundKind.arr:
|
|
||||||
for i, p in dc.arr.items:
|
|
||||||
yield (toPreserve(i, Cap), p,)
|
|
||||||
of DCompoundKind.dict:
|
|
||||||
for pair in dc.dict.entries.pairs:
|
|
||||||
yield pair
|
|
||||||
|
|
||||||
proc extendWalk(node: Node; popCount: Natural; stepIndex: Value; pat: Pattern; path: var Path): tuple[popCount: Natural, nextNode: Node] =
|
proc extendWalk(node: Node; popCount: Natural; stepIndex: Value; pat: Pattern; path: var Path): tuple[popCount: Natural, nextNode: Node] =
|
||||||
case pat.orKind
|
case pat.orKind
|
||||||
of PatternKind.DDiscard, PatternKind.DLit:
|
of PatternKind.`discard`, PatternKind.lit:
|
||||||
result = (popCount, node)
|
result = (popCount, node)
|
||||||
of PatternKind.DBind:
|
of PatternKind.`bind`:
|
||||||
result = extendWalk(node, popCount, stepIndex, pat.dbind.pattern, path)
|
result = extendWalk(node, popCount, stepIndex, pat.`bind`.pattern, path)
|
||||||
of PatternKind.DCompound:
|
of PatternKind.`group`:
|
||||||
let
|
let
|
||||||
selector: Selector = (popCount, stepIndex,)
|
selector: Selector = (popCount, stepIndex,)
|
||||||
table = node.edges.getOrNew(selector)
|
table = node.edges.getOrNew(selector)
|
||||||
|
@ -216,11 +180,11 @@ proc extendWalk(node: Node; popCount: Natural; stepIndex: Value; pat: Pattern; p
|
||||||
table[class] = result.nextNode
|
table[class] = result.nextNode
|
||||||
new result.nextNode.continuation
|
new result.nextNode.continuation
|
||||||
for a in node.continuation.cache:
|
for a in node.continuation.cache:
|
||||||
var v = projectPath(a, path)
|
var v = step(a, path)
|
||||||
if v.isSome and class == classOf(get v):
|
if v.isSome and class == classOf(get v):
|
||||||
result.nextNode.continuation.cache.incl a
|
result.nextNode.continuation.cache.incl a
|
||||||
result.popCount = 0
|
result.popCount = 0
|
||||||
for step, p in pat.dcompound.pairs:
|
for step, p in pat.group.entries:
|
||||||
add(path, step)
|
add(path, step)
|
||||||
result = extendWalk(result.nextNode, result.popCount, step, p, path)
|
result = extendWalk(result.nextNode, result.popCount, step, p, path)
|
||||||
discard pop(path)
|
discard pop(path)
|
||||||
|
@ -228,7 +192,7 @@ proc extendWalk(node: Node; popCount: Natural; stepIndex: Value; pat: Pattern; p
|
||||||
|
|
||||||
proc extend(node: var Node; pat: Pattern): Continuation =
|
proc extend(node: var Node; pat: Pattern): Continuation =
|
||||||
var path: Path
|
var path: Path
|
||||||
extendWalk(node, 0, toPreserve(0, Cap), pat, path).nextNode.continuation
|
extendWalk(node, 0, 0.toPreserves, pat, path).nextNode.continuation
|
||||||
|
|
||||||
type
|
type
|
||||||
Index* = object
|
Index* = object
|
||||||
|
@ -249,11 +213,11 @@ proc getEndpoints(leaf: Leaf; capturePaths: Paths): ObserverGroup =
|
||||||
if captures.isSome:
|
if captures.isSome:
|
||||||
discard result.cachedCaptures.change(get captures, +1)
|
discard result.cachedCaptures.change(get captures, +1)
|
||||||
|
|
||||||
proc add*(index: var Index; turn: var Turn; pattern: Pattern; observer: Cap) =
|
proc add*(index: var Index; turn: Turn; pattern: Pattern; observer: Cap) =
|
||||||
let
|
let
|
||||||
cont = index.root.extend(pattern)
|
cont = index.root.extend(pattern)
|
||||||
analysis = analyse pattern
|
analysis = analyse pattern
|
||||||
constValMap = cont.getLeaves(analysis.constPaths)
|
constValMap = cont.getLeaves(analysis.presentPaths, analysis.constPaths)
|
||||||
leaf = constValMap.getLeaf(analysis.constValues)
|
leaf = constValMap.getLeaf(analysis.constValues)
|
||||||
endpoints = leaf.getEndpoints(analysis.capturePaths)
|
endpoints = leaf.getEndpoints(analysis.capturePaths)
|
||||||
# TODO if endpoints.cachedCaptures.len > 0:
|
# TODO if endpoints.cachedCaptures.len > 0:
|
||||||
|
@ -262,7 +226,7 @@ proc add*(index: var Index; turn: var Turn; pattern: Pattern; observer: Cap) =
|
||||||
captureMap[capture] = publish(turn, observer, capture)
|
captureMap[capture] = publish(turn, observer, capture)
|
||||||
endpoints.observers[observer] = captureMap
|
endpoints.observers[observer] = captureMap
|
||||||
|
|
||||||
proc remove*(index: var Index; turn: var Turn; pattern: Pattern; observer: Cap) =
|
proc remove*(index: var Index; turn: Turn; pattern: Pattern; observer: Cap) =
|
||||||
let
|
let
|
||||||
cont = index.root.extend(pattern)
|
cont = index.root.extend(pattern)
|
||||||
analysis = analyse pattern
|
analysis = analyse pattern
|
||||||
|
@ -282,7 +246,7 @@ proc remove*(index: var Index; turn: var Turn; pattern: Pattern; observer: Cap)
|
||||||
if constValMap.len == 0:
|
if constValMap.len == 0:
|
||||||
cont.leafMap.del(analysis.constPaths)
|
cont.leafMap.del(analysis.constPaths)
|
||||||
|
|
||||||
proc adjustAssertion(index: var Index; turn: var Turn; outerValue: Value; delta: int): bool =
|
proc adjustAssertion(index: var Index; turn: Turn; outerValue: Value; delta: int): bool =
|
||||||
case index.allAssertions.change(outerValue, delta)
|
case index.allAssertions.change(outerValue, delta)
|
||||||
of cdAbsentToPresent:
|
of cdAbsentToPresent:
|
||||||
result = true
|
result = true
|
||||||
|
@ -290,11 +254,11 @@ proc adjustAssertion(index: var Index; turn: var Turn; outerValue: Value; delta:
|
||||||
c.cache.incl(v)
|
c.cache.incl(v)
|
||||||
proc modLeaf(l: Leaf; v: Value) =
|
proc modLeaf(l: Leaf; v: Value) =
|
||||||
l.cache.incl(v)
|
l.cache.incl(v)
|
||||||
proc modObserver(turn: var Turn; group: ObserverGroup; vs: seq[Value]) =
|
proc modObserver(turn: Turn; group: ObserverGroup; vs: seq[Value]) =
|
||||||
let change = group.cachedCaptures.change(vs, +1)
|
let change = group.cachedCaptures.change(vs, +1)
|
||||||
if change == cdAbsentToPresent:
|
if change == cdAbsentToPresent:
|
||||||
for (observer, captureMap) in group.observers.pairs:
|
for (observer, captureMap) in group.observers.pairs:
|
||||||
captureMap[vs] = publish(turn, observer, vs.toPreserve(Cap))
|
captureMap[vs] = publish(turn, observer, vs.toPreserves)
|
||||||
# TODO: this handle is coming from the facet?
|
# TODO: this handle is coming from the facet?
|
||||||
modify(index.root, turn, outerValue, addedEvent, modContinuation, modLeaf, modObserver)
|
modify(index.root, turn, outerValue, addedEvent, modContinuation, modLeaf, modObserver)
|
||||||
of cdPresentToAbsent:
|
of cdPresentToAbsent:
|
||||||
|
@ -303,23 +267,24 @@ proc adjustAssertion(index: var Index; turn: var Turn; outerValue: Value; delta:
|
||||||
c.cache.excl(v)
|
c.cache.excl(v)
|
||||||
proc modLeaf(l: Leaf; v: Value) =
|
proc modLeaf(l: Leaf; v: Value) =
|
||||||
l.cache.excl(v)
|
l.cache.excl(v)
|
||||||
proc modObserver(turn: var Turn; group: ObserverGroup; vs: seq[Value]) =
|
proc modObserver(turn: Turn; group: ObserverGroup; vs: seq[Value]) =
|
||||||
if group.cachedCaptures.change(vs, -1) == cdPresentToAbsent:
|
if group.cachedCaptures.change(vs, -1) == cdPresentToAbsent:
|
||||||
for (observer, captureMap) in group.observers.pairs:
|
for (observer, captureMap) in group.observers.pairs:
|
||||||
retract(observer.target, turn, captureMap[vs])
|
var h: Handle
|
||||||
captureMap.del(vs)
|
if captureMap.take(vs, h):
|
||||||
|
retract(observer.target, turn, h)
|
||||||
modify(index.root, turn, outerValue, removedEvent, modContinuation, modLeaf, modObserver)
|
modify(index.root, turn, outerValue, removedEvent, modContinuation, modLeaf, modObserver)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc continuationNoop(c: Continuation; v: Value) = discard
|
proc continuationNoop(c: Continuation; v: Value) = discard
|
||||||
proc leafNoop(l: Leaf; v: Value) = discard
|
proc leafNoop(l: Leaf; v: Value) = discard
|
||||||
|
|
||||||
proc add*(index: var Index; turn: var Turn; v: Assertion): bool =
|
proc add*(index: var Index; turn: Turn; v: Value): bool =
|
||||||
adjustAssertion(index, turn, v, +1)
|
adjustAssertion(index, turn, v, +1)
|
||||||
proc remove*(index: var Index; turn: var Turn; v: Assertion): bool =
|
proc remove*(index: var Index; turn: Turn; v: Value): bool =
|
||||||
adjustAssertion(index, turn, v, -1)
|
adjustAssertion(index, turn, v, -1)
|
||||||
|
|
||||||
proc deliverMessage*(index: var Index; turn: var Turn; v: Value) =
|
proc deliverMessage*(index: var Index; turn: Turn; v: Value) =
|
||||||
proc observersCb(turn: var Turn; group: ObserverGroup; vs: seq[Value]) =
|
proc observersCb(turn: Turn; group: ObserverGroup; vs: seq[Value]) =
|
||||||
for observer in group.observers.keys: message(turn, observer, vs)
|
for observer in group.observers.keys: message(turn, observer, vs)
|
||||||
index.root.modify(turn, v, messageEvent, continuationNoop, leafNoop, observersCb)
|
index.root.modify(turn, v, messageEvent, continuationNoop, leafNoop, observersCb)
|
||||||
|
|
|
@ -1,12 +1,61 @@
|
||||||
# Package
|
# Emulate Nimble from CycloneDX data at sbom.json.
|
||||||
|
|
||||||
version = "20230801"
|
import std/json
|
||||||
author = "Emery Hemingway"
|
|
||||||
description = "Syndicated actors for conversational concurrency"
|
|
||||||
license = "Unlicense"
|
|
||||||
srcDir = "src"
|
|
||||||
|
|
||||||
|
proc lookupComponent(sbom: JsonNode; bomRef: string): JsonNode =
|
||||||
|
for c in sbom{"components"}.getElems.items:
|
||||||
|
if c{"bom-ref"}.getStr == bomRef:
|
||||||
|
return c
|
||||||
|
result = newJNull()
|
||||||
|
|
||||||
# Dependencies
|
let
|
||||||
|
sbom = (getPkgDir() & "/sbom.json").readFile.parseJson
|
||||||
|
comp = sbom{"metadata", "component"}
|
||||||
|
bomRef = comp{"bom-ref"}.getStr
|
||||||
|
|
||||||
requires "hashlib", "nim >= 1.4.8", "preserves >= 20230720", "taps >= 20221119"
|
version = comp{"version"}.getStr
|
||||||
|
author = comp{"authors"}[0]{"name"}.getStr
|
||||||
|
description = comp{"description"}.getStr
|
||||||
|
license = comp{"licenses"}[0]{"license", "id"}.getStr
|
||||||
|
|
||||||
|
for prop in comp{"properties"}.getElems.items:
|
||||||
|
let (key, val) = (prop{"name"}.getStr, prop{"value"}.getStr)
|
||||||
|
case key
|
||||||
|
of "nim:skipDirs:":
|
||||||
|
add(skipDirs, val)
|
||||||
|
of "nim:skipFiles:":
|
||||||
|
add(skipFiles, val)
|
||||||
|
of "nim:skipExt":
|
||||||
|
add(skipExt, val)
|
||||||
|
of "nim:installDirs":
|
||||||
|
add(installDirs, val)
|
||||||
|
of "nim:installFiles":
|
||||||
|
add(installFiles, val)
|
||||||
|
of "nim:installExt":
|
||||||
|
add(installExt, val)
|
||||||
|
of "nim:binDir":
|
||||||
|
add(binDir, val)
|
||||||
|
of "nim:srcDir":
|
||||||
|
add(srcDir, val)
|
||||||
|
of "nim:backend":
|
||||||
|
add(backend, val)
|
||||||
|
else:
|
||||||
|
if key.startsWith "nim:bin:":
|
||||||
|
namedBin[key[8..key.high]] = val
|
||||||
|
|
||||||
|
for depend in sbom{"dependencies"}.items:
|
||||||
|
if depend{"ref"}.getStr == bomRef:
|
||||||
|
for depRef in depend{"dependsOn"}.items:
|
||||||
|
let dep = sbom.lookupComponent(depRef.getStr)
|
||||||
|
var spec = dep{"name"}.getStr
|
||||||
|
for extRef in dep{"externalReferences"}.elems:
|
||||||
|
if extRef{"type"}.getStr == "vcs":
|
||||||
|
spec = extRef{"url"}.getStr
|
||||||
|
break
|
||||||
|
let ver = dep{"version"}.getStr
|
||||||
|
if ver != "":
|
||||||
|
if ver.allCharsInSet {'0'..'9', '.'}: spec.add " == "
|
||||||
|
else: spec.add '#'
|
||||||
|
spec.add ver
|
||||||
|
requires spec
|
||||||
|
break
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
include_rules
|
include_rules
|
||||||
: foreach *.prs |> !preserves_schema_nim |> | {schema}
|
: foreach *.prs |> !preserves-schema-nim |> | {schema}
|
||||||
: foreach test*.nim | {schema} $(SYNDICATE_PROTOCOL) |> !nim_run |>
|
: foreach t*.nim | ../../preserves-nim/<tests> {schema} $(SYNDICATE_PROTOCOL) |> !nim_run |> | ../<test>
|
||||||
|
# : foreach solo5*.nim | ../../taps/<sources> ../../preserves-nim/<tests> {schema} $(SYNDICATE_PROTOCOL) |> !nim_solo5_spt |> | ../<test>
|
||||||
|
|
||||||
|
: | $(NIM_GROUPS) |> $(NIM) $(NIM_FLAGS) dump > %o |> nim.dump
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
#!/usr/bin/env spry
|
|
||||||
|
|
||||||
title = "Simple Chat Demo"
|
|
||||||
|
|
||||||
# Initialize libui
|
|
||||||
uiInit
|
|
||||||
|
|
||||||
username = "user"
|
|
||||||
|
|
||||||
menu = newMenu "Menu"
|
|
||||||
|
|
||||||
# menu addItem: "Username" onClicked: [
|
|
||||||
# dialog = newWindow: "Username" width: 200 height: 40 hasBar: false
|
|
||||||
# entry = newEntryText: username onChanged: []
|
|
||||||
# quitit = newButton: "Quit" onClicked: [
|
|
||||||
# destroy dialog
|
|
||||||
# true
|
|
||||||
# ]
|
|
||||||
# layout = newHorizontalBox
|
|
||||||
# #layout add: entry stretch: true
|
|
||||||
# layout.add: quitit stretch: false
|
|
||||||
# group = newGroup "Username"
|
|
||||||
# group setChild: layout
|
|
||||||
# dialog setChild: quitit
|
|
||||||
# dialog show
|
|
||||||
# ]
|
|
||||||
|
|
||||||
menu menuAppendAboutItem
|
|
||||||
|
|
||||||
menu addQuitItemShouldClose: [
|
|
||||||
win destroy
|
|
||||||
uiQuit
|
|
||||||
true
|
|
||||||
]
|
|
||||||
|
|
||||||
# Create a new Window
|
|
||||||
win = newWindow: title width: 640 height: 400 hasBar: true
|
|
||||||
win margined: true
|
|
||||||
|
|
||||||
# create text boxes
|
|
||||||
scrollback = newMultilineEntryText
|
|
||||||
scrollback readonly: true
|
|
||||||
|
|
||||||
sendEntry = newMultilineEntryText
|
|
||||||
|
|
||||||
# create layouts
|
|
||||||
layout = newVerticalBox
|
|
||||||
sendBox = newHorizontalBox
|
|
||||||
|
|
||||||
# Some buttons and their handlers
|
|
||||||
sendButton = newButton: "Send" onClicked: [
|
|
||||||
msg = (sendEntry text)
|
|
||||||
msg != "" then: [
|
|
||||||
scrollback addText: (msg, "\x0a")
|
|
||||||
sendEntry text: ""
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
# Group
|
|
||||||
group = newGroup "Workspace"
|
|
||||||
group margined: false
|
|
||||||
group setChild: layout
|
|
||||||
|
|
||||||
sendBox add: sendEntry stretch: true
|
|
||||||
sendBox add: sendButton stretch: false
|
|
||||||
|
|
||||||
# Put things in the boxes
|
|
||||||
layout padded: true
|
|
||||||
layout add: scrollback stretch: true
|
|
||||||
layout add: sendBox stretch: false
|
|
||||||
|
|
||||||
# Add box to window
|
|
||||||
win setChild: group
|
|
||||||
|
|
||||||
# Set initial text
|
|
||||||
sendEntry text: "compose a message here"
|
|
||||||
|
|
||||||
# Close handler
|
|
||||||
closeHandler = [
|
|
||||||
win destroy
|
|
||||||
uiQuit
|
|
||||||
true
|
|
||||||
]
|
|
||||||
|
|
||||||
# Set a handler on closing window
|
|
||||||
win onClosingShouldClose: [ true ]
|
|
||||||
|
|
||||||
# Show the window
|
|
||||||
win show
|
|
||||||
|
|
||||||
# Enter libui's event loop
|
|
||||||
uiMain
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import
|
||||||
|
std/solo5,
|
||||||
|
pkg/taps,
|
||||||
|
pkg/preserves,
|
||||||
|
syndicate, syndicate/relays
|
||||||
|
|
||||||
|
acquireDevices([("relay", netBasic)], netAcquireHook)
|
||||||
|
|
||||||
|
type Netif {.preservesRecord: "netif"} = object
|
||||||
|
device, ipAddr: string
|
||||||
|
|
||||||
|
proc spawnNetifActor(turn: Turn; ds: Cap) =
|
||||||
|
spawnActor(turn, "netif") do (turn: Turn):
|
||||||
|
let facet = turn.facet
|
||||||
|
onInterfaceUp do (device: string; ip: IpAddress):
|
||||||
|
run(facet) do (turn: Turn):
|
||||||
|
if not ip.isLinkLocal:
|
||||||
|
discard publish(turn, ds, Netif(device: device, ipAddr: $ip))
|
||||||
|
|
||||||
|
runActor("relay-test") do (turn: Turn):
|
||||||
|
let root = turn.facet
|
||||||
|
onStop(turn) do (turn: Turn):
|
||||||
|
quit()
|
||||||
|
let ds = newDataspace(turn)
|
||||||
|
spawnNetifActor(turn, ds)
|
||||||
|
spawnRelays(turn, ds)
|
||||||
|
var
|
||||||
|
route: Route
|
||||||
|
pr = parsePreserves $solo5_start_info.cmdline
|
||||||
|
if route.fromPreserves pr:
|
||||||
|
echo "parsed route ", route.toPreserves
|
||||||
|
during(turn, ds, Netif?:{1: grab()}) do (ip: string):
|
||||||
|
echo "Acquired address ", ip
|
||||||
|
resolve(turn, ds, route) do (turn: Turn; ds: Cap):
|
||||||
|
echo "route resolved!"
|
||||||
|
echo "stopping root facet"
|
||||||
|
stop(turn, root)
|
|
@ -0,0 +1,3 @@
|
||||||
|
define:ipv6Enabled
|
||||||
|
define:traceSyndicate
|
||||||
|
import:"std/assertions"
|
|
@ -0,0 +1,25 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
import std/times
|
||||||
|
import solo5
|
||||||
|
import syndicate, syndicate/drivers/timers
|
||||||
|
|
||||||
|
acquireDevices()
|
||||||
|
|
||||||
|
runActor("timer-test") do (turn: Turn):
|
||||||
|
let timers = newDataspace(turn)
|
||||||
|
spawnTimerDriver(turn, timers)
|
||||||
|
|
||||||
|
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
|
||||||
|
echo "now in 13th bʼakʼtun"
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 3)) do (turn: Turn):
|
||||||
|
echo "third timer expired"
|
||||||
|
stopActor(turn)
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 1)) do (turn: Turn):
|
||||||
|
echo "first timer expired"
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 2)) do (turn: Turn):
|
||||||
|
echo "second timer expired"
|
|
@ -0,0 +1,2 @@
|
||||||
|
define:ipv6Enabled
|
||||||
|
import:"std/assertions"
|
|
@ -1,8 +1,11 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[asyncdispatch, asyncfile, os, parseopt]
|
import std/[oserrors, parseopt, posix, strutils]
|
||||||
import preserves, syndicate, syndicate/protocols/transportAddress
|
import
|
||||||
|
pkg/sys/[files, handles, ioqueue],
|
||||||
|
pkg/preserves,
|
||||||
|
syndicate, syndicate/relays
|
||||||
|
|
||||||
type
|
type
|
||||||
Present {.preservesRecord: "Present".} = object
|
Present {.preservesRecord: "Present".} = object
|
||||||
|
@ -10,57 +13,64 @@ type
|
||||||
Says {.preservesRecord: "Says".} = object
|
Says {.preservesRecord: "Says".} = object
|
||||||
who, what: string
|
who, what: string
|
||||||
|
|
||||||
proc readStdin(facet: Facet; ds: Cap; username: string) =
|
proc syncAndStop(facet: Facet; cap: Cap) =
|
||||||
let file = openAsync("/dev/stdin")
|
## Stop the actor responsible for `facet` after
|
||||||
onStop(facet) do (turn: var Turn): close(file)
|
## synchronizing with `cap`.
|
||||||
close(stdin)
|
run(facet) do (turn: Turn):
|
||||||
proc readLine() {.gcsafe.} =
|
sync(turn, cap, stopActor)
|
||||||
let future = readLine(file)
|
|
||||||
addCallback(future, facet) do (turn: var Turn):
|
|
||||||
var msg = read(future)
|
|
||||||
message(turn, ds, Says(who: username, what: msg))
|
|
||||||
readLine()
|
|
||||||
readLine()
|
|
||||||
|
|
||||||
proc chat(turn: var Turn; ds: Cap; username: string) =
|
proc readStdin(facet: Facet; ds: Cap; username: string) {.asyncio.} =
|
||||||
during(turn, ds, ?Present) do (who: string):
|
let
|
||||||
|
fd = stdin.getOsFileHandle()
|
||||||
|
flags = fcntl(fd.cint, F_GETFL, 0)
|
||||||
|
if flags < 0:
|
||||||
|
raiseOSError(osLastError())
|
||||||
|
if fcntl(fd.cint, F_SETFL, flags or O_NONBLOCK) < 0:
|
||||||
|
raiseOSError(osLastError())
|
||||||
|
let
|
||||||
|
file = newAsyncFile(FD fd)
|
||||||
|
buf = new string
|
||||||
|
buf[].setLen(0x1000)
|
||||||
|
while true:
|
||||||
|
let n = read(file, buf)
|
||||||
|
if n < 1:
|
||||||
|
stderr.writeLine "test_chat calls stopsActor ", facet.actor
|
||||||
|
syncAndStop(facet, ds)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
var msg = buf[][0..<n].strip
|
||||||
|
proc send(turn: Turn) =
|
||||||
|
message(turn, ds, Says(who: username, what: msg))
|
||||||
|
run(facet, send)
|
||||||
|
|
||||||
|
proc chat(turn: Turn; ds: Cap; username: string) =
|
||||||
|
during(turn, ds, ?:Present) do (who: string):
|
||||||
echo who, " joined"
|
echo who, " joined"
|
||||||
do:
|
do:
|
||||||
echo who, " left"
|
echo who, " left"
|
||||||
|
|
||||||
onMessage(turn, ds, ?Says) do (who: string, what: string):
|
onMessage(turn, ds, ?:Says) do (who: string, what: string):
|
||||||
echo who, ": ", what
|
echo who, ": ", what
|
||||||
|
|
||||||
discard publish(turn, ds, Present(username: username))
|
discard publish(turn, ds, Present(username: username))
|
||||||
readStdin(turn.facet, ds, username)
|
|
||||||
|
discard trampoline:
|
||||||
|
whelp readStdin(turn.facet, ds, username)
|
||||||
|
|
||||||
proc main =
|
proc main =
|
||||||
var
|
var username = ""
|
||||||
transport: Preserve[void]
|
|
||||||
cap: Preserve[Cap]
|
|
||||||
username = getEnv("USER")
|
|
||||||
calledWithArguments = false
|
|
||||||
for kind, key, val in getopt():
|
for kind, key, val in getopt():
|
||||||
calledWithArguments = true
|
|
||||||
if kind == cmdLongOption:
|
if kind == cmdLongOption:
|
||||||
case key
|
case key
|
||||||
of "address", "transport":
|
|
||||||
transport = parsePreserves(val)
|
|
||||||
of "cap", "sturdy":
|
|
||||||
cap = parsePreserves(val, Cap)
|
|
||||||
of "user", "username":
|
of "user", "username":
|
||||||
username = val
|
username = val
|
||||||
|
|
||||||
if calledWithArguments:
|
if username == "":
|
||||||
runActor("chat") do (root: Cap; turn: var Turn):
|
stderr.writeLine "--user: unspecified"
|
||||||
var
|
else:
|
||||||
unixAddr: transportAddress.Unix
|
runActor("chat") do (turn: Turn):
|
||||||
tcpAddr: transportAddress.Tcp
|
resolveEnvironment(turn) do (turn: Turn; ds: Cap):
|
||||||
if fromPreserve(unixAddr, transport):
|
|
||||||
connect(turn, unixAddr, cap) do (turn: var Turn; ds: Cap):
|
|
||||||
chat(turn, ds, username)
|
|
||||||
elif fromPreserve(tcpAddr, transport):
|
|
||||||
connect(turn, tcpAddr, cap) do (turn: var Turn; ds: Cap):
|
|
||||||
chat(turn, ds, username)
|
chat(turn, ds, username)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,36 +1,85 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/unittest
|
import
|
||||||
|
std/[options, tables, unittest],
|
||||||
|
pkg/preserves, syndicate, syndicate/protocols/timer
|
||||||
|
|
||||||
import preserves, syndicate
|
suite "example":
|
||||||
from syndicate/protocols/dataspace import Observe
|
var pat: Pattern
|
||||||
type Observe = dataspace.Observe[Cap]
|
check pat.fromPreserves parsePreserves"""
|
||||||
|
<group <arr> {
|
||||||
|
0: <lit 1>
|
||||||
|
1: <bind <group <arr> {
|
||||||
|
0: <bind <_>>
|
||||||
|
1: <_>
|
||||||
|
}>>
|
||||||
|
2: <_>
|
||||||
|
}>
|
||||||
|
"""
|
||||||
|
|
||||||
import ./test_schema
|
const A = "[1 2 3]"
|
||||||
|
test A:
|
||||||
|
let v = parsePreserves A
|
||||||
test "patterns":
|
check:
|
||||||
let observerPat = ?Observe(pattern: !Foo) ?? {0: grab()}
|
not pat.matches(v)
|
||||||
check($observerPat == """<rec Observe [<rec rec [<lit foo> <arr [<bind <_>> <_> <_>]>]> <_>]>""")
|
|
||||||
|
|
||||||
|
const B = "[1 [2 3] 4]"
|
||||||
|
test B:
|
||||||
let
|
let
|
||||||
value = @["alles", "in", "ordnung"]
|
v = parsePreserves B
|
||||||
observer = toPreserve(Observe(pattern: inject(?Foo, { 0: ?value })), Cap)
|
c = parsePreserves "[[2 3] 2]"
|
||||||
have = capture(observerPat, observer).toPreserve(Cap).unpackLiterals
|
check pat.matches(v)
|
||||||
want = [value.toPreserve(Cap)].toPreserve(Cap)
|
check pat.capture(v).toPreserves == c
|
||||||
check(have == want)
|
|
||||||
|
|
||||||
type Record {.preservesDictionary.} = object
|
const C = "[1 [2] 5]"
|
||||||
a, b, c: int
|
test C:
|
||||||
|
let v = parsePreserves C
|
||||||
|
check:
|
||||||
|
not pat.matches(v)
|
||||||
|
|
||||||
test "dictionaries":
|
const D = "[1 [2 3 4] 5]"
|
||||||
let pat = ?Record
|
test D:
|
||||||
echo pat
|
let
|
||||||
var source = initDictionary(Cap)
|
v = parsePreserves D
|
||||||
source["b".toSymbol(Cap)] = 2.toPreserve(Cap)
|
c = parsePreserves "[[2 3 4] 2]"
|
||||||
source["c".toSymbol(Cap)] = 3.toPreserve(Cap)
|
check pat.matches(v)
|
||||||
source["a".toSymbol(Cap)] = 1.toPreserve(Cap)
|
check pat.capture(v).toPreserves == c
|
||||||
|
|
||||||
let values = capture(pat, source)
|
const E = "[1 [<x> <y>] []]"
|
||||||
check $values == "@[1, 2, 3]"
|
test E:
|
||||||
|
let
|
||||||
|
v = parsePreserves E
|
||||||
|
c = parsePreserves "[[<x> <y>] <x>]"
|
||||||
|
check pat.matches(v)
|
||||||
|
check pat.capture(v).toPreserves == c
|
||||||
|
|
||||||
|
suite "meta":
|
||||||
|
|
||||||
|
test "pattern-of-pattern":
|
||||||
|
let
|
||||||
|
pat = matchRecord("foo".toSymbol, matchDictionary({666.toPreserves: drop()}))
|
||||||
|
meta = pat.toPreserves.drop()
|
||||||
|
check $meta == "<group <rec group> {0: <group <rec rec> {0: <lit foo>}> 1: <group <dict> {0: <group <rec group> {0: <group <rec dict> {}> 1: <group <dict> {666: <_>}>}>}>}>"
|
||||||
|
|
||||||
|
test "observe":
|
||||||
|
let
|
||||||
|
val = Observe(pattern: LaterThan ?: {0: drop 12.24}).toPreserves
|
||||||
|
pat = grab(val)
|
||||||
|
check pat.matches(val)
|
||||||
|
check pat.capture(val) == @[val]
|
||||||
|
let
|
||||||
|
meta = observePattern(!LaterThan, {@[0.toPreserves]: grabLit()})
|
||||||
|
res = parsePreserves "[12.24]"
|
||||||
|
check meta.matches(val)
|
||||||
|
check meta.capture(val).toPreserves == res
|
||||||
|
|
||||||
|
test "connect-transport":
|
||||||
|
let pat = parsePreserves"""
|
||||||
|
<group <rec connect-transport> {0: <group <rec unix> {0: <lit "/run/user/1000/dataspace">}> 2: <group <rec accepted> {0: <bind <_>>}>}>
|
||||||
|
""".preservesTo(Pattern).get
|
||||||
|
let val = parsePreserves"""
|
||||||
|
<connect-transport <unix "/run/user/1000/dataspace"> #:#f <accepted #:#f>>
|
||||||
|
"""
|
||||||
|
check pat.matches(val)
|
||||||
|
check pat.capture(val).toPreserves == parsePreserves "[#:#f]"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import std/[streams, strutils, unittest]
|
import
|
||||||
|
std/[streams, strutils, unittest],
|
||||||
|
pkg/preserves,
|
||||||
|
syndicate/relays,
|
||||||
|
syndicate/protocols/sturdy
|
||||||
|
|
||||||
import preserves
|
type WireRef = sturdy.WireRef
|
||||||
import syndicate/relays
|
|
||||||
import syndicate/protocols/[protocol, sturdy]
|
|
||||||
|
|
||||||
type WireRef = sturdy.WireRef[void]
|
|
||||||
|
|
||||||
suite "protocols":
|
suite "protocols":
|
||||||
test "PDiscard":
|
test "PDiscard":
|
||||||
|
@ -20,9 +20,9 @@ suite "protocols":
|
||||||
var pos = str.getPosition
|
var pos = str.getPosition
|
||||||
echo "decode position: ", pos
|
echo "decode position: ", pos
|
||||||
try:
|
try:
|
||||||
var a = decodePreserves(str, WireRef)
|
var a = decodePreserves(str)
|
||||||
echo a
|
echo a
|
||||||
except:
|
except CatchableError:
|
||||||
str.setPosition pos
|
str.setPosition pos
|
||||||
echo str.readAll.toHex
|
echo str.readAll.toHex
|
||||||
break
|
break
|
||||||
|
|
|
@ -9,7 +9,7 @@ type
|
||||||
`z`*: BiggestInt
|
`z`*: BiggestInt
|
||||||
|
|
||||||
proc `$`*(x: Foo): string =
|
proc `$`*(x: Foo): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
proc encode*(x: Foo): seq[byte] =
|
proc encode*(x: Foo): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserves(x))
|
||||||
|
|
|
@ -1,17 +1,34 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/times
|
import
|
||||||
import syndicate, syndicate/actors/timers
|
std/times,
|
||||||
|
pkg/preserves,
|
||||||
|
syndicate, syndicate/drivers/timers
|
||||||
|
|
||||||
proc now: float64 = getTime().toUnixFloat()
|
var passCount = 0
|
||||||
|
|
||||||
runActor("test_timers") do (ds: Cap; turn: var Turn):
|
runActor("timer-test") do (turn: Turn):
|
||||||
onPublish(turn, ds, ?LaterThan(seconds: now()+1.0)) do:
|
let timers = newDataspace(turn)
|
||||||
stderr.writeLine "slept one second once"
|
spawnTimerDriver(turn, timers)
|
||||||
onPublish(turn, ds, ?LaterThan(seconds: now()+1.0)) do:
|
|
||||||
stderr.writeLine "slept one second twice"
|
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
|
||||||
onPublish(turn, ds, ?LaterThan(seconds: now()+1.0)) do:
|
echo "now in 13th bʼakʼtun"
|
||||||
stderr.writeLine "slept one second thrice"
|
inc passCount
|
||||||
quit()
|
|
||||||
spawnTimers(turn, ds)
|
after(turn, timers, initDuration(seconds = 3)) do (turn: Turn):
|
||||||
|
echo "third timer expired"
|
||||||
|
assert passCount == 3
|
||||||
|
inc passCount
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 1)) do (turn: Turn):
|
||||||
|
echo "first timer expired"
|
||||||
|
assert passCount == 1
|
||||||
|
inc passCount
|
||||||
|
|
||||||
|
after(turn, timers, initDuration(seconds = 2)) do (turn: Turn):
|
||||||
|
echo "second timer expired"
|
||||||
|
assert passCount == 2
|
||||||
|
inc passCount
|
||||||
|
|
||||||
|
doAssert passCount == 4, $passCount
|
||||||
|
|
Loading…
Reference in New Issue