diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/project.clj | 2 | ||||
-rw-r--r-- | stdlib/source/lux/math/number/nat.lux | 64 | ||||
-rw-r--r-- | stdlib/source/lux/target/python.lux | 17 | ||||
-rw-r--r-- | stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux | 68 | ||||
-rw-r--r-- | stdlib/source/lux/world/file.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/world/program.lux | 10 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/text/encoding.lux | 14 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/text/unicode/block.lux | 19 | ||||
-rw-r--r-- | stdlib/source/test/lux/locale/language.lux | 25 |
10 files changed, 138 insertions, 87 deletions
diff --git a/stdlib/project.clj b/stdlib/project.clj index 62474fea1..7905f82b3 100644 --- a/stdlib/project.clj +++ b/stdlib/project.clj @@ -5,7 +5,7 @@ (defproject com.github.luxlang/stdlib #=(identity version) :url ~repo - :license {:name "Lux License v0.1" + :license {:name "Lux License v0.1.1" :url ~(str repo "/blob/master/license.txt")} :plugins [[com.github.luxlang/lein-luxc ~version]] :deploy-repositories [["releases" {:url ~sonatype-releases :creds :gpg}] diff --git a/stdlib/source/lux/math/number/nat.lux b/stdlib/source/lux/math/number/nat.lux index e3d8d8628..7edc60be4 100644 --- a/stdlib/source/lux/math/number/nat.lux +++ b/stdlib/source/lux/math/number/nat.lux @@ -305,38 +305,6 @@ (^or (^ (char "f")) (^ (char "F"))) (#.Some 15) _ #.None)) -(structure: #export decimal - (Codec Text Nat) - - (def: (encode value) - (loop [input value - output ""] - (let [digit (decimal-character (..% 10 input)) - output' ("lux text concat" digit output)] - (case (../ 10 input) - 0 - output' - - input' - (recur input' output'))))) - - (def: (decode repr) - (let [input-size ("lux text size" repr)] - (with_expansions [<failure> (#try.Failure ("lux text concat" "Invalid decimal syntax for Nat: " repr))] - (if (..> 0 input-size) - (loop [idx 0 - output 0] - (if (..< input-size idx) - (case (decimal-value ("lux text char" idx repr)) - #.None - <failure> - - (#.Some digit-value) - (recur (inc idx) - (|> output (..* 10) (..+ digit-value)))) - (#try.Success output))) - <failure>))))) - (template [<shift> <struct> <to-character> <to-value> <error>] [(structure: #export <struct> (Codec Text Nat) @@ -379,6 +347,38 @@ [4 hex hexadecimal-character hexadecimal-value "Invalid hexadecimal syntax for Nat: "] ) +(structure: #export decimal + (Codec Text Nat) + + (def: (encode value) + (loop [input value + output ""] + (let [digit (decimal-character (..% 10 input)) + output' ("lux text concat" digit output)] + (case (../ 10 input) + 0 + output' + + input' + (recur input' output'))))) + + (def: (decode repr) + (let [input-size ("lux text size" repr)] + (with_expansions [<failure> (#try.Failure ("lux text concat" "Invalid decimal syntax for Nat: " repr))] + (if (..> 0 input-size) + (loop [idx 0 + output 0] + (if (..< input-size idx) + (case (decimal-value ("lux text char" idx repr)) + #.None + <failure> + + (#.Some digit-value) + (recur (inc idx) + (|> output (..* 10) (..+ digit-value)))) + (#try.Success output))) + <failure>))))) + (structure: #export hash (Hash Nat) diff --git a/stdlib/source/lux/target/python.lux b/stdlib/source/lux/target/python.lux index e27ae9b83..1ae1cca64 100644 --- a/stdlib/source/lux/target/python.lux +++ b/stdlib/source/lux/target/python.lux @@ -1,5 +1,7 @@ (.module: [lux (#- Location Code not or and list if cond int comment exec) + ["@" target] + ["." host] [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)] @@ -28,10 +30,21 @@ (-> Text Text) (text.enclose ["(" ")"])) +(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))))) (abstract: #export (Code brand) Text diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux index b87390e9a..d7133aa70 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux @@ -122,7 +122,9 @@ (/.install "-" (binary (product.uncurry _.-))) (/.install "*" (binary (product.uncurry _.*))) (/.install "/" (binary (product.uncurry _./))) - (/.install "%" (binary (product.uncurry _.%))) + (/.install "%" (binary (function (_ [parameter subject]) + (|> (_.__import__/1 (_.unicode "math")) + (_.do "fmod" (list subject parameter)))))) (/.install "=" (binary (product.uncurry _.=))) (/.install "<" (binary (product.uncurry _.<))) (/.install "i64" (unary _.int/1)) diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux index 6d218b137..22234bcc4 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux @@ -29,12 +29,12 @@ ["$" version] ["#." synthesis (#+ Synthesis)] ["#." generation] - ["//#" /// (#+ Output) + ["//#" /// ["#." phase] [reference [variable (#+ Register)]] [meta - [archive (#+ Archive) + [archive (#+ Output Archive) ["." artifact (#+ Registry)]]]]]]) (template [<name> <base>] @@ -270,24 +270,48 @@ @sum//get )) -(runtime: i64//top +(runtime: i64//+limit (|> (_.int +1) (_.bit_shl (_.int +63)) (_.- (_.int +1)))) -(runtime: i64//bottom +(runtime: i64//-limit (_.- (|> (_.int +1) (_.bit_shl (_.int +63))) (_.int +0))) +(runtime: i64//+iteration + (|> (_.int +1) + (_.bit_shl (_.int +64)))) + +(runtime: i64//-iteration + (|> ..i64//+iteration + _.negate)) + +(runtime: i64//+cap + (|> ..i64//+limit + (_.+ (_.int +1)))) + +(runtime: i64//-cap + (|> ..i64//-limit + (_.- (_.int +1)))) + (runtime: (i64//64 input) - (_.return (<| (_.? (|> input (_.< ..i64//bottom)) - (|> input (_.- ..i64//bottom) (_.+ (_.int +1)) (_.+ i64//top) i64//64)) - (_.? (|> input (_.> ..i64//top)) - (|> input (_.- ..i64//top) (_.- (_.int +1)) (_.+ ..i64//bottom) i64//64)) - (for {@.python input} - ## This +- is only necessary to guaranteed that values within the limits are always longs in Python 2 - (|> input (_.+ i64//top) (_.- ..i64//top)))))) + (with_vars [temp] + (`` (<| (~~ (template [<scenario> <iteration> <cap> <entrance>] + [(_.if (|> input <scenario>) + ($_ _.then + (_.set (list temp) (_.% <iteration> input)) + (_.return (_.? (|> temp <scenario>) + (|> temp (_.- <cap>) (_.+ <entrance>)) + temp))))] + + [(_.> ..i64//+limit) ..i64//+iteration ..i64//+cap ..i64//-limit] + [(_.< ..i64//-limit) ..i64//-iteration ..i64//-cap ..i64//+limit] + )) + (_.return (for {@.python input} + ## This +- is only necessary to guarantee that values within the limits are always longs in Python 2 + (|> input (_.+ ..i64//+limit) (_.- ..i64//+limit)))))))) (runtime: i64//nat_top (|> (_.int +1) @@ -299,15 +323,17 @@ (runtime: (i64//left_shift param subject) (_.return (|> subject - ..as_nat - (_.bit_shl param) - ..as_nat + (_.bit_shl (_.% (_.int +64) param)) ..i64//64))) (runtime: (i64//right_shift param subject) - (_.return (|> subject - ..as_nat - (_.bit_shr param)))) + ($_ _.then + (_.set (list param) (_.% (_.int +64) param)) + (_.return (_.? (_.= (_.int +0) param) + subject + (|> subject + ..as_nat + (_.bit_shr param)))))) (runtime: (i64//division param subject) (with_vars [floored] @@ -350,8 +376,12 @@ (def: runtime//i64 (Statement Any) ($_ _.then - @i64//top - @i64//bottom + @i64//+limit + @i64//-limit + @i64//+iteration + @i64//-iteration + @i64//+cap + @i64//-cap @i64//64 @i64//nat_top @i64//left_shift diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 69f5a17db..972019c39 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -852,7 +852,7 @@ (..can_open (function (create_file path) (do {! io.monad} - [file (..open [path "x"])] + [file (..open [path "w"])] (case file (#try.Success file) (do (try.with !) diff --git a/stdlib/source/lux/world/program.lux b/stdlib/source/lux/world/program.lux index 7763bed2c..7a3d125a0 100644 --- a/stdlib/source/lux/world/program.lux +++ b/stdlib/source/lux/world/program.lux @@ -169,17 +169,15 @@ (import: (require [host.String] Any))) @.python (as_is (import: os - (#static getcwd [] #io host.String)) + (#static getcwd [] #io host.String) + (#static _exit [host.Integer] #io Nothing)) (import: os/path (#static expanduser [host.String] #io host.String)) (import: os/environ (#static keys [] #io (Array host.String)) - (#static get [host.String] #io host.String)) - - (import: sys - (#static exit [host.Integer] #io Nothing))) + (#static get [host.String] #io host.String))) @.lua (as_is (host.import: LuaFile (read [host.String] #io #? host.String) (close [] #io host.Boolean)) @@ -293,5 +291,5 @@ ## else (..default_exit! code)) - @.python (sys::exit code) + @.python (os::_exit [code]) @.lua (os/exit [code])})))) diff --git a/stdlib/source/test/lux/data/text/encoding.lux b/stdlib/source/test/lux/data/text/encoding.lux index c2b438232..9a9ba67cf 100644 --- a/stdlib/source/test/lux/data/text/encoding.lux +++ b/stdlib/source/test/lux/data/text/encoding.lux @@ -26,7 +26,7 @@ (with_expansions [<encodings> (as_is [all/a [/.ascii]] - [all/ibm<1000 + [all/ibm<700 [/.ibm_37 /.ibm_273 /.ibm_277 @@ -40,8 +40,10 @@ /.ibm_420 /.ibm_424 /.ibm_437 - /.ibm_500 - /.ibm_737 + /.ibm_500]] + + [all/ibm<900 + [/.ibm_737 /.ibm_775 /.ibm_833 /.ibm_834 @@ -64,8 +66,10 @@ /.ibm_870 /.ibm_871 /.ibm_874 - /.ibm_875 - /.ibm_918 + /.ibm_875]] + + [all/ibm>900 + [/.ibm_918 /.ibm_921 /.ibm_922 /.ibm_930 diff --git a/stdlib/source/test/lux/data/text/unicode/block.lux b/stdlib/source/test/lux/data/text/unicode/block.lux index d822a69d3..7f77aa34f 100644 --- a/stdlib/source/test/lux/data/text/unicode/block.lux +++ b/stdlib/source/test/lux/data/text/unicode/block.lux @@ -49,8 +49,9 @@ /.bengali /.gurmukhi /.gujarati - /.oriya - /.tamil + /.oriya]] + [blocks/1 + [/.tamil /.telugu /.kannada /.malayalam @@ -72,7 +73,7 @@ /.tagbanwa /.khmer /.mongolian]] - [blocks/1 + [blocks/2 [/.limbu /.tai_le /.khmer_symbols @@ -94,8 +95,9 @@ /.box_drawing /.block_elements /.geometric_shapes - /.miscellaneous_symbols - /.dingbats + /.miscellaneous_symbols]] + [blocks/3 + [/.dingbats /.miscellaneous_mathematical_symbols_a /.supplemental_arrows_a /.braille_patterns @@ -112,8 +114,9 @@ /.bopomofo /.hangul_compatibility_jamo /.kanbun - /.bopomofo_extended - /.katakana_phonetic_extensions + /.bopomofo_extended]] + [blocks/4 + [/.katakana_phonetic_extensions /.enclosed_cjk_letters_and_months /.cjk_compatibility /.cjk_unified_ideographs_extension_a @@ -128,7 +131,7 @@ /.private_use_area /.cjk_compatibility_ideographs /.alphabetic_presentation_forms]] - [blocks/2 + [blocks/5 [/.arabic_presentation_forms_a /.variation_selectors /.combining_half_marks diff --git a/stdlib/source/test/lux/locale/language.lux b/stdlib/source/test/lux/locale/language.lux index b3bfffc4e..9e49fbb1e 100644 --- a/stdlib/source/test/lux/locale/language.lux +++ b/stdlib/source/test/lux/locale/language.lux @@ -120,17 +120,17 @@ [languages/q [/.quechua]] [languages/r [/.rajasthani /.rapanui /.rarotongan /.romance /.romansh /.romany /.romanian /.rundi /.aromanian /.russian]] - [languages/s [/.sandawe /.sango /.yakut /.south_american_indian /.salishan - /.samaritan_aramaic /.sanskrit /.sasak /.santali /.sicilian - /.scots /.selkup /.semitic /.old_irish /.sign - /.shan /.sidamo /.sinhalese /.siouan /.sino_tibetan - /.slavic /.slovak /.slovenian /.southern_sami /.northern_sami - /.sami /.lule /.inari /.samoan /.skolt_sami - /.shona /.sindhi /.soninke /.sogdian /.somali - /.songhai /.southern_sotho /.spanish /.albanian /.sardinian - /.sranan_tongo /.serbian /.serer /.nilo_saharan /.swati - /.sukuma /.sundanese /.susu /.sumerian /.swahili - /.swedish /.classical_syriac /.syriac]] + [languages/s0 [/.sandawe /.sango /.yakut /.south_american_indian /.salishan + /.samaritan_aramaic /.sanskrit /.sasak /.santali /.sicilian + /.scots /.selkup /.semitic /.old_irish /.sign + /.shan /.sidamo /.sinhalese /.siouan /.sino_tibetan + /.slavic /.slovak /.slovenian /.southern_sami /.northern_sami + /.sami /.lule /.inari /.samoan /.skolt_sami]] + [languages/s1 [/.shona /.sindhi /.soninke /.sogdian /.somali + /.songhai /.southern_sotho /.spanish /.albanian /.sardinian + /.sranan_tongo /.serbian /.serer /.nilo_saharan /.swati + /.sukuma /.sundanese /.susu /.sumerian /.swahili + /.swedish /.classical_syriac /.syriac]] [languages/t [/.tahitian /.tai /.tamil /.tatar /.telugu /.timne /.tereno /.tetum /.tajik /.tagalog /.thai /.tigre /.tigrinya /.tiv /.tokelau @@ -170,7 +170,8 @@ ..languages/p ..languages/q ..languages/r - ..languages/s + ..languages/s0 + ..languages/s1 ..languages/t ..languages/u ..languages/v |