aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/synthesis/function.lux
blob: 52aee9a49017f91c67fef04b6ba52564347cf9f1 (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
(;module:
  lux
  (luxc (lang ["la" analysis]
              ["ls" synthesis]
              [";L" variable #+ Variable])))

(do-template [<name> <comp> <ref>]
  [(def: #export (<name> arity)
     (-> ls;Arity Bool)
     (<comp> <ref> arity))]

  [nested? n.> +1]
  [top?    n.= +0]
  )

(def: #export (adjust-var outer var)
  (-> ls;Arity Variable Variable)
  (|> outer n.dec nat-to-int (i.+ var)))

(def: #export (unfold-apply apply)
  (-> la;Analysis [la;Analysis (List la;Analysis)])
  (loop [apply apply
         args (list)]
    (case apply
      (^code ("lux apply" (~ arg) (~ func)))
      (recur func (#;Cons arg args))

      _
      [apply args])))