aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEduardo Julian2015-05-02 16:30:04 -0400
committerEduardo Julian2015-05-02 16:30:04 -0400
commit5db5a27480efa109b883ad4f6c84e3a2e128bd30 (patch)
treef92666f30a1766ebd396f96b2bb556e20b365458 /source
parent6bb629a6917176ec46fee119b3b21fb1781cba78 (diff)
- Finally got find-macro & macro-expand to work... (Note: type-vars bug is still there. Must find & squash).
-
Diffstat (limited to 'source')
-rw-r--r--source/lux.lux100
1 files changed, 32 insertions, 68 deletions
diff --git a/source/lux.lux b/source/lux.lux
index e97d01759..94f4853d8 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -1281,89 +1281,53 @@
#Nil
#None))
-## (def #export (find-macro ident state)
-## (-> Ident ($' Lux Macro))
-## (let [[module name] ident]
-## (case' state
-## {#source source #modules modules #module-aliases module-aliases
-## #envs envs #types types #host host
-## #seed seed}
-## (case' (:' ($' Maybe Macro)
-## (do Maybe:Monad
-## [bindings (get module modules)
-## gdef (get name bindings)]
-## (case' gdef
-## (#MacroD macro')
-## (#Some macro')
-
-## _
-## #None)))
-## (#Some macro)
-## (#Right [state macro])
-
-## #None
-## (#Left ($ text:++ "There is no macro by the name: " module ";" name))))))
-
(def #export (find-macro ident state)
- (-> Ident ($' Lux Macro))
+ (-> Ident ($' Lux ($' Maybe Macro)))
(let [[module name] ident]
(case' state
{#source source #modules modules #module-aliases module-aliases
#envs envs #types types #host host
#seed seed}
- (case' (:' ($' Maybe Macro)
- (case' (get module modules)
- (#Some bindings)
- (case' (get name bindings)
- (#Some gdef)
- (case' gdef
- (#MacroD macro')
- (#Some macro')
-
- _
- #None)
-
- #None
- #None)
-
- #None
- #None))
- (#Some macro)
- (#Right [state macro])
+ (#Right [state (do Maybe:Monad
+ [bindings (get module modules)
+ gdef (get name bindings)]
+ (case' (:' ($' DefData' Macro) gdef)
+ (#MacroD macro')
+ (#Some macro')
- #None
- (#Left ($ text:++ "There is no macro by the name: " module ";" name))))))
+ _
+ #None))]))))
-(def (join-list xs)
+(def (list:join xs)
(All [a]
(-> ($' List ($' List a)) ($' List a)))
(fold list:++ #Nil xs))
-## (def #export (macro-expand syntax state)
-## (-> Syntax ($' Lux ($' List Syntax)))
-## (case' syntax
-## (#Meta [_ (#Form (#Cons [(#Meta [_ (#Symbol macro-name)]) args]))])
-## (do Lux:Monad
-## [macro' (find-macro macro-name)]
-## (case' macro'
-## (#Some macro)
-## (do Lux:Monad
-## [expansion (macro args)
-## expansion' (map% Lux:Monad macro-expand expansion)]
-## (return (:' SyntaxList (join-list expansion'))))
+(def #export (macro-expand syntax)
+ (-> Syntax ($' Lux ($' List Syntax)))
+ (case' syntax
+ (#Meta [_ (#Form (#Cons [(#Meta [_ (#Symbol macro-name)]) args]))])
+ (do Lux:Monad
+ [?macro (find-macro macro-name)]
+ (case' (:' ($' Maybe Macro) ?macro)
+ (#Some macro)
+ (do Lux:Monad
+ [expansion (macro args)
+ expansion' (map% Lux:Monad macro-expand expansion)]
+ (;return (:' SyntaxList (list:join expansion'))))
-## #None
-## (do Lux:Monad
-## [parts' (map% Lux:Monad macro-expand (list& ($symbol macro-name) args))]
-## (return (:' Syntax (list ($form (join-list parts'))))))))
+ #None
+ (do Lux:Monad
+ [parts' (map% Lux:Monad macro-expand (list& ($symbol macro-name) args))]
+ (;return (:' SyntaxList (list ($form (list:join parts'))))))))
-## (#Meta [_ (#Tuple members)])
-## (do Lux:Monad
-## [members' (map% Lux:Monad macro-expand members)]
-## (return (:' Syntax (list ($tuple (join-list members'))))))
+ (#Meta [_ (#Tuple members)])
+ (do Lux:Monad
+ [members' (map% Lux:Monad macro-expand members)]
+ (;return (:' SyntaxList (list ($tuple (list:join members'))))))
-## _
-## (return (:' SyntaxList (list syntax)))))
+ _
+ (return (:' SyntaxList (list syntax)))))
## ## (def (walk-type type)
## ## (-> Syntax ($' Lux Syntax))