aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/ffi/export.js.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/ffi/export.js.lux')
-rw-r--r--stdlib/source/library/lux/ffi/export.js.lux96
1 files changed, 96 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/ffi/export.js.lux b/stdlib/source/library/lux/ffi/export.js.lux
new file mode 100644
index 000000000..a73437f72
--- /dev/null
+++ b/stdlib/source/library/lux/ffi/export.js.lux
@@ -0,0 +1,96 @@
+(.using
+ [library
+ [lux "*"
+ [extension {"+" directive:}]
+ ["[0]" meta]
+ ["[0]" static]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["<>" parser
+ ["<[0]>" code]]]
+ [data
+ [text
+ ["%" format]]
+ [collection
+ ["[0]" list ("[1]#[0]" monad mix)]
+ ["[0]" set]]]
+ ["[0]" macro
+ [syntax {"+" syntax:}]
+ ["[0]" code]]
+ [math
+ ["[0]" random]]
+ [target
+ ["/" js]]
+ [tool
+ [compiler
+ ["[0]" phase]
+ [meta
+ [cache
+ ["[0]" dependency "_"
+ ["[1]" artifact]]]]
+ [language
+ [lux
+ ["[0]" generation]
+ ["[0]" directive]
+ [analysis
+ ["[0]" type]]]]]]]])
+
+(def: definition
+ (-> Code (Meta [Text Code]))
+ (|>> (list)
+ (<code>.result (<| <code>.form
+ (<>.after (<code>.text! "lux def"))
+ (<>.before <code>.any)
+ ($_ <>.and
+ <code>.local_symbol
+ <code>.any)))
+ meta.lifted))
+
+(with_expansions [<extension> (static.random (|>> %.nat (%.format "lua export ") code.text)
+ random.nat)]
+ (directive: (<extension> self phase archive [name <code>.text
+ term <code>.any])
+ (do [! phase.monad]
+ [next directive.analysis
+ [_ term] (<| directive.lifted_analysis
+ type.inferring
+ (next archive term))
+
+ next directive.synthesis
+ term (directive.lifted_synthesis
+ (next archive term))
+
+ dependencies (directive.lifted_generation
+ (dependency.dependencies archive term))
+
+ next directive.generation
+ [interim_artifacts term] (directive.lifted_generation
+ (generation.with_interim_artifacts archive
+ (next archive term)))
+
+ _ (directive.lifted_generation
+ (do !
+ [@self (generation.learn_custom name (list#mix set.has dependencies interim_artifacts))
+ .let [$module (/.var "module")
+ $exports (/.the "exports" $module)
+ definition (/.define (/.var name) term)
+ export (/.when (/.not (/.= (/.string "undefined") (/.type_of $module)))
+ (/.set (/.the name $exports) (/.var name)))
+ code ($_ /.then
+ definition
+ export)]
+ _ (generation.execute! definition)
+ _ (generation.save! @self {.#None} code)]
+ (generation.log! (%.format "Export " (%.text name)))))]
+ (in directive.no_requirements)))
+
+ (syntax: .public (export: [exports (<>.many <code>.any)])
+ (let [! meta.monad]
+ (|> exports
+ (monad.each ! macro.expansion)
+ (# ! each (|>> list#conjoint
+ (monad.each ! ..definition)))
+ (# ! conjoint)
+ (# ! each (list#each (function (_ [name term])
+ (` (<extension> (~ (code.text name)) (~ term))))))))))