aboutsummaryrefslogtreecommitdiff
path: root/source/lux/meta/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2015-08-02 22:38:43 -0400
committerEduardo Julian2015-08-02 22:38:43 -0400
commitbcf0cb737e348dc9e183b1608abbebc5a40ba847 (patch)
treeee9d611fc2c140d33da67afa0991c9d6a0121849 /source/lux/meta/lux.lux
parentc9e0b6c3a0c23b34cd6ffac1b93a266ae6243c4a (diff)
- Added a module for hashing.
- Refactored the standard library a bit. - Implemented the "loop" macro. - Added the expected type of expressions as a field in the compiler state. - Added syntactic sugar for using tuples with variants, in order to minimize the usage of brackets to delimit the contents of data-structures. - Fixed a bug wherein "macro-expand" was behaving like "macro-expand-all", and added a separate implementation for "macro-expand-all". - Fixed a few bugs.
Diffstat (limited to '')
-rw-r--r--source/lux/meta/lux.lux34
1 files changed, 27 insertions, 7 deletions
diff --git a/source/lux/meta/lux.lux b/source/lux/meta/lux.lux
index 13dcae284..66e4cc341 100644
--- a/source/lux/meta/lux.lux
+++ b/source/lux/meta/lux.lux
@@ -133,19 +133,39 @@
(M;wrap (:: List/Monad (M;join expansion'))))
#;None
+ (:: Lux/Monad (M;wrap (list syntax)))))
+
+ _
+ (:: Lux/Monad (M;wrap (list syntax)))))
+
+(def #export (macro-expand-all syntax)
+ (-> Syntax (Lux (List Syntax)))
+ (case syntax
+ (#;Meta [_ (#;FormS (#;Cons [(#;Meta [_ (#;SymbolS macro-name)]) args]))])
+ (do Lux/Monad
+ [macro-name' (normalize macro-name)
+ ?macro (find-macro macro-name')]
+ (case ?macro
+ (#;Some macro)
+ (do Lux/Monad
+ [expansion (macro args)
+ expansion' (M;map% Lux/Monad macro-expand-all expansion)]
+ (M;wrap (:: List/Monad (M;join expansion'))))
+
+ #;None
(do Lux/Monad
- [parts' (M;map% Lux/Monad macro-expand (list& (symbol$ macro-name) args))]
+ [parts' (M;map% Lux/Monad macro-expand-all (list& (symbol$ macro-name) args))]
(M;wrap (list (form$ (:: List/Monad (M;join parts'))))))))
(#;Meta [_ (#;FormS (#;Cons [harg targs]))])
(do Lux/Monad
- [harg+ (macro-expand harg)
- targs+ (M;map% Lux/Monad macro-expand targs)]
+ [harg+ (macro-expand-all harg)
+ targs+ (M;map% Lux/Monad macro-expand-all targs)]
(M;wrap (list (form$ (list:++ harg+ (:: List/Monad (M;join (: (List (List Syntax)) targs+))))))))
(#;Meta [_ (#;TupleS members)])
(do Lux/Monad
- [members' (M;map% Lux/Monad macro-expand members)]
+ [members' (M;map% Lux/Monad macro-expand-all members)]
(M;wrap (list (tuple$ (:: List/Monad (M;join members'))))))
_
@@ -234,7 +254,7 @@
(case state
{#;source source #;modules modules
#;envs envs #;types types #;host host
- #;seed seed #;eval? eval?}
+ #;seed seed #;eval? eval? #;expected expected}
(some (: (-> (Env Text (, LuxVar Type)) (Maybe Type))
(lambda [env]
(case env
@@ -254,7 +274,7 @@
(let [[v-prefix v-name] name
{#;source source #;modules modules
#;envs envs #;types types #;host host
- #;seed seed #;eval? eval?} state]
+ #;seed seed #;eval? eval? #;expected expected} state]
(case (get v-prefix modules)
#;None
#;None
@@ -289,6 +309,6 @@
_
(let [{#;source source #;modules modules
#;envs envs #;types types #;host host
- #;seed seed #;eval? eval?} state]
+ #;seed seed #;eval? eval? #;expected expected} state]
(#;Left ($ text:++ "Unknown var: " (ident->text name) "\n\n" (show-envs envs))))))))
))