Skip to content

Commit

Permalink
New type for Type (part 7).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 11, 2024
1 parent 8235d8f commit de49737
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 291 deletions.
13 changes: 4 additions & 9 deletions stdlib/source/library/lux/compiler/default/init.lux
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@
[(///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 @@ -124,7 +119,7 @@
(list.each' !
(function (_ [name handler])
(///declaration.of_analysis
(moduleA.override_definition [.prelude name] [true {@type.#Default [..Analysis' handler]}])))))]
(moduleA.override_definition [.prelude name] [true {@type.#Default [.Analysis handler]}])))))]
(in [])))

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/compiler/default/platform.lux
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@
module.binding#export
(phase.value analysis_state)
future#in)]
(future#in (if (check.< ..Custom (@type.old /#type))
(future#in (if (check.< ..Custom /#type)
{try.#Success [context (list.as_stack (its compiler.#parameters it)) /#value]}
(exception.except ..invalid_custom_compiler [/#definition (@type.old /#type)]))))))
(exception.except ..invalid_custom_compiler [/#definition /#type]))))))

(the .public (compile program global lux_compiler phase_wrapper import file_context extender expander platform compilation context
all_extensions)
Expand Down
32 changes: 2 additions & 30 deletions stdlib/source/library/lux/compiler/language/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,12 @@
["[0]" signature]
["[0]" key (.only Key)]]]]])

... TODO: Remove ASAP
(the type_as_binary
(Injection @type.Type)
(<| _.rec
(function (_ type))
(all _.or
(_.and _.text (_.list (_.and _.bit type)))
(_.and _.bit _.natural)
_.natural
_.natural
(all _.and _.bit (_.stack (_.and type type)) type)
(_.and type type)
(_.and (_.and _.text _.text) type))))

... TODO: Remove #module_hash, #imports & #module_state ASAP.
... TODO: Not just from this projection, but from the lux.Module type.
(the .public as_binary
(Injection @type.Module)
(let [definition (is (Injection @type.Definition)
(all _.and ..type_as_binary _.any))
(all _.and _.type _.any))
alias (is (Injection @type.Alias)
(_.and _.text _.text))
global (is (Injection @type.Global)
Expand All @@ -62,25 +48,11 @@
... #module_state
_.any)))

... TODO: Remove ASAP
(the type_of_binary
(Projection @type.Type)
(<| <>.rec
(function (_ type))
(all <>.or
(<>.and <binary>.text (<binary>.list (<>.and <binary>.bit type)))
(<>.and <binary>.bit <binary>.natural)
<binary>.natural
<binary>.natural
(all <>.and <binary>.bit (<binary>.stack (<>.and type type)) type)
(<>.and type type)
(<>.and (<>.and <binary>.text <binary>.text) type))))

(the .public of_binary
(Projection @type.Module)
(let [definition (is (Projection @type.Definition)
(all <>.and
..type_of_binary
<binary>.type
<binary>.any))
alias (is (Projection @type.Alias)
(all <>.and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Eval))
(function (eval archive type exprC)
(do phase.monad
[exprA (<| (//type.expecting (@type.old type))
[exprA (<| (//type.expecting type)
//scope.reset
(analysis archive exprC))
module module.current_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
{.#Quantification .existential _}
(do phase.monad
[:ex: /type.existential]
(general' variables archive analyse (maybe.trusted (type.reified (list (@type.old :ex:)) inferT)) args))
(general' variables archive analyse (maybe.trusted (type.reified (list :ex:) inferT)) args))

{.#Reification inputT transT}
(when (type.reified (list inputT) transT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
{try.#Success [exported? {@type.#Definition [def_type def_value]}]}
(if (.or (text.= this_module_name (name.module it))
exported?)
(if (type.= ,type (@type.old def_type))
(if (type.= ,type def_type)
(in (as @type.Label def_value))
(/.except ,not_a [it]))
(/.except ,cannot_access [it this_module_name]))
Expand Down Expand Up @@ -181,8 +181,7 @@
(macro de_aliased)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
(stack.reversed inner))
scopes (stack#composite inner' outer)]
{.#Right [(has @type.#scopes scopes state)
{.#Some [(@type.old ref_type) ref]}]})
{.#Some [ref_type ref]}]})
))))

(exception.the .public no_scope)
Expand All @@ -134,7 +134,7 @@
new_head (revised @type.#locals
(is (Change Local)
(|>> (revised @type.#counter ++)
(revised @type.#mappings (property.has name [(@type.new type) new_var_id]))))
(revised @type.#mappings (property.has name [type new_var_id]))))
head)]
(when (phase.value' (has @type.#scopes {.#Top new_head tail} state)
action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
(-> (Check it)
(Operation it)))
(function (_ state)
(when (action (@type.old_type_context (its @type.#type_context state)))
(when (action (its @type.#type_context state))
{try.#Success [context' output]}
{try.#Success [(has .#type_context (@type.new_type_context context') state)
{try.#Success [(has .#type_context context' state)
output]}

{try.#Failure error}
Expand Down Expand Up @@ -73,14 +73,14 @@
(Change (Operation it))))
(phase.localized (its @type.#expected)
(has @type.#expected)
(function.constant {.#Some (@type.new expected)})))
(function.constant {.#Some expected})))

(the .public fresh
(for_any (_ it)
(Change (Operation it)))
(phase.localized (its @type.#type_context)
(has @type.#type_context)
(function.constant (@type.new_type_context check.fresh_context))))
(function.constant check.fresh_context)))

(exception.the .public no_expectation)

Expand All @@ -100,7 +100,7 @@
(Operation Any))
(do phase.monad
[expectedT ..expectation]
(..check (check.check (@type.old expectedT) actualT)
(..check (check.check expectedT actualT)
... (do [! check.monad]
... [pre check.context
... it (check.check expectedT actualT)
Expand Down
20 changes: 10 additions & 10 deletions stdlib/source/library/lux/compiler/language/lux/phase/analysis.lux
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@
(if (text.contains? (its exception.#label extension.defaults_cannot_be_referenced)
error)
(when term
(@type.#Name _ ["" _])
{@type.#Name _ ["" _]}
(..not_an_abstraction term)

(@type.#Name _ it)
{@type.#Name _ it}
(in it)

_
Expand Down Expand Up @@ -200,36 +200,36 @@
... In order to allow macros to reference any definition their owning module can see, when programmatically generating a name, they set themselves
... as the module in the name's provenance.
... The compiler then picks that up as the `quoted_module`, and uses it for name resolution in order to guarantee visibility of names in the expansion.
(@type.#Name [quoted_module _line _row] it)
{@type.#Name [quoted_module _line _row] it}
(/reference.reference extender analysis archive quoted_module it)

(@type.#Form _ elems)
{@type.#Form _ elems}
(when (list.as_stack elems)
(stack.partial functionC argsC+)
(..reification extender expander analysis archive functionC argsC+)

_
failure)

(@type.#Variant _ elems)
{@type.#Variant _ elems}
(when (list.as_stack elems)
(stack.partial (@type.#Name _ tag) values)
(stack.partial {@type.#Name _ tag} values)
(..variant_analysis analysis archive tag (list.of_stack values))

(stack.partial (@type.#Bit _ right?) values)
(stack.partial {@type.#Bit _ right?} values)
(..sum_analysis analysis archive 0 right? (list.of_stack values))

(stack.partial (@type.#Natural _ lefts) (@type.#Bit _ right?) values)
(stack.partial {@type.#Natural _ lefts} {@type.#Bit _ right?} values)
(..sum_analysis analysis archive lefts right? (list.of_stack values))

_
failure)

(@type.#Tuple _ elems)
{@type.#Tuple _ elems}
(/complex.record analysis archive (list.as_stack elems))

(,, (template.with [<tag> <analyser>]
[(<tag> _ value)
[{<tag> _ value}
(<analyser> value)]

[@type.#Text /simple.text]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
(-> Phase Natural Bit Phase)
(function (again valueC)
(do [! phase.monad]
[expectedT (by ! each @type.old /type.expectation)
[expectedT /type.expectation
expectedT' (/type.check (check.clean (stack) expectedT))
@ /.provenance
here module.current_name]
Expand Down Expand Up @@ -196,10 +196,10 @@
{.#None}
(in [0 false]))
expectedT /type.expectation]
(when (@type.old expectedT)
(when expectedT
{.#Variable _}
(do !
[inferenceT (/inference.variant lefts right? (@type.old variantT))
[inferenceT (/inference.variant lefts right? variantT)
[inferredT valueA+] (/inference.general archive analyse inferenceT (stack valueC))
@ /.provenance]
(in (/.variant @ [lefts right? (|> valueA+ stack.head try.trusted)])))
Expand Down Expand Up @@ -250,7 +250,7 @@
(-> Phase Archive (Stack @type.Code)
(Operation /.Term))
(do [! phase.monad]
[expectedT (by ! each @type.old /type.expectation)
[expectedT /type.expectation
here module.current_name]
(/.with_exception ..cannot_analyse_tuple [here expectedT (list.of_stack membersC)]
(when expectedT
Expand Down Expand Up @@ -328,14 +328,14 @@
output (is (Stack [Name @type.Code])
{.#Empty})])
(when input
(stack.partial (@type.#Name _ ["" slotH]) valueH tail)
(stack.partial {@type.#Name _ ["" slotH]} valueH tail)
(if pattern_matching?
(phase#in {.#None})
(do phase.monad
[slotH (module.normal ["" slotH])]
(again tail {.#Top [slotH valueH] output})))

(stack.partial (@type.#Name _ slotH) valueH tail)
(stack.partial {@type.#Name _ slotH} valueH tail)
(do phase.monad
[slotH (module.normal slotH)]
(again tail {.#Top [slotH valueH] output}))
Expand Down Expand Up @@ -363,7 +363,7 @@
(the (slot_type [[_ it] _])
(-> [@type.Label @type.Code]
Type)
(@type.old it))
it)

(the (same_record? it)
(Predicate (Stack [@type.Label @type.Code]))
Expand Down Expand Up @@ -435,7 +435,7 @@
[[[_ :record:] _] (stack.head record)]
(in [(stack.size record)
(stack#each product.right record)
(@type.old :record:)])))))
:record:])))))

{try.#Failure error}
(in {.#None}))))
Expand Down Expand Up @@ -472,7 +472,7 @@
(stack singletonC)
(analyse archive singletonC)

(stack (@type.#Name _ pseudo_slot) singletonC)
(stack {@type.#Name _ pseudo_slot} singletonC)
(do [! phase.monad]
[head_k (module.normal pseudo_slot)
slot (phase.try (module.slot head_k))]
Expand Down Expand Up @@ -505,7 +505,7 @@
{.#Some [record_size membersC recordT]}
(do !
[expectedT /type.expectation]
(when (@type.old expectedT)
(when expectedT
{.#Variable _}
(do !
[inferenceT (/inference.record record_size recordT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(-> Phase Text Text
Phase)
(do [! phase.monad]
[functionT (by ! each @type.old /type.expectation)
[functionT /type.expectation
here module.current_name]
(loop (again [expectedT functionT])
(/.with_exception ..cannot_analyse [here expectedT function_name arg_name body]
Expand Down
Loading

0 comments on commit de49737

Please sign in to comment.