diff options
author | Eduardo Julian | 2023-01-17 01:14:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2023-01-17 01:14:08 -0400 |
commit | dfe09eb7a90dbf164bc0c78085b2d340e0928190 (patch) | |
tree | a7591cf3c196d2586da8c2cf0493b937c2e9adad /stdlib/source/library/lux/meta/compiler/language | |
parent | 2351250b79656014eb441c39dc8c9a02cad1ee40 (diff) |
Added compilation of (almost all non-loop) control structures for C++.
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/language')
5 files changed, 146 insertions, 24 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)))}))) |