From a10ff8416855e2079ba8da48cae43c80414666d0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 27 Dec 2016 19:40:11 -0400 Subject: - Now, it's possible to omit the module-prefix from the names of member functions/constants in struct auto-selection. --- stdlib/source/lux/compiler.lux | 12 ++++++++++++ stdlib/source/lux/type/auto.lux | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/compiler.lux b/stdlib/source/lux/compiler.lux index 437389717..feade4a8c 100644 --- a/stdlib/source/lux/compiler.lux +++ b/stdlib/source/lux/compiler.lux @@ -532,6 +532,18 @@ _ (fail ($_ Text/append "Unknown tag: " (Ident/encode tag)))))) +(def: #export (tag-lists module) + (-> Text (Lux (List [(List Ident) Type]))) + (do Monad + [=module (find-module module) + this-module-name current-module-name] + (wrap (|> (get@ #;types =module) + (list;filter (lambda [[type-name [tag-list exported? type]]] + (or exported? + (Text/= this-module-name module)))) + (List/map (lambda [[type-name [tag-list exported? type]]] + [tag-list type])))))) + (def: #export locals (Lux (List (List [Text Type]))) (lambda [state] diff --git a/stdlib/source/lux/type/auto.lux b/stdlib/source/lux/type/auto.lux index c22434e9f..31439af3d 100644 --- a/stdlib/source/lux/type/auto.lux +++ b/stdlib/source/lux/type/auto.lux @@ -6,7 +6,7 @@ (;module: lux (lux (control monad) - (data [text] + (data [text "Text/" Eq] text/format [number] (struct [list "List/" Monad Fold] @@ -75,10 +75,38 @@ (:: Monad wrap sig-type) (tc;fail (format "Can't find member type " (%n idx) " for " (%type sig-type)))))) +(def: (find-member-name member) + (-> Ident (Lux Ident)) + (case member + ["" simple-name] + (compiler;either (do Monad + [member (compiler;normalize member) + _ (compiler;resolve-tag member)] + (wrap member)) + (do Monad + [this-module-name compiler;current-module-name + imp-mods (compiler;imported-modules this-module-name) + tag-lists (mapM @ compiler;tag-lists imp-mods) + #let [tag-lists (|> tag-lists List/join (List/map product;left) List/join) + candidates (list;filter (. (Text/= simple-name) product;right) + tag-lists)]] + (case candidates + #;Nil + (compiler;fail (format "Unknown tag: " (%ident member))) + + (#;Cons winner #;Nil) + (wrap winner) + + _ + (compiler;fail (format "Too many candidate tags: " (%list %ident candidates)))))) + + _ + (:: Monad wrap member))) + (def: (resolve-member member) (-> Ident (Lux [Nat Type])) (do Monad - [member (compiler;normalize member) + [member (find-member-name member) [idx tag-list sig-type] (compiler;resolve-tag member)] (wrap [idx sig-type]))) -- cgit v1.2.3