aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux
diff options
context:
space:
mode:
authorEduardo Julian2022-10-03 20:14:08 -0400
committerEduardo Julian2022-10-03 20:14:08 -0400
commitd9a1d70ec04fd5796276aeb46038654ade4484f9 (patch)
tree9d658e79313853703f74077dc0087aae598ea542 /stdlib/source/library/lux
parent2800492f26ee51c75fc056493e0946b39d5f503b (diff)
Migrating default extensions to the new format [Part 1]
Diffstat (limited to 'stdlib/source/library/lux')
-rw-r--r--stdlib/source/library/lux/ffi/export.js.lux4
-rw-r--r--stdlib/source/library/lux/ffi/export.lua.lux2
-rw-r--r--stdlib/source/library/lux/ffi/export.py.lux2
-rw-r--r--stdlib/source/library/lux/ffi/export.rb.lux2
-rw-r--r--stdlib/source/library/lux/meta.lux65
-rw-r--r--stdlib/source/library/lux/meta/compiler/default/init.lux28
-rw-r--r--stdlib/source/library/lux/meta/compiler/default/platform.lux2
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/reference.lux9
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux91
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux24
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux8
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/synthesis.lux8
-rw-r--r--stdlib/source/library/lux/meta/macro/syntax/definition.lux6
13 files changed, 155 insertions, 96 deletions
diff --git a/stdlib/source/library/lux/ffi/export.js.lux b/stdlib/source/library/lux/ffi/export.js.lux
index 2f9e4e99d..6b0732c7a 100644
--- a/stdlib/source/library/lux/ffi/export.js.lux
+++ b/stdlib/source/library/lux/ffi/export.js.lux
@@ -40,14 +40,14 @@
(-> Code (Meta [Text Code]))
(|>> (list)
(<code>.result (<| <code>.form
- (<>.after (<code>.this_text "lux def"))
+ (<>.after (<code>.this_symbol (symbol .def#)))
(<>.before <code>.any)
(all <>.and
<code>.local
<code>.any)))
meta.lifted))
-(with_expansions [<extension> (static.random (|>> %.nat (%.format "lua export ") code.text)
+(with_expansions [<extension> (static.random (|>> %.nat (%.format "js export ") code.text)
random.nat)]
(declaration (<extension> self phase archive [name <code>.text
term <code>.any])
diff --git a/stdlib/source/library/lux/ffi/export.lua.lux b/stdlib/source/library/lux/ffi/export.lua.lux
index c00493f77..ce6949ea7 100644
--- a/stdlib/source/library/lux/ffi/export.lua.lux
+++ b/stdlib/source/library/lux/ffi/export.lua.lux
@@ -40,7 +40,7 @@
(-> Code (Meta [Text Code]))
(|>> (list)
(<code>.result (<| <code>.form
- (<>.after (<code>.this_text "lux def"))
+ (<>.after (<code>.this_symbol (symbol .def#)))
(<>.before <code>.any)
(all <>.and
<code>.local
diff --git a/stdlib/source/library/lux/ffi/export.py.lux b/stdlib/source/library/lux/ffi/export.py.lux
index 7633ed73a..d67b9539c 100644
--- a/stdlib/source/library/lux/ffi/export.py.lux
+++ b/stdlib/source/library/lux/ffi/export.py.lux
@@ -40,7 +40,7 @@
(-> Code (Meta [Text Code]))
(|>> (list)
(<code>.result (<| <code>.form
- (<>.after (<code>.this_text "lux def"))
+ (<>.after (<code>.this_symbol (symbol .def#)))
(<>.before <code>.any)
(all <>.and
<code>.local
diff --git a/stdlib/source/library/lux/ffi/export.rb.lux b/stdlib/source/library/lux/ffi/export.rb.lux
index 614cd7b45..9798cdb96 100644
--- a/stdlib/source/library/lux/ffi/export.rb.lux
+++ b/stdlib/source/library/lux/ffi/export.rb.lux
@@ -78,7 +78,7 @@
(-> Code (Meta [Name Code]))
(|>> (list)
(<code>.result (<| <code>.form
- (<>.after (<code>.this_text "lux def"))
+ (<>.after (<code>.this_symbol (symbol .def#)))
(<>.before <code>.any)
(all <>.and
(<text>.then ..name <code>.local)
diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux
index 69211a03c..c126d7c70 100644
--- a/stdlib/source/library/lux/meta.lux
+++ b/stdlib/source/library/lux/meta.lux
@@ -1,6 +1,6 @@
(.require
[library
- [lux (.except try macro type)
+ [lux (.except try macro type local)
[abstract
[functor (.only Functor)]
[apply (.only Apply)]
@@ -412,6 +412,54 @@
(in it)
(failure (all text#composite "Default is not an export: " (symbol#encoded name))))))))))
+(with_template [<name> <slot> <type>]
+ [(def .public <name>
+ (Meta <type>)
+ (function (_ lux)
+ {try.#Success [lux (the <slot> lux)]}))]
+
+ [compiler_state [] Lux]
+
+ [type_context .#type_context Type_Context]
+
+ [target [.#info .#target] Text]
+ [version [.#info .#version] Text]
+ [configuration [.#info .#configuration] (List [Text Text])]
+ )
+
+(def .public (local name)
+ (-> Symbol (Meta Global))
+ (do ..monad
+ [name (..normal name)
+ current_module_name ..current_module_name
+ lux ..compiler_state]
+ (loop (again [[normal_module normal_short] name])
+ (when (is (Maybe Global)
+ (do maybe.monad
+ [(open "/[0]") (|> lux
+ (the .#modules)
+ (property.value normal_module))]
+ (property.value normal_short /#definitions)))
+ {.#Some it}
+ (when it
+ {.#Definition [exported? type value]}
+ (if (or exported?
+ (text#= current_module_name normal_module))
+ (in it)
+ (failure (all text#composite "Global is not an export: " (symbol#encoded name))))
+
+ {.#Default [exported? type value]}
+ (if (or exported?
+ (text#= current_module_name normal_module))
+ (in it)
+ (failure (all text#composite "Global is not an export: " (symbol#encoded name))))
+
+ {.#Alias de_aliased}
+ (again de_aliased))
+
+ {.#None it}
+ (failure (all text#composite "Unknown global: " (symbol#encoded name)))))))
+
(def .public (definition_type name)
(-> Symbol (Meta Type))
(do ..monad
@@ -662,21 +710,6 @@
{try.#Failure error}
(..failure error)))
-(with_template [<name> <slot> <type>]
- [(def .public <name>
- (Meta <type>)
- (function (_ lux)
- {try.#Success [lux (the <slot> lux)]}))]
-
- [compiler_state [] Lux]
-
- [type_context .#type_context Type_Context]
-
- [target [.#info .#target] Text]
- [version [.#info .#version] Text]
- [configuration [.#info .#configuration] (List [Text Text])]
- )
-
(def .public (eval type code)
(-> Type Code (Meta Any))
(do [! ..monad]
diff --git a/stdlib/source/library/lux/meta/compiler/default/init.lux b/stdlib/source/library/lux/meta/compiler/default/init.lux
index b30769ba6..07cfaf968 100644
--- a/stdlib/source/library/lux/meta/compiler/default/init.lux
+++ b/stdlib/source/library/lux/meta/compiler/default/init.lux
@@ -83,16 +83,14 @@
///declaration.#generation [///declaration.#state generation_state
///declaration.#phase (generate extender)]]]))
-(def .public (with_default_declarations host_analysis program extender)
+(def .public (with_default_declarations host_analysis)
(All (_ anchor expression declaration)
(-> ///analysis.Bundle
- (Program expression declaration)
- (Extender anchor expression declaration)
(-> (///declaration.State+ anchor expression declaration)
(///declaration.State+ anchor expression declaration))))
(function (_ [declaration_extensions sub_state])
[(dictionary.composite declaration_extensions
- (luxD.bundle host_analysis program extender))
+ (luxD.bundle host_analysis))
sub_state]))
(type Reader
@@ -126,9 +124,21 @@
[(///generation.Buffer declaration)
Registry])
-(def (with_generation_defaults module)
- (-> Text
- (Operation Any))
+(def with_declaration_defaults
+ (Operation Any)
+ (do [! ///phase.monad]
+ [state ///phase.state
+ _ (|> state
+ (the extension.#bundle)
+ dictionary.entries
+ (monad.each !
+ (function (_ [name handler])
+ (///declaration.lifted_analysis
+ (moduleA.define name {.#Default [true .Declaration handler]})))))]
+ (in [])))
+
+(def with_generation_defaults
+ (Operation Any)
(do [! ///phase.monad]
[state ///phase.state
_ (|> state
@@ -146,8 +156,8 @@
(when module
.prelude
(do ///phase.monad
- []
- (with_generation_defaults module))
+ [_ with_generation_defaults]
+ with_declaration_defaults)
_
(with ///phase.monad
diff --git a/stdlib/source/library/lux/meta/compiler/default/platform.lux b/stdlib/source/library/lux/meta/compiler/default/platform.lux
index eecc1ed00..aa0f1d2eb 100644
--- a/stdlib/source/library/lux/meta/compiler/default/platform.lux
+++ b/stdlib/source/library/lux/meta/compiler/default/platform.lux
@@ -276,7 +276,7 @@
(initialize_state extender
(as_expected (..complete_extensions host_declaration_bundle (as_expected bundles)))
analysis_state)
- (try#each (//init.with_default_declarations host_analysis program extender))
+ (try#each (//init.with_default_declarations host_analysis))
async#in)))]]
(if (archive.archived? archive descriptor.runtime)
(do !
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/reference.lux
index 6d74996cc..668ee5376 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/reference.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/reference.lux
@@ -35,10 +35,10 @@
(exception.report
(list ["Definition" (%.symbol definition)])))
-(exception.def .public (labels_are_not_definitions definition)
+(exception.def .public (defaults_are_not_definitions global)
(Exception Symbol)
(exception.report
- (list ["Label" (%.symbol definition)])))
+ (list ["Default" (%.symbol global)])))
(def (definition quoted_module def_name)
(-> Text Symbol (Operation Analysis))
@@ -63,7 +63,10 @@
(text#= quoted_module ::module))
<return>
(/.except ..foreign_module_has_not_been_imported [current ::module quoted_module def_name])))
- (/.except ..definition_has_not_been_exported def_name))))))))
+ (/.except ..definition_has_not_been_exported [def_name]))))
+
+ {.#Default _}
+ (/.except ..defaults_are_not_definitions [def_name])))))
(def (variable var_name)
(-> Text (Operation (Maybe Analysis)))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux
index 363c97fe5..88ce8f82b 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux
@@ -12,13 +12,13 @@
[collection
["[0]" list (.use "[1]#[0]" mix monoid)]]]
["[0]" meta (.only)
- [type
+ [type (.only sharing)
["[0]" check]]]]]
["[0]" //
["[1][0]" extension]
["[1][0]" analysis]
["/[1]" //
- ["/" declaration (.only Operation Phase Extender)]
+ ["/" declaration (.only Operation Phase Handler Extender)]
["[1][0]" analysis (.only)
["[0]" evaluation]
["[1]/[0]" macro (.only Expander)]
@@ -40,11 +40,6 @@
(exception.report
(list ["Code" (%.code code)])))
-(exception.def .public (macro_was_not_found name)
- (Exception Symbol)
- (exception.report
- (list ["Name" (%.symbol name)])))
-
(type Eval
(-> Type Code (Meta Any)))
@@ -86,6 +81,33 @@
["Expected" (%.type expected)]
["Actual" (%.type actual)])))
+(type Value
+ (Variant
+ {#Normal Any}
+ {#Special Any}))
+
+(def (global_value name)
+ (-> Symbol (Meta [Type Value]))
+ (do meta.monad
+ [global (meta.local name)]
+ (when global
+ {.#Definition [exported? type value]}
+ (in [type {#Normal value}])
+
+ {.#Default [exported? type value]}
+ (in [type {#Special value}])
+
+ {.#Alias _}
+ (undefined))))
+
+(def (global_declaration name)
+ (-> Symbol (Meta Value))
+ (do meta.monad
+ [[type value] (global_value name)]
+ (if (check.subsumes? .Declaration type)
+ (in value)
+ (meta.failure (exception.error ..not_an_extension [name .Declaration type])))))
+
(def (extension_application extender
phase archive
name parameters)
@@ -95,19 +117,27 @@
Symbol (List Code)
(Operation anchor expression declaration /.Requirements)))
(do //.monad
- [[exported? type value] (<| /.lifted_analysis
- //extension.lifted
- (meta.export name))]
- (if (check.subsumes? .Declaration type)
- ((extender value) "" phase archive parameters)
- (//.except ..not_an_extension [name .Declaration type]))))
+ [value (<| /.lifted_analysis
+ //extension.lifted
+ (global_declaration name))]
+ (when value
+ {#Normal definition}
+ ((extender definition) "" phase archive parameters)
+
+ {#Special default}
+ (let [default (sharing [anchor expression declaration]
+ (is (Extender anchor expression declaration)
+ extender)
+ (is (Handler anchor expression declaration)
+ (as_expected default)))]
+ (default "" phase archive parameters)))))
(type Outcome
(Variant
{#More (List Code)}
{#Done /.Requirements}))
-(with_expansions [<lux_def_module> (these [|form_location| {.#Form (list.partial [|text_location| {.#Text "lux def module"}] annotations)}])]
+(with_expansions [<lux_def_module> (these [|form_location| {.#Form (list.partial [|text_location| {.#Symbol [..prelude "module#"]}] annotations)}])]
(def .public (phase wrapper extender expander)
(All (_ anchor expression declaration)
(-> //.Wrapper (Extender anchor expression declaration) Expander (Phase anchor expression declaration)))
@@ -128,37 +158,34 @@
[_ {.#Form (list.partial [_ {.#Text name}] inputs)}]
(//extension.apply archive again [name inputs])
- [_ {.#Form (list.partial macro|extension inputs)}]
+ [_ {.#Form (list.partial [_ {.#Symbol macro|extension}] inputs)}]
(do !
[expansion|requirements (do !
- [[def_type def_analysis] (<| /.lifted_analysis
- ///analysis/type.inferring
- (analysis archive macro|extension))]
- (when def_analysis
- (///analysis.constant def_name)
+ [[def_type def_value] (<| /.lifted_analysis
+ //extension.lifted
+ (global_value macro|extension))]
+ (when def_value
+ {#Normal def_value}
(cond (check.subsumes? Macro def_type)
(/.lifted_analysis
(do !
- [?macro (//extension.lifted (meta.macro def_name))
- macro (when ?macro
- {.#Some macro}
- (in macro)
-
- {.#None}
- (//.except ..macro_was_not_found def_name))
- expansion (//extension.lifted (///analysis/macro.expansion expander def_name macro inputs))]
+ [expansion (//extension.lifted (///analysis/macro.expansion expander macro|extension (as Macro def_value) inputs))]
(in {#More expansion})))
(check.subsumes? .Declaration def_type)
(do !
- [requirements (extension_application extender again archive def_name inputs)]
+ [requirements (extension_application extender again archive macro|extension inputs)]
(in {#Done requirements}))
... else
(//.except ..invalid_macro_call [code]))
-
- _
- (//.except ..invalid_macro_call [code])))]
+
+ {#Special def_value}
+ (if (check.subsumes? .Declaration def_type)
+ (do !
+ [requirements (extension_application extender again archive macro|extension inputs)]
+ (in {#Done requirements}))
+ (//.except ..invalid_macro_call [code]))))]
(when expansion|requirements
{.#Left expansion}
(when expansion
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux
index caddd4c81..22317eaea 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux
@@ -364,25 +364,11 @@
{.#Named name anonymous}
{.#Named name (again anonymous)}))))
-(def (bundle::def host_analysis program extender)
+(def .public (bundle host_analysis)
(All (_ anchor expression declaration)
(-> /////analysis.Bundle
- (Program expression declaration)
- (Extender anchor expression declaration)
(Bundle anchor expression declaration)))
- (<| (///bundle.prefix "def")
- (|> ///bundle.empty
- (dictionary.has "module" def_module)
- (dictionary.has "alias" def_alias)
- )))
-
-(def .public (bundle host_analysis program extender)
- (All (_ anchor expression declaration)
- (-> /////analysis.Bundle
- (Program expression declaration)
- (Extender anchor expression declaration)
- (Bundle anchor expression declaration)))
- (<| (///bundle.prefix "lux")
- (|> ///bundle.empty
- (dictionary.has "def" (lux::def host_analysis))
- (dictionary.composite (..bundle::def host_analysis program extender)))))
+ (|> ///bundle.empty
+ (dictionary.has "def#" (lux::def host_analysis))
+ (dictionary.has "module#" def_module)
+ (dictionary.has "alias#" def_alias)))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
index b31d36e9b..8c55204b3 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/generation/jvm.lux
@@ -61,15 +61,15 @@
[definition (meta.try (meta.export name))]
(when definition
{try.#Success [exported? type definition]}
- (in [exported? type {.#Left definition}])
+ (in [type {.#Left definition}])
{try.#Failure error}
(do !
[[exported? type default] (meta.default name)]
- (in [exported? type {.#Right default}]))))
- (is (Meta [Bit Type (Either Any Any)]))
+ (in [type {.#Right default}]))))
+ (is (Meta [Type (Either Any Any)]))
(meta.result lux))
- {try.#Success [exported? type value]}
+ {try.#Success [type value]}
(if (check.subsumes? .Generation type)
(when value
{.#Left definition}
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/synthesis.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/synthesis.lux
index 539c17856..49f847b4d 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/synthesis.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/synthesis.lux
@@ -75,15 +75,15 @@
[definition (meta.try (meta.export name))]
(when definition
{try.#Success [exported? type definition]}
- (in [exported? type {.#Left definition}])
+ (in [type {.#Left definition}])
{try.#Failure error}
(do !
[[exported? type default] (meta.default name)]
- (in [exported? type {.#Right default}]))))
- (is (Meta [Bit Type (Either Any Any)]))
+ (in [type {.#Right default}]))))
+ (is (Meta [Type (Either Any Any)]))
(meta.result lux))
- {try.#Success [exported? type value]}
+ {try.#Success [type value]}
(if (check.subsumes? .Synthesis type)
(when value
{.#Left definition}
diff --git a/stdlib/source/library/lux/meta/macro/syntax/definition.lux b/stdlib/source/library/lux/meta/macro/syntax/definition.lux
index 0db62599f..6c58ff992 100644
--- a/stdlib/source/library/lux/meta/macro/syntax/definition.lux
+++ b/stdlib/source/library/lux/meta/macro/syntax/definition.lux
@@ -43,7 +43,7 @@
))
(def extension
- "lux def")
+ (symbol .def#))
(def dummy
Code
@@ -53,7 +53,7 @@
(def .public (format (open "_[0]"))
(-> Definition Code)
- (` ((, (code.text ..extension))
+ (` ((, (code.symbol ..extension))
(, (code.local _#name))
(, (when _#value
{.#Left check}
@@ -73,7 +73,7 @@
<>.lifted)]
(<| (<code>.locally me_raw)
<code>.form
- (<>.after (<code>.this_text ..extension))
+ (<>.after (<code>.this_symbol ..extension))
(all <>.and
<code>.local
(<>.or //check.parser