Skip to content

Commit

Permalink
Adapting to new List type (part 17).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 13, 2024
1 parent 3812076 commit 75f54c8
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 261 deletions.
3 changes: 1 addition & 2 deletions stdlib/source/library/lux/compiler/language/lux/analysis.lux
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
[collection
["[0]" list (.use "[1]#[0]" functor mix monoid)
["?[1]" \\projection]
["[0]" property (.use "[1]#[0]" functor)]]
["[0]" stack (.use "[1]#[0]" functor mix)]]]
["[0]" property (.use "[1]#[0]" functor)]]]]
[math
[number
["n" natural]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
["[0]" text (.only)
["%" \\injection]]
[collection
["[0]" stack (.use "[1]#[0]" mix functor)]
["[0]" list (.use "[1]#[0]" mix functor monoid)
["[0]" property]]]]
[macro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@
(function (_ [@it :it:]))
(do phase.monad
[it (..expecting :it: action)
:it: (..check (check.identity (stack) @it))]
:it: (..check (check.identity (list) @it))]
(in [:it: it]))))
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@
(the sum_analysis
(template.macro (_ analysis archive lefts right? values)
... (-> Phase Archive Natural Bit (Stack @type.Code) (Operation /.Term))
[(when values
(list value)
(/complex.sum analysis lefts right? archive value)
[(/complex.sum lefts right? analysis archive
(when values
(list value)
value

_
(/complex.sum analysis lefts right? archive (code.tuple values)))]))
_
(code.tuple values)))]))

(every Macro_Abstraction
[Name .Macro])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@
(list.item tag)
(try.else .Nothing)))))

(the .public (sum analyse lefts right? archive)
(-> Phase Natural Bit Phase)
(the .public (sum lefts right? analysis archive)
(-> Natural Bit
(Change Phase))
(function (again valueC)
(do [! phase.monad]
[expectedT meta.expected_type
expectedT' (/type.check (check.clean (stack) expectedT))
expectedT' (/type.check (check.clean (list) expectedT))
@ meta.provenance
here module.current_name]
(/.with_exception ..cannot_analyse_sum [here expectedT' lefts right? valueC]
(when expectedT
(type.Sum _ _)
(|> (analyse archive valueC)
(|> (analysis archive valueC)
(by ! each (|>> [lefts right?] (/.variant @)))
(/type.expecting (..case lefts right? (type.flat_variant expectedT))))

Expand Down Expand Up @@ -208,7 +209,7 @@
(do !
[here module.current_name]
(/.with_exception ..cannot_analyse_variant [here else tag valueC]
(..sum analyse lefts right? archive valueC))))))
(..sum lefts right? analyse archive valueC))))))

(the (typed_product analyse expectedT archive members)
(-> Phase Type Archive (Stack @type.Code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
[functionA (again (type.Function :input: :output:))])
/type.check
(do check.monad
[:output: (check.identity (stack) @output)
?:input: (check.try (check.identity (stack @output) @input))
[:output: (check.identity (list) @output)
?:input: (check.try (check.identity (list @output) @input))
? (check.linked? @input @output)
.let [not_quantified (type.Function :input: (if ? :input: :output:))]
_ (<| (check.check expectedT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
[collection
["[0]" list (.only)
["[0]" property]]
["[0]" stack]
["[0]" dictionary (.only Dictionary)]]]
["[0]" type (.only sharing)
["[0]" check]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@
[_ (typeA.inference ..int)
arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:)))
(analyse archive arrayC))
:read: (typeA.check (check.clean (stack) :read:))
:write: (typeA.check (check.clean (stack) :write:))
:read: (typeA.check (check.clean (list) :read:))
:write: (typeA.check (check.clean (list) :write:))
arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))
@ meta.provenance]
(in [@ {analysis.#Extension [.prelude (text extension_name "|translation")]
Expand Down Expand Up @@ -754,8 +754,8 @@
(analyse archive arrayC))
idxA (<| (typeA.expecting ..int)
(analyse archive idxC))
:read: (typeA.check (check.clean (stack) :read:))
:write: (typeA.check (check.clean (stack) :write:))
:read: (typeA.check (check.clean (list) :read:))
:write: (typeA.check (check.clean (list) :write:))
arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))
@ meta.provenance]
(in [@ {analysis.#Extension [.prelude (text extension_name "|translation")]
Expand Down Expand Up @@ -802,8 +802,8 @@
(analyse archive idxC))
valueA (<| (typeA.expecting :write:)
(analyse archive valueC))
:read: (typeA.check (check.clean (stack) :read:))
:write: (typeA.check (check.clean (stack) :write:))
:read: (typeA.check (check.clean (list) :read:))
:write: (typeA.check (check.clean (list) :write:))
arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))
@ meta.provenance]
(in [@ {analysis.#Extension [.prelude (text extension_name "|translation")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
(do !
[[code//type codeA] (typeA.inferring
(analysis archive codeC))
code//type (typeA.check (check.clean (stack) code//type))]
code//type (typeA.check (check.clean (list) code//type))]
(in [code//type codeA])))))
codeS (/////declaration.of_synthesis
(synthesis archive codeA))]
Expand Down Expand Up @@ -247,45 +247,6 @@
(in [/////declaration.#imports (list.as_stack imports)
/////declaration.#referrals (stack)])))]))

... TODO: Stop requiring these types and the "swapped" function below to make types line-up.
(template.with [<name> <anonymous>]
[(the <name>
Type
(expansion.let [<original> binary.Binary]
(let [_ <original>]
{.#Named (name <original>)
<anonymous>})))]

[Binary|Python (Nominal "bytearray")]
[Binary|DEFAULT (type (array.Array (I64 Any)))]
)

(the (swapped original replacement)
(-> Type Type
(Change Type))
(function (again type)
(if (type.= original type)
replacement
(`` (when type
{.#Nominal name parameters}
{.#Nominal name (list#each (function (_ [polarity it])
[polarity (again it)])
parameters)}

{.#Reification left right}
{.#Reification (again left) (again right)}

{.#Quantification quantification closure body}
{.#Quantification quantification closure (again body)}

{.#Named name anonymous}
{.#Named name (again anonymous)}

(^.or {.#Parameter _}
{.#Variable _}
{.#Opaque _})
type)))))

(the .public bundle
Bundle
(|> ///.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
[collection
["[0]" dictionary (.only Dictionary)]
["[0]" list (.use "[1]#[0]" functor mix monoid)]
["[0]" stack (.use "[1]#[0]" functor mix)]
["[0]" set]]]
[math
[number
Expand All @@ -42,8 +41,8 @@
(-> Register Register
Register)
(if (n.> redundant register)
(-- register)
register))
(-- register)
register))

(every (Remover it)
(-> Register
Expand All @@ -57,9 +56,9 @@
{/.#Seq {/.#Bind register}
post}
(if (n.= redundant register)
(again post)
{/.#Seq {/.#Bind (..prune redundant register)}
(again post)})
(again post)
{/.#Seq {/.#Bind (..prune redundant register)}
(again post)})

(,, (template.with [,access]
[(^.or {/.#Seq {/.#Access ,access}
Expand All @@ -71,10 +70,10 @@
{/.#Bind register}}
post})
(if (n.= redundant register)
(again post)
{/.#Seq {/.#Access ,access}
{/.#Seq {/.#Bind (..prune redundant register)}
(again post)}})]
(again post)
{/.#Seq {/.#Access ,access}
{/.#Seq {/.#Bind (..prune redundant register)}
(again post)}})]

[{/access.#Member member}]
[{/access.#Item position}]
Expand Down Expand Up @@ -185,13 +184,13 @@

(the (extended offset amount redundancy)
(-> Register Natural Redundancy
[(Stack Register) Redundancy])
(let [extension (|> amount stack.indices (stack#each (n.+ offset)))]
[(List Register) Redundancy])
(let [extension (|> amount list.indices (list#each (n.+ offset)))]
[extension
(stack#mix (function (_ register redundancy)
(dictionary.has register ..necessary! redundancy))
redundancy
extension)]))
(list#mix (function (_ register redundancy)
(dictionary.has register ..necessary! redundancy))
redundancy
extension)]))

(the (default arity)
(-> Arity
Expand All @@ -208,14 +207,14 @@
(Optimization (List it))))
(function (again [redundancy values])
(if (list.empty? values)
{try.#Success [redundancy
values]}
(do try.monad
[head (list.item 0 values)
[redundancy head] (optimization [redundancy head])
[redundancy tail] (again [redundancy (list.after 1 values)])]
(in [redundancy
(list#composite (list head) tail)])))))
{try.#Success [redundancy
values]}
(do try.monad
[head (list.item 0 values)
[redundancy head] (optimization [redundancy head])
[redundancy tail] (again [redundancy (list.after 1 values)])]
(in [redundancy
(list#composite (list head) tail)])))))

(template.with [<name>]
[(exception.the .public (<name> register)
Expand Down Expand Up @@ -381,7 +380,7 @@
[[redundancy inits] (..list_optimization optimization' [redundancy inits])
.let [[extension redundancy] (..extended start (list.size inits) redundancy)]
[redundancy iteration] (optimization' [redundancy iteration])]
(in [(stack#mix dictionary.lacks redundancy extension)
(in [(list#mix dictionary.lacks redundancy extension)
[@ {/.#Control {/.#Loop {/.#Tail_Recursion [start inits iteration]}}}]]))

{/.#Tail_Iteration resets}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@

(^.or (/.path/seq left right)
(/.path/alt left right))
(stack#mix for_path path_storage (stack left right))
(list#mix for_path path_storage (list left right))

(/.path/then bodyS)
(loop (for_synthesis [bodyS bodyS
Expand Down
24 changes: 12 additions & 12 deletions stdlib/source/library/lux/compiler/language/lux/translation.lux
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@
... TODO: Optimize by no longer checking for overwrites...
... TODO: Optimize by using a dictionary instead of a sequence for the buffer.
(if (sequence.any? (|>> product.left (n.= artifact_id)) buffer)
(phase.except ..cannot_overwrite_output [artifact_id])
(phase.update (has #buffer {.#Some (sequence.suffix [artifact_id custom code] buffer)})))
(phase.except ..cannot_overwrite_output [artifact_id])
(phase.update (has #buffer {.#Some (sequence.suffix [artifact_id custom code] buffer)})))

{.#None}
(phase.except ..no_buffer_for_saving_code [artifact_id]))))
Expand All @@ -288,11 +288,11 @@
)

(exception.the .public (unknown_definition [name known_definitions])
(Exception [Name (Stack definition.Definition)])
(Exception [Name (List definition.Definition)])
(exception.report
(list ["Definition" (name.proper name)]
["Module" (name.module name)]
["Known Definitions" (exception.listing product.left (list.of_stack known_definitions))])))
["Known Definitions" (exception.listing product.left known_definitions)])))

(the .public (remember archive name)
(for_any (_ anchor expression declaration)
Expand All @@ -303,10 +303,10 @@
(do try.monad
[@module (archive.id _module archive)
registry (if (text.= (its #module state) _module)
{try.#Success (its #registry state)}
(do try.monad
[[_module output registry] (archive.find _module archive)]
{try.#Success registry}))]
{try.#Success (its #registry state)}
(do try.monad
[[_module output registry] (archive.find _module archive)]
{try.#Success registry}))]
(when (registry.id _name registry)
{.#None}
(exception.except ..unknown_definition [name (registry.definitions registry)])
Expand All @@ -323,10 +323,10 @@
(do try.monad
[@module (archive.id _module archive)
registry (if (text.= (its #module state) _module)
{try.#Success (its #registry state)}
(do try.monad
[[_module output registry] (archive.find _module archive)]
{try.#Success registry}))]
{try.#Success (its #registry state)}
(do try.monad
[[_module output registry] (archive.find _module archive)]
{try.#Success registry}))]
(when (registry.find_definition _name registry)
{.#None}
(exception.except ..unknown_definition [name (registry.definitions registry)])
Expand Down
15 changes: 7 additions & 8 deletions stdlib/source/library/lux/compiler/meta/archive/registry.lux
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
[collection
[set (.only Set)]
["[0]" list]
["[0]" stack]
["[0]" sequence (.only Sequence) (.use "[1]#[0]" functor mix)]
["[0]" dictionary (.only Dictionary)]]]
[macro
Expand Down Expand Up @@ -82,17 +81,17 @@
nominal.abstraction)]))

(the .public (<fetch> registry)
(-> Registry (Stack <type>))
(-> Registry
(List <type>))
(|> registry
nominal.reification
(its #artifacts)
sequence.as_list
list.as_stack
(stack.all (|>> product.left
(its //.#category)
(pipe.when
{<tag> it} {.#Some it}
_ {.#None})))))]
(list.all (|>> product.left
(its //.#category)
(pipe.when
{<tag> it} {.#Some it}
_ {.#None})))))]

[//category.#Definition definition definitions //definition.Definition
product.left {.#Some it}]
Expand Down

0 comments on commit 75f54c8

Please sign in to comment.