aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2023-02-10 15:24:47 -0400
committerEduardo Julian2023-02-10 15:24:47 -0400
commit6c4c9a8c10950e3244f15451fe18fb768abee924 (patch)
treeb67aee15d8dc602b5322c8910f897bb4690f9804
parentb0023e3411ab1c5a6671520c33dd723f822d6b61 (diff)
Can now compile loops in C++.
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/data/format/tar.lux61
-rw-r--r--stdlib/source/library/lux/ffi/export.rb.lux4
-rw-r--r--stdlib/source/library/lux/math/number/frac.lux2
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux13
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/function.lux13
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/loop.lux117
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux4
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux20
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux15
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux6
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux15
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux15
-rw-r--r--stdlib/source/library/lux/meta/compiler/target/c++.lux109
-rw-r--r--stdlib/source/library/lux/world/finance/market/price.lux14
-rw-r--r--stdlib/source/test/lux/math/number/frac.lux14
-rw-r--r--stdlib/source/test/lux/meta/compiler.lux43
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux4
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux96
-rw-r--r--stdlib/source/test/lux/meta/compiler/target/ruby.lux5
19 files changed, 432 insertions, 138 deletions
diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux
index b5627f0b2..13819cdb5 100644
--- a/stdlib/source/library/lux/data/format/tar.lux
+++ b/stdlib/source/library/lux/data/format/tar.lux
@@ -855,8 +855,8 @@
(n.- |checksum|)
(n.+ ..checksum_checksum))))
-(def header_parser
- (Parser Header)
+(def header_parser/0
+ (Parser [Binary [Path Mode ID ID Big Big [Nat Checksum]]])
(function (_ state)
(`` (<| (,, (with_template [<binding> <parser>]
[(parsed state <binding> <parser>)]
@@ -870,10 +870,12 @@
[modification_time ..big_parser]
[[actual checksum_code] ..checksum_parser]
))
- (let [expected (expected_checksum checksum_code binary_header)])
- (if (not (n.= expected actual))
- (exception.except ..wrong_checksum [expected actual]))
- (,, (with_template [<binding> <parser>]
+ {try.#Success [state [binary_header path mode user_id group_id size modification_time [actual checksum_code]]]}))))
+
+(def header_parser/1
+ (Parser [Link_Flag Path Magic Name Name Device Device])
+ (function (_ state)
+ (`` (<| (,, (with_template [<binding> <parser>]
[(parsed state <binding> <parser>)]
[link_flag ..link_flag_parser]
@@ -885,20 +887,39 @@
[minor_device ..small_parser]
[_ (?binary.segment ..header_padding_size)]
))
- {try.#Success [state [#path path
- #mode mode
- #user_id user_id
- #group_id group_id
- #size size
- #modification_time modification_time
- #checksum checksum_code
- #link_flag link_flag
- #link_name link_name
- #magic magic
- #user_name user_name
- #group_name group_name
- #major_device major_device
- #minor_device minor_device]]}))))
+ {try.#Success [state [link_flag link_name magic user_name group_name major_device minor_device]]}))))
+
+(def header_parser
+ (Parser Header)
+ (let [phase/1 (all <>.and
+ ..link_flag_parser
+ ..path_parser
+ ..magic_parser
+ ..name_parser
+ ..name_parser
+ ..small_parser
+ ..small_parser
+ (?binary.segment ..header_padding_size))]
+ (function (_ state)
+ (`` (<| (parsed state [binary_header path mode user_id group_id size modification_time [actual checksum_code]] ..header_parser/0)
+ (let [expected (expected_checksum checksum_code binary_header)])
+ (if (not (n.= expected actual))
+ (exception.except ..wrong_checksum [expected actual]))
+ (parsed state [link_flag link_name magic user_name group_name major_device minor_device] ..header_parser/1)
+ {try.#Success [state [#path path
+ #mode mode
+ #user_id user_id
+ #group_id group_id
+ #size size
+ #modification_time modification_time
+ #checksum checksum_code
+ #link_flag link_flag
+ #link_name link_name
+ #magic magic
+ #user_name user_name
+ #group_name group_name
+ #major_device major_device
+ #minor_device minor_device]]})))))
(def (file_parser header)
(-> Header
diff --git a/stdlib/source/library/lux/ffi/export.rb.lux b/stdlib/source/library/lux/ffi/export.rb.lux
index 0a5c6592c..0f4ab736d 100644
--- a/stdlib/source/library/lux/ffi/export.rb.lux
+++ b/stdlib/source/library/lux/ffi/export.rb.lux
@@ -23,9 +23,9 @@
[macro
[syntax (.only syntax)]
["[0]" expansion]]
- [target
- ["/" ruby]]
[compiler
+ [target
+ ["/" ruby]]
[meta
[cache
["[0]" dependency
diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux
index a2148b973..b35168133 100644
--- a/stdlib/source/library/lux/math/number/frac.lux
+++ b/stdlib/source/library/lux/math/number/frac.lux
@@ -926,8 +926,8 @@
Frac)
(|>> (* <factor>)))]
- [+100.0 percentage]
[+360.0 degree]
+ [+100.0 percentage]
... https://en.wikipedia.org/wiki/Per_mille
[+01,000.0 permille]
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux
index 207a9e98e..60e5f3795 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux
@@ -30,7 +30,7 @@
["[1][0]" reference]
["[1][0]" function]
["[1][0]" when]
- ... ["[1][0]" loop]
+ ["[1][0]" loop]
[///
["[0]" extension]
[//
@@ -82,17 +82,14 @@
... (synthesis.branch/get @ [path recordS])
... (/when.get phase archive [path recordS])
- ... (synthesis.loop/scope @ scope)
- ... (/loop.scope phase archive scope)
+ (synthesis.loop/scope @ it)
+ (/loop.scope phase archive it)
... (synthesis.loop/again @ updates)
... (/loop.again phase archive updates)
- (synthesis.function/abstraction @ [environment arity (synthesis.loop/scope @ [1 (list) iteration])])
- (/function.abstraction phase archive [environment arity iteration])
-
- ... (synthesis.function/abstraction @ abstraction)
- ... (/function.abstraction phase archive abstraction)
+ (synthesis.function/abstraction @ it)
+ (/function.abstraction phase archive it)
(synthesis.function/apply @ it)
(/function.reification phase archive it)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/function.lux
index b7d1ab4d7..c56cebbd2 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/function.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/function.lux
@@ -18,7 +18,7 @@
["[0]" reference]
[////
[analysis (.only Reification)]
- [synthesis (.only Abstraction)]
+ ["[0]" synthesis (.only Abstraction')]
["[0]" phase]
[///
[meta
@@ -34,7 +34,7 @@
(in (runtime.on arguments abstraction))))
(def .public (abstraction next archive [environment arity body])
- (runtime.Term Abstraction)
+ (runtime.Term Abstraction')
(do [! phase.monad]
[dependencies (cache.dependencies archive body)
body (next archive body)
@@ -44,8 +44,13 @@
(_.lambda (|> environment
list.enumeration
(list#each (function (_ [register variable])
- (_.alias (reference.foreign register)
- (reference.variable variable)))))
+ (when variable
+ (synthesis.variable @ variable)
+ (_.alias (reference.foreign register)
+ (reference.variable variable))
+
+ _
+ (undefined)))))
(list [runtime.value_type $self]
[(_.* runtime.value_type) $arguments])
{.#Some runtime.value_type}
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/loop.lux
new file mode 100644
index 000000000..64b84edc2
--- /dev/null
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/loop.lux
@@ -0,0 +1,117 @@
+... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+(.require
+ [library
+ [lux (.except Scope)
+ [abstract
+ ["[0]" monad (.only do)]]
+ [data
+ ["[0]" product]
+ ["[0]" text (.only)
+ ["%" \\format (.only format)]]
+ [collection
+ ["[0]" list (.use "[1]#[0]" functor mix)]]]
+ [math
+ [number
+ ["n" nat]]]
+ [meta
+ [compiler
+ [target
+ ["_" c++]]]]]]
+ [//
+ ["[0]" runtime (.only Operation Phase)]
+ ["[0]" reference]
+ [////
+ ["[0]" phase]
+ ["[0]" synthesis (.only Scope)]
+ ["[0]" translation]
+ [///
+ [reference
+ [variable (.only Register)]]]]])
+
+(def @scope
+ (-> Nat
+ _.Label)
+ (|>> %.nat
+ (format "scope")
+ _.label))
+
+(def $iteration_parameters
+ (-> Nat
+ _.Local)
+ (|>> %.nat
+ (format "iteration_parameters")
+ _.local))
+
+(def (setup $iteration_parameters initial? offset bindings body)
+ (-> _.Local Bit Register (List _.Expression) _.Statement
+ _.Statement)
+ (when bindings
+ (list)
+ body
+
+ (list binding)
+ (let [$binding (reference.local offset)]
+ (_.block
+ (all _.then
+ (if initial?
+ (_.variable $binding runtime.value_type binding)
+ (_.:= $binding binding))
+ body
+ )))
+
+ _
+ (|> bindings
+ list.enumeration
+ (list#each (is (-> [Register _.Expression]
+ _.Statement)
+ (function (_ [register _])
+ (let [variable (reference.local (n.+ offset register))
+ value (_.item (_.int (.int register)) $iteration_parameters)]
+ (if initial?
+ (_.variable variable runtime.value_type value)
+ (_.:= variable value))))))
+ list.reversed
+ (list#mix _.then body)
+ (_.then (_.constant_array $iteration_parameters
+ runtime.value_type
+ (_.int (.int (list.size bindings)))
+ (_.initialization bindings)))
+ _.block)))
+
+(def .public (scope next archive [start initialization body])
+ (runtime.Term Scope)
+ (when initialization
+ ... function/false/non-independent loop
+ {.#End}
+ (next archive body)
+
+ ... true loop
+ _
+ (do [! phase.monad]
+ [@scope (of ! each ..@scope translation.next)
+ initialization (monad.each ! (next archive) initialization)
+ body (translation.with_anchor [start @scope]
+ (next archive body))
+ $iteration_parameters (of ! each ..$iteration_parameters translation.next)]
+ (in (|> (..setup $iteration_parameters
+ true start
+ initialization
+ (all _.then
+ (_.set_label @scope)
+ (_.return body)))
+ (_.lambda (list _.all_by_value)
+ (list)
+ {.#Some runtime.value_type})
+ (_.on (list)))))))
+
+... (def .public (iteration statement expression archive it)
+... (runtime.Term List)
+... (do [! phase.monad]
+... [[offset @scope] translation.anchor
+... it (monad.each ! (expression archive) it)
+... $iteration_parameters (of ! each ..$iteration_parameters translation.next)]
+... (in (..setup $iteration_parameters
+... false offset it
+... (_.go_to @scope)))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux
index 14e791d31..6f58e2dfe 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux
@@ -32,6 +32,8 @@
["[0]" synthesis]
["[0]" translation]
[///
+ [reference
+ [variable (.only Register)]]
[meta
[archive (.only Output Archive)
["[0]" registry (.only Registry)]
@@ -39,7 +41,7 @@
["[0]" unit]]]]])
(type .public Anchor
- Any)
+ [Register _.Label])
(type .public Value
_.Expression)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux
index 50e19dcf6..da097fea9 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux
@@ -100,21 +100,13 @@
[loop! (scope! statement expression archive [start initsS+ bodyS])]
(in (_.apply (_.closure (list) loop!) (list))))))
-(def @temp
- (_.var "lux_again_values"))
-
-(def .public (again! statement expression archive argsS+)
+(def .public (again! statement expression archive it)
(Translator! (List synthesis.Term))
(do [! phase.monad]
[[offset @scope] /////translation.anchor
- argsO+ (monad.each ! (expression archive) argsS+)
+ it (monad.each ! (expression archive) it)
$iteration (of ! each ..$iteration /////translation.next)]
- (in (all _.then
- (_.define @temp (_.array argsO+))
- (..setup $iteration
- false offset
- (|> argsO+
- list.enumeration
- (list#each (function (_ [idx _])
- (_.at (_.i32 (.int idx)) @temp))))
- (_.continue_at (_.label @scope)))))))
+ (in (..setup $iteration
+ false offset
+ it
+ (_.continue_at (_.label @scope))))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux
index e300ab9cf..dbb35688f 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux
@@ -26,17 +26,20 @@
[reference
[variable (.only Register)]]]])
-(def .public type ////type.value)
+(def .public type
+ ////type.value)
(def .public (get class name)
- (-> (Type Class) Text (Bytecode Any))
+ (-> (Type Class) Text
+ (Bytecode Any))
(all _.composite
////reference.this
(_.getfield class name ..type)
))
(def .public (put naming class register value)
- (-> (-> Register Text) (Type Class) Register (Bytecode Any) (Bytecode Any))
+ (-> (-> Register Text) (Type Class) Register (Bytecode Any)
+ (Bytecode Any))
(all _.composite
////reference.this
value
@@ -50,11 +53,13 @@
))
(def .public (variable name type)
- (-> Text (Type Value) (Resource Field))
+ (-> Text (Type Value)
+ (Resource Field))
(field.field ..modifier name false type (sequence.sequence)))
(def .public (variables naming amount)
- (-> (-> Register Text) Nat (List (Resource Field)))
+ (-> (-> Register Text) Nat
+ (List (Resource Field)))
(|> amount
list.indices
(list#each (function (_ register)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux
index b12c5d271..74bf480b5 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux
@@ -120,9 +120,9 @@
_ (/////translation.save! artifact_id {.#None} declaration)]
(in (_.apply initsO+ instantiation)))))
-(def .public (again! statement expression archive argsS+)
+(def .public (again! statement expression archive it)
(Translator! (List synthesis.Term))
(do [! phase.monad]
[[offset @scope] /////translation.anchor
- argsO+ (monad.each ! (expression archive) argsS+)]
- (in (..setup false offset argsO+ false (_.go_to @scope)))))
+ it (monad.each ! (expression archive) it)]
+ (in (..setup false offset it false (_.go_to @scope)))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux
index d7a494c1a..f46f99529 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux
@@ -115,17 +115,10 @@
_ (/////translation.save! loop_artifact {.#None} declaration)]
(in (_.apply initsO+ instantiation)))))
-(def .public (again! statement expression archive argsS+)
+(def .public (again! statement expression archive it)
(Translator! (List synthesis.Term))
(do [! phase.monad]
[offset /////translation.anchor
- @temp (//when.symbol "lux_again_values")
- argsO+ (monad.each ! (expression archive) argsS+)
- .let [re_binds (|> argsO+
- list.enumeration
- (list#each (function (_ [idx _])
- (_.item (_.int (.int idx)) @temp))))]]
- (in (all _.then
- (_.set (list @temp) (_.list argsO+))
- (..setup offset re_binds
- _.continue)))))
+ it (monad.each ! (expression archive) it)]
+ (in (..setup offset it
+ _.continue))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux
index 4cff08fc6..1ef6a91a5 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux
@@ -84,17 +84,10 @@
[(list)] (_.lambda {.#None})
(_.apply_lambda (list)))))))
-(def .public (again! statement expression archive argsS+)
+(def .public (again! statement expression archive it)
(Translator! (List synthesis.Term))
(do [! phase.monad]
[offset /////translation.anchor
- @temp (//when.symbol "lux_again_values")
- argsO+ (monad.each ! (expression archive) argsS+)
- .let [re_binds (|> argsO+
- list.enumeration
- (list#each (function (_ [idx _])
- (_.item (_.int (.int idx)) @temp))))]]
- (in (all _.then
- (_.set (list @temp) (_.array argsO+))
- (..setup offset re_binds
- _.next)))))
+ it (monad.each ! (expression archive) it)]
+ (in (..setup offset it
+ _.next))))
diff --git a/stdlib/source/library/lux/meta/compiler/target/c++.lux b/stdlib/source/library/lux/meta/compiler/target/c++.lux
index b29ce98ad..56566a3e1 100644
--- a/stdlib/source/library/lux/meta/compiler/target/c++.lux
+++ b/stdlib/source/library/lux/meta/compiler/target/c++.lux
@@ -3,7 +3,7 @@
(.require
[library
- [lux (.except Code Type Global Declaration Definition
+ [lux (.except Code Type Global Declaration Definition Label
int as function template local global type also of is if for alias)
[abstract
[equivalence (.only Equivalence)]]
@@ -35,6 +35,7 @@
(def template_delimiters ["<" ">"])
(def initialization_delimiters ["{" "}"])
(def capture_delimiters ["[" "]"])
+(def array_delimiters ..capture_delimiters)
(nominal.def .public (Code of)
Text
@@ -75,7 +76,8 @@
[[Capture []]
[Parameter [of]]
[Expression [of]]
- [Statement [of]]]]
+ [Statement [of]]
+ [Label [of]]]]
[Parameter
[[Type [of]]]]
@@ -99,10 +101,12 @@
[Computation [of]]]]
[Computation
- [[Instantiation []]]]
+ [[Instantiation []]
+ [Initialization []]]]
[Statement
- [[Declaration [of]]]]
+ [[Declaration [of]]
+ [Block []]]]
[Declaration
[[Definition [of]]]]
@@ -237,22 +241,26 @@
Instantiation)
(<% (%.format (%> constructor) (application parameters))))
- (def initialization
+ (def .public initialization
(-> (List Expression)
- Text)
+ Initialization)
(|>> (list#each ..code)
(text.interposed ..parameter_separator)
- (text.enclosed ..initialization_delimiters)))
+ (text.enclosed ..initialization_delimiters)
+ <%))
(def .public (structure name parameters)
(-> Type (List Expression)
Instantiation)
- (<% (%.format (%> name) (initialization parameters))))
+ (<% (%.format (%> name)
+ (%> (initialization parameters)))))
(def .public (array type arity initials)
(-> Type Expression (List Expression)
Instantiation)
- (<% (%.format (%> type) "[" (%> arity) "]" " " (initialization initials))))
+ (<% (%.format (%> type)
+ (text.enclosed ..array_delimiters (%> arity))
+ " " (%> (initialization initials)))))
(def .public (new it)
(-> Instantiation
@@ -347,28 +355,30 @@
(text.interposed ..parameter_separator)
(text.enclosed ..term_delimiters)))
- (def block
- (-> Text
- Text)
+ (def .public block
+ (-> Statement
+ Block)
(let [\n\t (%.format \n \t)
<| (%.format "{" \n\t)
|> (%.format \n "}")]
- (|>> (text.replaced \n \n\t)
- (text.enclosed [<| |>]))))
+ (|>> %>
+ (text.replaced \n \n\t)
+ (text.enclosed [<| |>])
+ <%)))
(def .public (function name types inputs output body)
(-> Local (List Type_Name) (List Argument) Type Statement
Definition)
(<% (%.format (..template types)
(%> output) " " (%> name) (..arguments inputs)
- " " (..block (%> body)))))
+ " " (%> (..block body)))))
(def .public (namespace it body)
(-> Namespace Declaration
Declaration)
(<% (%.format "namespace"
" " it
- " " (..block (%> body)))))
+ " " (%> (..block body)))))
... https://en.cppreference.com/w/cpp/types/integer
(with_template [<name>]
@@ -418,7 +428,7 @@
Method)
(.function (_ of)
(<% (%.format "~" (%> of) "()"
- " " (block (%> body))))))
+ " " (%> (block body))))))
(def .public (var_declaration name type)
(-> Local Type
@@ -431,6 +441,13 @@
Definition)
(..statement (%.format (%> type) " const " (%> name) " = " (%> value))))
+ (def .public (constant_array name type size value)
+ (-> Local Type Literal Expression
+ Definition)
+ (..statement (%.format (%> type) " const " (%> name)
+ (text.enclosed ..array_delimiters (%> size))
+ " = " (%> value))))
+
(def .public (variable name type value)
(-> Local Type Expression
Definition)
@@ -447,14 +464,17 @@
(..statement
(%.format "struct"
" " (%> name)
- " " (block (|> (all list#composite
- (list#each (.function (_ [name type])
- (%> (var_declaration name type)))
- fields)
- (list#each (.function (_ it)
- (..code (it name)))
- methods))
- (text.interposed \n))))))
+ " " (|> (all list#composite
+ (list#each (.function (_ [name type])
+ (%> (var_declaration name type)))
+ fields)
+ (list#each (.function (_ it)
+ (..code (it name)))
+ methods))
+ (text.interposed \n)
+ <%
+ ..block
+ %>))))
(def .public (enum_definition name options)
(-> Local (List Local)
@@ -462,9 +482,12 @@
(..statement
(%.format "enum"
" " (%> name)
- " " (block (|> options
- (list#each ..code)
- (text.interposed ..parameter_separator))))))
+ " " (|> options
+ (list#each ..code)
+ (text.interposed ..parameter_separator)
+ <%
+ ..block
+ %>))))
(def captures
(-> (List Capture)
@@ -496,7 +519,7 @@
(|> output
(maybe#each (|>> %> (%.format " -> ")))
(maybe.else ""))
- " " (..block (%> body)))))
+ " " (%> (..block body)))))
(def .public (? when then else)
(-> Expression Expression Expression
@@ -515,7 +538,8 @@
(def .public (item index array)
(-> Expression Expression
LValue)
- (<% (%.format (%> array) "[" (%> index) "]")))
+ (<% (%.format (%> array)
+ (text.enclosed ..array_delimiters (%> index)))))
(with_template [<name> <operator>]
[(def .public (<name> parameter subject)
@@ -542,8 +566,8 @@
(-> Expression Statement Statement
Statement)
(<% (%.format "if" (..term (%> when))
- " " (..block (%> then))
- " else " (..block (%> else)))))
+ " " (%> (..block then))
+ " else " (%> (..block else)))))
(def (for_initialization [type variable value])
(-> [Type Local Expression]
@@ -566,5 +590,24 @@
(text.interposed (%.format ..statement_separator " "))
(text.enclosed ..term_delimiters))]
(<% (%.format "for" setup
- " " (..block (%> body))))))
+ " " (%> (..block body))))))
+
+ (def .public label
+ (-> Text
+ Label)
+ (|>> <%))
+
+ (def .public set_label
+ (-> Label
+ Statement)
+ (|>> %>
+ (text.suffix ":")
+ <%))
+
+ (def .public go_to
+ (-> Label
+ Statement)
+ (|>> %>
+ (%.format "goto ")
+ ..statement))
)
diff --git a/stdlib/source/library/lux/world/finance/market/price.lux b/stdlib/source/library/lux/world/finance/market/price.lux
index 041ce59d7..ca75ca370 100644
--- a/stdlib/source/library/lux/world/finance/market/price.lux
+++ b/stdlib/source/library/lux/world/finance/market/price.lux
@@ -30,12 +30,26 @@
(Price $)))
(money.money $ 0))
+(def .public (maximum $)
+ (All (_ $)
+ (-> (Currency $)
+ (Price $)))
+ (money.money $ (of n.interval top)))
+
... https://en.wikipedia.org/wiki/Price_action_trading
(nominal.def .public (Action $)
(Record
[#currency (Currency $)
#movement Int])
+ (def .public (none $)
+ (All (_ $)
+ (-> (Currency $)
+ (Action $)))
+ (nominal.abstraction
+ [#currency $
+ #movement +0]))
+
(def .public (action from to)
(All (_ $)
(-> (Price $) (Price $)
diff --git a/stdlib/source/test/lux/math/number/frac.lux b/stdlib/source/test/lux/math/number/frac.lux
index 7ae0e0aff..7a7f1c6bf 100644
--- a/stdlib/source/test/lux/math/number/frac.lux
+++ b/stdlib/source/test/lux/math/number/frac.lux
@@ -395,6 +395,20 @@
(|> expected /.opposite /.opposite (/.= expected))]
(and subtraction!
inverse!))))
+ (do [! random.monad]
+ [it (of ! each /.abs random.safe_frac)]
+ (_.coverage [/.degree]
+ (/.> it
+ (/.degree it))))
+ (do [! random.monad]
+ [it (of ! each /.abs random.safe_frac)]
+ (_.coverage [/.percentage /.permille /.permyriad]
+ (and (/.> it
+ (/.percentage it))
+ (/.> (/.percentage it)
+ (/.permille it))
+ (/.> (/.permille it)
+ (/.permyriad it)))))
..constant
..predicate
diff --git a/stdlib/source/test/lux/meta/compiler.lux b/stdlib/source/test/lux/meta/compiler.lux
index 682c7f96f..baa92d71f 100644
--- a/stdlib/source/test/lux/meta/compiler.lux
+++ b/stdlib/source/test/lux/meta/compiler.lux
@@ -31,28 +31,27 @@
"Ruby" (.,, (.these ["[1]/[0]" ruby]))
(.,, (.these))))]])))
-(`` (`` (def .public test
- Test
- (<| (_.covering /._)
- (do [! random.monad]
- [])
- (all _.and
- (_.coverage [/.Code /.Parameter /.Input]
- true)
+(`` (def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [])
+ (all _.and
+ (_.coverage [/.Code /.Parameter /.Input]
+ true)
- /arity.test
- /version.test
- /reference.test
-
- /language/lux.test
+ /arity.test
+ /version.test
+ /reference.test
+
+ /language/lux.test
- /meta.test
+ /meta.test
- /target.test
- (,, (for @.jvm (,, (these /target/jvm.test))
- @.old (,, (these /target/jvm.test))
- @.js (,, (these /target/js.test))
- @.lua (,, (these /target/lua.test))
- @.python (,, (these /target/python.test))
- @.ruby (,, (these /target/ruby.test))))
- )))))
+ /target.test
+ (,, (for @.jvm /target/jvm.test
+ @.js /target/js.test
+ @.lua /target/lua.test
+ @.python /target/python.test
+ @.ruby /target/ruby.test))
+ ))))
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux
index fc26af607..16df01422 100644
--- a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux
@@ -47,7 +47,8 @@
[constant
["[0]T" arity]]
[variable
- ["[0]T" count]]]
+ ["[0]T" count]
+ ["[0]T" foreign]]]
[//
["[0]T" complex]]])
@@ -154,4 +155,5 @@
/method.test
arityT.test
countT.test
+ foreignT.test
)))
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux
new file mode 100644
index 000000000..372439c33
--- /dev/null
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux
@@ -0,0 +1,96 @@
+... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" io]
+ ["[0]" try (.use "[1]#[0]" functor)]
+ ["[0]" function]]
+ [data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]
+ [collection
+ ["[0]" list]]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["n" nat (.use "[1]#[0]" equivalence)]
+ ["[0]" i64 (.use "[1]#[0]" equivalence)]]]
+ [meta
+ ["[0]" location]
+ [compiler
+ [target
+ [jvm
+ ["!" bytecode]
+ ["[0]" type]]]
+ [meta
+ ["[0]" archive]]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" / (.only)
+ [///
+ [constant
+ ["[0]" arity]]
+ [//
+ ["[0]" abstract]
+ [///
+ ["[0]" jvm (.only)
+ ["[0]" host]
+ ["[0]" runtime]
+ ["[0]" value]
+ ["[0]" complex
+ ["[1]T" \\test]]
+ [///
+ ["[0]" extension]
+ [//
+ ["[0]" phase]
+ ["[0]" synthesis]
+ ["[0]" translation]]]]]]]]])
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [module (random.lower_cased 1)
+
+ expected_i64 random.i64
+ dummy_i64 (random.only (|>> (i64#= expected_i64) not) random.i64)
+
+ .let [extender (is extension.Extender
+ (function (_ _)
+ (undefined)))
+ next (jvm.translate extender complexT.lux)
+ @ [module 0 0]]])
+ (all _.and
+ (_.coverage [/.closure /.variables
+ /.get /.put]
+ (|> (do try.monad
+ [[_ archive] (archive.reserve "" archive.empty)
+ [_ archive] (archive.reserve module archive)
+ .let [[_ host] (io.run! host.host)
+ state (is runtime.State
+ (translation.state host module))]]
+ (<| (phase.result state)
+ (do phase.monad
+ [_ (translation.set_buffer translation.empty_buffer)
+ it (next archive (<| (synthesis.function/abstraction @)
+ [(list) 1]
+ (synthesis.function/abstraction @)
+ [(list (synthesis.variable/local @ 1)) 1]
+ (synthesis.variable/foreign @ 0)))]
+ (in (|> it
+ [{.#None}]
+ (of host evaluate)
+ (try#each (function (_ it)
+ (i64#= expected_i64
+ ((as (-> I64 I64 I64)
+ it)
+ expected_i64
+ dummy_i64))))
+ (try.else false))))))
+ (try.else false)))
+ )))
diff --git a/stdlib/source/test/lux/meta/compiler/target/ruby.lux b/stdlib/source/test/lux/meta/compiler/target/ruby.lux
index f706adfa5..ab02eea80 100644
--- a/stdlib/source/test/lux/meta/compiler/target/ruby.lux
+++ b/stdlib/source/test/lux/meta/compiler/target/ruby.lux
@@ -7,13 +7,14 @@
["[0]" ffi]
[abstract
[monad (.only do)]
- ["[0]" predicate]
["[0]" equivalence
["[1]T" \\test]]]
[control
["[0]" pipe]
["[0]" maybe (.use "[1]#[0]" functor)]
- ["[0]" try (.only Try) (.use "[1]#[0]" functor)]]
+ ["[0]" try (.only Try) (.use "[1]#[0]" functor)]
+ [function
+ ["[0]" predicate]]]
[data
["[0]" bit (.use "[1]#[0]" equivalence)]
["[0]" text (.use "[1]#[0]" equivalence)