diff options
author | Eduardo Julian | 2019-03-27 23:26:22 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-03-27 23:26:22 -0400 |
commit | 023b761c13744ccfe65090b0f4e10640093faa03 (patch) | |
tree | 30709a91846a271c3e9e1ecfb4ca61c4a0003b8f /stdlib/source/lux/tool | |
parent | 8df108600f6791237d0079af6b582e6cb306906d (diff) |
The Python compiler is alive.
Diffstat (limited to '')
7 files changed, 50 insertions, 44 deletions
diff --git a/stdlib/source/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/lux/tool/compiler/meta/packager/script.lux index ac4582346..57e0800b1 100644 --- a/stdlib/source/lux/tool/compiler/meta/packager/script.lux +++ b/stdlib/source/lux/tool/compiler/meta/packager/script.lux @@ -1,5 +1,7 @@ (.module: [lux #* + [control + [pipe (#+ case>)]] [data ["." product] ["." text @@ -28,9 +30,14 @@ (:coerce (List [Name _.Statement])) (list@map product.right)))) list@join - (list@fold (function (_ post! pre!) - (_.then pre! post!)) - _.use-strict) - (: _.Statement) - _.code - encoding.to-utf8)) + (case> (#.Cons head tail) + (|> (list@fold (function (_ post! pre!) + (_.then pre! post!)) + head + tail) + (: _.Statement) + _.code + encoding.to-utf8) + + #.Nil + (encoding.to-utf8 "")))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux index b5ef432f6..0e3864bd0 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux @@ -746,5 +746,7 @@ (Operation Any) (///.with-buffer (do ////.monad - [_ (///.save! ["" ..prefix] ..runtime)] + [_ (///.save! ["" ..prefix] ($_ _.then + _.use-strict + ..runtime))] (///.save-buffer! ..artifact)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/extension/common.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/extension/common.lux index 48fd005fb..4cfc7a1e6 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/extension/common.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/extension/common.lux @@ -29,14 +29,14 @@ Bundle (<| (bundle.prefix "i64") (|> bundle.empty - (bundle.install "and" (binary (product.uncurry _.bit-and))) - (bundle.install "or" (binary (product.uncurry _.bit-or))) - (bundle.install "xor" (binary (product.uncurry _.bit-xor))) - (bundle.install "left-shift" (binary (|>> (product.uncurry _.bit-shl) ///runtime.i64//64))) - (bundle.install "logical-right-shift" (binary (product.uncurry (function.flip ///runtime.i64//logic-right-shift)))) - (bundle.install "arithmetic-right-shift" (binary (product.uncurry (function.flip _.bit-shr)))) - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "+" (binary (product.uncurry _.+))) + (bundle.install "and" (binary (product.uncurry (function.flip _.bit-and)))) + (bundle.install "or" (binary (product.uncurry (function.flip _.bit-or)))) + (bundle.install "xor" (binary (product.uncurry (function.flip _.bit-xor)))) + (bundle.install "left-shift" (binary (function.compose ///runtime.i64//64 (product.uncurry _.bit-shl)))) + (bundle.install "logical-right-shift" (binary (product.uncurry ///runtime.i64//logic-right-shift))) + (bundle.install "arithmetic-right-shift" (binary (product.uncurry _.bit-shr))) + (bundle.install "=" (binary (product.uncurry (function.flip _.=)))) + (bundle.install "+" (binary (product.uncurry (function.flip _.+)))) (bundle.install "-" (binary (product.uncurry (function.flip _.-)))) ))) @@ -59,7 +59,7 @@ (<| (bundle.prefix "int") (|> bundle.empty (bundle.install "<" (binary (product.uncurry (function.flip _.<)))) - (bundle.install "*" (binary (product.uncurry _.*))) + (bundle.install "*" (binary (product.uncurry (function.flip _.*)))) (bundle.install "/" (binary (product.uncurry (function.flip _./)))) (bundle.install "%" (binary (product.uncurry (function.flip _.%)))) (bundle.install "frac" (unary _.float/1)) @@ -69,12 +69,12 @@ Bundle (<| (bundle.prefix "frac") (|> bundle.empty - (bundle.install "+" (binary (product.uncurry _.+))) + (bundle.install "+" (binary (product.uncurry (function.flip _.+)))) (bundle.install "-" (binary (product.uncurry (function.flip _.-)))) - (bundle.install "*" (binary (product.uncurry _.*))) + (bundle.install "*" (binary (product.uncurry (function.flip _.*)))) (bundle.install "/" (binary (product.uncurry (function.flip _./)))) (bundle.install "%" (binary (product.uncurry (function.flip _.%)))) - (bundle.install "=" (binary (product.uncurry _.=))) + (bundle.install "=" (binary (product.uncurry (function.flip _.=)))) (bundle.install "<" (binary (product.uncurry (function.flip _.<)))) (bundle.install "smallest" (nullary frac//smallest)) (bundle.install "min" (nullary frac//min)) @@ -99,7 +99,7 @@ Bundle (<| (bundle.prefix "text") (|> bundle.empty - (bundle.install "=" (binary (product.uncurry _.=))) + (bundle.install "=" (binary (product.uncurry (function.flip _.=)))) (bundle.install "<" (binary (product.uncurry (function.flip _.<)))) (bundle.install "concat" (binary (product.uncurry (function.flip _.+)))) (bundle.install "index" (trinary text//index)) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/primitive.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/primitive.lux index 1ddd3950e..33b9b7781 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/primitive.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/primitive.lux @@ -16,7 +16,7 @@ (def: #export i64 (-> (I64 Any) (Expression Any)) - (|>> .int _.int)) + (|>> .int _.long)) (def: #export f64 (-> Frac (Expression Any)) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux index e3a8a4537..564bbdb35 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux @@ -33,10 +33,6 @@ [Bundle ///.Bundle] ) -(def: #export variant-tag-field "_lux_tag") -(def: #export variant-flag-field "_lux_flag") -(def: #export variant-value-field "_lux_value") - (def: prefix Text "LuxRuntime") (def: #export unit (_.string synthesis.unit)) @@ -49,9 +45,7 @@ (def: (variant' tag last? value) (-> (Expression Any) (Expression Any) (Expression Any) (Computation Any)) - (_.dict (list [(_.string ..variant-tag-field) tag] - [(_.string ..variant-flag-field) last?] - [(_.string ..variant-value-field) value]))) + (_.tuple (list tag last? value))) (def: #export (variant tag last? value) (-> Nat Bit (Expression Any) (Computation Any)) @@ -83,7 +77,7 @@ (def: (feature name definition) (-> SVar (-> SVar (Statement Any)) (Statement Any)) - (_.def name (list) (definition name))) + (definition name)) (syntax: #export (with-vars {vars (s.tuple (p.some s.local-identifier))} body) @@ -216,15 +210,15 @@ ## Must slice (_.return (_.slice-from index product)))))) -(runtime: (sum//get sum wantedTag wantsLast) +(runtime: (sum//get sum wantsLast wantedTag) (let [no-match! (_.return _.none) - sum-tag (_.nth (_.string ..variant-tag-field) sum) - sum-flag (_.nth (_.string ..variant-flag-field) sum) - sum-value (_.nth (_.string ..variant-value-field) sum) + sum-tag (_.nth (_.int +0) sum) + sum-flag (_.nth (_.int +1) sum) + sum-value (_.nth (_.int +2) sum) is-last? (_.= (_.string "") sum-flag) test-recursion! (_.if is-last? ## Must recurse. - (_.return (sum//get sum-value (_.- sum-tag wantedTag) wantsLast)) + (_.return (sum//get sum-value wantsLast (_.- sum-tag wantedTag))) no-match!)] (_.cond (list [(_.= sum-tag wantedTag) (_.if (_.= wantsLast sum-flag) @@ -312,14 +306,7 @@ ) (runtime: (text//clip @text @from @to) - (with-vars [length] - ($_ _.then - (_.set (list length) (_.len/1 @text)) - (_.if ($_ _.and - (|> @to (within? length)) - (|> @from (up-to? @to))) - (_.return (..some (|> @text (_.slice @from (inc @to))))) - (_.return ..none))))) + (_.return (|> @text (_.slice @from (inc @to))))) (runtime: (text//char text idx) (_.if (|> idx (within? (_.len/1 text))) @@ -388,5 +375,6 @@ (Operation Any) (///.with-buffer (do ////.monad - [_ (///.save! ["" ..prefix] ..runtime)] + [_ (///.save! ["" ..prefix] (<| (_.comment "-*- coding: utf-8 -*-") + ..runtime))] (///.save-buffer! ..artifact)))) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/structure.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/structure.lux index 1415251df..6daf5e532 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/structure.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/structure.lux @@ -24,7 +24,7 @@ _ (do ////.monad [elemsT+ (monad.map @ generate elemsS+)] - (wrap (_.tuple elemsT+))))) + (wrap (_.list elemsT+))))) (def: #export (variant generate [lefts right? valueS]) (-> Phase (Variant Synthesis) (Operation (Expression Any))) diff --git a/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux b/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux index 841846351..7da1a41c7 100644 --- a/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux +++ b/stdlib/source/lux/tool/compiler/phase/synthesis/case.lux @@ -244,9 +244,18 @@ synthesis-storage) (list inputS exprS)) + (^ (/.branch/if [testS thenS elseS])) + (list@fold for-synthesis synthesis-storage (list testS thenS elseS)) + (^ (/.branch/case [inputS pathS])) (|> synthesis-storage (for-synthesis inputS) (for-path pathS)) + (^ (/.loop/scope [start initsS+ iterationS])) + (list@fold for-synthesis synthesis-storage (#.Cons iterationS initsS+)) + + (^ (/.loop/recur replacementsS+)) + (list@fold for-synthesis synthesis-storage replacementsS+) + (#/.Extension [extension argsS]) (list@fold for-synthesis synthesis-storage argsS) |