aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux')
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux18
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/reference.lux8
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/when.lux124
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux18
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux2
-rw-r--r--stdlib/source/library/lux/meta/compiler/target/c++.lux55
6 files changed, 199 insertions, 26 deletions
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 395d31e39..6b1423ba0 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
@@ -29,7 +29,7 @@
["[1][0]" complex]
["[1][0]" reference]
... ["[1][0]" function]
- ... ["[1][0]" when]
+ ["[1][0]" when]
... ["[1][0]" loop]
[///
["[0]" extension]
@@ -59,8 +59,8 @@
(synthesis.tuple @ it)
(/complex.tuple phase archive it)
- [@ {synthesis.#Reference reference}]
- (when reference
+ [@ {synthesis.#Reference it}]
+ (when it
{reference.#Variable it}
(/reference.variable it)
@@ -70,14 +70,14 @@
... (synthesis.branch/when @ [valueS pathS])
... (/when.when phase archive [valueS pathS])
- ... (synthesis.branch/exec @ [this that])
- ... (/when.exec phase archive [this that])
+ (synthesis.branch/exec @ it)
+ (/when.exec phase archive it)
- ... (synthesis.branch/let @ [inputS register bodyS])
- ... (/when.let phase archive [inputS register bodyS])
+ (synthesis.branch/let @ it)
+ (/when.let phase archive it)
- ... (synthesis.branch/if @ [conditionS thenS elseS])
- ... (/when.if phase archive [conditionS thenS elseS])
+ (synthesis.branch/if @ it)
+ (/when.if phase archive it)
... (synthesis.branch/get @ [path recordS])
... (/when.get phase archive [path recordS])
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/reference.lux
index b43340b91..f449c76bf 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/reference.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/reference.lux
@@ -32,7 +32,7 @@
(with_template [<prefix> <name>]
[(def .public <name>
(-> Register
- /.Value)
+ _.Local)
(|>> %.nat
(%.format <prefix>)
_.local))]
@@ -43,12 +43,12 @@
)
(def .public this
- /.Value
+ _.Local
(..local 0))
(def .public variable
(-> Variable
- (Operation /.Value))
+ (Operation _.Local))
(|>> (|.when
{variable.#Local it}
(..local it)
@@ -59,7 +59,7 @@
(def .public (constant archive it)
(-> Archive Symbol
- (Operation /.Value))
+ (Operation _.Reference))
(phase#each (|>> product.left
reference.artifact
_.local)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/when.lux
new file mode 100644
index 000000000..1f58294e5
--- /dev/null
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/when.lux
@@ -0,0 +1,124 @@
+... 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 Type Label if let exec when int)
+ [abstract
+ ["[0]" monad (.only do)]]
+ [control
+ ["[0]" function]]
+ [data
+ [collection
+ ["[0]" list (.use "[1]#[0]" mix)]]
+ ["[0]" text (.use "[1]#[0]" equivalence)
+ ["%" \\format (.only format)]]]
+ [math
+ [number
+ ["n" nat]
+ ["[0]" i32]]]
+ [meta
+ [macro
+ ["^" pattern]]
+ [compiler
+ [target
+ ["_" c++]]]]]]
+ ["[0]" //
+ ["[1][0]" type]
+ ["[1][0]" reference]
+ ["[1][0]" runtime (.only Operation Phase Term)]
+ [////
+ ["[0]" phase (.use "[1]#[0]" functor)]
+ ["[0]" translation]
+ ["[0]" synthesis (.only Path Fork)
+ [access
+ ["[0]" member (.only Member)]]]
+ [///
+ [reference
+ [variable (.only Register)]]]]])
+
+(type (If of)
+ (Record
+ [#when of
+ #then of
+ #else of]))
+
+(def .public (if next archive it)
+ (Term If)
+ (do phase.monad
+ [when (next archive (the #when it))
+ then (next archive (the #then it))
+ else (next archive (the #else it))]
+ (in (_.? when then else))))
+
+(type (Let of)
+ (Record
+ [#input of
+ #register Register
+ #body of]))
+
+(def (sub_bindings body)
+ (-> synthesis.Term
+ [(List [Register synthesis.Term]) synthesis.Term])
+ (.when body
+ (synthesis.branch/let @ [input register body])
+ (.let [[tail body] (sub_bindings body)]
+ [(list.partial [register input] tail) body])
+
+ _
+ [(list) body]))
+
+(def .public (let next archive it)
+ (Term Let)
+ (do [! phase.monad]
+ [.let [[tail body] (sub_bindings (the #body it))
+ head_binding (the #register it)]
+ bindings (monad.each ! (function (_ [binding value])
+ (do !
+ [value (next archive value)]
+ (in (_.variable (//reference.local binding) //type.value value))))
+ (list.partial [head_binding (the #input it)]
+ tail))
+ body (next archive body)]
+ (in (_.on (list)
+ (_.lambda (.when head_binding
+ 0 (list)
+ _ (list _.all_by_value))
+ (list)
+ {.#Some //type.value}
+ (list#mix _.then
+ (_.return body)
+ (list.reversed bindings))
+ )))))
+
+(type (Exec of)
+ (Record
+ [#before of
+ #after of]))
+
+(def (sub_statements after)
+ (-> synthesis.Term
+ [(List synthesis.Term) synthesis.Term])
+ (.when after
+ (synthesis.branch/exec @ [before after])
+ (.let [[tail after] (sub_statements after)]
+ [(list.partial before tail) after])
+
+ _
+ [(list) after]))
+
+(def .public (exec next archive it)
+ (Term Exec)
+ (do [! phase.monad]
+ [.let [[tail after] (sub_statements (the #after it))]
+ all_before (monad.each ! (|>> (next archive)
+ (phase#each _.;))
+ (list.partial (the #before it) tail))
+ after (next archive after)]
+ (in (_.on (list)
+ (_.lambda (list _.all_by_value)
+ (list)
+ {.#Some //type.value}
+ (list#mix _.then
+ (_.return after)
+ (list.reversed all_before)))))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux
index 2080ea9c5..3f26f3b5f 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux
@@ -13,13 +13,15 @@
["_" bytecode (.only Bytecode)]
["[0]" type]
[encoding
- [name (.only External)]
["[0]" signed]]]]]]]]
- ["[0]" ////
- ["[1][0]" abstract]])
+ [///
+ [constant
+ ["[0]" arity]]
+ [//
+ ["[0]" abstract]]])
(def .public field "partials")
-(def .public type type.int)
+(def .public type arity.type)
(def .public initial
(Bytecode Any)
@@ -28,12 +30,6 @@
try.trusted
_.bipush))
-(def this
- _.aload_0)
-
(def .public value
(Bytecode Any)
- (all _.composite
- ..this
- (_.getfield ////abstract.class ..field ..type)
- ))
+ (_.getfield abstract.class ..field ..type))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux
index ceb7ee756..c18822e3c 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux
@@ -153,6 +153,7 @@
(_.new class)
_.dup
current_environment
+ ////reference.this
///count.value
(..increment apply_arity)
current_partials
@@ -162,6 +163,7 @@
_.areturn)))))))
(monad.all _.monad))]]
(all _.composite
+ ////reference.this
///count.value
(_.tableswitch (try.trusted (signed.s4 +0)) @default [@labelsH @labelsT])
cases)))})))
diff --git a/stdlib/source/library/lux/meta/compiler/target/c++.lux b/stdlib/source/library/lux/meta/compiler/target/c++.lux
index eda5a1440..014bf887a 100644
--- a/stdlib/source/library/lux/meta/compiler/target/c++.lux
+++ b/stdlib/source/library/lux/meta/compiler/target/c++.lux
@@ -8,7 +8,8 @@
[abstract
[equivalence (.only Equivalence)]]
[control
- ["|" pipe]]
+ ["|" pipe]
+ ["[0]" maybe (.use "[1]#[0]" functor)]]
[data
["[0]" text (.only \n \t) (.use "[1]#[0]" equivalence)
["%" \\format]]
@@ -31,6 +32,7 @@
(def term_delimiters ["(" ")"])
(def template_delimiters ["<" ">"])
(def initialization_delimiters ["{" "}"])
+(def capture_delimiters ["[" "]"])
(nominal.def .public (Code of)
Text
@@ -68,7 +70,8 @@
(,, (template.spliced <type>+))))]
[Code
- [[Type [of]]
+ [[Capture []]
+ [Type [of]]
[Expression [of]]
[Statement [of]]]]
@@ -268,6 +271,13 @@
(|>> %>
..statement))
+ (def .public return
+ (-> Expression
+ Statement)
+ (|>> %>
+ (%.format "return ")
+ ..statement))
+
(with_template [<name> <command>]
[(def .public <name>
(-> Expression
@@ -389,6 +399,11 @@
Definition)
(..statement (%.format (%> type) " const " (%> name) " = " (%> value))))
+ (def .public (variable name type value)
+ (-> Local Type Expression
+ Definition)
+ (..statement (%.format (%> type) " " (%> name) " = " (%> value))))
+
(def .public (structure_definition name [fields methods])
(-> Local [(List [Local Type]) (List Method)]
Definition)
@@ -402,4 +417,40 @@
(list#each ..code
methods))
(text.interposed \n))))))
+
+ (def captures
+ (-> (List Capture)
+ Text)
+ (|>> (list#each ..code)
+ (text.interposed ..parameter_separator)
+ (text.enclosed ..capture_delimiters)))
+
+ (with_template [<sigil> <name>]
+ [(def .public <name>
+ Capture
+ (<% <sigil>))]
+
+ ["=" all_by_value]
+ ["&" all_by_reference]
+ )
+
+ (def .public (lambda captures inputs output body)
+ (-> (List Capture) (List Argument) (Maybe Type) Statement
+ Expression)
+ (<| <%
+ (text.enclosed ..term_delimiters)
+ (%.format (..captures captures) (..arguments inputs)
+ (|> output
+ (maybe#each (|>> %> (%.format " -> ")))
+ (maybe.else ""))
+ " " (..block (%> body)))))
+
+ (def .public (? when then else)
+ (-> Expression Expression Expression
+ Expression)
+ (<| <%
+ (text.enclosed ..term_delimiters)
+ (%.format (%> when)
+ " ? " (%> then)
+ " : " (%> else))))
)