tobogganSe connecter

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 runEn cours#127 · main
0Étoiles
0Forks
40Issues
64 lignes · 1609 octetsBrut · Historique
1// All five instanced roots on one entry (proc/clock/random/fs/net), followed by
2// a wide general closure call with a Show dictionary and user arguments beyond
3// the fixed registers. The run test executes it on both backends; the codegen
4// wide_calls test inspects the entry tags and spill slots too.
5
6import std/file.{type fs}
7import std/io
8import std/list
9import std/net.{type net, connect_to, listen_at, resolve}
10import std/process.{type proc}
11import std/random.{type random}
12import std/time.{type clock}
13
14fn wide ::
15 label: a
16 p0: Int
17 p1: Int
18 p2: Int
19 p3: Int
20 p4: Int
21 p5: Int
22 p6: Int
23 p7: Int
24 -> String
25 where Show<a>
26{
27 show label <> ":" <> show (p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7)
28}
29
30fn with_fake_net :: action: fn() -> a / <net | e> -> a / <e>
31{
32 handle
33 {
34 action ()
35 }
36 with
37 { resolve _ -> Ok(["192.0.2.1"])
38 , listen_at _ _ -> Error("wide fake: no listener was opened")
39 , connect_to _ _ -> Error("wide fake: no connection was opened")
40 }
41}
42
43pub fn main :: -> () / <proc, clock, random, fs, net, io>
44{
45 let _ = process.self ()
46 let _ = time.monotonic ()
47 let _ = random.bytes 1
48 io.println "fs root: {file.exists "/definitely/not/a/louise/capability/file"}"
49 with_fake_net
50 fn
51 {
52 match list.reverse [wide]
53 { [f] -> io.println "wide: {f "roots" 1 2 3 4 5 6 7 8}"
54 , _ -> panic "wide closure missing"
55 }
56 match net.listen "fixture-no-os-call" 0
57 { Ok(_) -> panic "a fake cannot forge a listener"
58 , Error(e) -> io.println e
59 }
60 }
61}
62//> fs root: False
63//> wide: roots:36
64//> wide fake: no listener was opened