Skip to content

Commit

Permalink
Clean-up of adaptation functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Oct 22, 2024
1 parent 7d5e327 commit 02aa5b3
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 171 deletions.
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 @@ -772,9 +772,9 @@
phase.export
(phase.value analysis_state)
future#pure)]
(future#pure (if (check.< ..Custom (@type.old_type /#type))
(future#pure (if (check.< ..Custom (@type.old /#type))
{try.#Success [context (its compiler.#parameters it) /#value]}
(exception.except ..invalid_custom_compiler [/#definition (@type.old_type /#type)]))))))
(exception.except ..invalid_custom_compiler [/#definition (@type.old /#type)]))))))

(the .public (compile program global lux_compiler phase_wrapper import file_context extender expander platform compilation context
all_extensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
Eval))
(function (eval archive type exprC)
(<| (monad.let phase.monad
[exprA (<| (//type.with (@type.old_type type))
[exprA (<| (//type.with (@type.old type))
//scope.reset
(analysis archive exprC))
module phase.name_of_current_module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
(monad.let phase.monad
[:ex: /type.existential]
(general archive analysis
(maybe.trusted (type.reified (list (@type.old_type :ex:)) morphism))
(maybe.trusted (type.reified (list (@type.old :ex:)) morphism))
args))

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

(exception.the .public no_scope)
Expand All @@ -132,7 +132,7 @@
new_head (revised @type.#locals
(is (Change Local)
(|>> (revised @type.#counter ++)
(revised @type.#mappings (property.has name [(@type.new_type type) new_var_id]))))
(revised @type.#mappings (property.has name [(@type.new 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 (@type.old_context (its @type.#type_context state)))
{try.#Success [context' output]}
{try.#Success [(has @type.#type_context (@type.new_type_context context') state)
{try.#Success [(has @type.#type_context (@type.new_context context') state)
output]}

{try.#Failure error}
Expand Down Expand Up @@ -73,21 +73,21 @@
(Change (Operation it))))
(phase.localized (its @type.#expected)
(has @type.#expected)
(function.constant {.#Some (@type.new_type expected)})))
(function.constant {.#Some (@type.new 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 (@type.new_context check.fresh_context))))

(the .public (inference actualT)
(-> .Type
(Operation Any))
(monad.let phase.monad
[expectedT /.expected_type]
(..check (check.check (@type.old_type expectedT) actualT))))
(..check (check.check (@type.old expectedT) actualT))))

(the .public (with_var it)
(for_any (_ it)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/compiler/language/lux/phase.lux
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
(when (property.value (name.proper it) (its @type.#definitions module))
{try.#Success [exported? {@type.#Definition [def_type expression_of_definition def_value]}]}
(if (visible? exported? (name.module it) this_module_name)
(if (type.= ,type (@type.old_type def_type))
(if (type.= ,type (@type.old def_type))
(pure (as (-> Any @type.Label) def_value))
(..of_try (exception.except ,not_a [it])))
(..of_try (exception.except ,cannot_access [it this_module_name])))
Expand Down Expand Up @@ -415,7 +415,7 @@
(macro de_aliased)

{@type.#Definition [def_type expression_of_definition def_value]}
(if (type.= @type.Macro (@type.old_type def_type))
(if (type.= @type.Macro (@type.old def_type))
{try.#Success [lux (as (-> Any @type.Macro) def_value)]}
{try.#Failure binding.not_a_macro})))))))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
(function (again valueC)
(monad.let [! phase.monad]
[expectedT /.expected_type
.let [expectedT (@type.old_type expectedT)]
.let [expectedT (@type.old expectedT)]
expectedT' (/type.check (check.clean (list) expectedT))
@ /.provenance
here phase.name_of_current_module]
Expand Down Expand Up @@ -200,11 +200,11 @@
{.#None}
[0 false]))
expectedT /.expected_type
.let [expectedT (@type.old_type expectedT)]]
.let [expectedT (@type.old expectedT)]]
(when expectedT
{.#Variable .general _}
(monad.let !
[inferenceT (/inference.variant lefts right? (@type.old_type variantT))
[inferenceT (/inference.variant lefts right? (@type.old variantT))
[inferredT valueA+] (/inference.general archive analyse inferenceT (stack valueC))
@ /.provenance]
(pure (/.variant @ [lefts right? (|> valueA+ stack.top try.trusted)])))
Expand Down Expand Up @@ -256,7 +256,7 @@
(Operation /.Term))
(monad.let [! phase.monad]
[expectedT /.expected_type
.let [expectedT (@type.old_type expectedT)]
.let [expectedT (@type.old expectedT)]
here phase.name_of_current_module]
(/.with_exception ..cannot_analyse_tuple [here expectedT membersC]
(when expectedT
Expand Down Expand Up @@ -362,7 +362,7 @@
(the (slot_type [[_ it] _])
(-> [@type.Label @type.Code]
Type)
(@type.old_type it))
(@type.old it))

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

{try.#Failure error}
(pure {.#None}))))
Expand Down Expand Up @@ -504,7 +504,7 @@
{.#Some [record_size membersC recordT]}
(monad.let !
[expectedT /.expected_type
.let [expectedT (@type.old_type expectedT)]]
.let [expectedT (@type.old expectedT)]]
(when expectedT
{.#Variable .general _}
(monad.let !
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
Phase)
(monad.let [! phase.monad]
[functionT /.expected_type
.let [functionT (@type.old_type functionT)]
.let [functionT (@type.old functionT)]
here phase.name_of_current_module]
(loop (again [expectedT functionT])
(/.with_exception ..cannot_analyse [here expectedT function_name arg_name body]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@

{.#None}
[0 false]))
_ (/type.check (check.check :input: (@type.old_type variantT)))]
_ (/type.check (check.check :input: (@type.old variantT)))]
(pattern_analysis :input:
(code.variant (.list (code.natural lefts)
(code.bit right?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
(Operation @type.Lux Value))
(monad.let phase.monad
[[actual_type value] (global_value name)]
(if (check.< expected_type (@type.old_type actual_type))
(if (check.< expected_type (@type.old actual_type))
(pure value)
(phase.except ..invalid [name expected_type (@type.old_type actual_type)]))))
(phase.except ..invalid [name expected_type (@type.old actual_type)]))))

(the .public (reification extender
lux phase archive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@
[lengthA (<| (typeA.with ..int)
(analyse archive lengthC))
expectedT analysis.expected_type
.let [expectedT (@type.old_type expectedT)]
.let [expectedT (@type.old expectedT)]
expectedJT (jvm_array_type expectedT)
elementJT (when (projection.array? expectedJT)
{.#Some elementJT}
Expand Down Expand Up @@ -871,7 +871,7 @@
(function (_ extension_name analyse archive [])
(monad.let phase.monad
[expectedT analysis.expected_type
.let [expectedT (@type.old_type expectedT)]
.let [expectedT (@type.old expectedT)]
[_ :object:] (check_object expectedT)
_ (typeA.inference :object:)
@ analysis.provenance]
Expand Down Expand Up @@ -997,7 +997,7 @@
(function (_ extension_name analyse archive [fromC])
(monad.let [! phase.monad]
[toT analysis.expected_type
.let [toT (@type.old_type toT)]
.let [toT (@type.old toT)]
toJT (check_jvm toT)
[fromT fromA] (typeA.inferring
(analyse archive fromC))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
[input (<| (typeA.with @type.Character)
(analysis archive input))
expectedT analysis.expected_type
.let [expectedT (@type.old_type expectedT)]
.let [expectedT (@type.old expectedT)]
conditionals (list.each' ! (.function (_ [cases branch])
(<| (by ! each (|>> [cases]))
(typeA.with expectedT)
Expand Down Expand Up @@ -221,7 +221,7 @@
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [module 'expression])
(monad.let [! phase.monad]
[module (eval archive (@type.new_type @type.Text) module)]
[module (eval archive (@type.new @type.Text) module)]
(analysis.with_current_module (as (-> Any Text) module)
(analysis archive (code.with [(as (-> Any Text) module) 0 0] 'expression)))))]))

Expand All @@ -233,9 +233,9 @@
(.function (_ extension_name analysis archive [typeC valueC])
(monad.let [! phase.monad]
[actualT (by ! each (|>> (as (-> Any @type.Type)))
(eval archive (@type.new_type @type.Type) typeC))
_ (typeA.inference (@type.old_type actualT))]
(<| (typeA.with (@type.old_type actualT))
(eval archive (@type.new @type.Type) typeC))
_ (typeA.inference (@type.old actualT))]
(<| (typeA.with (@type.old actualT))
(analysis archive valueC))))]))

(the .public (as#_extension eval)
Expand All @@ -245,8 +245,8 @@
[(?.and ?list.any ?list.any)
(.function (_ extension_name analysis archive [typeC it])
(monad.let [! phase.monad]
[coercion (eval archive (@type.new_type @type.Type) typeC)
[actual_type it] (inference.general archive analysis (@type.old_type (as (-> Any @type.Type) coercion)) (stack it))
[coercion (eval archive (@type.new @type.Type) typeC)
[actual_type it] (inference.general archive analysis (@type.old (as (-> Any @type.Type) coercion)) (stack it))
_ (typeA.inference actual_type)]
(.when it
(stack it)
Expand Down Expand Up @@ -301,12 +301,12 @@
... the exception, and know that the default it was looking for has the correct type, because
... the exception is only ever raised _after_ the inference.
(monad.let !
[_ (typeA.inference (@type.old_type type))]
[_ (typeA.inference (@type.old type))]
(analysis.except ///.defaults_cannot_be_referenced [def_name]))

else
(monad.let !
[_ (typeA.inference (@type.old_type type))
[_ (typeA.inference (@type.old type))
@ analysis.provenance]
(pure (analysis.constant @ def_name)))))
(analysis.except ..cannot_access_global [expected def_name])))))]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
[type valueT value] (..definition archive full_name valueC)
[_ _ exported?] (evaluate! archive @type.Bit exported?C)
_ (<| /////declaration.of_analysis
(module.define short_name [(as (-> Any Bit) exported?) {@type.#Definition [(@type.new_type type) {.#None} value]}]))]
(module.define short_name [(as (-> Any Bit) exported?) {@type.#Definition [(@type.new type) {.#None} value]}]))]
(pure /////declaration.no_requirements))))]))

(the imports
Expand Down
Loading

0 comments on commit 02aa5b3

Please sign in to comment.