From 539ad81bbb9034e41e6ca8f5445a9dd239c60be1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 3 Mar 2019 02:38:11 -0400 Subject: Macros are used for analysis and statements, so they shouldn't belong to analysis. --- .../lux/tool/compiler/default/evaluation.lux | 4 +- stdlib/source/lux/tool/compiler/default/init.lux | 4 +- .../source/lux/tool/compiler/default/platform.lux | 3 +- stdlib/source/lux/tool/compiler/phase/analysis.lux | 10 +-- .../lux/tool/compiler/phase/analysis/macro.lux | 88 --------------------- stdlib/source/lux/tool/compiler/phase/macro.lux | 90 ++++++++++++++++++++++ .../lux/tool/compiler/phase/statement/total.lux | 4 +- stdlib/source/lux/tool/compiler/program.lux | 3 +- 8 files changed, 103 insertions(+), 103 deletions(-) delete mode 100644 stdlib/source/lux/tool/compiler/phase/analysis/macro.lux create mode 100644 stdlib/source/lux/tool/compiler/phase/macro.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/tool/compiler/default/evaluation.lux b/stdlib/source/lux/tool/compiler/default/evaluation.lux index 98da861d7..3310a1fd1 100644 --- a/stdlib/source/lux/tool/compiler/default/evaluation.lux +++ b/stdlib/source/lux/tool/compiler/default/evaluation.lux @@ -8,9 +8,9 @@ format]]] [/// ["." phase + [macro (#+ Expander)] ["." analysis - ["." type] - [macro (#+ Expander)]] + ["." type]] ["." synthesis [".S" expression]] ["." translation] diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux index 465112327..41ecc851a 100644 --- a/stdlib/source/lux/tool/compiler/default/init.lux +++ b/stdlib/source/lux/tool/compiler/default/init.lux @@ -20,9 +20,9 @@ ["." analysis] ["." host] ["." phase + [macro (#+ Expander)] [".P" analysis - ["." module] - [macro (#+ Expander)]] + ["." module]] ["." synthesis [".S" expression]] ["." translation] diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index d751d2321..959478f28 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -12,8 +12,7 @@ ["." syntax] ["/." // ["." phase - [analysis - [macro (#+ Expander)]] + [macro (#+ Expander)] ["." translation] ["." statement]] ["." cli (#+ Configuration)] diff --git a/stdlib/source/lux/tool/compiler/phase/analysis.lux b/stdlib/source/lux/tool/compiler/phase/analysis.lux index e9fd18a9d..917ea1632 100644 --- a/stdlib/source/lux/tool/compiler/phase/analysis.lux +++ b/stdlib/source/lux/tool/compiler/phase/analysis.lux @@ -15,9 +15,9 @@ ["/." reference] ["/." case] ["/." function] - ["/." macro (#+ Expander)] ["." // - ["." extension] + ["//." macro (#+ Expander)] + ["//." extension] [// ["." reference] ["/" analysis (#+ Analysis Operation Phase)]]]]) @@ -90,7 +90,7 @@ (/case.case compile input branches) (^ (#.Form (list& [_ (#.Text extension-name)] extension-args))) - (extension.apply compile [extension-name extension-args]) + (//extension.apply compile [extension-name extension-args]) (^ (#.Form (list [_ (#.Tuple (list [_ (#.Identifier ["" function-name])] [_ (#.Identifier ["" arg-name])]))] @@ -104,11 +104,11 @@ (case functionA (#/.Reference (#reference.Constant def-name)) (do @ - [?macro (extension.lift (macro.find-macro def-name))] + [?macro (//extension.lift (macro.find-macro def-name))] (case ?macro (#.Some macro) (do @ - [expansion (extension.lift (/macro.expand-one expander def-name macro argsC+))] + [expansion (//extension.lift (//macro.expand-one expander def-name macro argsC+))] (compile expansion)) _ diff --git a/stdlib/source/lux/tool/compiler/phase/analysis/macro.lux b/stdlib/source/lux/tool/compiler/phase/analysis/macro.lux deleted file mode 100644 index aae26ada7..000000000 --- a/stdlib/source/lux/tool/compiler/phase/analysis/macro.lux +++ /dev/null @@ -1,88 +0,0 @@ -(.module: - [lux #* - [control - [monad (#+ do)] - ["ex" exception (#+ exception:)]] - [data - ["." error (#+ Error)] - ["." text - format] - [collection - [array (#+ Array)] - ["." list ("#/." functor)]]] - ["." macro] - ["." host (#+ import:)]] - ["." ///]) - -(exception: #export (expansion-failed {macro Name} {inputs (List Code)} {error Text}) - (ex.report ["Macro" (%name macro)] - ["Inputs" (|> inputs - (list/map (|>> %code (format text.new-line text.tab))) - (text.join-with ""))] - ["Error" error])) - -(exception: #export (must-have-single-expansion {macro Name} {inputs (List Code)}) - (ex.report ["Macro" (%name macro)] - ["Inputs" (|> inputs - (list/map (|>> %code (format text.new-line text.tab))) - (text.join-with ""))])) - -(import: #long java/lang/reflect/Method - (invoke [java/lang/Object (Array java/lang/Object)] #try java/lang/Object)) - -(import: #long (java/lang/Class c) - (getMethod [java/lang/String (Array (java/lang/Class java/lang/Object))] #try java/lang/reflect/Method)) - -(import: #long java/lang/Object - (getClass [] (java/lang/Class java/lang/Object))) - -(def: _object-class - (java/lang/Class java/lang/Object) - (host.class-for java/lang/Object)) - -(def: _apply-args - (Array (java/lang/Class java/lang/Object)) - (|> (host.array (java/lang/Class java/lang/Object) 2) - (host.array-write 0 _object-class) - (host.array-write 1 _object-class))) - -(type: #export Expander - (-> Macro (List Code) Lux (Error (Error [Lux (List Code)])))) - -(def: #export (jvm macro inputs lux) - Expander - (do error.monad - [apply-method (|> macro - (:coerce java/lang/Object) - (java/lang/Object::getClass) - (java/lang/Class::getMethod "apply" _apply-args))] - (:coerce (Error (Error [Lux (List Code)])) - (java/lang/reflect/Method::invoke - (:coerce java/lang/Object macro) - (|> (host.array java/lang/Object 2) - (host.array-write 0 (:coerce java/lang/Object inputs)) - (host.array-write 1 (:coerce java/lang/Object lux))) - apply-method)))) - -(def: #export (expand expander name macro inputs) - (-> Expander Name Macro (List Code) (Meta (List Code))) - (function (_ state) - (do error.monad - [output (expander macro inputs state)] - (case output - (#error.Success output) - (#error.Success output) - - (#error.Failure error) - ((///.throw expansion-failed [name inputs error]) state))))) - -(def: #export (expand-one expander name macro inputs) - (-> Expander Name Macro (List Code) (Meta Code)) - (do macro.monad - [expansion (expand expander name macro inputs)] - (case expansion - (^ (list single)) - (wrap single) - - _ - (///.throw must-have-single-expansion [name inputs])))) diff --git a/stdlib/source/lux/tool/compiler/phase/macro.lux b/stdlib/source/lux/tool/compiler/phase/macro.lux new file mode 100644 index 000000000..0aca19898 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/macro.lux @@ -0,0 +1,90 @@ +(.module: + [lux #* + [control + [monad (#+ do)] + ["." exception (#+ exception:)]] + [data + ["." error (#+ Error)] + ["." text + format] + [collection + [array (#+ Array)] + ["." list ("#/." functor)]]] + ["." macro] + ["." host (#+ import:)]] + ["." //]) + +(exception: #export (expansion-failed {macro Name} {inputs (List Code)} {error Text}) + (exception.report + ["Macro" (%name macro)] + ["Inputs" (|> inputs + (list/map (|>> %code (format text.new-line text.tab))) + (text.join-with ""))] + ["Error" error])) + +(exception: #export (must-have-single-expansion {macro Name} {inputs (List Code)}) + (exception.report + ["Macro" (%name macro)] + ["Inputs" (|> inputs + (list/map (|>> %code (format text.new-line text.tab))) + (text.join-with ""))])) + +(import: #long java/lang/reflect/Method + (invoke [java/lang/Object (Array java/lang/Object)] #try java/lang/Object)) + +(import: #long (java/lang/Class c) + (getMethod [java/lang/String (Array (java/lang/Class java/lang/Object))] #try java/lang/reflect/Method)) + +(import: #long java/lang/Object + (getClass [] (java/lang/Class java/lang/Object))) + +(def: _object-class + (java/lang/Class java/lang/Object) + (host.class-for java/lang/Object)) + +(def: _apply-args + (Array (java/lang/Class java/lang/Object)) + (|> (host.array (java/lang/Class java/lang/Object) 2) + (host.array-write 0 _object-class) + (host.array-write 1 _object-class))) + +(type: #export Expander + (-> Macro (List Code) Lux (Error (Error [Lux (List Code)])))) + +(def: #export (jvm macro inputs lux) + Expander + (do error.monad + [apply-method (|> macro + (:coerce java/lang/Object) + (java/lang/Object::getClass) + (java/lang/Class::getMethod "apply" _apply-args))] + (:coerce (Error (Error [Lux (List Code)])) + (java/lang/reflect/Method::invoke + (:coerce java/lang/Object macro) + (|> (host.array java/lang/Object 2) + (host.array-write 0 (:coerce java/lang/Object inputs)) + (host.array-write 1 (:coerce java/lang/Object lux))) + apply-method)))) + +(def: #export (expand expander name macro inputs) + (-> Expander Name Macro (List Code) (Meta (List Code))) + (function (_ state) + (do error.monad + [output (expander macro inputs state)] + (case output + (#error.Success output) + (#error.Success output) + + (#error.Failure error) + ((//.throw expansion-failed [name inputs error]) state))))) + +(def: #export (expand-one expander name macro inputs) + (-> Expander Name Macro (List Code) (Meta Code)) + (do macro.monad + [expansion (expand expander name macro inputs)] + (case expansion + (^ (list single)) + (wrap single) + + _ + (//.throw must-have-single-expansion [name inputs])))) diff --git a/stdlib/source/lux/tool/compiler/phase/statement/total.lux b/stdlib/source/lux/tool/compiler/phase/statement/total.lux index e1ba173ad..166425ffa 100644 --- a/stdlib/source/lux/tool/compiler/phase/statement/total.lux +++ b/stdlib/source/lux/tool/compiler/phase/statement/total.lux @@ -9,9 +9,9 @@ ["." macro]] ["." // (#+ Phase) ["/." // + ["///." macro (#+ Expander)] [".P" analysis - ["." type] - ["///." macro (#+ Expander)]] + ["." type]] ["." extension] [// ["." analysis]]]]) diff --git a/stdlib/source/lux/tool/compiler/program.lux b/stdlib/source/lux/tool/compiler/program.lux index 4194e0e8d..167f64221 100644 --- a/stdlib/source/lux/tool/compiler/program.lux +++ b/stdlib/source/lux/tool/compiler/program.lux @@ -16,8 +16,7 @@ [tool [compiler [phase - [analysis - [macro (#+ Expander)]] + [macro (#+ Expander)] ["." translation] ["." statement]] [default -- cgit v1.2.3