aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library')
-rw-r--r--stdlib/source/library/lux/debug.lux82
-rw-r--r--stdlib/source/library/lux/ffi.js.lux4
-rw-r--r--stdlib/source/library/lux/ffi.lua.lux53
-rw-r--r--stdlib/source/library/lux/ffi.py.lux27
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux11
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/reference.lux4
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux69
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/structure.lux37
8 files changed, 128 insertions, 159 deletions
diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux
index 132fff652..923919c16 100644
--- a/stdlib/source/library/lux/debug.lux
+++ b/stdlib/source/library/lux/debug.lux
@@ -1,45 +1,45 @@
(.using
- [library
- [lux {"-" type private}
- ["@" target]
- ["[0]" type]
- ["[0]" ffi {"+" import:}]
- ["[0]" meta]
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- [pipe {"+" new>}]
- ["[0]" function]
- ["[0]" try {"+" Try}]
- ["[0]" exception {"+" exception:}]
- ["<>" parser
- ["<[0]>" type {"+" Parser}]
- ["<[0]>" code]]]
- [data
- ["[0]" text
- ["%" format {"+" Format}]]
- [format
- [xml {"+" XML}]
- ["[0]" json]]
- [collection
- ["[0]" array]
- ["[0]" list ("[1]#[0]" functor)]
- ["[0]" dictionary]]]
- [macro
- ["[0]" template]
- ["[0]" syntax {"+" syntax:}]
- ["[0]" code]]
- [math
- [number
- [ratio {"+" Ratio}]
- ["n" nat]
- ["i" int]]]
- [time {"+" Time}
- [instant {"+" Instant}]
- [duration {"+" Duration}]
- [date {"+" Date}]
- [month {"+" Month}]
- [day {"+" Day}]]]])
+ [library
+ [lux {"-" type private}
+ ["@" target]
+ ["[0]" type]
+ ["[0]" ffi {"+" import:}]
+ ["[0]" meta]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ [pipe {"+" new>}]
+ ["[0]" function]
+ ["[0]" try {"+" Try}]
+ ["[0]" exception {"+" exception:}]
+ ["<>" parser
+ ["<[0]>" type {"+" Parser}]
+ ["<[0]>" code]]]
+ [data
+ ["[0]" text
+ ["%" format {"+" Format}]]
+ [format
+ [xml {"+" XML}]
+ ["[0]" json]]
+ [collection
+ ["[0]" array]
+ ["[0]" list ("[1]#[0]" functor)]
+ ["[0]" dictionary]]]
+ [macro
+ ["[0]" template]
+ ["[0]" syntax {"+" syntax:}]
+ ["[0]" code]]
+ [math
+ [number
+ [ratio {"+" Ratio}]
+ ["n" nat]
+ ["i" int]]]
+ [time {"+" Time}
+ [instant {"+" Instant}]
+ [duration {"+" Duration}]
+ [date {"+" Date}]
+ [month {"+" Month}]
+ [day {"+" Day}]]]])
(with_expansions [<jvm> (as_is (import: java/lang/String)
diff --git a/stdlib/source/library/lux/ffi.js.lux b/stdlib/source/library/lux/ffi.js.lux
index cfc38cc24..ece090ecd 100644
--- a/stdlib/source/library/lux/ffi.js.lux
+++ b/stdlib/source/library/lux/ffi.js.lux
@@ -1,6 +1,6 @@
(.using
[library
- [lux "*"
+ [lux {"-" Symbol}
["[0]" meta]
[abstract
[monad {"+" do}]]
@@ -244,7 +244,7 @@
(function (_ member_name)
(|> format
(text.replaced "[1]" class_name)
- (text.replaced "." member_name)
+ (text.replaced "[0]" member_name)
code.local_symbol)))
class_parameters (list#each code.local_symbol class_parameters)
declaration (` ((~ (code.local_symbol class_name))
diff --git a/stdlib/source/library/lux/ffi.lua.lux b/stdlib/source/library/lux/ffi.lua.lux
index 346519334..1a99178cd 100644
--- a/stdlib/source/library/lux/ffi.lua.lux
+++ b/stdlib/source/library/lux/ffi.lua.lux
@@ -1,27 +1,27 @@
(.using
- [library
- [lux "*"
- ["@" target]
- ["[0]" meta]
- [abstract
- [monad {"+" do}]]
- [control
- ["[0]" io]
- ["[0]" maybe]
- ["<>" parser ("[1]#[0]" monad)
- ["<[0]>" code {"+" Parser}]]]
- [data
- ["[0]" product]
- ["[0]" text
- ["%" format]]
- [collection
- ["[0]" list ("[1]#[0]" functor mix)]]]
- [type
- abstract]
- [macro {"+" with_symbols}
- [syntax {"+" syntax:}]
- ["[0]" code]
- ["[0]" template]]]])
+ [library
+ [lux "*"
+ ["@" target]
+ ["[0]" meta]
+ [abstract
+ [monad {"+" do}]]
+ [control
+ ["[0]" io]
+ ["[0]" maybe]
+ ["<>" parser ("[1]#[0]" monad)
+ ["<[0]>" code {"+" Parser}]]]
+ [data
+ ["[0]" product]
+ ["[0]" text
+ ["%" format]]
+ [collection
+ ["[0]" list ("[1]#[0]" functor mix)]]]
+ [type
+ abstract]
+ [macro {"+" with_symbols}
+ [syntax {"+" syntax:}]
+ ["[0]" code]
+ ["[0]" template]]]])
(abstract: .public (Object brand) Any)
@@ -217,8 +217,6 @@
(~+ (list#each (with_nil g!temp) g!inputs)))))))))))
(syntax: .public (import: [import ..import])
- ... {.#doc (example "Easily import types, methods, functions and constants."
- ... (import: (os/getenv [..String] "io" "?" ..String)))}
(with_symbols [g!temp]
(case import
{#Class [class format members]}
@@ -309,11 +307,6 @@
)))
(template: .public (closure <inputs> <output>)
- ... {.#doc (example "Allows defining closures/anonymous-functions in the form that Lua expects."
- ... "This is useful for adapting Lux functions for usage by Lua code."
- ... (: ..Function
- ... (closure [left right]
- ... (do_something (:as Foo left) (:as Bar right)))))}
[(.:as ..Function
(`` ("lua function"
(~~ (template.amount <inputs>))
diff --git a/stdlib/source/library/lux/ffi.py.lux b/stdlib/source/library/lux/ffi.py.lux
index e35da749c..4cb39155c 100644
--- a/stdlib/source/library/lux/ffi.py.lux
+++ b/stdlib/source/library/lux/ffi.py.lux
@@ -217,28 +217,6 @@
(~+ (list#each (with_none g!temp) g!inputs)))))))))))
(syntax: .public (import: [import ..import])
- ... {.#doc (example "Easily import types, methods, functions and constants."
- ... (import: os
- ... ["[1]::[0]"
- ... ("static" F_OK ..Integer)
- ... ("static" R_OK ..Integer)
- ... ("static" W_OK ..Integer)
- ... ("static" X_OK ..Integer)
-
- ... ("static" mkdir [..String] "io" "try" "?" Any)
- ... ("static" access [..String ..Integer] "io" "try" ..Boolean)
- ... ("static" remove [..String] "io" "try" "?" Any)
- ... ("static" rmdir [..String] "io" "try" "?" Any)
- ... ("static" rename [..String ..String] "io" "try" "?" Any)
- ... ("static" listdir [..String] "io" "try" (Array ..String))])
-
- ... (import: os/path
- ... ["[1]::[0]"
- ... ("static" isfile [..String] "io" "try" ..Boolean)
- ... ("static" isdir [..String] "io" "try" ..Boolean)
- ... ("static" sep ..String)
- ... ("static" getsize [..String] "io" "try" ..Integer)
- ... ("static" getmtime [..String] "io" "try" ..Float)]))}
(with_symbols [g!temp]
(case import
{#Class [class format members]}
@@ -334,11 +312,6 @@
)))
(template: .public (lambda <inputs> <output>)
- ... {.#doc (example "Allows defining closures/anonymous-functions in the form that Python expects."
- ... "This is useful for adapting Lux functions for usage by Python code."
- ... (: ..Function
- ... (lambda [left right]
- ... (do_something (:as Foo left) (:as Bar right)))))}
[(.:as ..Function
(`` ("python function"
(~~ (template.amount <inputs>))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
index c44b73500..c21dc12ec 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
@@ -80,7 +80,7 @@
(in (list#mix (function (_ side source)
(.let [method (.case side
(^template [<side> <accessor>]
- [(<side> lefts)
+ [{<side> lefts}
(<accessor> (_.i32 (.int lefts)))])
([.#Left //runtime.tuple//left]
[.#Right //runtime.tuple//right]))]
@@ -131,11 +131,12 @@
(_.statement (|> @cursor (_.do "splice" (list (|> @cursor ..length (_.- popsJS))
popsJS))))))
-(template [<name> <flag> <prep>]
+(template [<name> <flag>]
[(def: (<name> simple? idx)
(-> Bit Nat Statement)
($_ _.then
- (_.set @temp (|> idx <prep> .int _.i32 (//runtime.sum//get ..peek_cursor <flag>)))
+ (_.set @temp (//runtime.sum//get ..peek_cursor <flag>
+ (|> idx .int _.i32)))
(.if simple?
(_.when (_.= _.null @temp)
..fail_pm!)
@@ -143,8 +144,8 @@
..fail_pm!
(push_cursor! @temp)))))]
- [left_choice _.null (<|)]
- [right_choice (_.string "") ++]
+ [left_choice _.null]
+ [right_choice //runtime.unit]
)
(def: (alternation pre! post!)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/reference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/reference.lux
index 25dab5ed7..0874ed4f3 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/reference.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/reference.lux
@@ -9,5 +9,5 @@
(implementation: .public system
(System Expression)
- (def: constant _.var)
- (def: variable _.var))
+ (def: constant' _.var)
+ (def: variable' _.var))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
index 766d7e940..1fdba6ac2 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
@@ -190,38 +190,35 @@
(-> Expression Expression Expression Computation)
(_.new ..variant//new (list tag last? value)))
-(runtime: (sum//get sum wants_last wanted_tag)
- (let [no_match! (_.return _.null)
- sum_tag (|> sum (_.the ..variant_tag_field))
- sum_flag (|> sum (_.the ..variant_flag_field))
- sum_value (|> sum (_.the ..variant_value_field))
- is_last? (_.= ..unit sum_flag)
- extact_match! (_.return sum_value)
- test_recursion! (_.if is_last?
- ... Must recurse.
- ($_ _.then
- (_.set wanted_tag (_.- sum_tag wanted_tag))
- (_.set sum sum_value))
- no_match!)
- extrac_sub_variant! (_.return (..variant (_.- wanted_tag sum_tag) sum_flag sum_value))]
+(runtime: (sum//get sum expected##right? expected##lefts)
+ (let [mismatch! (_.return _.null)
+ actual##lefts (|> sum (_.the ..variant_tag_field))
+ actual##right? (|> sum (_.the ..variant_flag_field))
+ actual##value (|> sum (_.the ..variant_value_field))
+ is_last? (_.= ..unit actual##right?)
+ recur! ($_ _.then
+ (_.set expected##lefts (|> expected##lefts
+ (_.- actual##lefts)
+ (_.- (_.i32 +1))))
+ (_.set sum actual##value))]
(<| (_.while (_.boolean true))
- (_.cond (list [(_.= wanted_tag sum_tag)
- (_.if (_.= wants_last sum_flag)
- extact_match!
- test_recursion!)]
- [(_.< wanted_tag sum_tag)
- test_recursion!]
- [(_.= ..unit wants_last)
- extrac_sub_variant!])
- no_match!))))
-
-(def: none
- Computation
- (..variant (_.i32 +0) (flag #0) unit))
-
-(def: some
- (-> Expression Computation)
- (..variant (_.i32 +1) (flag #1)))
+ (_.cond (list [(_.= expected##lefts actual##lefts)
+ (_.if (_.= expected##right? actual##right?)
+ (_.return actual##value)
+ mismatch!)]
+
+ [(_.< expected##lefts actual##lefts)
+ (_.if (_.= ..unit actual##right?)
+ recur!
+ mismatch!)]
+
+ [(_.= ..unit expected##right?)
+ (_.return (..variant (|> actual##lefts
+ (_.- expected##lefts)
+ (_.- (_.i32 +1)))
+ actual##right?
+ actual##value))])
+ mismatch!))))
(def: left
(-> Expression Computation)
@@ -229,7 +226,15 @@
(def: right
(-> Expression Computation)
- (..variant (_.i32 +1) (flag #1)))
+ (..variant (_.i32 +0) (flag #1)))
+
+(def: none
+ Computation
+ (..left ..unit))
+
+(def: some
+ (-> Expression Computation)
+ ..right)
(def: runtime//structure
Statement
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/structure.lux
index 6629816d0..9aefc6a48 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/structure.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/structure.lux
@@ -1,18 +1,18 @@
(.using
- [library
- [lux {"-" Variant Tuple}
- [abstract
- ["[0]" monad {"+" do}]]
- [target
- ["_" js {"+" Expression}]]]]
- ["[0]" // "_"
- ["[1][0]" runtime {"+" Operation Phase Generator}]
- ["[1][0]" primitive]
- ["///[1]" //// "_"
- [analysis {"+" Variant Tuple}]
- ["[1][0]" synthesis {"+" Synthesis}]
- ["//[1]" ///
- ["[1][0]" phase ("[1]#[0]" monad)]]]])
+ [library
+ [lux {"-" Variant Tuple}
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [target
+ ["_" js {"+" Expression}]]]]
+ ["[0]" // "_"
+ ["[1][0]" runtime {"+" Operation Phase Generator}]
+ ["[1][0]" primitive]
+ ["///[1]" //// "_"
+ [analysis {"+" Variant Tuple}]
+ ["[1][0]" synthesis {"+" Synthesis}]
+ ["//[1]" ///
+ ["[1][0]" phase ("[1]#[0]" monad)]]]])
(def: .public (tuple generate archive elemsS+)
(Generator (Tuple Synthesis))
@@ -30,9 +30,6 @@
(def: .public (variant generate archive [lefts right? valueS])
(Generator (Variant Synthesis))
- (let [tag (if right?
- (++ lefts)
- lefts)]
- (///////phase#each (//runtime.variant (_.i32 (.int tag))
- (//runtime.flag right?))
- (generate archive valueS))))
+ (///////phase#each (//runtime.variant (_.i32 (.int lefts))
+ (//runtime.flag right?))
+ (generate archive valueS)))