aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/procedure.jvm.lux
blob: cd57576638f868d939c49ef2a7bb262818896caa (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
  (lux (control [monad #+ do]
                ["ex" exception #+ exception:])
       (data [maybe]
             text/format
             (coll (dictionary ["dict" unordered #+ Dict]))))
  (luxc ["&" lang]
        (lang ["ls" synthesis]
              (host [js #+ JS Expression Statement])))
  [//]
  (/ ["/." common]
     ["/." host]))

(exception: #export (Unknown-Procedure {message Text})
  message)

(def: procedures
  /common.Bundle
  (|> /common.procedures
      (dict.merge /host.procedures)))

(def: #export (translate-procedure translate name args)
  (-> (-> ls.Synthesis (Meta Expression)) Text (List ls.Synthesis)
      (Meta Expression))
  (<| (maybe.default (&.throw Unknown-Procedure (%t name)))
      (do maybe.Monad<Maybe>
        [proc (dict.get name procedures)]
        (wrap (proc translate args)))))