Skip to content

Commit

Permalink
Adapting to new List type (part 18).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 14, 2024
1 parent 75f54c8 commit d184a37
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 392 deletions.
549 changes: 258 additions & 291 deletions stdlib/source/library/lux.lux

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions stdlib/source/library/lux/compiler/extension/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@

[type_name]
[type]

[array]
[array_size]
[array_its]
[array_has?]
[array_has]
[array_lacks]
)
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,8 @@
(..custom
[?list.any
(function (_ extension_name analyse archive [arrayC])
(<| typeA.with_var
(function (_ [@read :read:]))
typeA.with_var
(function (_ [@write :write:]))
(<| typeA.with_var (function (_ [@read :read:]))
typeA.with_var (function (_ [@write :write:]))
(do phase.monad
[_ (typeA.inference ..int)
arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:)))
Expand Down Expand Up @@ -744,10 +742,8 @@
(..custom
[(<>.and ?list.any ?list.any)
(function (_ extension_name analyse archive [idxC arrayC])
(<| typeA.with_var
(function (_ [@read :read:]))
typeA.with_var
(function (_ [@write :write:]))
(<| typeA.with_var (function (_ [@read :read:]))
typeA.with_var (function (_ [@write :write:]))
(do phase.monad
[_ (typeA.inference :read:)
arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:)))
Expand Down Expand Up @@ -790,10 +786,8 @@
(..custom
[(all <>.and ?list.any ?list.any ?list.any)
(function (_ extension_name analyse archive [idxC valueC arrayC])
(<| typeA.with_var
(function (_ [@read :read:]))
typeA.with_var
(function (_ [@write :write:]))
(<| typeA.with_var (function (_ [@read :read:]))
typeA.with_var (function (_ [@write :write:]))
(do phase.monad
[_ (typeA.inference (.type (array.Array' :read: :write:)))
arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
["[0]" analysis (.only Operation Phase Bundle)
[evaluation (.only Eval)]
["[0]A" type]
["[0]" scope]]
["[0]" scope]
["[0]" inference]]
[///
["[0]" reference]
[meta
Expand Down Expand Up @@ -190,8 +191,7 @@
(the (lux::is? extension_name)
Handler
(.function (_ analysis archive args)
(<| typeA.with_var
(.function (_ [@var :var:]))
(<| typeA.with_var (.function (_ [@var :var:]))
((binary :var: :var: @type.Bit extension_name)
analysis archive args))))

Expand All @@ -201,8 +201,7 @@
(..custom
[?list.any
(.function (_ extension_name analysis archive opC)
(<| typeA.with_var
(.function (_ [@var :var:]))
(<| typeA.with_var (.function (_ [@var :var:]))
(do [! phase.monad]
[_ (typeA.inference (.type (Either @type.Text :var:)))
@ meta.provenance]
Expand Down Expand Up @@ -249,6 +248,23 @@
[valueT valueA] (typeA.inferring (analysis archive valueC))]
(in valueA)))]))

... (the .public (as#_extension eval)
... (-> Eval
... Handler)
... (..custom
... [(?.and ?list.any ?list.any)
... (.function (_ extension_name analysis archive [typeC it])
... (do [! phase.monad]
... [coercion (eval archive @type.Type typeC)
... [actual_type it] (inference.general archive analysis (as @type.Type coercion) (stack it))
... _ (typeA.inference actual_type)]
... (.when it
... (stack it)
... (in it)

... _
... (undefined))))]))

(exception.the .public (cannot_access_global [from global])
(Exception [Text Name])
(exception.report
Expand Down Expand Up @@ -455,8 +471,7 @@
[_ (typeA.inference @type.List)
@ meta.provenance]
(in [@ {analysis.#Extension (..translation extension_name) (list)}]))
(<| typeA.with_var
(.function (_ [_ it]))
(<| typeA.with_var (.function (_ [_ it]))
(do [! phase.monad]
[_ (typeA.inference (.type (@type.List it)))
elements (list.each' ! (|>> (analysis archive)
Expand All @@ -472,8 +487,7 @@
(..custom
[?list.any
(.function (_ extension_name analysis archive it)
(<| typeA.with_var
(.function (_ [_ type_of_item]))
(<| typeA.with_var (.function (_ [_ type_of_item]))
(do [! phase.monad]
[@ meta.provenance
_ (typeA.inference @type.Natural)]
Expand All @@ -489,8 +503,7 @@
(..custom
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [address it])
(<| typeA.with_var
(.function (_ [_ type_of_item]))
(<| typeA.with_var (.function (_ [_ type_of_item]))
(do [! phase.monad]
[@ meta.provenance
_ (typeA.inference type_of_item)
Expand All @@ -509,8 +522,7 @@
(..custom
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [prefix suffix])
(<| typeA.with_var
(.function (_ [_ type_of_item]))
(<| typeA.with_var (.function (_ [_ type_of_item]))
(do [! phase.monad]
[@ meta.provenance
.let [type_of_list (.type (@type.List type_of_item))
Expand Down Expand Up @@ -578,6 +590,133 @@
(with extension/lux.type ..type)
))

(the array
Handler
(..custom
[?list.any
(.function (_ extension_name analysis archive size)
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference (@type.Array to_write to_read))
size (|> size
(analysis archive)
(typeA.expecting @type.Natural))
@ meta.provenance]
(in (|> (list size)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the array_size
Handler
(..custom
[?list.any
(.function (_ extension_name analysis archive it)
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference @type.Natural)
it (<| (typeA.expecting (@type.Array to_write to_read))
(analysis archive)
it)
@ meta.provenance]
(in (|> (list it)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the array_its
Handler
(..custom
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [address it])
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference to_read)
it (<| (typeA.expecting (@type.Array to_write to_read))
(analysis archive)
it)
address (<| (typeA.expecting @type.Natural)
(analysis archive)
address)
@ meta.provenance]
(in (|> (list address it)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the array_has?
Handler
(..custom
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [address it])
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference @type.Bit)
it (<| (typeA.expecting (@type.Array to_write to_read))
(analysis archive)
it)
address (<| (typeA.expecting @type.Natural)
(analysis archive)
address)
@ meta.provenance]
(in (|> (list address it)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the array_has
Handler
(..custom
[(all ?.and ?list.any ?list.any ?list.any)
(.function (_ extension_name analysis archive [address value it])
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference (@type.Array to_write to_read))
it (<| (typeA.expecting (@type.Array to_write to_read))
(analysis archive)
it)
value (<| (typeA.expecting to_write)
(analysis archive)
value)
address (<| (typeA.expecting @type.Natural)
(analysis archive)
address)
@ meta.provenance]
(in (|> (list address value it)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the array_lacks
Handler
(..custom
[(all ?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [address it])
(<| typeA.with_var (.function (_ [_ to_write]))
typeA.with_var (.function (_ [_ to_read]))
(do [! phase.monad]
[_ (typeA.inference (@type.Array to_write to_read))
it (<| (typeA.expecting (@type.Array to_write to_read))
(analysis archive)
it)
address (<| (typeA.expecting @type.Natural)
(analysis archive)
address)
@ meta.provenance]
(in (|> (list address it)
{analysis.#Extension (..translation extension_name)}
[@])))))]))

(the with_array_extensions
(Change Bundle)
(|>> (with extension/lux.array ..array)
(with extension/lux.array_size ..array_size)
(with extension/lux.array_its ..array_its)
(with extension/lux.array_has? ..array_has?)
(with extension/lux.array_has ..array_has)
(with extension/lux.array_lacks ..array_lacks)
))

(the .public bundle
(|> ///.empty
with_basic_extensions
Expand All @@ -588,4 +727,5 @@
with_decimal_extensions
with_list_extensions
with_type_extensions
with_array_extensions
))
Loading

0 comments on commit d184a37

Please sign in to comment.