aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/debug.lux
blob: 65c1412832cf8a34cd629cd0ef31ec1904543d7d (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
(.module:
  [library
   [lux #*
    [abstract
     [monad (#+ do)]]
    [control
     ["." io (#+ IO)]
     ["." try (#+ Try)]]
    [data
     [binary (#+ Binary)]
     [text
      ["%" format (#+ format)]]]
    [world
     ["." file (#+ File)]]]])

(def: extension ".class")

(def: #export (write-class! name bytecode)
  (-> Text Binary (IO Text))
  (let [file-path (format name ..extension)]
    (do io.monad
      [outcome (do (try.with @)
                 [file (: (IO (Try (File IO)))
                          (file.get-file io.monad file.default file-path))]
                 (\ file over-write bytecode))]
      (wrap (case outcome
              (#try.Success definition)
              file-path

              (#try.Failure error)
              error)))))