diff options
Diffstat (limited to '')
-rw-r--r-- | source/lux.lux | 100 |
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)) |