Skip to content

Commit

Permalink
New type for Type (part 0).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 4, 2024
1 parent ddc3986 commit 490e1fd
Show file tree
Hide file tree
Showing 28 changed files with 804 additions and 539 deletions.
35 changes: 19 additions & 16 deletions stdlib/source/library/lux/compiler/default/init.lux
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
Configuration
extension.Extender Expander
(///translation.Host expression declaration)
(-> extension.Extender Lux (///translation.Phase anchor expression declaration))
(-> extension.Extender @type.Lux (///translation.Phase anchor expression declaration))
(///declaration.State anchor expression declaration)))
(let [lux (analysis.state (analysis.info version.latest target configuration))]
[///declaration.#analysis [///declaration.#state lux
Expand Down Expand Up @@ -110,6 +110,11 @@
[(///translation.Buffer declaration)
Registry])

(the Analysis' (@type.new .Analysis))
(the Synthesis' (@type.new .Synthesis))
(the Translation' (@type.new .Translation))
(the Declaration' (@type.new .Declaration))

(the (with_analysis_defaults bundle)
(-> analysis.Bundle
(Operation Any))
Expand All @@ -119,7 +124,7 @@
(list.each' !
(function (_ [name handler])
(///declaration.of_analysis
(moduleA.override_definition [.prelude name] [true {.#Default [.Analysis handler]}])))))]
(moduleA.override_definition [.prelude name] [true {@type.#Default [..Analysis' handler]}])))))]
(in [])))

(the (with_synthesis_defaults bundle)
Expand All @@ -131,7 +136,7 @@
(list.each' !
(function (_ [name handler])
(///declaration.of_analysis
(moduleA.override_definition [.prelude name] [true {.#Default [.Synthesis handler]}])))))]
(moduleA.override_definition [.prelude name] [true {@type.#Default [..Synthesis' handler]}])))))]
(in [])))

(the (with_translation_defaults bundle)
Expand All @@ -144,7 +149,7 @@
(list.each' !
(function (_ [name handler])
(///declaration.of_analysis
(moduleA.override_definition [.prelude name] [true {.#Default [.Translation handler]}])))))]
(moduleA.override_definition [.prelude name] [true {@type.#Default [..Translation' handler]}])))))]
(in [])))

(the (with_declaration_defaults bundle)
Expand All @@ -158,7 +163,7 @@
(function (_ [name handler])
(do !
[_ (///declaration.of_analysis
(moduleA.override_definition [.prelude name] [true {.#Default [.Declaration handler]}]))]
(moduleA.override_definition [.prelude name] [true {@type.#Default [..Declaration' handler]}]))]
(in [])))))]
(in [])))

Expand Down Expand Up @@ -208,14 +213,12 @@
(the (end module)
(-> descriptor.Module
(for_any (_ anchor expression declaration)
(///declaration.Operation anchor expression declaration [.Module (Payload declaration)])))
(///declaration.Operation anchor expression declaration [@type.Module (Payload declaration)])))
(do phase.monad
[_ (///declaration.of_analysis
(moduleA.set_compiled module))
[_ analysis_module] (<| (is (Operation [module.Name .Module]))
///declaration.of_analysis
analysis.with_lux
module.current)
[_ analysis_module] (<| ///declaration.of_analysis
moduleA.current)
final_buffer (///declaration.of_translation
///translation.buffer)
final_registry (///declaration.of_translation
Expand Down Expand Up @@ -290,8 +293,9 @@
(stack descriptor.runtime prelude)))

(the module_aliases
(-> .Module Aliases)
(|>> (its .#module_aliases)
(-> @type.Module
Aliases)
(|>> (its @type.#module_aliases)
(dictionary.of_list text.hash)))

(expansion.let [<parameters> (these anchor expression declaration)]
Expand Down Expand Up @@ -355,7 +359,7 @@
(in [state
{.#Right [[moduleM.#id (try.else moduleM.runtime (archive.id module archive))
moduleM.#descriptor descriptor
moduleM.#document (document.document key analysis_module)]
moduleM.#document (document.document key (@type.old_module analysis_module))]
(sequence#each (function (_ [artifact_id custom declaration])
[artifact_id custom (write_declaration declaration)])
final_buffer)
Expand All @@ -370,10 +374,9 @@
///.#process (function (_ state archive)
(again (<| (phase.value' state)
(do [! phase.monad]
[[_ analysis_module] (<| (is (Operation [module.Name .Module]))
[[_ analysis_module] (<| (is (Operation [module.Name @type.Module]))
///declaration.of_analysis
analysis.with_lux
module.current)
moduleA.current)
_ (///declaration.of_translation
(///translation.set_buffer temporary_buffer))
_ (///declaration.of_translation
Expand Down
17 changes: 8 additions & 9 deletions stdlib/source/library/lux/compiler/default/platform.lux
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
["[0]" type (.only sharing)
["[0]" check]]
["[0]" meta (.only)
["[0]" module]
["[0]" binding]
["[0]" static]
["[0]" configuration (.only Configuration)]
Expand All @@ -55,7 +54,7 @@
["[1][0]" declaration (.only Extender)]
["[0]" analysis (.only)
[macro (.only Expander)]
["[0]A" module]]
["[0]" module]]
["[0]" phase (.only Phase) (.use "[1]#[0]" monad)
["[0]" extension]]]]
[meta
Expand Down Expand Up @@ -86,7 +85,7 @@
(Record
[#file_system (file.System Future)
#host (///translation.Host expression declaration)
#phase (-> extension.Extender Lux (///translation.Phase <type_vars>))
#phase (-> extension.Extender @type.Lux (///translation.Phase <type_vars>))
#runtime (<Operation> [Registry Output])
#phase_wrapper phase.Wrapper
#write (-> declaration Binary)]))
Expand Down Expand Up @@ -175,7 +174,7 @@

(the runtime_document
(Document .Module)
(document.document $.key (moduleA.empty 0)))
(document.document $.key (@type.old_module (module.empty 0))))

(the runtime_module
(moduleM.Module .Module)
Expand Down Expand Up @@ -209,13 +208,13 @@
(//init.with_defaults .prelude all_extensions)))

(the (with_extended_prelude state archive)
(-> Lux Archive
(-> @type.Lux Archive
Archive)
(|> (do try.monad
[prelude (meta.value state (module.by_name .prelude))
[prelude (phase.value state (module.by_name .prelude))
entry (archive.find .prelude archive)
.let [entry (has [archive.#module moduleM.#document]
(document.document $.key prelude)
(document.document $.key (@type.old_module prelude))
entry)]]
(archive.has! .prelude entry archive))
(try.else archive)))
Expand Down Expand Up @@ -257,7 +256,7 @@
(if (archive.archived? archive descriptor.runtime)
(do !
[state (with_missing_extensions all_extensions state)
.let [archive (with_extended_prelude (analysis.as_lux (its [///declaration.#analysis ///declaration.#state] state)) archive)]]
.let [archive (with_extended_prelude (its [///declaration.#analysis ///declaration.#state] state) archive)]]
(in [state archive phase_wrapper]))
(do !
[[state [archive payload]] (|> (..process_runtime archive platform)
Expand Down Expand Up @@ -496,7 +495,7 @@
it (|> entry
(its [archive.#module moduleM.#document])
(document.content $.key))]
(in [module it])))
(in [module (@type.new_module it)])))
(archive.archived archive)))
.let [additions (|> modules
(list#each product.left)
Expand Down
6 changes: 4 additions & 2 deletions stdlib/source/library/lux/compiler/language/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
["_" \\injection (.only Injection)]
["<[1]>" \\projection (.only Projection)]]]
[meta
["[0]" version]]]]
["[0]" version]]
[compiler
["@[0]" type]]]]
["[0]" /
[analysis
["[0]" module]]
Expand Down Expand Up @@ -77,4 +79,4 @@
(Key .Module)
(key.key [signature.#name (name ..compiler)
signature.#version version.latest]
(module.empty 0)))
(@type.old_module (module.empty 0))))
82 changes: 29 additions & 53 deletions stdlib/source/library/lux/compiler/language/lux/analysis.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[hash (.only Hash)]
[monad (.only do)]]
[control
["[0]" maybe]]
["[0]" maybe (.use "[1]#[0]" functor)]]
[error
["[0]" try (.only Try)]
["[0]" exception (.only Exception)]]
Expand All @@ -22,7 +22,8 @@
["%" \\injection]]
[collection
["[0]" list (.use "[1]#[0]" functor mix monoid)
["?[1]" \\projection]]
["?[1]" \\projection]
["[0]" property (.use "[1]#[0]" functor)]]
["[0]" stack (.use "[1]#[0]" functor mix)]]]
[math
[number
Expand Down Expand Up @@ -296,8 +297,8 @@

(the .public (with_source_code source action)
(for_any (_ it)
(-> Source (Operation it)
(Operation it)))
(-> Source
(Change (Operation it))))
(function (_ state)
(let [old_source (its @type.#source state)]
(.when (action (has @type.#source source state))
Expand All @@ -318,6 +319,12 @@
(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 @@ -334,6 +341,12 @@
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 Expand Up @@ -403,15 +416,10 @@
[set_provenance Provenance @type.#provenance value]
)

(the .public (provenance file)
(-> Text
Provenance)
[file 1 0])

(the .public (source file code)
(-> Text Text
Source)
[(provenance file) 0 code])
[[file 1 0] 0 code])

(the dummy_source
Source
Expand Down Expand Up @@ -452,6 +460,7 @@
(the no_adjustment_is_necessary!
(type.= ..State .Lux))

... TODO: Remove ASAP
(the .public as_lux
(static.if ..no_adjustment_is_necessary!
..as_is
Expand All @@ -462,60 +471,27 @@
.#source (its @type.#source it)
.#provenance (its @type.#provenance it)
.#current_module (its @type.#current_module it)
.#modules (its @type.#modules it)
.#modules (|> (its @type.#modules it)
(property#each @type.old_module))
.#scopes (stack#each (function (_ it)
[.#scope_name (stack)
.#inner_scopes 0
.#locals (revised .#mappings list.as_stack (its @type.#locals it))
.#captured (revised .#mappings list.as_stack (its @type.#captured it))])
[.#locals (|> (its @type.#locals it)
(revised @type.#mappings (property#each (product.then @type.old function.identity))))
.#captured (|> (its @type.#captured it)
(revised @type.#mappings (property#each (product.then @type.old function.identity))))])
(its @type.#scopes it))
.#type_context (its @type.#type_context it)
.#expected (its @type.#expected it)
.#type_context (|> (its @type.#type_context it)
(revised @type.#var_bindings (list#each (product.then function.identity (maybe#each @type.old)))))
.#expected (maybe#each @type.old (its @type.#expected it))
.#seed (its @type.#seed it)
.#eval (its @type.#eval it)]))))

(the of_lux
(static.if ..no_adjustment_is_necessary!
..as_is
(is (-> .Lux
..State)
(function (_ it)
[@type.#info (its .#info it)
@type.#source (its .#source it)
@type.#provenance (its .#provenance it)
@type.#current_module (its .#current_module it)
@type.#modules (its .#modules it)
@type.#scopes (stack#each (function (_ it)
[@type.#locals (revised .#mappings list.of_stack (its .#locals it))
@type.#captured (revised .#mappings list.of_stack (its .#captured it))])
(its .#scopes it))
@type.#type_context (its .#type_context it)
@type.#expected (its .#expected it)
@type.#seed (its .#seed it)
@type.#eval (its .#eval it)]))))

(the .public with_lux
(static.if ..no_adjustment_is_necessary!
..as_is
(is (for_any (_ it)
(-> (Meta it)
(Operation it)))
(function (_ it)
(function (_ state)
(.when (it (as_lux state))
{try.#Success [state it]}
{try.#Success [(..of_lux state) it]}

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

(the .public (delegated extender analysis archive extension parameters)
(-> Extender Phase Archive Name (List @type.Code)
(Operation Term))
(do phase.monad
[lux phase.state]
(extension.reification extender
(..as_lux lux) analysis archive
lux analysis archive
.Analysis extension parameters
(|>>)
(function (_ _) {.#None}))))
Loading

0 comments on commit 490e1fd

Please sign in to comment.