diff options
author | Eduardo Julian | 2017-11-15 23:40:46 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-11-15 23:40:46 -0400 |
commit | 37b94ba49afb272c63ec66e42d56b8fba35cea9f (patch) | |
tree | 85c5ad242dc2a0d4bf187094e90f779b7072ef8c /new-luxc/source/luxc/lang/macro.lux | |
parent | 190b512a822fefbb9c66271feb189cc6ccebaf85 (diff) |
- Moved "luxc/lang/host/macro" to "luxc/lang/macro".
Diffstat (limited to 'new-luxc/source/luxc/lang/macro.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/macro.lux | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/macro.lux b/new-luxc/source/luxc/lang/macro.lux new file mode 100644 index 000000000..4885e21db --- /dev/null +++ b/new-luxc/source/luxc/lang/macro.lux @@ -0,0 +1,37 @@ +(;module: + lux + (lux (control [monad #+ do]) + (data ["e" error]) + [macro] + [host]) + (luxc (lang [";L" host] + (translation [";T" common])))) + +(for {"JVM" (as-is (host;import java.lang.reflect.Method + (invoke [Object (Array Object)] #try Object)) + (host;import (java.lang.Class c) + (getMethod [String (Array (Class Object))] #try Method)) + (host;import java.lang.Object + (getClass [] (Class Object)) + (toString [] String)) + (def: _object-class (Class Object) (host;class-for Object)) + (def: _apply-args + (Array (Class Object)) + (|> (host;array (Class Object) +2) + (host;array-write +0 _object-class) + (host;array-write +1 _object-class))) + (def: #export (expand macro inputs) + (-> Macro (List Code) (Meta (List Code))) + (do macro;Monad<Meta> + [class (commonT;load-class hostL;function-class)] + (function [compiler] + (do e;Monad<Error> + [apply-method (Class.getMethod ["apply" _apply-args] class) + output (Method.invoke [(:! Object macro) + (|> (host;array Object +2) + (host;array-write +0 (:! Object inputs)) + (host;array-write +1 (:! Object compiler)))] + apply-method)] + (:! (e;Error [Compiler (List Code)]) + output)))))) + }) |