aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool
diff options
context:
space:
mode:
authorEduardo Julian2021-06-29 00:54:13 -0400
committerEduardo Julian2021-06-29 00:54:13 -0400
commit6633cd42f2892ea71530ddeeb93a7e7c0b59faa3 (patch)
treeaef31dba019fe7bc5141084ab8c25369bd7e83ca /stdlib/source/lux/tool
parentdb3e864ae66da7f7d1034ae95967605144d5ec47 (diff)
Some updates for the new compilers.
Diffstat (limited to 'stdlib/source/lux/tool')
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux42
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux8
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/case.lux10
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/primitive.lux2
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux157
5 files changed, 115 insertions, 104 deletions
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 66e09f33b..61a154efc 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
@@ -86,32 +86,32 @@
(|> /.empty
(/.install "syntax char case!" lux::syntax_char_case!)
(/.install "is" (binary (product.uncurry _.is)))
- (/.install "try" (unary //runtime.lux//try))))
+ (/.install "try" (unary //runtime.lux::try))))
(def: (capped operation parameter subject)
(-> (-> (Expression Any) (Expression Any) (Expression Any))
(-> (Expression Any) (Expression Any) (Expression Any)))
- (//runtime.i64//64 (operation parameter subject)))
+ (//runtime.i64::64 (operation parameter subject)))
(def: i64_procs
Bundle
(<| (/.prefix "i64")
(|> /.empty
- (/.install "and" (binary (product.uncurry //runtime.i64//and)))
- (/.install "or" (binary (product.uncurry //runtime.i64//or)))
- (/.install "xor" (binary (product.uncurry //runtime.i64//xor)))
- (/.install "left-shift" (binary (product.uncurry //runtime.i64//left_shift)))
- (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift)))
+ (/.install "and" (binary (product.uncurry //runtime.i64::and)))
+ (/.install "or" (binary (product.uncurry //runtime.i64::or)))
+ (/.install "xor" (binary (product.uncurry //runtime.i64::xor)))
+ (/.install "left-shift" (binary (product.uncurry //runtime.i64::left_shift)))
+ (/.install "right-shift" (binary (product.uncurry //runtime.i64::right_shift)))
(/.install "<" (binary (product.uncurry _.<)))
(/.install "=" (binary (product.uncurry _.=)))
(/.install "+" (binary (product.uncurry (..capped _.+))))
(/.install "-" (binary (product.uncurry (..capped _.-))))
(/.install "*" (binary (product.uncurry (..capped _.*))))
- (/.install "/" (binary (product.uncurry //runtime.i64//division)))
- (/.install "%" (binary (product.uncurry //runtime.i64//remainder)))
+ (/.install "/" (binary (product.uncurry //runtime.i64::division)))
+ (/.install "%" (binary (product.uncurry //runtime.i64::remainder)))
(/.install "f64" (unary _.float/1))
- (/.install "char" (unary //runtime.i64//char))
+ (/.install "char" (unary //runtime.i64::char))
)))
(def: f64_procs
@@ -121,7 +121,7 @@
(/.install "+" (binary (product.uncurry _.+)))
(/.install "-" (binary (product.uncurry _.-)))
(/.install "*" (binary (product.uncurry _.*)))
- (/.install "/" (binary (product.uncurry _./)))
+ (/.install "/" (binary (product.uncurry //runtime.f64::/)))
(/.install "%" (binary (function (_ [parameter subject])
(|> (_.__import__/1 (_.unicode "math"))
(_.do "fmod" (list subject parameter))))))
@@ -129,15 +129,15 @@
(/.install "<" (binary (product.uncurry _.<)))
(/.install "i64" (unary _.int/1))
(/.install "encode" (unary _.repr/1))
- (/.install "decode" (unary //runtime.f64//decode)))))
+ (/.install "decode" (unary //runtime.f64::decode)))))
-(def: (text//clip [paramO extraO subjectO])
+(def: (text::clip [paramO extraO subjectO])
(Trinary (Expression Any))
- (//runtime.text//clip paramO extraO subjectO))
+ (//runtime.text::clip paramO extraO subjectO))
-(def: (text//index [startO partO textO])
+(def: (text::index [startO partO textO])
(Trinary (Expression Any))
- (//runtime.text//index startO partO textO))
+ (//runtime.text::index startO partO textO))
(def: text_procs
Bundle
@@ -146,18 +146,18 @@
(/.install "=" (binary (product.uncurry _.=)))
(/.install "<" (binary (product.uncurry _.<)))
(/.install "concat" (binary (product.uncurry (function.flip _.+))))
- (/.install "index" (trinary text//index))
+ (/.install "index" (trinary ..text::index))
(/.install "size" (unary _.len/1))
- (/.install "char" (binary (product.uncurry //runtime.text//char)))
- (/.install "clip" (trinary text//clip))
+ (/.install "char" (binary (product.uncurry //runtime.text::char)))
+ (/.install "clip" (trinary ..text::clip))
)))
(def: io_procs
Bundle
(<| (/.prefix "io")
(|> /.empty
- (/.install "log" (unary //runtime.io//log!))
- (/.install "error" (unary //runtime.io//throw!)))))
+ (/.install "log" (unary //runtime.io::log!))
+ (/.install "error" (unary //runtime.io::throw!)))))
(def: #export bundle
Bundle
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
index 0c1478eea..a46bbb9cc 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
@@ -37,7 +37,7 @@
(def: array::length
(Unary (Expression Any))
- (|>> _.len/1 //runtime.i64//64))
+ (|>> _.len/1 //runtime.i64::64))
(def: (array::read [indexG arrayG])
(Binary (Expression Any))
@@ -45,11 +45,11 @@
(def: (array::write [indexG valueG arrayG])
(Trinary (Expression Any))
- (//runtime.array//write indexG valueG arrayG))
+ (//runtime.array::write indexG valueG arrayG))
(def: (array::delete [indexG arrayG])
(Binary (Expression Any))
- (//runtime.array//write indexG _.none arrayG))
+ (//runtime.array::write indexG _.none arrayG))
(def: array
Bundle
@@ -147,7 +147,7 @@
(do {! ////////phase.monad}
[codeG (phase archive codeS)
globalsG (phase archive globalsS)]
- (wrap (//runtime.lux//exec codeG globalsG))))]))
+ (wrap (//runtime.lux::exec codeG globalsG))))]))
(def: #export bundle
Bundle
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/case.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/case.lux
index 23368285c..28ffbb624 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/case.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/case.lux
@@ -93,8 +93,8 @@
(^template [<side> <accessor>]
[(<side> lefts)
(<accessor> (_.int (.int lefts)))])
- ([#.Left //runtime.tuple//left]
- [#.Right //runtime.tuple//right]))]
+ ([#.Left //runtime.tuple::left]
+ [#.Right //runtime.tuple::right]))]
(method source)))
valueO
(list.reverse pathP)))))
@@ -138,7 +138,7 @@
[(def: (<name> simple? idx)
(-> Bit Nat (Statement Any))
($_ _.then
- (_.set (list @temp) (|> idx <prep> .int _.int (//runtime.sum//get ..peek <flag>)))
+ (_.set (list @temp) (|> idx <prep> .int _.int (//runtime.sum::get ..peek <flag>)))
(.if simple?
(_.when (_.= _.none @temp)
fail_pm!)
@@ -237,8 +237,8 @@
(^template [<pm> <getter>]
[(^ (<pm> lefts))
(///////phase\wrap (|> ..peek (<getter> (_.int (.int lefts))) ..push!))])
- ([/////synthesis.member/left //runtime.tuple//left]
- [/////synthesis.member/right //runtime.tuple//right])
+ ([/////synthesis.member/left //runtime.tuple::left]
+ [/////synthesis.member/right //runtime.tuple::right])
(^ (/////synthesis.!bind_top register thenP))
(do ///////phase.monad
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/primitive.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/primitive.lux
index 270560266..ec8889281 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/primitive.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/python/primitive.lux
@@ -11,7 +11,7 @@
<implementation>)]
[Bit bit _.bool]
- [(I64 Any) i64 (|>> .int _.int //runtime.i64//64)]
+ [(I64 Any) i64 (|>> .int _.int //runtime.i64::64)]
[Frac f64 _.float]
[Text text _.unicode]
)
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 2345ab763..b77d0c915 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
@@ -21,6 +21,7 @@
["." code]]
[math
[number (#+ hex)
+ ["f" frac]
["." i64]]]
["@" target
["_" python (#+ Expression SVar Computation Literal Statement)]]]
@@ -155,13 +156,13 @@
(_.def (~ g!_) (list (~+ inputsC))
(~ code)))))))))))))
-(runtime: (lux//try op)
+(runtime: (lux::try op)
(with_vars [exception]
(_.try (_.return (..right (_.apply/* op (list ..unit))))
(list [(list (_.var "Exception")) exception
(_.return (..left (_.str/1 exception)))]))))
-(runtime: (lux//program_args program_args)
+(runtime: (lux::program_args program_args)
(with_vars [inputs value]
($_ _.then
(_.set (list inputs) ..none)
@@ -170,32 +171,32 @@
(..some (_.list (list value inputs)))))
(_.return inputs))))
-(runtime: (lux//exec code globals)
+(runtime: (lux::exec code globals)
($_ _.then
(_.exec code (#.Some globals))
(_.return ..unit)))
-(def: runtime//lux
+(def: runtime::lux
(Statement Any)
($_ _.then
- @lux//try
- @lux//program_args
- @lux//exec
+ @lux::try
+ @lux::program_args
+ @lux::exec
))
-(runtime: (io//log! message)
+(runtime: (io::log! message)
($_ _.then
(_.print message)
(_.return ..unit)))
-(runtime: (io//throw! message)
+(runtime: (io::throw! message)
(_.raise (_.Exception/1 message)))
-(def: runtime//io
+(def: runtime::io
(Statement Any)
($_ _.then
- @io//log!
- @io//throw!
+ @io::log!
+ @io::throw!
))
(def: last_index
@@ -204,7 +205,7 @@
(with_expansions [<recur> (as_is ($_ _.then
(_.set (list lefts) (_.- last_index_right lefts))
(_.set (list tuple) (_.nth last_index_right tuple))))]
- (runtime: (tuple//left lefts tuple)
+ (runtime: (tuple::left lefts tuple)
(with_vars [last_index_right]
(_.while (_.bool true)
($_ _.then
@@ -216,7 +217,7 @@
<recur>))
#.None)))
- (runtime: (tuple//right lefts tuple)
+ (runtime: (tuple::right lefts tuple)
(with_vars [last_index_right right_index]
(_.while (_.bool true)
($_ _.then
@@ -230,7 +231,7 @@
(_.return (_.slice_from right_index tuple))))
#.None))))
-(runtime: (sum//get sum wantsLast wantedTag)
+(runtime: (sum::get sum wantsLast wantedTag)
(let [no_match! (_.return _.none)
sum_tag (_.nth (_.int +0) sum)
sum_flag (_.nth (_.int +1) sum)
@@ -257,22 +258,22 @@
no_match!)
#.None)))
-(def: runtime//adt
+(def: runtime::adt
(Statement Any)
($_ _.then
- @tuple//left
- @tuple//right
- @sum//get
+ @tuple::left
+ @tuple::right
+ @sum::get
))
-(def: i64//+limit (_.manual "+0x7FFFFFFFFFFFFFFF"))
-(def: i64//-limit (_.manual "-0x8000000000000000"))
-(def: i64//+iteration (_.manual "+0x10000000000000000"))
-(def: i64//-iteration (_.manual "-0x10000000000000000"))
-(def: i64//+cap (_.manual "+0x8000000000000000"))
-(def: i64//-cap (_.manual "-0x8000000000000001"))
+(def: i64::+limit (_.manual "+0x7FFFFFFFFFFFFFFF"))
+(def: i64::-limit (_.manual "-0x8000000000000000"))
+(def: i64::+iteration (_.manual "+0x10000000000000000"))
+(def: i64::-iteration (_.manual "-0x10000000000000000"))
+(def: i64::+cap (_.manual "+0x8000000000000000"))
+(def: i64::-cap (_.manual "-0x8000000000000001"))
-(runtime: (i64//64 input)
+(runtime: (i64::64 input)
(with_vars [temp]
(`` (<| (~~ (template [<scenario> <iteration> <cap> <entrance>]
[(_.if (|> input <scenario>)
@@ -282,22 +283,22 @@
(|> temp (_.- <cap>) (_.+ <entrance>))
temp))))]
- [(_.> ..i64//+limit) ..i64//+iteration ..i64//+cap ..i64//-limit]
- [(_.< ..i64//-limit) ..i64//-iteration ..i64//-cap ..i64//+limit]
+ [(_.> ..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))))))))
+ (|> input (_.+ ..i64::+limit) (_.- ..i64::+limit))))))))
(def: as_nat
- (_.% ..i64//+iteration))
+ (_.% ..i64::+iteration))
-(runtime: (i64//left_shift param subject)
+(runtime: (i64::left_shift param subject)
(_.return (|> subject
(_.bit_shl (_.% (_.int +64) param))
- ..i64//64)))
+ ..i64::64)))
-(runtime: (i64//right_shift param subject)
+(runtime: (i64::right_shift param subject)
($_ _.then
(_.set (list param) (_.% (_.int +64) param))
(_.return (_.? (_.= (_.int +0) param)
@@ -306,7 +307,7 @@
..as_nat
(_.bit_shr param))))))
-(runtime: (i64//division param subject)
+(runtime: (i64::division param subject)
(with_vars [floored]
($_ _.then
(_.set (list floored) (_.// param subject))
@@ -320,17 +321,17 @@
(_.+ (_.int +1) floored)
floored))))))
-(runtime: (i64//remainder param subject)
- (_.return (_.- (|> subject (..i64//division param) (_.* param))
+(runtime: (i64::remainder param subject)
+ (_.return (_.- (|> subject (..i64::division param) (_.* param))
subject)))
(template [<runtime> <host>]
[(runtime: (<runtime> left right)
- (_.return (..i64//64 (<host> (..as_nat left) (..as_nat right)))))]
+ (_.return (..i64::64 (<host> (..as_nat left) (..as_nat right)))))]
- [i64//and _.bit_and]
- [i64//or _.bit_or]
- [i64//xor _.bit_xor]
+ [i64::and _.bit_and]
+ [i64::or _.bit_or]
+ [i64::xor _.bit_xor]
)
(def: python_version
@@ -339,45 +340,55 @@
(_.the "version_info")
(_.the "major")))
-(runtime: (i64//char value)
+(runtime: (i64::char value)
(_.return (_.? (_.= (_.int +3) ..python_version)
(_.chr/1 value)
(_.unichr/1 value))))
-(def: runtime//i64
+(def: runtime::i64
(Statement Any)
($_ _.then
- @i64//64
- @i64//left_shift
- @i64//right_shift
- @i64//division
- @i64//remainder
- @i64//and
- @i64//or
- @i64//xor
- @i64//char
+ @i64::64
+ @i64::left_shift
+ @i64::right_shift
+ @i64::division
+ @i64::remainder
+ @i64::and
+ @i64::or
+ @i64::xor
+ @i64::char
))
-(runtime: (f64//decode input)
+(runtime: (f64::/ parameter subject)
+ (_.return (_.? (_.= (_.float +0.0) parameter)
+ (<| (_.? (_.> (_.float +0.0) subject)
+ (_.float f.positive_infinity))
+ (_.? (_.< (_.float +0.0) subject)
+ (_.float f.negative_infinity))
+ (_.float f.not_a_number))
+ (_./ parameter subject))))
+
+(runtime: (f64::decode input)
(with_vars [ex]
(_.try
(_.return (..some (_.float/1 input)))
(list [(list (_.var "Exception")) ex
(_.return ..none)]))))
-(def: runtime//f64
+(def: runtime::f64
(Statement Any)
($_ _.then
- @f64//decode
+ @f64::/
+ @f64::decode
))
-(runtime: (text//index start param subject)
+(runtime: (text::index start param subject)
(with_vars [idx]
($_ _.then
(_.set (list idx) (|> subject (_.do "find" (list param start))))
(_.return (_.? (_.= (_.int -1) idx)
..none
- (..some (..i64//64 idx)))))))
+ (..some (..i64::64 idx)))))))
(def: inc
(|>> (_.+ (_.int +1))))
@@ -387,43 +398,43 @@
(_.and (|> value (_.>= (_.int +0)))
(|> value (_.< top))))
-(runtime: (text//clip @offset @length @text)
+(runtime: (text::clip @offset @length @text)
(_.return (|> @text (_.slice @offset (_.+ @offset @length)))))
-(runtime: (text//char idx text)
+(runtime: (text::char idx text)
(_.if (|> idx (within? (_.len/1 text)))
- (_.return (|> text (_.slice idx (..inc idx)) _.ord/1 ..i64//64))
+ (_.return (|> text (_.slice idx (..inc idx)) _.ord/1 ..i64::64))
(_.raise (_.Exception/1 (_.unicode "[Lux Error] Cannot get char from text.")))))
-(def: runtime//text
+(def: runtime::text
(Statement Any)
($_ _.then
- @text//index
- @text//clip
- @text//char
+ @text::index
+ @text::clip
+ @text::char
))
-(runtime: (array//write idx value array)
+(runtime: (array::write idx value array)
($_ _.then
(_.set (list (_.nth idx array)) value)
(_.return array)))
-(def: runtime//array
+(def: runtime::array
(Statement Any)
($_ _.then
- @array//write
+ @array::write
))
(def: runtime
(Statement Any)
($_ _.then
- runtime//lux
- runtime//io
- runtime//adt
- runtime//i64
- runtime//f64
- runtime//text
- runtime//array
+ runtime::lux
+ runtime::io
+ runtime::adt
+ runtime::i64
+ runtime::f64
+ runtime::text
+ runtime::array
))
(def: module_id