louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // `std/dist`'s typing roots (ADR 0072): a `Name<m>` exists only for a |
| 2 | // message type that can cross hosts, `register` and `whereis` keep the |
| 3 | // subject's type the name's, and `spawn_on`'s argument is its `@remote` |
| 4 | // function's. |
| 5 | |
| 6 | import std/dist.{type DistError, type Name, type Remote} |
| 7 | import std/process.{type Pid, type Subject, type proc} |
| 8 | |
| 9 | type Counter { Add(Int), Get(Subject<Int>) } |
| 10 | |
| 11 | type Job { Job(run: fn() -> Int) } |
| 12 | |
| 13 | fn named :: -> Name<Counter> |
| 14 | { |
| 15 | dist.name "counter" |
| 16 | } |
| 17 | |
| 18 | fn a_function_cannot_cross :: -> Name<fn() -> ()> |
| 19 | { |
| 20 | dist.name "f" //~ ERROR E0706 a function's code |
| 21 | } |
| 22 | |
| 23 | fn nor_a_field_of_one :: -> Name<Job> |
| 24 | { |
| 25 | dist.name "job" |
| 26 | //~^ ERROR E0706 `Job` has a field `run` that cannot cross hosts |
| 27 | } |
| 28 | |
| 29 | fn nor_a_reply_of_one :: -> Name<Subject<fn() -> ()>> |
| 30 | { |
| 31 | dist.name "replies" |
| 32 | //~^ ERROR E0706 a `Subject`'s messages must cross hosts too |
| 33 | } |
| 34 | |
| 35 | fn registered :: s: Subject<Counter> -> Result<(), DistError> / <io> |
| 36 | { |
| 37 | dist.register (named ()) s |
| 38 | } |
| 39 | |
| 40 | fn of_another_type :: s: Subject<Int> -> Result<(), DistError> / <io> |
| 41 | { |
| 42 | dist.register |
| 43 | (named ()) |
| 44 | s //~ ERROR E0202 expected `Subject<Counter>`, found `Subject<Int>` |
| 45 | } |
| 46 | |
| 47 | fn found :: -> Result<Subject<Counter>, DistError> / <proc, io> |
| 48 | { |
| 49 | dist.whereis (named ()) "node-b.cluster.example" 1000 |
| 50 | } |
| 51 | |
| 52 | // The name is opaque: only `dist.name` makes one. |
| 53 | fn forged :: -> Name<Counter> |
| 54 | { |
| 55 | dist.Name("counter") //~ ERROR E0117 `Name` is opaque |
| 56 | } |
| 57 | |
| 58 | @remote |
| 59 | fn worker :: counter: Subject<Counter> -> () / <proc> |
| 60 | { |
| 61 | process.send counter Add(1) |
| 62 | } |
| 63 | |
| 64 | fn spawned :: c: Subject<Counter> -> Result<Pid, DistError> / <proc, io> |
| 65 | { |
| 66 | dist.spawn_on "node-b.cluster.example" worker c 1000 |
| 67 | } |
| 68 | //~ TYPE spawned: fn(Subject<Counter>) -> Result<Pid, DistError> / <proc, io> |
| 69 | |
| 70 | // `dist.Remote` is `std/dist/remote`'s. |
| 71 | fn entry :: -> Remote<Subject<Counter>> |
| 72 | { |
| 73 | worker |
| 74 | } |
| 75 | |
| 76 | fn with_another_argument :: -> Result<Pid, DistError> / <proc, io> |
| 77 | { |
| 78 | dist.spawn_on "node-b.cluster.example" worker 42 1000 |
| 79 | //~^ ERROR E0202 expected `Subject<Counter>`, found `Int` |
| 80 | } |
| 81 | |
| 82 | fn through_a_reference :: c: Subject<Int> -> Result<Pid, DistError> / <proc, io> |
| 83 | { |
| 84 | dist.spawn_on "node-b.cluster.example" (entry ()) c 1000 |
| 85 | //~^ ERROR E0202 expected `Subject<Counter>`, found `Subject<Int>` |
| 86 | } |