aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library')
-rw-r--r--stdlib/source/library/lux/target/lua.lux7
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux52
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux6
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux62
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux2
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux4
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/packager/script.lux85
7 files changed, 114 insertions, 104 deletions
diff --git a/stdlib/source/library/lux/target/lua.lux b/stdlib/source/library/lux/target/lua.lux
index 12885861e..72324192f 100644
--- a/stdlib/source/library/lux/target/lua.lux
+++ b/stdlib/source/library/lux/target/lua.lux
@@ -1,6 +1,6 @@
(.using
[library
- [lux {"-" Location Code Label int if cond function or and not let ^ local}
+ [lux {"-" Location Code Label int if cond function or and not let ^ local comment}
["@" target]
[abstract
[equivalence {"+" Equivalence}]
@@ -365,6 +365,11 @@
(def: .public (go_to label)
(-> Label Statement)
(:abstraction (format "goto " (:representation label))))
+
+ ... https://www.lua.org/pil/1.3.html
+ (def: .public (comment commentary on)
+ (All (_ kind) (-> Text (Code kind) (Code kind)))
+ (:abstraction (format "-- " commentary \n+ (:representation on))))
)
(def: .public (cond clauses else!)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux
index 82be19890..988b31f55 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux
@@ -114,38 +114,26 @@
(<s>.tuple (<>.many <s>.i64))
<s>.any))))
(function (_ extension_name phase archive [input else conditionals])
- (do [! /////.monad]
- [inputG (phase archive input)
- else! (..statement phase archive else)
- @input (# ! each _.var (generation.symbol "input"))
- conditionals! (: (Operation (List [Expression Statement]))
- (monad.each ! (function (_ [chars branch])
- (do !
- [branch! (..statement phase archive branch)]
- (in [(|> chars
- (list#each (|>> .int _.int (_.= @input)))
- (list#mix (function (_ clause total)
- (if (same? _.nil total)
- clause
- (_.or clause total)))
- _.nil))
- branch!])))
- conditionals))
- ... .let [closure (_.closure (list @input)
- ... (list#mix (function (_ [test then] else)
- ... (_.if test (_.return then) else))
- ... (_.return elseG)
- ... conditionalsG))]
- ]
- ... (in (_.apply/1 closure inputG))
- (in (<| (:as Expression)
- (: Statement)
- ($_ _.then
- (_.set (list @input) inputG)
- (list#mix (function (_ [test then!] else!)
- (_.if test then! else!))
- else!
- conditionals!))))))]))
+ (|> conditionals
+ (list#each (function (_ [chars branch])
+ {synthesis.#Seq (case chars
+ {.#End}
+ {synthesis.#Pop}
+
+ {.#Item head tail}
+ {synthesis.#I64_Fork
+ [head {synthesis.#Pop}]
+ (list#each (function (_ char)
+ [char {synthesis.#Pop}])
+ tail)})
+ {synthesis.#Then branch}}))
+ list.reversed
+ (list#mix (function (_ pre post)
+ {synthesis.#Alt pre post})
+ {synthesis.#Then else})
+ [input]
+ (//case.case! statement phase archive)
+ (# /////.monad each (|>> (:as Expression)))))]))
(def: lux_procs
Bundle
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux
index 5b5d0be04..649692ccc 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux
@@ -26,6 +26,9 @@
["//[1]" /// "_"
[arity {"+" Arity}]
["[1][0]" phase ("[1]#[0]" monad)]
+ [meta
+ [archive
+ ["[0]" dependency]]]
[reference
[variable {"+" Register Variable}]]]]]])
@@ -66,7 +69,8 @@
(def: .public (function statement expression archive [environment arity bodyS])
(-> Phase! (Generator (Abstraction Synthesis)))
(do [! ///////phase.monad]
- [[function_name body!] (/////generation.with_new_context archive
+ [dependencies (dependency.dependencies archive bodyS)
+ [function_name body!] (/////generation.with_new_context archive dependencies
(do !
[@scope (# ! each ..@scope
(/////generation.context archive))]
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux
index 2bc8a7868..c58a5d476 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux
@@ -1,34 +1,35 @@
(.using
- [library
- [lux {"-" Label Scope}
- [abstract
- ["[0]" monad {"+" do}]]
- [data
- ["[0]" product]
- [text
- ["%" format {"+" format}]]
- [collection
- ["[0]" list ("[1]#[0]" functor)]
- ["[0]" set]]]
- [math
- [number
- ["n" nat]]]
- [target
- ["_" lua {"+" Var Expression Label Statement}]]]]
- ["[0]" // "_"
- [runtime {"+" Operation Phase Phase! Generator Generator!}]
- ["[1][0]" case]
- ["/[1]" // "_"
- ["[1][0]" reference]
+ [library
+ [lux {"-" Label Scope}
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [data
+ ["[0]" product]
+ [text
+ ["%" format {"+" format}]]
+ [collection
+ ["[0]" list ("[1]#[0]" functor)]
+ ["[0]" set]]]
+ [math
+ [number
+ ["n" nat]]]
+ [target
+ ["_" lua {"+" Var Expression Label Statement}]]]]
+ ["[0]" // "_"
+ [runtime {"+" Operation Phase Phase! Generator Generator!}]
+ ["[1][0]" case]
+ ["/[1]" // "_"
+ ["[1][0]" reference]
+ ["//[1]" /// "_"
+ ["[0]"synthesis {"+" Scope Synthesis}]
+ ["[1][0]" generation]
["//[1]" /// "_"
- ["[0]"synthesis {"+" Scope Synthesis}]
- ["[1][0]" generation]
- ["//[1]" /// "_"
- ["[1][0]" phase]
- [meta
- [archive {"+" Archive}]]
- [reference
- [variable {"+" Register}]]]]]])
+ ["[1][0]" phase]
+ [meta
+ [archive {"+" Archive}
+ ["[0]" dependency]]]
+ [reference
+ [variable {"+" Register}]]]]]])
(def: @scope
(-> Nat Label)
@@ -81,7 +82,8 @@
... true loop
_
(do [! ///////phase.monad]
- [[[artifact_module artifact_id] [initsO+ scope!]] (/////generation.with_new_context archive
+ [dependencies (dependency.dependencies archive bodyS)
+ [[artifact_module artifact_id] [initsO+ scope!]] (/////generation.with_new_context archive dependencies
(scope! statement expression archive true [start initsS+ bodyS]))
.let [@loop (_.var (///reference.artifact [artifact_module artifact_id]))
locals (|> initsO+
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux
index 087f3e146..f20a6cb12 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux
@@ -428,7 +428,7 @@
[_ (/////generation.execute! ..runtime)
_ (/////generation.save! ..module_id {.#None} ..runtime)]
(in [(|> artifact.empty
- artifact.resource
+ (artifact.resource true artifact.no_dependencies)
product.right)
(sequence.sequence [..module_id
{.#None}
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux
index 9ca68013e..e93e347e1 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux
@@ -51,7 +51,9 @@
["[0]" frac]]]]])
(template: (inline: <declaration> <type> <body>)
- [(for [@.python (def: <declaration> <type> <body>)]
+ [(for [@.python (def: <declaration> <type> <body>)
+ ... TODO: No longer skip inlining Lua after Rembulan isn't being used anymore.
+ @.lua (def: <declaration> <type> <body>)]
(template: <declaration> [<body>]))])
... TODO: Implement "lux syntax char case!" as a custom extension.
diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux
index 3f5e2dd61..7d6954d1a 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux
@@ -1,45 +1,50 @@
(.using
- [library
- [lux "*"
- [type {"+" :sharing}]
- [abstract
- ["[0]" monad {"+" Monad do}]]
- [control
- ["[0]" try {"+" Try}]]
- [data
- [binary {"+" Binary}]
- ["[0]" product]
- [text
- ["%" format {"+" format}]
- [encoding
- ["[0]" utf8]]]
- [collection
- ["[0]" sequence]
- ["[0]" list ("[1]#[0]" functor)]]]]]
- [program
- [compositor
- ["[0]" static {"+" Static}]]]
- ["[0]" // {"+" Packager}
+ [library
+ [lux "*"
+ [type {"+" :sharing}]
+ [abstract
+ ["[0]" monad {"+" Monad do}]]
+ [control
+ ["[0]" try {"+" Try}]]
+ [data
+ [binary {"+" Binary}]
+ ["[0]" product]
+ [text
+ ["%" format {"+" format}]
+ [encoding
+ ["[0]" utf8]]]
+ [collection
+ ["[0]" sequence]
+ ["[0]" set {"+" Set}]
+ ["[0]" list ("[1]#[0]" functor)]]]]]
+ [program
+ [compositor
+ ["[0]" static {"+" Static}]]]
+ ["[0]" // {"+" Packager}
+ [//
+ ["[0]" archive {"+" Output}
+ ["[0]" descriptor]
+ ["[0]" artifact]
+ ["tree_shaking" dependency]]
+ [cache
+ ["[0]" dependency]]
+ ["[0]" io "_"
+ ["[1]" archive]]
[//
- ["[0]" archive {"+" Output}
- ["[0]" descriptor]
- ["[0]" artifact]]
- [cache
- ["[0]" dependency]]
- ["[0]" io "_"
- ["[1]" archive]]
- [//
- [language
- ["$" lux
- [generation {"+" Context}]]]]]])
+ [language
+ ["$" lux
+ [generation {"+" Context}]]]]]])
-(def: (write_module sequence [module output] so_far)
+(def: (write_module necessary_dependencies sequence [module_id output] so_far)
(All (_ directive)
- (-> (-> directive directive directive) [archive.ID Output] directive
+ (-> (Set Context) (-> directive directive directive) [archive.ID Output] directive
(Try directive)))
(|> output
sequence.list
- (list#each (|>> product.right product.right))
+ (list.all (function (_ [artifact_id custom content])
+ (if (set.member? necessary_dependencies [module_id artifact_id])
+ {.#Some content}
+ {.#None})))
(monad.mix try.monad
(function (_ content so_far)
(|> content
@@ -63,9 +68,13 @@
Packager))
(function (package host_dependencies archive program)
(do [! try.monad]
- [order (dependency.load_order $.key archive)]
+ [.let [necessary_dependencies (tree_shaking.necessary_dependencies archive)]
+ order (dependency.load_order $.key archive)]
(|> order
(list#each (function (_ [module [module_id [descriptor document output]]])
[module_id output]))
- (monad.mix ! (..write_module sequence) header)
- (# ! each (|>> scope code (# utf8.codec encoded)))))))
+ (monad.mix ! (..write_module necessary_dependencies sequence) header)
+ (# ! each (|>> scope
+ code
+ (# utf8.codec encoded)
+ {.#Left}))))))