Skip to content

Commit

Permalink
New type for Type (part 8).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 12, 2024
1 parent de49737 commit e49ec99
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 358 deletions.
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/compiler/default/init.lux
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
[_ (///declaration.of_analysis
(moduleA.set_compiled module))
[_ analysis_module] (<| ///declaration.of_analysis
moduleA.current)
module.current)
final_buffer (///declaration.of_translation
///translation.buffer)
final_registry (///declaration.of_translation
Expand Down Expand Up @@ -371,7 +371,7 @@
(do [! phase.monad]
[[_ analysis_module] (<| (is (Operation [module.Name @type.Module]))
///declaration.of_analysis
moduleA.current)
module.current)
_ (///declaration.of_translation
(///translation.set_buffer temporary_buffer))
_ (///declaration.of_translation
Expand Down
7 changes: 4 additions & 3 deletions stdlib/source/library/lux/compiler/default/platform.lux
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
["[0]" binding]
["[0]" static]
["[0]" configuration (.only Configuration)]
["[0]" name]]
["[0]" name]
["[1]/[0]" module]]
[world
["[0]" file (.only Path)]
["[0]" console]]]]
Expand Down Expand Up @@ -211,7 +212,7 @@
(-> @type.Lux Archive
Archive)
(|> (do try.monad
[prelude (phase.value state (module.by_name .prelude))
[prelude (phase.value state (meta/module.by_name .prelude))
entry (archive.find .prelude archive)
.let [entry (has [archive.#module moduleM.#document]
(document.document $.key prelude)
Expand Down Expand Up @@ -768,7 +769,7 @@
///declaration.#state]
state)]
[/#type /#value] (|> /#definition
module.binding#export
binding.export
(phase.value analysis_state)
future#in)]
(future#in (if (check.< ..Custom /#type)
Expand Down
12 changes: 0 additions & 12 deletions stdlib/source/library/lux/compiler/language/lux/analysis.lux
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,6 @@
(has @type.#current_module))
(function.constant {.#Some name})))

... TODO: Remove this definition ASAP
(the .public provenance
(Operation Provenance)
(function (_ state)
{try.#Success [state (its @type.#provenance state)]}))

(the .public (with_provenance provenance action)
(for_any (_ it)
(-> Provenance (Operation it)
Expand All @@ -341,12 +335,6 @@
failure
failure)))))

... TODO: Remove this definition ASAP
(the .public seed
(Operation Natural)
(function (_ state)
{try.#Success [state (its @type.#seed state)]}))

(the (located provenance error)
(-> Provenance Text
Text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
[number
["n" natural]
["[0]" i64]]]
["[0]" meta]]]
[meta
["[0]" module]]]]
["[0]" // (.only Operation)
["[1][0]" type]
["[1][0]" scope]
Expand All @@ -31,8 +32,6 @@
["[0]" phase]
["[0]" synthesis]
["[0]" translation]
[analysis
["[0]" module]]
[///
[meta
["[0]" archive (.only Archive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
["[0]" type (.only)
["[0]" check]]
["[0]" meta (.only)
["[0]" code]]]]
["[0]" code]
["[0]" module]]]]
["/" // (.only Operation Phase)
["[1][0]" type]
[//
["[0]" phase (.use "[1]#[0]" monad)
["[0]" extension]]
[analysis
["[0]" module]]
[///
[meta
[archive (.only Archive)]]
Expand Down
203 changes: 7 additions & 196 deletions stdlib/source/library/lux/compiler/language/lux/analysis/module.lux
Original file line number Diff line number Diff line change
Expand Up @@ -71,191 +71,11 @@
.#imports (list)
.#module_state {.#Active}])

... TODO: Remove this definition ASAP
(the .public (by_name name)
(-> module.Name
(Operation @type.Module))
(function (_ state)
(when (|> state
(its @type.#modules)
(property.value name))
{try.#Success module}
{try.#Success [state module]}

failure
((/.except ..not_known [name]) state))))

... TODO: Remove this definition ASAP
(the .public current_name
(Operation module.Name)
(function (_ state)
(when (its @type.#current_module state)
{.#Some it}
{try.#Success [state it]}

_
((/.except ..no_current [name]) state))))

... TODO: Remove this definition ASAP
(the .public current
(Operation [module.Name @type.Module])
(do phase.monad
[name ..current_name
module (..by_name name)]
(in [name module])))

... TODO: Remove this definition ASAP
(the .public (normal name)
(-> Name
(Operation Name))
(when name
["" name]
(by phase.monad each
(function (_ module)
[module name])
..current_name)

_
(by phase.monad in name)))

... TODO: Remove these definitions ASAP
(template.with [,singular ,type ,cannot_access ,not_a ,unknown]
[(the .public (,singular it)
(-> Name
(Operation @type.Label))
(do phase.monad
[it (..normal it)
module (..by_name (name.module it))
this_module_name ..current_name]
(when (property.value (name.proper it) (its @type.#definitions module))
{try.#Success [exported? {@type.#Definition [def_type def_value]}]}
(if (.or (text.= this_module_name (name.module it))
exported?)
(if (type.= ,type def_type)
(in (as @type.Label def_value))
(/.except ,not_a [it]))
(/.except ,cannot_access [it this_module_name]))

failure
(/.except ,unknown [it]))))]

[tag @type.Tag label.cannot_access_tag label.not_a_tag label.unknown_tag]
[slot @type.Slot label.cannot_access_slot label.not_a_slot label.unknown_slot]
)

... TODO: Remove this definition ASAP
(the .public local#all
(Operation (Stack (property.List @type.Type)))
(function (_ lux)
(when (stack.inits (its @type.#scopes lux))
{try.#Success scopes}
{try.#Success [lux
(stack#each (|>> (its [@type.#locals @type.#mappings])
(list#each (function (_ [name [type _]])
[name type])))
scopes)]}

{try.#Failure error}
{try.#Failure error})))

... TODO: Remove this definition ASAP
(the .public (binding#macro full_name)
(-> Name
(Operation Macro))
(do phase.monad
[full_name (..normal full_name)]
(is (Operation Macro)
(function (_ lux)
(when (..current_name lux)
{try.#Success [_ this_module]}
(let [modules (its @type.#modules lux)]
(loop (macro [[module name] full_name])
(do try.monad
[$module (property.value module modules)
[exported? definition] (|> $module
(is @type.Module)
(its @type.#definitions)
(property.value name))]
(when definition
{@type.#Alias de_aliased}
(macro de_aliased)

{@type.#Definition [def_type def_value]}
(if (type.= @type.Macro def_type)
{try.#Success [lux (as Macro def_value)]}
{try.#Failure "..not_a_macro"})

{@type.#Default _}
{try.#Failure "..not_a_macro"}))))

{try.#Failure error}
{try.#Failure error})))))

... TODO: Remove this definition ASAP
(template.with [<name>]
[(the .public (<name> name)
(-> Name
(Operation [Bit @type.Global]))
(do phase.monad
[name (..normal name)
.let [[normal_module normal_proper] name]]
(function (_ lux)
(when (is (Maybe [Bit @type.Global])
(do maybe.monad
[it (|> lux
(its @type.#modules)
(property.value normal_module))]
(|> it
(its @type.#definitions)
(property.value normal_proper))))
{.#Some exported?,definition}
{try.#Success [lux exported?,definition]}

_
{try.#Failure "Unknown definition."}))))]

[binding#definition]
)

... TODO: Remove this definition ASAP
(the .public (binding#export name)
(-> Name
(Operation @type.Definition))
(do phase.monad
[name (..normal name)
.let [[expected _] name]
[exported? definition] (binding#definition name)
actual ..current_name]
(when definition
{@type.#Definition it}
(if (.or exported?
(text.= expected actual))
(in it)
(phase.failure (text "Definition is not an export: " (name.as_text name))))

{@type.#Alias it}
(if (.or exported?
(text.= expected actual))
(binding#export it)
(phase.failure (text "Alias is not an export: " (name.as_text name))))

{@type.#Default _}
(phase.failure (text "Defaults are not considered exports: "
(name.as_text name))))))

... TODO: Remove this definition ASAP
(the .public (import#by? import module)
(-> Text Text
(Operation Bit))
(phase#each (|>> (its @type.#imports)
(list.any? (text.= import)))
(..by_name module)))

(the .public (import module)
(-> module.Name
(Operation Any))
(do phase.monad
[self_name ..current_name]
[self_name module.current_name]
(function (_ state)
{try.#Success [(revised @type.#modules
(property.revised self_name (revised @type.#imports (function (_ current)
Expand All @@ -266,25 +86,16 @@
state)
[]]})))

... TODO: Remove this definition ASAP
(the .public all
(Operation (property.List @type.Module))
(function (_ state)
(|> state
(its @type.#modules)
[state]
{try.#Success})))

(the .public (by_alias it origin)
(-> Text module.Name
(Operation [module.Name @type.Module]))
(do phase.monad
[modules ..all
[modules module.all
name (phase.of_try
(do try.monad
[origin (property.value origin modules)]
(property.value it (its @type.#module_aliases origin))))
module (..by_name name)]
module (module.by_name name)]
(in [name module])))

(exception.the .public (cannot_re-use_alias [alias for previous origin])
Expand All @@ -299,7 +110,7 @@
(-> Text module.Name
(Operation Any))
(do phase.monad
[current ..current_name
[current module.current_name
previous (phase.try (by_alias it current))]
(when previous
{try.#Success [previous _]}
Expand Down Expand Up @@ -343,7 +154,7 @@
(-> Text [Bit @type.Global]
(Operation Any))
(do phase.monad
[[self_name self] ..current]
[[self_name self] module.current]
(when (property.value name (its @type.#definitions self))
{try.#Success [_ already_existing]}
(/.except ..cannot_define_more_than_once [[self_name name] already_existing])
Expand All @@ -368,15 +179,15 @@
[_ (..create hash name)
output (/.with_current_module name
action)
module (..by_name name)]
module (module.by_name name)]
(in [module output])))

(template.with [<setter> <asker> <tag>]
[(the .public (<setter> module_name)
(-> module.Name
(Operation Any))
(do phase.monad
[module (..by_name module_name)]
[module (module.by_name module_name)]
(let [active? (when (its @type.#module_state module)
{.#Active}
true
Expand Down
Loading

0 comments on commit e49ec99

Please sign in to comment.