diff options
author | Eduardo Julian | 2022-12-23 20:58:58 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-12-23 20:58:58 -0400 |
commit | ad1391ea1cdd33167339d25dbff2567f5a8d5c68 (patch) | |
tree | 7b8c1154e3cdbc9a79fc7c3e468f07544c51f910 /stdlib/source/library | |
parent | 6f1bf11af05bd03183fee7721ac99eca826ca041 (diff) |
Began work on C++ back-end.
Diffstat (limited to 'stdlib/source/library')
9 files changed, 101 insertions, 66 deletions
diff --git a/stdlib/source/library/lux/data/color/cmyk.lux b/stdlib/source/library/lux/data/color/cmyk.lux index bd0a9d298..dc85a4a97 100644 --- a/stdlib/source/library/lux/data/color/cmyk.lux +++ b/stdlib/source/library/lux/data/color/cmyk.lux @@ -75,7 +75,7 @@ Frac) (f.- it ..most)) -(def .public (cmyk it) +(def .public (of_rgb it) (-> RGB CMYK) (let [red (..down (the rgb.#red it)) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux index 30c217bf3..a703fba70 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux @@ -23,10 +23,9 @@ [/// ["[0]" extension] [// + ["[0]" phase] ["[0]" analysis (.only Analysis Operation Phase Handler Bundle) - ["[1]/[0]" type]] - [/// - ["[0]" phase]]]]]) + ["[1]/[0]" type]]]]]) (def array::new (-> Text Handler) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux index 3dbaa594b..407f22b4f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux @@ -37,10 +37,9 @@ ["[1][0]" loop] ["[1][0]" function]]] [// + ["[0]" phase (.use "[1]#[0]" monad)] ["[0]" synthesis (.only %synthesis) - ["?[1]" \\parser (.only Parser)]] - [/// - ["[0]" phase (.use "[1]#[0]" monad)]]]]) + ["?[1]" \\parser (.only Parser)]]]]) (def .public (custom [parser handler]) (All (_ s) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux index 6be0522c3..cae36908d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux @@ -24,11 +24,10 @@ ["[0]" runtime (.only Operation Phase Handler Bundle with_vars)]]] [// + ["[0]" phase] ["[0]" translation] [synthesis - ["<s>" \\parser (.only Parser)]] - [/// - ["[0]" phase]]]]]) + ["<s>" \\parser (.only Parser)]]]]]) (def array::new (Unary Expression) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js.lux index cd0145243..e5e199068 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js.lux @@ -27,9 +27,9 @@ ["[1]/[0]" common]]]] ["/[1]" // [analysis (.only)] + ["[0]" phase (.use "[1]#[0]" monad)] ["[0]" synthesis] ["//[1]" /// - ["[1][0]" phase (.use "[1]#[0]" monad)] [reference (.only) [variable (.only)]]]]]]]) @@ -42,7 +42,7 @@ (when synthesis (^.with_template [<tag> <translator>] [(<tag> @ value) - (//////phase#in (<translator> value))]) + (phase#in (<translator> value))]) ([synthesis.bit /primitive.bit] [synthesis.i64 /primitive.i64] [synthesis.f64 /primitive.f64] @@ -76,7 +76,7 @@ (/loop.scope ///extension/common.statement expression archive scope) (synthesis.loop/again @ updates) - (//////phase.except ..cannot_recur_as_an_expression []) + (phase.except ..cannot_recur_as_an_expression []) (synthesis.function/abstraction @ abstraction) (/function.function ///extension/common.statement expression archive abstraction) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux index efca8fc3e..04ebfa62a 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux @@ -37,14 +37,12 @@ ["[0]" descriptor]]]] [compiler [meta - [io (.only lux_context)] [archive ["[0]" unit]]]]]]] ["[0]" // ["[1][0]" runtime (.only Definition)] ["[1][0]" type] - ["[1][0]" value]] - ) + ["[1][0]" value]]) (import java/lang/reflect/Field "[1]::[0]" @@ -61,10 +59,22 @@ (import java/lang/ClassLoader "[1]::[0]") -(def value::modifier (all modifier#composite field.public field.final field.static)) +(def value::modifier + (all modifier#composite + field.public + field.final + field.static + )) -(def init::type (type.method [(list) (list) type.void (list)])) -(def init::modifier (all modifier#composite method.public method.static method.strict)) +(def init::type + (type.method [(list) (list) type.void (list)])) + +(def init::modifier + (all modifier#composite + method.public + method.static + method.strict + )) (exception.def .public (cannot_load [class error]) (Exception [Text Text]) @@ -85,8 +95,9 @@ (list ["Class" class]))) (def (class_value class_name class) - (-> Text (java/lang/Class java/lang/Object) (Try Any)) - (when (java/lang/Class::getField //value.field class) + (-> Text (java/lang/Class java/lang/Object) + (Try Any)) + (when (java/lang/Class::getField (ffi.as_string //value.field) class) {try.#Success field} (when (java/lang/reflect/Field::get {.#None} field) {try.#Success ?value} @@ -107,7 +118,8 @@ ".") (def (evaluate! library loader eval_class [@it valueG]) - (-> Library java/lang/ClassLoader Text [(Maybe unit.ID) (Bytecode Any)] (Try [Any Definition])) + (-> Library java/lang/ClassLoader Text [(Maybe unit.ID) (Bytecode Any)] + (Try [Any Definition])) (let [bytecode_name (text.replaced class_path_separator .module_separator eval_class) :value: (when @it {.#Some @it} @@ -122,13 +134,13 @@ (encoding/name.internal "java.lang.Object") (list) (list (field.field ..value::modifier //value.field false :value: (sequence.sequence))) (list (method.method ..init::modifier "<clinit>" - false ..init::type - (list) - {.#Some - (all _.composite - valueG - (_.putstatic (type.class bytecode_name (list)) //value.field :value:) - _.return)})) + false ..init::type + (list) + {.#Some + (all _.composite + valueG + (_.putstatic (type.class bytecode_name (list)) //value.field :value:) + _.return)})) (list))] (io.run! (do [! (try.with io.monad)] [bytecode (of ! each (\\format.result class.format) @@ -140,7 +152,8 @@ [eval_class bytecode]]))))) (def (execute! library loader [class_name class_bytecode]) - (-> Library java/lang/ClassLoader Definition (Try Any)) + (-> Library java/lang/ClassLoader Definition + (Try Any)) (io.run! (do (try.with io.monad) [existing_class? (|> (atom.read! library) (of io.monad each (function (_ library) @@ -153,7 +166,8 @@ (loader.load class_name loader)))) (def (define! library loader context custom @it,valueG) - (-> Library java/lang/ClassLoader unit.ID (Maybe Text) [(Maybe unit.ID) (Bytecode Any)] (Try [Text Any Definition])) + (-> Library java/lang/ClassLoader unit.ID (Maybe Text) [(Maybe unit.ID) (Bytecode Any)] + (Try [Text Any Definition])) (let [class_name (maybe.else (//runtime.class_name context) custom)] (do try.monad diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux index be0a4dd59..4a82f30f1 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux @@ -173,7 +173,12 @@ (with_vars [exception] (_.try (_.return (..right (_.apply (list ..unit) op))) (list [(list "Exception") exception - (_.return (..left (_.str/1 exception)))])))) + (_.return (..left (_.do "join" + (list (_.do "format_exception_only" + (list (_.the "__class__" exception) + exception) + (_.__import__/1 (_.string "traceback")))) + (_.string ""))))])))) (runtime (lux::program_args program_args) @@ -211,7 +216,12 @@ (runtime (io::throw! message) - (_.raise (_.Exception/1 message))) + (_.raise (_.Exception/1 (|> message + (_.+ (_.string text.\n)) + (_.+ (_.do "join" + (list (_.do "format_stack" (list) + (_.__import__/1 (_.string "traceback")))) + (_.string ""))))))) (def runtime//io (Statement Any) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/translation.lux b/stdlib/source/library/lux/meta/compiler/language/lux/translation.lux index fc6ab8350..5f519f39d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/translation.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/translation.lux @@ -108,8 +108,7 @@ (def .public (state host module) (All (_ anchor expression declaration) - (-> (Host expression declaration) - descriptor.Module + (-> (Host expression declaration) descriptor.Module (..State anchor expression declaration))) [#module module #anchor {.#None} @@ -132,7 +131,8 @@ [(exception.def .public <exception>) (def .public <with_declaration> - (All (_ anchor expression declaration output) <with_type>) + (All (_ anchor expression declaration output) + <with_type>) (function (_ body) (function (_ state) (when (body (has <tag> {.#Some <with_value>} state)) @@ -156,7 +156,8 @@ (def .public (<set> value) (All (_ anchor expression declaration) - (-> <get_type> (Operation anchor expression declaration Any))) + (-> <get_type> + (Operation anchor expression declaration Any))) (function (_ state) {try.#Success [(has <tag> {.#Some value} state) []]}))] @@ -184,7 +185,8 @@ (def .public (set_registry value) (All (_ anchor expression declaration) - (-> Registry (Operation anchor expression declaration Any))) + (-> Registry + (Operation anchor expression declaration Any))) (function (_ state) {try.#Success [(has #registry value state) []]})) @@ -199,12 +201,14 @@ (def .public (symbol prefix) (All (_ anchor expression declaration) - (-> Text (Operation anchor expression declaration Text))) + (-> Text + (Operation anchor expression declaration Text))) (of phase.monad each (|>> %.nat (format prefix)) ..next)) (def .public (enter_module module) (All (_ anchor expression declaration) - (-> descriptor.Module (Operation anchor expression declaration Any))) + (-> descriptor.Module + (Operation anchor expression declaration Any))) (phase.update (has #module module))) (def .public module @@ -214,7 +218,8 @@ (def .public (evaluate! label code) (All (_ anchor expression declaration) - (-> unit.ID [(Maybe unit.ID) expression] (Operation anchor expression declaration Any))) + (-> unit.ID [(Maybe unit.ID) expression] + (Operation anchor expression declaration Any))) (function (_ state) (when (of (the #host state) evaluate label code) {try.#Success output} @@ -225,7 +230,8 @@ (def .public (execute! code) (All (_ anchor expression declaration) - (-> declaration (Operation anchor expression declaration Any))) + (-> declaration + (Operation anchor expression declaration Any))) (function (_ state) (when (of (the #host state) execute code) {try.#Success output} @@ -236,7 +242,8 @@ (def .public (define! context custom code) (All (_ anchor expression declaration) - (-> unit.ID (Maybe Text) [(Maybe unit.ID) expression] (Operation anchor expression declaration [Text Any declaration]))) + (-> unit.ID (Maybe Text) [(Maybe unit.ID) expression] + (Operation anchor expression declaration [Text Any declaration]))) (function (_ state) (when (of (the #host state) define context custom code) {try.#Success output} @@ -247,7 +254,8 @@ (def .public (save! artifact_id custom code) (All (_ anchor expression declaration) - (-> artifact.ID (Maybe Text) declaration (Operation anchor expression declaration Any))) + (-> artifact.ID (Maybe Text) declaration + (Operation anchor expression declaration Any))) (do [! phase.monad] [?buffer (phase.read (the #buffer))] (when ?buffer @@ -263,7 +271,8 @@ (with_template [<type> <mandatory?> <inputs> <input_types> <name> <artifact>] [(`` (def .public (<name> it (,, (template.spliced <inputs>)) dependencies) (All (_ anchor expression declaration) - (-> <type> (,, (template.spliced <input_types>)) (Set unit.ID) (Operation anchor expression declaration artifact.ID))) + (-> <type> (,, (template.spliced <input_types>)) (Set unit.ID) + (Operation anchor expression declaration artifact.ID))) (function (_ state) (let [[id registry'] (<artifact> it <mandatory?> dependencies (the #registry state))] {try.#Success [(has #registry registry' state) @@ -282,7 +291,8 @@ (def .public (remember archive name) (All (_ anchor expression declaration) - (-> Archive Symbol (Operation anchor expression declaration unit.ID))) + (-> Archive Symbol + (Operation anchor expression declaration unit.ID))) (function (_ state) (let [[_module _name] name] (do try.monad @@ -301,7 +311,8 @@ (def .public (definition archive name) (All (_ anchor expression declaration) - (-> Archive Symbol (Operation anchor expression declaration [unit.ID (Maybe category.Definition)]))) + (-> Archive Symbol + (Operation anchor expression declaration [unit.ID (Maybe category.Definition)]))) (function (_ state) (let [[_module _name] name] (do try.monad @@ -322,7 +333,8 @@ (def .public (module_id module archive) (All (_ anchor expression declaration) - (-> descriptor.Module Archive (Operation anchor expression declaration module.ID))) + (-> descriptor.Module Archive + (Operation anchor expression declaration module.ID))) (function (_ state) (do try.monad [@module (archive.id module archive)] @@ -330,7 +342,8 @@ (def .public (context archive) (All (_ anchor expression declaration) - (-> Archive (Operation anchor expression declaration unit.ID))) + (-> Archive + (Operation anchor expression declaration unit.ID))) (function (_ state) (when (the #context state) {.#None} @@ -342,10 +355,9 @@ (in [state [@module id]]))))) (def .public (with_context @artifact body) - (All (_ anchor expression declaration a) - (-> artifact.ID - (Operation anchor expression declaration a) - (Operation anchor expression declaration a))) + (All (_ anchor expression declaration of) + (-> artifact.ID (Operation anchor expression declaration of) + (Operation anchor expression declaration of))) (function (_ state) (do try.monad [[state' output] (body (has #context {.#Some @artifact} state))] @@ -353,10 +365,9 @@ output])))) (def .public (with_registry_shift shift body) - (All (_ anchor expression declaration a) - (-> Nat - (Operation anchor expression declaration a) - (Operation anchor expression declaration a))) + (All (_ anchor expression declaration of) + (-> Nat (Operation anchor expression declaration of) + (Operation anchor expression declaration of))) (function (_ state) (do try.monad [[state' output] (body (has #registry_shift shift state))] @@ -364,9 +375,9 @@ output])))) (def .public (with_new_context archive dependencies body) - (All (_ anchor expression declaration a) - (-> Archive (Set unit.ID) (Operation anchor expression declaration a) - (Operation anchor expression declaration [unit.ID a]))) + (All (_ anchor expression declaration of) + (-> Archive (Set unit.ID) (Operation anchor expression declaration of) + (Operation anchor expression declaration [unit.ID of]))) (function (_ state) (let [[@artifact registry'] (registry.resource false dependencies (the #registry state)) @artifact (n.+ @artifact (the #registry_shift state))] @@ -381,16 +392,17 @@ output]]))))) (def .public (log! message) - (All (_ anchor expression declaration a) - (-> Text (Operation anchor expression declaration Any))) + (All (_ anchor expression declaration) + (-> Text + (Operation anchor expression declaration Any))) (function (_ state) {try.#Success [(revised #log (sequence.suffix message) state) []]})) (def .public (with_interim_artifacts archive body) - (All (_ anchor expression declaration a) - (-> Archive (Operation anchor expression declaration a) - (Operation anchor expression declaration [(List unit.ID) a]))) + (All (_ anchor expression declaration of) + (-> Archive (Operation anchor expression declaration of) + (Operation anchor expression declaration [(List unit.ID) of]))) (do phase.monad [module (phase.read (the #module))] (function (_ state) diff --git a/stdlib/source/library/lux/meta/macro/syntax/export.lux b/stdlib/source/library/lux/meta/macro/syntax/export.lux index 522fefb6b..3ffff3e05 100644 --- a/stdlib/source/library/lux/meta/macro/syntax/export.lux +++ b/stdlib/source/library/lux/meta/macro/syntax/export.lux @@ -38,5 +38,7 @@ (in default))))) (def .public with - (All (_ a) (-> (Parser a) (Parser [Policy a]))) + (All (_ of) + (-> (Parser of) + (Parser [Policy of]))) (<>.and ..policy)) |