aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2021-11-29 21:39:44 -0400
committerEduardo Julian2021-11-29 21:39:44 -0400
commit872c097327c0a5b3baa69e88dacd09718ddfa793 (patch)
tree2a8160df511b167ff7f69c158410b1d0aeb4fda2
parent13323c55a4d34ddb74b67fab684d4431f9624dd1 (diff)
Got "lux syntax char case!" to work on Rembulan.
-rw-r--r--lux-lua/source/program.lux130
-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
-rw-r--r--stdlib/source/test/lux/extension.lux7
9 files changed, 185 insertions, 170 deletions
diff --git a/lux-lua/source/program.lux b/lux-lua/source/program.lux
index 962da273f..bedd9dbb8 100644
--- a/lux-lua/source/program.lux
+++ b/lux-lua/source/program.lux
@@ -1,69 +1,69 @@
(.using
- [library
- [lux "*"
- [program {"+" program:}]
- ["[0]" ffi]
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- ["[0]" maybe]
- ["[0]" try {"+" Try}]
- ["[0]" exception {"+" exception:}]
- ["[0]" io {"+" IO io}]
- ["[0]" function]
- [concurrency
- ["[0]" async {"+" Async}]]]
- [data
- ["[0]" text ("[1]#[0]" hash)
- ["%" format {"+" format}]
- [encoding
- ["[0]" utf8]]]
- [collection
- ["[0]" array {"+" Array}]
- ["[0]" list]]]
- [macro
- ["[0]" template]]
- [math
- [number {"+" hex}
- ["n" nat]
- ["[0]" i64]]]
- ["[0]" world "_"
- ["[0]" file]
- ["[1]/[0]" program]]
- ["@" target
- ["_" lua]]
- [tool
- [compiler
- ["[0]" phase {"+" Operation Phase}]
- [reference
- [variable {"+" Register}]]
- [language
- [lux
- [program {"+" Program}]
- [generation {"+" Context Host}]
- [analysis
- [macro {"+" Expander}]]
- [phase
- ["[0]" extension {"+" Extender Handler}
- ["[1]/[0]" bundle]
- ["[0]" analysis "_"
- ["[1]" lua]]
- ["[0]" generation "_"
- ["[1]" lua]]]
- [generation
- ["[0]" reference]
- ["[0]" lua
- ["[0]" runtime]]]]]]
- [default
- ["[0]" platform {"+" Platform}]]
- [meta
- [archive {"+" Archive}]
- ["[0]" packager "_"
- ["[1]" script]]]]]]]
- [program
- ["/" compositor
- ["[1][0]" cli]
- ["[1][0]" static]]])
+ [library
+ [lux "*"
+ [program {"+" program:}]
+ ["[0]" ffi]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" maybe]
+ ["[0]" try {"+" Try}]
+ ["[0]" exception {"+" exception:}]
+ ["[0]" io {"+" IO io}]
+ ["[0]" function]
+ [concurrency
+ ["[0]" async {"+" Async}]]]
+ [data
+ ["[0]" text ("[1]#[0]" hash)
+ ["%" format {"+" format}]
+ [encoding
+ ["[0]" utf8]]]
+ [collection
+ ["[0]" array {"+" Array}]
+ ["[0]" list]]]
+ [macro
+ ["[0]" template]]
+ [math
+ [number {"+" hex}
+ ["n" nat]
+ ["[0]" i64]]]
+ ["[0]" world "_"
+ ["[0]" file]
+ ["[1]/[0]" program]]
+ ["@" target
+ ["_" lua]]
+ [tool
+ [compiler
+ ["[0]" phase {"+" Operation Phase}]
+ [reference
+ [variable {"+" Register}]]
+ [language
+ [lux
+ [program {"+" Program}]
+ [generation {"+" Context Host}]
+ [analysis
+ [macro {"+" Expander}]]
+ [phase
+ ["[0]" extension {"+" Extender Handler}
+ ["[1]/[0]" bundle]
+ ["[0]" analysis "_"
+ ["[1]" lua]]
+ ["[0]" generation "_"
+ ["[1]" lua]]]
+ [generation
+ ["[0]" reference]
+ ["[0]" lua
+ ["[0]" runtime]]]]]]
+ [default
+ ["[0]" platform {"+" Platform}]]
+ [meta
+ [archive {"+" Archive}]
+ ["[0]" packager "_"
+ ["[1]" script]]]]]]]
+ [program
+ ["/" compositor
+ ["[1][0]" cli]
+ ["[1][0]" static]]])
(with_expansions [<jvm> (as_is (ffi.import: java/lang/String)
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}))))))
diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux
index 7422823e9..92b314dc7 100644
--- a/stdlib/source/test/lux/extension.lux
+++ b/stdlib/source/test/lux/extension.lux
@@ -150,13 +150,18 @@
@.js (generation.save! artifact_id {.#None}
(js.comment commentary
(js.statement (js.string commentary))))
+ @.lua (generation.save! artifact_id {.#None}
+ (lua.comment commentary
+ (lua.statement (lua.string commentary))))
@.ruby (generation.save! artifact_id {.#None}
(ruby.comment commentary
(ruby.statement (ruby.string commentary))))])]
(generation.log! commentary))))]
(in directive.no_requirements)))
- (`` ((~~ (static ..directive)) (n.* 2 3)))
+ ... TODO: No longer skip testing Lua after Rembulan isn't being used anymore.
+ (for [@.lua (as_is)]
+ (`` ((~~ (static ..directive)) (n.* 2 3))))
))
(def: .public test