aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/ffi/export.py.lux
blob: faf492f1e13e688174d7886980ff9c95dae48181 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(.require
 [library
  [lux (.except)
   [abstract
    ["[0]" monad (.only do)]]
   [control
    ["<>" parser]]
   [data
    [text
     ["%" \\format]]
    [collection
     ["[0]" list (.use "[1]#[0]" monad mix)]
     ["[0]" set]]]
   ["[0]" meta (.only)
    [extension (.only declaration)]
    ["[0]" code (.only)
     ["<[1]>" \\parser]]
    [macro
     [syntax (.only syntax)]
     ["[0]" expansion]]
    [target
     ["/" python]]
    [compiler
     [meta
      [cache
       ["[0]" dependency
        ["[1]" artifact]]]]
     [language
      [lux
       ["[0]" phase]
       ["[0]" translation]
       ["[0]" declaration]
       [analysis
        ["[0]" type]]]]]]]])

(def definition
  (-> Code (Meta [Text Code]))
  (|>> (list)
       (<code>.result (<| <code>.form
                          (<>.after (<code>.this_symbol (symbol .def#)))
                          (<>.before <code>.any)
                          (all <>.and
                               <code>.local
                               <code>.any)))
       meta.of_try))

(def .public export_one
  (declaration (_ phase archive [name <code>.text
                                 term <code>.any])
    (do [! phase.monad]
      [next declaration.analysis
       [_ term] (<| declaration.of_analysis
                    type.inferring
                    (next archive term))

       lux (declaration.of_analysis meta.compiler_state)
       next declaration.synthesis
       term (declaration.of_synthesis
             (next lux archive term))

       dependencies (declaration.of_translation
                     (dependency.dependencies archive term))

       next declaration.translation
       [interim_artifacts term] (declaration.of_translation
                                 (translation.with_interim_artifacts archive
                                   (next lux archive term)))

       _ (declaration.of_translation
          (do !
            [@self (translation.learn_custom name (list#mix set.has dependencies interim_artifacts))
             .let [code (/.set (list (/.item (/.string name) /.globals/0)) term)]
             _ (translation.execute! code)
             _ (translation.save! @self {.#None} code)]
            (translation.log! (%.format "Export " (%.text name)))))]
      (in declaration.no_requirements))))

(def .public export
  (syntax (_ [exports (<>.many <code>.any)])
    (let [! meta.monad]
      (|> exports
          (monad.each ! expansion.complete)
          (of ! each (|>> list#conjoint
                          (monad.each ! ..definition)))
          (of ! conjoint)
          (of ! each (list#each (function (_ [name term])
                                  (` (..export_one (, (code.text name)) (, term))))))))))