diff options
author | Eduardo Julian | 2015-09-06 02:11:23 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-09-06 02:11:23 -0400 |
commit | 0f596a44ffc486b7e0369eebd3b79d22315e8814 (patch) | |
tree | 616c6f55fe88f27048a1964f855849955f3201e5 /source/lux.lux | |
parent | 455018ec68f2c127db489048351bc48f3982fe23 (diff) |
- Removed the (unnecessary) lux/meta/macro module.
Diffstat (limited to '')
-rw-r--r-- | source/lux.lux | 122 |
1 files changed, 78 insertions, 44 deletions
diff --git a/source/lux.lux b/source/lux.lux index 164dea835..76ca9517f 100644 --- a/source/lux.lux +++ b/source/lux.lux @@ -621,7 +621,7 @@ ))) (_lux_declare-macro def'') -(def'' (defmacro tokens) +(def'' (defmacro' tokens) Macro (_lux_case tokens (#Cons [[_ (#FormS (#Cons [name args]))] (#Cons [body #Nil])]) @@ -646,13 +646,13 @@ #Nil])])) _ - (fail "Wrong syntax for defmacro"))) -(_lux_declare-macro defmacro) + (fail "Wrong syntax for defmacro'"))) +(_lux_declare-macro defmacro') -(defmacro #export (comment tokens) +(defmacro' #export (comment tokens) (return #Nil)) -(defmacro ($' tokens) +(defmacro' ($' tokens) (_lux_case tokens (#Cons x #Nil) (return tokens) @@ -817,7 +817,7 @@ (#Cons x xs') (foldL f (f init x) xs'))) -(defmacro #export (All tokens) +(defmacro' #export (All tokens) (let'' [self-name tokens] (_lux_: (#TupleT (#Cons Text (#Cons ASTList #Nil))) (_lux_case tokens (#Cons [_ (#SymbolS "" self-name)] tokens) @@ -844,7 +844,7 @@ (fail "Wrong syntax for All")) )) -(defmacro #export (Ex tokens) +(defmacro' #export (Ex tokens) (let'' [self-name tokens] (_lux_: (#TupleT (#Cons Text (#Cons ASTList #Nil))) (_lux_case tokens (#Cons [_ (#SymbolS "" self-name)] tokens) @@ -877,7 +877,7 @@ #Nil list)) -(defmacro #export (-> tokens) +(defmacro' #export (-> tokens) (_lux_case (reverse tokens) (#Cons output inputs) (return (#Cons (foldL (_lux_: (#LambdaT AST (#LambdaT AST AST)) @@ -889,7 +889,7 @@ _ (fail "Wrong syntax for ->"))) -(defmacro (@list xs) +(defmacro' (@list xs) (return (#Cons (foldL (lambda'' [tail head] (form$ (#Cons (tag$ ["lux" "Cons"]) (#Cons (tuple$ (#Cons [head (#Cons [tail #Nil])])) @@ -898,7 +898,7 @@ (reverse xs)) #Nil))) -(defmacro (@list& xs) +(defmacro' (@list& xs) (_lux_case (reverse xs) (#Cons last init) (return (@list (foldL (lambda'' [tail head] @@ -910,7 +910,7 @@ _ (fail "Wrong syntax for @list&"))) -(defmacro #export (^ tokens) +(defmacro' #export (^ tokens) (_lux_case tokens (#Cons [_ (#SymbolS "" class-name)] #Nil) (return (@list (form$ (@list (tag$ ["lux" "DataT"]) (text$ class-name))))) @@ -918,13 +918,13 @@ _ (fail "Wrong syntax for ^"))) -(defmacro #export (, tokens) +(defmacro' #export (, tokens) (return (@list (form$ (@list (tag$ ["lux" "TupleT"]) (foldL (lambda'' [tail head] (form$ (@list (tag$ ["lux" "Cons"]) head tail))) (tag$ ["lux" "Nil"]) (reverse tokens))))))) -(defmacro (lambda' tokens) +(defmacro' (lambda' tokens) (let'' [name tokens'] (_lux_: (, Text ($' List AST)) (_lux_case tokens (#Cons [[_ (#SymbolS ["" name])] tokens']) @@ -953,7 +953,7 @@ _ (fail "Wrong syntax for lambda'")))) -(defmacro (def''' tokens) +(defmacro' (def''' tokens) (_lux_case tokens (#Cons [[_ (#TagS ["" "export"])] (#Cons [[_ (#FormS (#Cons [name args]))] @@ -1005,7 +1005,7 @@ _ #Nil)) -(defmacro (let' tokens) +(defmacro' (let' tokens) (_lux_case tokens (#Cons [[_ (#TupleS bindings)] (#Cons [body #Nil])]) (return (@list (foldL (_lux_: (-> AST (, AST AST) @@ -1064,7 +1064,7 @@ #Nil ys)) -(defmacro #export ($ tokens) +(defmacro' #export ($ tokens) (_lux_case tokens (#Cons op (#Cons init args)) (return (@list (foldL (lambda' [a1 a2] (form$ (@list op a1 a2))) @@ -1125,7 +1125,7 @@ (#Right state' a) (f a state'))))}) -(defmacro (do tokens) +(defmacro' (do tokens) (_lux_case tokens (#Cons monad (#Cons [_ (#TupleS bindings)] (#Cons body #Nil))) (let' [g!wrap (symbol$ ["" "wrap"]) @@ -1171,7 +1171,7 @@ (wrap (#Cons y ys))) ))) -(defmacro #export (if tokens) +(defmacro' #export (if tokens) (_lux_case tokens (#Cons test (#Cons then (#Cons else #Nil))) (return (@list (form$ (@list (symbol$ ["" "_lux_case"]) test @@ -1279,19 +1279,19 @@ (-> Bool Text AST ($' Lux AST)) (_lux_case (_lux_: (, Bool AST) [replace? token]) [_ [_ (#BoolS value)]] - (return (wrap-meta (form$ (@list (tag$ ["lux" "BoolS"]) (_meta (#BoolS value)))))) + (return (wrap-meta (form$ (@list (tag$ ["lux" "BoolS"]) (bool$ value))))) [_ [_ (#IntS value)]] - (return (wrap-meta (form$ (@list (tag$ ["lux" "IntS"]) (_meta (#IntS value)))))) + (return (wrap-meta (form$ (@list (tag$ ["lux" "IntS"]) (int$ value))))) [_ [_ (#RealS value)]] - (return (wrap-meta (form$ (@list (tag$ ["lux" "RealS"]) (_meta (#RealS value)))))) + (return (wrap-meta (form$ (@list (tag$ ["lux" "RealS"]) (real$ value))))) [_ [_ (#CharS value)]] - (return (wrap-meta (form$ (@list (tag$ ["lux" "CharS"]) (_meta (#CharS value)))))) + (return (wrap-meta (form$ (@list (tag$ ["lux" "CharS"]) (char$ value))))) [_ [_ (#TextS value)]] - (return (wrap-meta (form$ (@list (tag$ ["lux" "TextS"]) (_meta (#TextS value)))))) + (return (wrap-meta (form$ (@list (tag$ ["lux" "TextS"]) (text$ value))))) [_ [_ (#TagS [module name])]] (let' [module' (_lux_case module @@ -1353,31 +1353,31 @@ #Nil (#Left "Can't get the module name without a module!") - (#Cons [{#name module-name #inner-closures _ #locals _ #closure _} _]) + (#Cons {#name module-name #inner-closures _ #locals _ #closure _} _) (#Right [state module-name])))) -(defmacro #export (` tokens) +(defmacro' #export (` tokens) (_lux_case tokens (#Cons template #Nil) (do Lux/Monad [current-module get-module-name =template (untemplate true current-module template)] - (wrap (@list =template))) + (wrap (@list (form$ (@list (symbol$ ["" "_lux_:"]) (symbol$ ["lux" "AST"]) =template))))) _ (fail "Wrong syntax for `"))) -(defmacro #export (' tokens) +(defmacro' #export (' tokens) (_lux_case tokens (#Cons template #Nil) (do Lux/Monad [=template (untemplate false "" template)] - (wrap (@list =template))) + (wrap (@list (form$ (@list (symbol$ ["" "_lux_:"]) (symbol$ ["lux" "AST"]) =template))))) _ (fail "Wrong syntax for '"))) -(defmacro #export (|> tokens) +(defmacro' #export (|> tokens) (_lux_case tokens (#Cons [init apps]) (return (@list (foldL (_lux_: (-> AST AST AST) @@ -1467,7 +1467,7 @@ (#Cons [x xs']) (list:++ (f x) (join-map f xs')))) -(defmacro #export (do-template tokens) +(defmacro' #export (do-template tokens) (_lux_case tokens (#Cons [[_ (#TupleS bindings)] (#Cons [[_ (#TupleS templates)] data])]) (_lux_case (_lux_: (, ($' Maybe ($' List Text)) ($' Maybe ($' List ($' List AST)))) @@ -1688,7 +1688,7 @@ _ type)) -(defmacro #export (@type tokens) +(defmacro' #export (@type tokens) (_lux_case tokens (#Cons type #Nil) (do Lux/Monad @@ -1703,7 +1703,7 @@ _ (fail "Wrong syntax for @type"))) -(defmacro #export (: tokens) +(defmacro' #export (: tokens) (_lux_case tokens (#Cons type (#Cons value #Nil)) (return (@list (` (;_lux_: (@type (~ type)) (~ value))))) @@ -1711,7 +1711,7 @@ _ (fail "Wrong syntax for :"))) -(defmacro #export (:! tokens) +(defmacro' #export (:! tokens) (_lux_case tokens (#Cons type (#Cons value #Nil)) (return (@list (` (;_lux_:! (@type (~ type)) (~ value))))) @@ -1791,7 +1791,7 @@ #cursor cursor} (symbol$ ["" ($ text:++ "__gensym__" prefix (->text seed))])))) -(defmacro #export (Rec tokens) +(defmacro' #export (Rec tokens) (_lux_case tokens (#Cons [_ (#SymbolS "" name)] (#Cons body #Nil)) (let' [body' (replace-syntax (@list [name (` (#AppT (~ (make-bound 0)) (~ (make-bound 1))))]) body)] @@ -1800,7 +1800,7 @@ _ (fail "Wrong syntax for Rec"))) -(defmacro #export (deftype tokens) +(defmacro' #export (deftype tokens) (let' [[export? tokens'] (: (, Bool (List AST)) (_lux_case tokens (#Cons [_ (#TagS "" "export")] tokens') @@ -1872,7 +1872,7 @@ (fail "Wrong syntax for deftype")) )) -(defmacro #export (exec tokens) +(defmacro' #export (exec tokens) (_lux_case (reverse tokens) (#Cons value actions) (let' [dummy (symbol$ ["" ""])] @@ -1884,7 +1884,7 @@ _ (fail "Wrong syntax for exec"))) -(defmacro (def' tokens) +(defmacro' (def' tokens) (let' [[export? tokens'] (: (, Bool (List AST)) (_lux_case tokens (#Cons [_ (#TagS "" "export")] tokens') @@ -1979,7 +1979,7 @@ (let' [[left right] pair] (@list left right))) -(defmacro #export (case tokens) +(defmacro' #export (case tokens) (_lux_case tokens (#Cons value branches) (do Lux/Monad @@ -2007,7 +2007,7 @@ _ (fail "Wrong syntax for case"))) -(defmacro #export (\ tokens) +(defmacro' #export (\ tokens) (case tokens (#Cons body (#Cons pattern #Nil)) (do Lux/Monad @@ -2023,7 +2023,7 @@ _ (fail "Wrong syntax for \\"))) -(defmacro #export (\or tokens) +(defmacro' #export (\or tokens) (case tokens (#Cons body patterns) (case patterns @@ -2048,7 +2048,7 @@ _ false)) -(defmacro #export (let tokens) +(defmacro' #export (let tokens) (case tokens (\ (@list [_ (#TupleS bindings)] body)) (if (multiple? 2 (length bindings)) @@ -2067,7 +2067,7 @@ _ (fail "Wrong syntax for let"))) -(defmacro #export (lambda tokens) +(defmacro' #export (lambda tokens) (case (: (Maybe (, Ident AST (List AST) AST)) (case tokens (\ (@list [_ (#TupleS (#Cons head tail))] body)) @@ -2086,7 +2086,7 @@ (if (symbol? arg) (` (;_lux_lambda (~ g!blank) (~ arg) (~ body'))) (` (;_lux_lambda (~ g!blank) (~ g!blank) - (case (~ g!blank) (~ arg) (~ body'))))))) + (case (~ g!blank) (~ arg) (~ body'))))))) body (reverse tail)))] (return (@list (if (symbol? head) @@ -2096,7 +2096,7 @@ #None (fail "Wrong syntax for lambda"))) -(defmacro #export (def tokens) +(defmacro' #export (def tokens) (let [[export? tokens'] (: (, Bool (List AST)) (case tokens (#Cons [_ (#TagS "" "export")] tokens') @@ -2144,6 +2144,40 @@ #None (fail "Wrong syntax for def")))) +(defmacro' #export (defmacro tokens) + (let [[exported? tokens] (: (, Bool (List AST)) + (case tokens + (\ (@list& [_ (#TagS ["" "export"])] tokens')) + [true tokens'] + + _ + [false tokens])) + name+args+body?? (: (Maybe (, Ident (List AST) AST)) + (case tokens + (\ (@list [_ (#;FormS (@list& [_ (#SymbolS name)] args))] body)) + (#Some [name args body]) + + (\ (@list [_ (#;SymbolS name)] body)) + (#Some [name #Nil body]) + + _ + #None))] + (case name+args+body?? + (#Some [name args body]) + (let [name (symbol$ name) + decls (list:++ (: (List AST) (if exported? (@list (` (;_lux_export (~ name)))) #;Nil)) + (: (List AST) (@list (` (;;_lux_declare-macro (~ name)))))) + def-sig (: AST + (case args + #;Nil name + _ (` ((~ name) (~@ args)))))] + (return (@list& (` (;;def (~ def-sig) ;;Macro (~ body))) + decls))) + + + #None + (fail "Wrong syntax for defmacro")))) + (defmacro #export (defsig tokens) (let [[export? tokens'] (: (, Bool (List AST)) (case tokens |