diff options
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase')
4 files changed, 28 insertions, 28 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/module.lux b/stdlib/source/lux/tool/compiler/phase/analysis/module.lux index 4894ce931..6a33171f1 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/module.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/module.lux @@ -118,7 +118,7 @@ [state] #error.Success)))) (def: #export (define name definition) - (-> Text Definition (Operation Any)) + (-> Text Global (Operation Any)) (///extension.lift (do ///.monad [self-name macro.current-module-name @@ -129,7 +129,7 @@ (#error.Success [(update@ #.modules (plist.put self-name (update@ #.definitions - (: (-> (List [Text Definition]) (List [Text Definition])) + (: (-> (List [Text Global]) (List [Text Global])) (|>> (#.Cons [name definition]))) self)) state) diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/reference.lux b/stdlib/source/lux/tool/compiler/phase/analysis/reference.lux index a484eaebb..c09ea55ba 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis/reference.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis/reference.lux @@ -30,12 +30,12 @@ (-> Name (Operation Analysis)) (with-expansions [<return> (wrap (|> def-name ////reference.constant #/.Reference))] (do ///.monad - [[exported? actualT def-anns _] (///extension.lift (macro.find-def def-name))] - (case (macro.get-identifier-ann (name-of #.alias) def-anns) - (#.Some real-def-name) + [constant (///extension.lift (macro.find-def def-name))] + (case constant + (#.Left real-def-name) (definition real-def-name) - - _ + + (#.Right [exported? actualT def-anns _]) (do @ [_ (//type.infer actualT) (^@ def-name [::module ::name]) (///extension.lift (macro.normalize def-name)) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux index 2b17c9f8a..992d5a932 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux @@ -4,6 +4,7 @@ ["." monad (#+ do)]] [control [io (#+ IO)] + ["." exception (#+ exception:)] ["p" parser ["s" code (#+ Parser)]]] [data @@ -139,7 +140,7 @@ #let [annotations (:coerce Code annotations)] [type valueT valueN value] (..definition full-name #.None valueC) _ (////statement.lift-analysis - (module.define short-name [exported? type annotations value])) + (module.define short-name (#.Right [exported? type annotations value]))) #let [_ (log! (format "Definition " (%name full-name)))] _ (////statement.lift-generation (///generation.learn full-name valueN)) @@ -179,7 +180,7 @@ [type valueT valueN value] (..definition full-name (#.Some .Type) valueC) _ (////statement.lift-analysis (do ///.monad - [_ (module.define short-name [exported? type annotations value])] + [_ (module.define short-name (#.Right [exported? type annotations value]))] (module.declare-tags tags exported? (:coerce Type value)))) #let [_ (log! (format "Definition " (%name full-name)))] _ (////statement.lift-generation @@ -214,36 +215,35 @@ (wrap {#////statement.imports imports #////statement.referrals (list)})))])) -## TODO: Reify aliasing as a feature of the compiler, instead of -## manifesting it implicitly through definition annotations. -(def: (alias-annotations original) - (-> Name Code) - (` {#.alias (~ (code.identifier original))})) +(exception: #export (cannot-alias-an-alias {local Alias} {foreign Alias} {target Name}) + (exception.report + ["Local alias" (%name local)] + ["Foreign alias" (%name foreign)] + ["Target definition" (%name target)])) (def: (define-alias alias original) (-> Text Name (////analysis.Operation Any)) (do ///.monad - [[exported? original-type original-annotations original-value] - (//.lift (macro.find-def original))] - (module.define alias [false - original-type - (alias-annotations original) - original-value]))) + [current-module (//.lift macro.current-module-name) + constant (//.lift (macro.find-def original))] + (case constant + (#.Left de-aliased) + (///.throw ..cannot-alias-an-alias [[current-module alias] original de-aliased]) + + (#.Right [exported? original-type original-annotations original-value]) + (module.define alias (#.Left original))))) (def: def::alias Handler - (function (_ extension-name phase inputsC+) - (case inputsC+ - (^ (list [_ (#.Identifier ["" alias])] [_ (#.Identifier def-name)])) + (..custom + [($_ p.and s.local-identifier s.identifier) + (function (_ extension-name phase [alias def-name]) (do ///.monad [_ (//.lift (///.sub [(get@ [#////statement.analysis #////statement.state]) (set@ [#////statement.analysis #////statement.state])] (define-alias alias def-name)))] - (wrap ////statement.no-requirements)) - - _ - (///.throw //.invalid-syntax [extension-name %code inputsC+])))) + (wrap ////statement.no-requirements)))])) (template [<mame> <type> <scope>] [(def: <mame> diff --git a/stdlib/source/lux/tool/compiler/phase/generation/php/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/php/runtime.lux index 7281a0c0e..b67f4d20a 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/php/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/php/runtime.lux @@ -1,5 +1,5 @@ (.module: - [lux (#- inc) + [lux (#- Global inc) [abstract [monad (#+ do)]] [control |