aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/bytecode/environment/limit/registry.lux
blob: ddc600162a160e6fc410bf991c988fdff1bae0d1 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(.module:
  [library
   [lux (#- Type for static)
    [abstract
     ["." equivalence (#+ Equivalence)]]
    [control
     ["." try (#+ Try) ("#\." functor)]]
    [data
     [format
      [binary (#+ Writer)]]
     [collection
      ["." list ("#\." functor fold)]]]
    [math
     [number
      ["n" nat]]]
    [type
     abstract]]]
  ["." ///// #_
   [encoding
    ["#." unsigned (#+ U1 U2)]]
   ["#." type (#+ Type)
    [category (#+ Method)]
    ["#/." parser]]])

(type: .public Register U1)

(def: normal 1)
(def: wide 2)

(abstract: .public Registry
  {}
  
  U2

  (def: .public registry
    (-> U2 Registry)
    (|>> :abstraction))

  (def: (minimal type)
    (-> (Type Method) Nat)
    (let [[type_variables inputs output exceptions] (/////type/parser.method type)]
      (|> inputs
          (list\map (function (_ input)
                      (if (or (same? /////type.long input)
                              (same? /////type.double input))
                        ..wide
                        ..normal)))
          (list\fold n.+ 0))))

  (template [<start> <name>]
    [(def: .public <name>
       (-> (Type Method) (Try Registry))
       (|>> ..minimal
            (n.+ <start>)
            /////unsigned.u2
            (try\map ..registry)))]

    [0 static]
    [1 virtual]
    )

  (def: .public equivalence
    (Equivalence Registry)
    (\ equivalence.functor map
       (|>> :representation)
       /////unsigned.equivalence))

  (def: .public writer
    (Writer Registry)
    (|>> :representation /////unsigned.writer/2))

  (def: .public (has needed)
    (-> Registry Registry Registry)
    (|>> :representation
         (/////unsigned.max/2 (:representation needed))
         :abstraction))

  (template [<name> <extra>]
    [(def: .public <name>
       (-> Register Registry)
       (let [extra (|> <extra> /////unsigned.u2 try.assumed)]
         (|>> /////unsigned.lift/2
              (/////unsigned.+/2 extra)
              try.assumed
              :abstraction)))]

    [for ..normal]
    [for_wide ..wide]
    )
  )

(def: .public length
  /////unsigned.bytes/2)