diff options
Diffstat (limited to 'stdlib/source/lux/target/lua.lux')
-rw-r--r-- | stdlib/source/lux/target/lua.lux | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/stdlib/source/lux/target/lua.lux b/stdlib/source/lux/target/lua.lux index ef646cddc..586b060a2 100644 --- a/stdlib/source/lux/target/lua.lux +++ b/stdlib/source/lux/target/lua.lux @@ -1,5 +1,7 @@ (.module: [lux (#- Location Code int if cond function or and not let ^) + ["@" target] + ["." host] [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)] @@ -25,13 +27,23 @@ [type abstract]]) -(def: input_separator ", ") -(def: statement_suffix ";") +(for {@.old (as_is (host.import: java/lang/CharSequence) + (host.import: java/lang/String + ["#::." + (replace [java/lang/CharSequence java/lang/CharSequence] java/lang/String)]))} + (as_is)) (def: nest (-> Text Text) - (|>> (format text.new_line) - (text.replace_all text.new_line (format text.new_line text.tab)))) + (.let [nested_new_line (format text.new_line text.tab)] + (for {@.old (|>> (format text.new_line) + (:coerce java/lang/String) + (java/lang/String::replace (:coerce java/lang/CharSequence text.new_line) + (:coerce java/lang/CharSequence nested_new_line)))} + (|>> (format text.new_line) + (text.replace_all text.new_line nested_new_line))))) + +(def: input_separator ", ") (abstract: #export (Code brand) Text @@ -231,7 +243,7 @@ (def: #export statement (-> Expression Statement) - (|>> :representation (text.suffix ..statement_suffix) :abstraction)) + (|>> :representation :abstraction)) (def: #export (then pre! post!) (-> Statement Statement Statement) @@ -247,39 +259,39 @@ (def: #export (local vars) (-> (List Var) Statement) - (:abstraction (format "local " (..locations vars) ..statement_suffix))) + (:abstraction (format "local " (..locations vars)))) (def: #export (set vars value) (-> (List Location) Expression Statement) - (:abstraction (format (..locations vars) " = " (:representation value) ..statement_suffix))) + (:abstraction (format (..locations vars) " = " (:representation value)))) (def: #export (let vars value) (-> (List Var) Expression Statement) - (:abstraction (format "local " (..locations vars) " = " (:representation value) ..statement_suffix))) + (:abstraction (format "local " (..locations vars) " = " (:representation value)))) (def: #export (local/1 var value) (-> Var Expression Statement) - (:abstraction (format "local " (:representation var) " = " (:representation value) ..statement_suffix))) + (:abstraction (format "local " (:representation var) " = " (:representation value)))) (def: #export (if test then! else!) (-> Expression Statement Statement Statement) (:abstraction (format "if " (:representation test) text.new_line "then" (..nest (:representation then!)) text.new_line "else" (..nest (:representation else!)) - text.new_line "end" ..statement_suffix))) + text.new_line "end"))) (def: #export (when test then!) (-> Expression Statement Statement) (:abstraction (format "if " (:representation test) text.new_line "then" (..nest (:representation then!)) - text.new_line "end" ..statement_suffix))) + text.new_line "end"))) (def: #export (while test body!) (-> Expression Statement Statement) (:abstraction (format "while " (:representation test) " do" (..nest (:representation body!)) - text.new_line "end" ..statement_suffix))) + text.new_line "end"))) (def: #export (for_in vars source body!) (-> (List Var) Expression Statement Statement) @@ -289,7 +301,7 @@ (text.join_with ..input_separator)) " in " (:representation source) " do" (..nest (:representation body!)) - text.new_line "end" ..statement_suffix))) + text.new_line "end"))) (def: #export (for_step var from to step body!) (-> Var Expression Expression Expression Statement @@ -300,11 +312,11 @@ ..input_separator (:representation to) ..input_separator (:representation step) " do" (..nest (:representation body!)) - text.new_line "end" ..statement_suffix))) + text.new_line "end"))) (def: #export (return value) (-> Expression Statement) - (:abstraction (format "return " (:representation value) ..statement_suffix))) + (:abstraction (format "return " (:representation value)))) (def: #export (closure args body!) (-> (List Var) Statement Expression) @@ -325,7 +337,7 @@ ..locations (text.enclose ["(" ")"])) (..nest (:representation body!)) - text.new_line "end" ..statement_suffix)))] + text.new_line "end")))] [function "function"] [local_function "local function"] @@ -333,9 +345,7 @@ (def: #export break Statement - (|> "break" - (text.suffix ..statement_suffix) - :abstraction)) + (:abstraction "break")) (def: #export (set_label label) (-> Label Statement) |