aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/bytecode/environment/limit.lux
blob: 3cda1e1f1329787205417eb607eb21368b904b43 (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
(.require
 [library
  [lux (.except Type static)
   [abstract
    [monad (.only do)]
    [equivalence (.only Equivalence)]]
   [control
    ["[0]" try (.only Try)]]
   [data
    ["[0]" product]
    [binary
     ["[0]" \\format (.only Writer) (.use "[1]#[0]" monoid)]]]
   [math
    [number
     ["n" nat]]]]]
 ["[0]" /
  ["[1][0]" stack (.only Stack)]
  ["[1][0]" registry (.only Registry)]
  [////
   [type (.only Type)
    [category (.only Method)]]]])

(type: .public Limit
  (Record
   [#stack Stack
    #registry Registry]))

(with_template [<name> <registry>]
  [(def .public (<name> type)
     (-> (Type Method) (Try Limit))
     (do try.monad
       [registry (<registry> type)]
       (in [#stack /stack.empty
            #registry registry])))]

  [static /registry.static]
  [virtual /registry.virtual]
  )

(def .public length
  (all n.+
       ... u2 max_stack;
       /stack.length
       ... u2 max_locals;
       /registry.length))

(def .public equivalence
  (Equivalence Limit)
  (all product.equivalence
       /stack.equivalence
       /registry.equivalence
       ))

(def .public (writer limit)
  (Writer Limit)
  (all \\format#composite
       (/stack.writer (the #stack limit))
       (/registry.writer (the #registry limit))
       ))