aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control/security/capability.lux
blob: 82b7a9a867dbddeaf71f80b7e8bb29bc31fb0a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(.using
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" io (.only IO)]
    ["<>" parser (.only)
     ["<c>" code]]
    [concurrency
     ["[0]" async (.only Async)]]]
   [data
    [text
     ["%" format (.only format)]]
    [collection
     ["[0]" list (.open: "[1]#[0]" functor)]]]
   [type
    [primitive (.except)]]
   ["[0]" meta]
   ["[0]" macro (.only)
    ["[0]" code]
    [syntax (.only syntax:)
     ["|[0]|" export]
     ["|[0]|" declaration]]]]])

(primitive: .public (Capability brand input output)
  (-> input output)

  (def: capability
    (All (_ brand input output)
      (-> (-> input output)
          (Capability brand input output)))
    (|>> abstraction))

  (def: .public (use capability input)
    (All (_ brand input output)
      (-> (Capability brand input output)
          input
          output))
    ((representation capability) input))

  (syntax: .public (capability: [[export_policy declaration [forger input output]]
                                 (|export|.parser
                                  (all <>.and
                                       |declaration|.parser
                                       (<c>.form (all <>.and <c>.local <c>.any <c>.any))))])
    (macro.with_symbols [g!_]
      (do [! meta.monad]
        [this_module meta.current_module_name
         .let [[name vars] declaration]
         g!brand (# ! each (|>> %.code code.text)
                    (macro.symbol (format (%.symbol [this_module name]))))
         .let [capability (` (..Capability (.Primitive (~ g!brand)) (~ input) (~ output)))]]
        (in (list (` (type: (~ export_policy)
                       (~ (|declaration|.format declaration))
                       (~ capability)))
                  (` (def: (~ (code.local forger))
                       (All ((~ g!_) (~+ (list#each code.local vars)))
                         (-> (-> (~ input) (~ output))
                             (~ capability)))
                       (~! ..capability)))
                  )))))

  (def: .public (async capability)
    (All (_ brand input output)
      (-> (Capability brand input (IO output))
          (Capability brand input (Async output))))
    (..capability (|>> ((representation capability)) async.future)))
  )