From 92af791a1a361769c293e50dd5dbd263152e747a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 26 Jun 2017 21:28:00 -0400 Subject: - Some refactoring. --- stdlib/source/lux/macro.lux | 48 ++++++++++++------------ stdlib/source/lux/macro/syntax/common/reader.lux | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux/macro.lux b/stdlib/source/lux/macro.lux index 75ba9d587..c2ea0f04e 100644 --- a/stdlib/source/lux/macro.lux +++ b/stdlib/source/lux/macro.lux @@ -272,16 +272,16 @@ _ (:: Monad wrap ident))) -(def: #export (macro-expand-once syntax) +(def: #export (expand-once syntax) {#;doc "Given code that requires applying a macro, does it once and returns the result. Otherwise, returns the code as-is."} (-> Code (Lux (List Code))) (case syntax - [_ (#;Form (#;Cons [[_ (#;Symbol macro-name)] args]))] + [_ (#;Form (#;Cons [[_ (#;Symbol name)] args]))] (do Monad - [macro-name' (normalize macro-name) - ?macro (find-macro macro-name')] + [name' (normalize name) + ?macro (find-macro name')] (case ?macro (#;Some macro) (macro args) @@ -292,21 +292,21 @@ _ (:: Monad wrap (list syntax)))) -(def: #export (macro-expand syntax) +(def: #export (expand syntax) {#;doc "Given code that requires applying a macro, expands repeatedly until no more direct macro-calls are left. Otherwise, returns the code as-is."} (-> Code (Lux (List Code))) (case syntax - [_ (#;Form (#;Cons [[_ (#;Symbol macro-name)] args]))] + [_ (#;Form (#;Cons [[_ (#;Symbol name)] args]))] (do Monad - [macro-name' (normalize macro-name) - ?macro (find-macro macro-name')] + [name' (normalize name) + ?macro (find-macro name')] (case ?macro (#;Some macro) (do Monad [expansion (macro args) - expansion' (mapM Monad macro-expand expansion)] + expansion' (mapM Monad expand expansion)] (wrap (:: Monad join expansion'))) #;None @@ -315,35 +315,35 @@ _ (:: Monad wrap (list syntax)))) -(def: #export (macro-expand-all syntax) +(def: #export (expand-all syntax) {#;doc "Expands all macro-calls everywhere recursively, until only primitive/base code remains."} (-> Code (Lux (List Code))) (case syntax - [_ (#;Form (#;Cons [[_ (#;Symbol macro-name)] args]))] + [_ (#;Form (#;Cons [[_ (#;Symbol name)] args]))] (do Monad - [macro-name' (normalize macro-name) - ?macro (find-macro macro-name')] + [name' (normalize name) + ?macro (find-macro name')] (case ?macro (#;Some macro) (do Monad [expansion (macro args) - expansion' (mapM Monad macro-expand-all expansion)] + expansion' (mapM Monad expand-all expansion)] (wrap (:: Monad join expansion'))) #;None (do Monad - [parts' (mapM Monad macro-expand-all (list& (code;symbol macro-name) args))] + [parts' (mapM Monad expand-all (list& (code;symbol name) args))] (wrap (list (code;form (:: Monad join parts'))))))) [_ (#;Form (#;Cons [harg targs]))] (do Monad - [harg+ (macro-expand-all harg) - targs+ (mapM Monad macro-expand-all targs)] + [harg+ (expand-all harg) + targs+ (mapM Monad expand-all targs)] (wrap (list (code;form (List/append harg+ (:: Monad join (: (List (List Code)) targs+))))))) [_ (#;Tuple members)] (do Monad - [members' (mapM Monad macro-expand-all members)] + [members' (mapM Monad expand-all members)] (wrap (list (code;tuple (:: Monad join members'))))) _ @@ -391,11 +391,11 @@ _ (fail "Wrong syntax for with-gensyms"))) -(def: #export (macro-expand-1 token) - {#;doc "Works just like macro-expand, except that it ensures that the output is a single Code token."} +(def: #export (expand-1 token) + {#;doc "Works just like expand, except that it ensures that the output is a single Code token."} (-> Code (Lux Code)) (do Monad - [token+ (macro-expand token)] + [token+ (expand token)] (case token+ (^ (list token')) (wrap token') @@ -646,7 +646,7 @@ _ (fail ($_ Text/append "Wrong syntax for " "."))))] - [log-expand macro-expand "log-macro-expand"] - [log-expand-all macro-expand-all "log-macro-expand-all"] - [log-expand-once macro-expand-once "log-macro-expand-once"] + [log-expand expand "log-expand"] + [log-expand-all expand-all "log-expand-all"] + [log-expand-once expand-once "log-expand-once"] ) diff --git a/stdlib/source/lux/macro/syntax/common/reader.lux b/stdlib/source/lux/macro/syntax/common/reader.lux index 2e14825d5..84d40fb03 100644 --- a/stdlib/source/lux/macro/syntax/common/reader.lux +++ b/stdlib/source/lux/macro/syntax/common/reader.lux @@ -106,7 +106,7 @@ (do p;Monad [definition-raw s;any me-definition-raw (s;on compiler - (macro;macro-expand-all definition-raw))] + (macro;expand-all definition-raw))] (s;local me-definition-raw (s;form (do @ [_ (s;this (' lux;_lux_def)) -- cgit v1.2.3