diff options
Diffstat (limited to 'stdlib/source/library')
9 files changed, 178 insertions, 41 deletions
diff --git a/stdlib/source/library/lux/math/arithmetic/fixed_point.lux b/stdlib/source/library/lux/math/arithmetic/fixed_point.lux index 4498bce85..560068499 100644 --- a/stdlib/source/library/lux/math/arithmetic/fixed_point.lux +++ b/stdlib/source/library/lux/math/arithmetic/fixed_point.lux @@ -77,7 +77,7 @@ (I64 Any))) (|> it .i64 - (i.right_shifted (n.- (nominal.representation Point @) i64.width))))) + (i64.right_shifted (n.- (nominal.representation Point @) i64.width))))) (def .public (fixed @ units sub_units) (All (_ @) 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 new file mode 100644 index 000000000..519863128 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++.lux @@ -0,0 +1,104 @@ +... 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 Synthesis) + [abstract + [monad (.only do)]] + [control + ["[0]" try] + ["[0]" exception (.only Exception)]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format]]] + ["[0]" meta (.only) + [macro + ["^" pattern]] + [type + ["[0]" check]] + [compiler + [meta + ["[0]" archive (.only Archive)] + ["[0]" cache + [dependency + ["[1]/[0]" artifact]]]]]]]] + ["[0]" / + [runtime (.only Operation Phase Handler)] + ["[1][0]" primitive] + ["[1][0]" complex] + ... ["[1][0]" reference] + ... ["[1][0]" function] + ... ["[1][0]" when] + ... ["[1][0]" loop] + ["//[1]" /// + ["[0]" extension] + [// + ["[0]" phase (.use "[1]#[0]" monad)] + ["[0]" synthesis (.only Synthesis)] + ["[0]" translation] + [/// + ["[0]" reference]]]]]) + +(def .public (translation extender lux) + (-> extension.Extender Lux + Phase) + (function (phase archive it) + (when it + (^.with_template [<tag> <translator>] + [(<tag> @ it) + (phase#in (<translator> it))]) + ([synthesis.bit /primitive.bit] + [synthesis.i64 /primitive.i64] + [synthesis.f64 /primitive.f64] + [synthesis.text /primitive.text]) + + (synthesis.variant @ it) + (/complex.variant phase archive it) + + (synthesis.tuple @ it) + (/complex.tuple phase archive it) + + ... [@ {synthesis.#Reference reference}] + ... (when reference + ... {reference.#Variable variable} + ... (/reference.variable archive variable) + + ... {reference.#Constant constant} + ... (/reference.constant archive constant)) + + ... (synthesis.branch/when @ [valueS pathS]) + ... (/when.when phase archive [valueS pathS]) + + ... (synthesis.branch/exec @ [this that]) + ... (/when.exec phase archive [this that]) + + ... (synthesis.branch/let @ [inputS register bodyS]) + ... (/when.let phase archive [inputS register bodyS]) + + ... (synthesis.branch/if @ [conditionS thenS elseS]) + ... (/when.if phase archive [conditionS thenS elseS]) + + ... (synthesis.branch/get @ [path recordS]) + ... (/when.get phase archive [path recordS]) + + ... (synthesis.loop/scope @ scope) + ... (/loop.scope phase archive scope) + + ... (synthesis.loop/again @ updates) + ... (/loop.again phase archive updates) + + ... (synthesis.function/abstraction @ abstraction) + ... (/function.abstraction phase archive abstraction) + + ... (synthesis.function/apply @ application) + ... (/function.apply phase archive application) + + ... [@ {synthesis.#Extension [name parameters]}] + ... (extension.application extender lux phase archive .Translation false name parameters + ... (|>>) + ... (function (_ _) {.#None})) + + _ + (undefined) + ))) 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 4e488a289..461b0ead8 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 @@ -4,11 +4,17 @@ (.require [library [lux (.except Declaration Translation) + [abstract + ["[0]" monad (.only do)]] [data + ["[0]" product] [text - ["%" \\format]] + ["%" \\format] + [encoding + ["[0]" utf8]]] [collection - ["[0]" list]]] + ["[0]" list] + ["[0]" sequence]]] ["[0]" meta (.use "[1]#[0]" functor) ["[0]" code] [macro @@ -20,10 +26,13 @@ ["[0]" // ["[1][0]" type]] [///// + ["[0]" phase] ["[0]" translation] [/// [meta - [archive (.only Archive)]]]]) + [archive (.only Output Archive) + ["[0]" registry (.only Registry)] + ["[0]" unit]]]]]) (type .public Anchor Any) @@ -32,7 +41,7 @@ _.Expression) (type .public Declaration - _.Statement) + _.Declaration) (with_template [<name> <base>] [(type .public <name> @@ -44,6 +53,9 @@ [Bundle translation.Bundle] ) +(type .public Host + (translation.Host Value Declaration)) + (type .public (Translation of) (-> Phase Archive of (Operation Value))) @@ -156,3 +168,17 @@ _.Expression (_.global [..namespace <unit>] (list))) ) + +(def artifact_id + 0) + +(def .public translation + (Operation [Registry Output]) + (do phase.monad + [_ (translation.execute! ..declaration) + _ (translation.save! ..artifact_id {.#None} ..declaration)] + (in [(|> registry.empty + (registry.resource .true unit.none) + product.right) + (sequence.sequence [..artifact_id {.#None} + (of utf8.codec encoded (_.code ..declaration))])]))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux index 15a4a8057..4e47ca19b 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux @@ -60,69 +60,69 @@ (def .public (translate extender lux) (-> extension.Extender Lux Phase) - (function (phase archive synthesis) - (when synthesis + (function (phase archive it) + (when it (^.with_template [<tag> <translator>] - [(<tag> @ value) + [(<tag> @ it) (with_source_mapping @ - (phase#in (<translator> value)))]) + (phase#in (<translator> it)))]) ([synthesis.bit /primitive.bit] [synthesis.i64 /primitive.i64] [synthesis.f64 /primitive.f64] [synthesis.text /primitive.text]) - (synthesis.variant @ variantS) + (synthesis.variant @ it) (with_source_mapping @ - (/complex.variant phase archive variantS)) + (/complex.variant phase archive it)) - (synthesis.tuple @ members) + (synthesis.tuple @ it) (with_source_mapping @ - (/complex.tuple phase archive members)) + (/complex.tuple phase archive it)) - [@ {synthesis.#Reference reference}] + [@ {synthesis.#Reference it}] (with_source_mapping @ - (when reference - {reference.#Variable variable} - (/reference.variable archive variable) + (when it + {reference.#Variable it} + (/reference.variable archive it) - {reference.#Constant constant} - (/reference.constant archive constant))) + {reference.#Constant it} + (/reference.constant archive it))) - (synthesis.branch/when @ [valueS pathS]) + (synthesis.branch/when @ it) (with_source_mapping @ - (/when.when phase archive [valueS pathS])) + (/when.when phase archive it)) - (synthesis.branch/exec @ [this that]) + (synthesis.branch/exec @ it) (with_source_mapping @ - (/when.exec phase archive [this that])) + (/when.exec phase archive it)) - (synthesis.branch/let @ [inputS register bodyS]) + (synthesis.branch/let @ it) (with_source_mapping @ - (/when.let phase archive [inputS register bodyS])) + (/when.let phase archive it)) - (synthesis.branch/if @ [conditionS thenS elseS]) + (synthesis.branch/if @ it) (with_source_mapping @ - (/when.if phase archive [conditionS thenS elseS])) + (/when.if phase archive it)) - (synthesis.branch/get @ [path recordS]) + (synthesis.branch/get @ it) (with_source_mapping @ - (/when.get phase archive [path recordS])) + (/when.get phase archive it)) - (synthesis.loop/scope @ scope) + (synthesis.loop/scope @ it) (with_source_mapping @ - (/loop.scope phase archive scope)) + (/loop.scope phase archive it)) - (synthesis.loop/again @ updates) + (synthesis.loop/again @ it) (with_source_mapping @ - (/loop.again phase archive updates)) + (/loop.again phase archive it)) - (synthesis.function/abstraction @ abstraction) + (synthesis.function/abstraction @ it) (with_source_mapping @ - (/function.abstraction phase archive abstraction)) + (/function.abstraction phase archive it)) - (synthesis.function/apply @ application) + (synthesis.function/apply @ it) (with_source_mapping @ - (/function.apply phase archive application)) + (/function.apply phase archive it)) [@ {synthesis.#Extension [name parameters]}] (with_source_mapping @ diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux index 43d0cb6b6..80a700340 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux @@ -146,7 +146,8 @@ //runtime.apply)) (def .public (program artifact_name context program) - (-> (-> unit.ID Text) (Program (Bytecode Any) Definition)) + (-> (-> unit.ID Text) + (Program (Bytecode Any) Definition)) (let [super_class (|> ..^Object type.reflection reflection.reflection name.internal) main (method.method ..main::modifier "main" false ..main::type diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux index 1cd97d325..9c7a0aa24 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux @@ -8,7 +8,6 @@ [text ["%" \\format (.only format)]]] [meta - ["[0]" version] [compiler ["@" target]]]]] [//// @@ -54,8 +53,7 @@ (def .public (artifact [module artifact]) (-> unit.ID Text) - (format "l" (%.nat version.latest) - ..universe_label + (format ..universe_label "m" (%.nat module) "a" (%.nat artifact))) diff --git a/stdlib/source/library/lux/meta/compiler/meta/context.lux b/stdlib/source/library/lux/meta/compiler/meta/context.lux index ccd7fe4ea..d2c76f8dc 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/context.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/context.lux @@ -33,4 +33,5 @@ [lua @.lua ".lua" ".lua"] [python @.python ".py" ".py"] [ruby @.ruby ".rb" ".rb"] + [c++ @.c++ ".cpp" ".cpp"] ) diff --git a/stdlib/source/library/lux/meta/compiler/target.lux b/stdlib/source/library/lux/meta/compiler/target.lux index 82f1c4b53..ee3bbedc2 100644 --- a/stdlib/source/library/lux/meta/compiler/target.lux +++ b/stdlib/source/library/lux/meta/compiler/target.lux @@ -21,6 +21,7 @@ [lua "Lua"] [python "Python"] [ruby "Ruby"] + [c++ "C++"] ... Not available yet. [common_lisp "Common Lisp"] [php "PHP"] diff --git a/stdlib/source/library/lux/meta/compiler/target/c++.lux b/stdlib/source/library/lux/meta/compiler/target/c++.lux index d2cde8f5b..eda5a1440 100644 --- a/stdlib/source/library/lux/meta/compiler/target/c++.lux +++ b/stdlib/source/library/lux/meta/compiler/target/c++.lux @@ -43,6 +43,12 @@ (text#= (%> refererence) (%> it))))) + (def .public manual + (All (_ of) + (-> Text + (Code of))) + (|>> <%)) + (def .public code (-> (Code Any) Text) |