aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/compiler/default/reference.lux
blob: 0bbeb2db53cfdc083c2e3d752c4ea72d2b5bcaf9 (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
(.module:
  [lux #*
   [control
    [equivalence (#+ Equivalence)]
    [hash (#+ Hash)]
    pipe]])

(type: #export Register Nat)

(type: #export Variable
  (#Local Register)
  (#Foreign Register))

(type: #export Reference
  (#Variable Variable)
  (#Constant Name))

(structure: #export _ (Equivalence Variable)
  (def: (= reference sample)
    (case [reference sample]
      (^template [<tag>]
        [(<tag> reference') (<tag> sample')]
        (n/= reference' sample'))
      ([#Local] [#Foreign])

      _
      #0)))

(structure: #export _ (Hash Variable)
  (def: eq Equivalence<Variable>)
  (def: (hash var)
    (case var
      (#Local register)
      (n/* 1 register)
      
      (#Foreign register)
      (n/* 2 register))))

(do-template [<name> <family> <tag>]
  [(template: #export (<name> content)
     (<| <family>
         <tag>
         content))]

  [local   #..Variable #..Local]
  [foreign #..Variable #..Foreign]
  )

(do-template [<name> <tag>]
  [(template: #export (<name> content)
     (<| <tag>
         content))]

  [variable #..Variable]
  [constant #..Constant]
  )

(def: #export self Reference (..local 0))

(def: #export self?
  (-> Variable Bit)
  (|>> ..variable
       (case> (^ (..local 0))
              #1

              _
              #0)))